Add some extra handlers to make engine less likely to crash unexpectedly
This commit is contained in:
parent
377bb43e42
commit
301d3d75db
|
@ -63,35 +63,43 @@ class Handler(npyscreen.ButtonPress):
|
|||
|
||||
# TODO: Should upgrade these to use fuzzy words library! and not direct comparisons!
|
||||
if command == 'LOOK':
|
||||
if arguments[0] == 'AROUND':
|
||||
try:
|
||||
self.parent.update_log(room['look_around'])
|
||||
except KeyError:
|
||||
self.parent.update_log('There is nothing to look at?.. This might be a bug.')
|
||||
if arguments[0] == 'AT':
|
||||
try:
|
||||
# Argument[1] is the "thing" you want to look at, yaml is lowercase so we lowercase it.
|
||||
self.parent.update_log(room[arguments[1].lower()]['look_at'])
|
||||
except KeyError:
|
||||
self.parent.update_log("Not sure what you're trying to look at.")
|
||||
try:
|
||||
if arguments[0] == 'AROUND':
|
||||
try:
|
||||
self.parent.update_log(room['look_around'])
|
||||
except KeyError:
|
||||
self.parent.update_log('There is nothing to look at?.. This might be a bug.')
|
||||
if arguments[0] == 'AT':
|
||||
try:
|
||||
# Argument[1] is the "thing" you want to look at, yaml is lowercase so we lowercase it.
|
||||
self.parent.update_log(room[arguments[1].lower()]['look_at'])
|
||||
except KeyError:
|
||||
self.parent.update_log("Im not sure what you're trying to look at.")
|
||||
except IndexError:
|
||||
self.parent.parentApp.log.error('Could not handle {0}, {1}'.format(command, arguments))
|
||||
self.parent.update_log("You must specify something to look at.")
|
||||
|
||||
elif command == 'PICK':
|
||||
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
|
||||
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]))
|
||||
self.parent.update_log(room[arguments[1].lower()]['pick_up'])
|
||||
except KeyError:
|
||||
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))
|
||||
self.parent.update_log(room[long_arg.lower()]['pick_up'])
|
||||
except KeyError:
|
||||
self.parent.update_log("You cant pick that up.")
|
||||
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
|
||||
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]))
|
||||
self.parent.update_log(room[arguments[1].lower()]['pick_up'])
|
||||
except KeyError:
|
||||
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))
|
||||
self.parent.update_log(room[long_arg.lower()]['pick_up'])
|
||||
except KeyError:
|
||||
self.parent.update_log("You cant pick that up.")
|
||||
except IndexError:
|
||||
self.parent.parentApp.log.error('Could not handle {0}, {1}'.format(command, arguments))
|
||||
self.parent.update_log("You must specify something to pick up.")
|
||||
|
||||
elif command == 'OPEN':
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue