Added conditional evaluation to dialogs. Conditionals for the NPC have been tested, for the player have not.
This commit is contained in:
parent
b332d579e9
commit
ed7fe60a6d
3 changed files with 94 additions and 46 deletions
35
gamebase.py
35
gamebase.py
|
@ -232,6 +232,23 @@ Returns (thing, x, y). "Thing" can be None."""
|
|||
else:
|
||||
raise GameError('Invalid argument to getValueFromString: {}'.format(arg))
|
||||
return val
|
||||
|
||||
def compareValues(self, operator: str, left: str, right: str):
|
||||
"""Generalized comparisons, may eventually be extended to other operators"""
|
||||
lval = self.getValueFromString(left)
|
||||
rval = self.getValueFromString(right)
|
||||
if operator == '==':
|
||||
return lval == rval
|
||||
elif operator == '!=':
|
||||
return lval != rval
|
||||
elif operator == '<=':
|
||||
return lval <= rval
|
||||
elif operator == '>=':
|
||||
return lval >= rval
|
||||
elif operator == '<':
|
||||
return lval < rval
|
||||
elif operator == '>':
|
||||
return lval > rval
|
||||
|
||||
# commands
|
||||
|
||||
|
@ -876,26 +893,12 @@ Object can be the name of the object, or its coordinates."""
|
|||
raise GameError('Incomplete If statement: if {}'.format(' '.join(args)))
|
||||
|
||||
# evaluate condition
|
||||
val = self.parseValue(args[0])
|
||||
if args[1] in ('==', '!=', '<=', '>=', '<', '>'):
|
||||
if len(args) < 4:
|
||||
raise GameError('Incomplete If statement: if {}'.format(' '.join(args)))
|
||||
val2 = self.parseValue(args[2])
|
||||
if args[1] == '==':
|
||||
ret = val == val2
|
||||
elif args[1] == '!=':
|
||||
ret = val != val2
|
||||
elif args[1] == '<=':
|
||||
ret = val <= val2
|
||||
elif args[1] == '>=':
|
||||
ret = val >= val2
|
||||
elif args[1] == '<':
|
||||
ret = val < val2
|
||||
elif args[1] == '>':
|
||||
ret = val > val2
|
||||
args = args[3:]
|
||||
ret = self.compareValues(args[1], args[0], args[2])
|
||||
else:
|
||||
ret = bool(val)
|
||||
ret = bool(self.parseValue(args[0]))
|
||||
args = args[1:]
|
||||
if inverse:
|
||||
ret = not ret
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue