Added simple scripting for yaml files.

This commit is contained in:
Patrick Marsee 2019-05-30 15:44:29 -04:00
parent 8355dccb33
commit b332d579e9
6 changed files with 506 additions and 4 deletions

View file

@ -155,6 +155,8 @@ If -l is given, a map legend will be printed under the map."""
elif thing.thingType == 'i': # item
items[len(items)+1] = (thing.name, thing.graphic[1])
rows[-1].append('I{0}'.format(len(items)))
elif thing.thingType == 'a': # entrance
rows[-1].append(' ')
elif pos[0] == 'w':
if level.wallColors[level.mapMatrix[y][x][1]] != textColor:
textColor = level.wallColors[level.mapMatrix[y][x][1]]
@ -210,6 +212,9 @@ If -l is given, a map legend will be printed under the map."""
ret.append("Event queue:")
for i in sorted(self.gameBase.eventQueue):
ret.append("{0:.<8.3}:{1:.>72}".format(i[0], str(i[1])))
ret.append("custom values:")
for i in self.gameBase.customValues:
ret.append("{0:<22}: {1}".format(i, self.gameBase.customValues[i]))
ret.append("Player name:{0:.>68}".format(self.gameBase.playerName))
ret.append("Player position:{0:.>64}".format("{0}{1}".format(self.gameBase.numberToLetter(self.gameBase.playerx), self.gameBase.playery)))
ret.append("Prev. position:{0:.>65}".format("{0}{1}".format(self.gameBase.numberToLetter(self.gameBase.prevx), self.gameBase.prevy)))
@ -230,6 +235,8 @@ If -l is given, a map legend will be printed under the map."""
def inv(self, args):
print('\n'.join([self.gameBase.playerInv[i].name for i in self.gameBase.playerInv]))
# IO calls
def container(self, inv, cont):
"""container IO"""
# Pretty print: get length of the longest inventory item's name
@ -310,6 +317,8 @@ If -l is given, a map legend will be printed under the map."""
def dialog(self, dialogObj):
if 'opener' in dialogObj:
print(_tw.fill(dialogObj['opener'], width = TERM_SIZE))
if 'script' in dialogObj:
self.gameBase.parseScript(dialogObj['script'])
while isinstance(dialogObj, dict):
if 'action' in dialogObj:
action = dialogObj['action']
@ -333,6 +342,9 @@ If -l is given, a map legend will be printed under the map."""
return int(action[4:])
elif action == 'exit':
return 0
def playercmd(self, args):
self.handleCommand(args)
def update(self):
self.gameBase.gameEventLoop()