Fixed list of persistent objects not being updated when things are removed from the level.

This commit is contained in:
Patrick Marsee 2019-05-24 14:06:34 -04:00
parent e81345e793
commit 1b41c46105
4 changed files with 13 additions and 5 deletions

3
.gitignore vendored
View file

@ -1,5 +1,4 @@
maps
saves
__pycache__
winsh.py
yamltest.py
gameshell.geany

View file

@ -448,7 +448,7 @@ Object can be the name of the object, or its coordinates."""
if self.level.name not in self.persist:
self.persist[self.level.name] = {}
for i in self.level.persistent:
self.persist[self.level.name][i] = self.level.getThingByName(i)
self.persist[self.level.name][i] = self.level.getThingByID(i)
preLoaded = False
if args[0] in self.persist:
@ -613,7 +613,7 @@ Object can be the name of the object, or its coordinates."""
return False
def handleTake(self, e):
self.level.removeThing(e.item.name)
self.level.removeThingByName(e.item.name)
self.playerInv[e.item.name] = e.item
return True

View file

@ -697,7 +697,7 @@ list of lists of tuples."""
self.thingNames[thing.name].append(thing.thingID)
self.things[thing.thingID] = thing
if persist:
self.persistent.append(thing.name)
self.persistent.append(thing.thingID)
return nextThing
def getThing(self, **kwargs):
@ -889,6 +889,8 @@ The closeEnough parameter will create a path that lands beside the source if nec
self.thingNames[oldName].remove(thing.thingID)
if len(self.thingNames[oldName]) == 0:
del self.thingNames[oldName]
if thing.thingID in self.persistent:
self.persistent.remove(thing.thingID)
del self.things[thing.thingID]
return thing
else:

View file

@ -212,6 +212,13 @@ If -l is given, a map legend will be printed under the map."""
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)))
ret.append("Things:\nID Name X Y")
for i in self.gameBase.level.things:
j = self.gameBase.level.things[i]
ret.append("{0:<7} {1:<31} {2:<3} {3:<3}".format(i, j.name, j.x, j.y))
ret.append("Persistent:")
for i in self.gameBase.level.persistent:
ret.append(str(i))
print('\n'.join(ret))
#heapq.heappush(self.gameBase.eventQueue, (self.gameBase.gameTime, gameevents.NoOpEvent()))
return