Add in some better art handling.

This commit is contained in:
Joe S 2021-02-26 22:41:26 -05:00
parent 22017b2c42
commit ebd518dd01
2 changed files with 40 additions and 17 deletions

View File

@ -29,12 +29,16 @@ class GameNavigator(npyscreen.FormBaseNew):
self.logBox.value = res # Set the logbox to that value
def update_location(self, location):
def update_location(self, location, art=None):
"""
This may not be needed in the future, dynamic
handling of location is something the navigator should do and should inherit from player.
"""
self.artBox.footer = location
if art != None:
self.artContent.value = art
else:
self.artContent.value = self.parentApp.gamelib['menu']['graphics']['not_found']
def update_inventory(self, items):
res = ''
@ -62,7 +66,7 @@ class GameNavigator(npyscreen.FormBaseNew):
relx=inventory_width + 2,
max_width=art_width - 2,
max_height=top_division_height - 2,
value=self.parentApp.gamelib['menu']['graphics']['not_found'],
value=self.parentApp.gamelib['menu']['graphics']['start_to_continue'],
editable=False)
self.artBox.footer = 'Unknown Location'

View File

@ -11,6 +11,23 @@ class Handler(npyscreen.ButtonPress):
3: re-render the screen
"""
def localize_room(self, roomlocation):
"""
This method can re-localize the room.
"""
try:
room = parse(self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation)['room']
# If the file could not be found
except FileNotFoundError:
# Log a critical error!
self.parent.parentApp.log.critical(
'Handler could not load the current room! Is the player file corrupt or was there a typo? Path was {0}'.format(
self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation))
# Put the player in a blank room i forgot to finish
room = parse(self.parent.parentApp.mainPath / 'gamedata/world/blank_room.yaml')
return room
def whenPressed(self):
self.parent.parentApp.log.debug('Send button pressed!')
# This is the raw command from the user
@ -44,17 +61,8 @@ class Handler(npyscreen.ButtonPress):
# Localize the player
player = self.parent.parentApp.player
roomlocation = player.playerData['player']['location']
try:
room = parse(self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation)['room']
# If the file could not be found
except FileNotFoundError:
# Log a critical error!
self.parent.parentApp.log.critical('Handler could not load the current room! Is the player file corrupt or was there a typo? Path was {0}'.format(
self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation))
# Put the player in a blank room i forgot to finish
room = parse(self.parent.parentApp.mainPath / 'gamedata/world/blank_room.yaml')
room = self.localize_room(player.playerData['player']['location']) # Localize the room
# By now we should be situated in our room, and with our player.
# self.parent.parentApp.log.debug(room) # We dont need to log this, its too verbose!
@ -80,7 +88,8 @@ class Handler(npyscreen.ButtonPress):
elif command == 'PICK':
try:
if arguments[0] == 'UP':
if len(arguments) <= 2: # If there are only 2 args ex:up, item then we dont need to merge that last arg
if len(
arguments) <= 2: # If there are only 2 args ex:up, item then we dont need to merge that last arg
try:
# Argument[1] is the "thing" you want to pick up, yaml is lowercase so we lowercase it.
self.parent.parentApp.log.info('Player tried to pick up {0}'.format(arguments[1]))
@ -90,8 +99,10 @@ class Handler(npyscreen.ButtonPress):
self.parent.update_log("You cant pick that up.")
else: # if its a longer list of args, the player prolly wants to pick up an item with multiple words, like hand_axe, or log_viewer
try:
long_arg = '_'.join(arguments[1:]) # Joins whatever comes after 1 in our args with '_' between
self.parent.parentApp.log.info('Player tried to pick up long object {0}'.format(long_arg))
long_arg = '_'.join(
arguments[1:]) # Joins whatever comes after 1 in our args with '_' between
self.parent.parentApp.log.info(
'Player tried to pick up long object {0}'.format(long_arg))
self.parent.update_log(room[long_arg.lower()]['pick_up'])
player.add_inventory(room[long_arg.lower()]['item_name'])
except KeyError:
@ -107,6 +118,8 @@ class Handler(npyscreen.ButtonPress):
self.parent.parentApp.log.debug('New room is: {0}'.format(new_room))
upon_enter = player.change_room(new_room) # Change the player to that new room.
self.parent.update_log(upon_enter) # Print the new room upon enter text.
room = self.localize_room(player.playerData['player']['location']) # Re-Localize!
except KeyError:
self.parent.update_log("You cant open that.")
except IndexError:
@ -115,12 +128,16 @@ class Handler(npyscreen.ButtonPress):
elif command == 'INSPECT':
try:
self.parent.parentApp.log.info('Player inspecting: {0}'.format(arguments[0]))
self.parent.update_log(room[arguments[0].lower()]['inspect']) # Prints the inspect text, if it exists
self.parent.update_log(
room[arguments[0].lower()]['inspect']) # Prints the inspect text, if it exists
except KeyError:
self.parent.update_log("Nothing more to inspect here.")
except IndexError:
self.parent.update_log("You must specify something to inspect.")
elif command == 'START':
self.parent.update_log('Welcome to the game! Try to |LOOK AROUND|.')
else:
self.parent.parentApp.log.info('Player\'s command was not understood: {0}'.format(command))
self.parent.update_log('I didn\'t understand {0}'.format(command))
@ -137,7 +154,9 @@ class Handler(npyscreen.ButtonPress):
need to, change the text at the bottom and update the inventory.
"""
try:
self.parent.update_location(room['name'])
self.parent.update_location(
room['name'],
room['art'])
except KeyError:
self.parent.update_location('Unknown Location')