diff --git a/gamebase.py b/gamebase.py index 5d249d8..b30ef64 100644 --- a/gamebase.py +++ b/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): diff --git a/gamemap.py b/gamemap.py index fcb2605..cb099cc 100644 --- a/gamemap.py +++ b/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 diff --git a/gameshell.py b/gameshell.py index 4a2fd74..6f1e610 100644 --- a/gameshell.py +++ b/gameshell.py @@ -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 diff --git a/testing/testdata.yml b/testing/testdata.yml new file mode 100644 index 0000000..b15ade8 --- /dev/null +++ b/testing/testdata.yml @@ -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 +