Fixed instant crash in last commit by adding valid testdata.yml, and fixed testdata.yml parsing.
This commit is contained in:
parent
9cda61a895
commit
aba0014e27
4 changed files with 39 additions and 14 deletions
17
gamebase.py
17
gamebase.py
|
@ -555,23 +555,28 @@ Object can be the name of the object, or its coordinates."""
|
|||
data = None
|
||||
with open(dataFile, 'r') as f:
|
||||
data = yaml.load(f)
|
||||
# In this context, 'singleton' means a 'thing' that can be accessed by
|
||||
# any map. This is useful for when you have major characters who will
|
||||
# show up in many scenes, and their inventory must stay the same, for
|
||||
# example.
|
||||
if 'singletons' in data:
|
||||
for datum in data['singletons']:
|
||||
thing = data['singletons'][datum]
|
||||
for thing in data['singletons']:
|
||||
#thing = data['singletons'][datum]
|
||||
if not isinstance(thing, _gt.Thing):
|
||||
print("Non-thing in singletons, ignoring.\n", _sys.stderr)
|
||||
continue
|
||||
thing.thingID = self.nextThing
|
||||
self.nextThing += 1
|
||||
if thing.thingType in 'iun':
|
||||
nextThing = self.addThingRecursive(thing.customValues, nextThing)
|
||||
self.nextThing = _gm.GameMap.addThingRecursive(thing.customValues, self.nextThing)
|
||||
if thing.thingType == 'n':
|
||||
for i in thing.tempInventory:
|
||||
if i.thingID == -1:
|
||||
i.thingID = nextThing
|
||||
nextThing = self.addThingRecursive(i.customValues, nextThing + 1)
|
||||
i.thingID = self.nextThing
|
||||
self.nextThing = _gm.GameMap.addThingRecursive(i.customValues, self.nextThing + 1)
|
||||
thing.addThing(i)
|
||||
del thing.tempInventory
|
||||
self.singletons = dict(data[singletons])
|
||||
self.singletons = list(data['singletons'])
|
||||
return data
|
||||
|
||||
def gameEventLoop(self):
|
||||
|
|
13
gamemap.py
13
gamemap.py
|
@ -220,12 +220,12 @@ list of lists of tuples."""
|
|||
# Some things, like containers, have other things as custom values,
|
||||
# so they need IDs as well.
|
||||
if thing.thingType in 'iun':
|
||||
nextThing = self.addThingRecursive(thing.customValues, nextThing)
|
||||
nextThing = GameMap.addThingRecursive(thing.customValues, nextThing)
|
||||
if thing.thingType == 'n':
|
||||
for i in thing.tempInventory:
|
||||
if i.thingID == -1:
|
||||
i.thingID = nextThing
|
||||
nextThing = self.addThingRecursive(i.customValues, nextThing + 1)
|
||||
nextThing = GameMap.addThingRecursive(i.customValues, nextThing + 1)
|
||||
thing.addThing(i)
|
||||
del thing.tempInventory
|
||||
pos = self.coordsToInt(thing.x, thing.y)
|
||||
|
@ -242,21 +242,22 @@ list of lists of tuples."""
|
|||
self.persistent.append(thing.thingID)
|
||||
return nextThing
|
||||
|
||||
def addThingRecursive(self, container, nextThing = 0):
|
||||
@staticmethod
|
||||
def addThingRecursive(container, nextThing = 0):
|
||||
if isinstance(container, _gt.Thing):
|
||||
if container.thingID == -1:
|
||||
container.thingID = nextThing
|
||||
nextThing = self.addThingRecursive(container.customValues, nextThing)
|
||||
nextThing = GameMap.addThingRecursive(container.customValues, nextThing)
|
||||
return nextThing + 1
|
||||
else:
|
||||
return nextThing
|
||||
elif isinstance(container, dict):
|
||||
for i in container:
|
||||
nextThing = self.addThingRecursive(container[i], nextThing)
|
||||
nextThing = GameMap.addThingRecursive(container[i], nextThing)
|
||||
return nextThing
|
||||
elif isinstance(container, list):
|
||||
for i in container:
|
||||
nextThing = self.addThingRecursive(i, nextThing)
|
||||
nextThing = GameMap.addThingRecursive(i, nextThing)
|
||||
return nextThing
|
||||
else:
|
||||
return nextThing
|
||||
|
|
|
@ -34,10 +34,10 @@ class GameShell(Shell):
|
|||
self.gameTitle = data['title']
|
||||
self.startLevel = 'testing/test1.yml' # should be changed for actual games
|
||||
if 'startLevel' in data:
|
||||
self.gameTitle = data['startLevel']
|
||||
self.startLevel = data['startLevel']
|
||||
self.openingText = '{}\nIn Development'
|
||||
if 'openingText' in data:
|
||||
self.gameTitle = data['openingText']
|
||||
self.openingText = data['openingText']
|
||||
self.ps2 = '?> '
|
||||
self.__inGame = False
|
||||
|
||||
|
|
19
testing/testdata.yml
Normal file
19
testing/testdata.yml
Normal file
|
@ -0,0 +1,19 @@
|
|||
%YAML 1.2
|
||||
---
|
||||
title: Sample Text
|
||||
openingText: "{}\nsample text"
|
||||
startLevel: testing/test1.yml
|
||||
singletons:
|
||||
- !NPC
|
||||
name: follower
|
||||
description: a follower
|
||||
location: [0, 0]
|
||||
behaviors:
|
||||
go: [-1, follow]
|
||||
arrive: [-1, follow]
|
||||
customValues:
|
||||
follow:
|
||||
distance: 2
|
||||
isFollowing: True
|
||||
target: You
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue