Containers now work. Discovered issue with loading saved games.

This commit is contained in:
Patrick Marsee 2019-03-14 19:52:58 -04:00
parent eeab517213
commit 2719075a33
3 changed files with 94 additions and 11 deletions

View file

@ -19,6 +19,7 @@ class GameBase(object):
self.outstream = _sys.stdout
self.__useFuncs = {}
self.__gameEvents = {}
self.__IOCalls = {} # {str : function}
self.customVals = {} # for setting flags and such
self.level = None
self.persist = {} # {level : {thingName : thing}}
@ -37,7 +38,7 @@ class GameBase(object):
# function deligates
self.onLevelLoad = None # str : level name? -> None
self.onContainer = None # list : contents -> list : newContents, float : timeOpen
#self.onContainer = None # list : contents -> list : newContents, float : timeOpen
# default events and useFuncs
self.registerEvent('noop', self.handleNoOp)
@ -49,6 +50,7 @@ class GameBase(object):
self.registerEvent('drop', self.handleDrop)
self.registerUseFunc('examine', self.examine)
self.registerUseFunc('key', self.key)
self.registerUseFunc('container', self.container)
# Helper functions
@ -608,8 +610,8 @@ Object can be the name of the object, or its coordinates."""
def container(self, thing):
"""Acts as a container. Items can be traded between the container and the player's inventory."""
items = thing.customValues['items']
thing.customValues['items'], timeOpen = self.onContainer(items)
items = list(thing.customValues['items'])
self.playerInv, thing.customValues['items'], timeOpen = self.getIO('container')(self.playerInv, items)
return timeOpen
def key(self, item, thing):
@ -636,3 +638,11 @@ callable by the player."""
They should take the event as an argument, and return True if it should
always give the player a turn, False otherwise."""
self.__gameEvents[name] = func
def registerIO(self, name, func):
"""Registers a function for useFuncs and such to use."""
self.__IOCalls[name] = func
def getIO(self, name):
"""This is so derived classes can access their IOCalls."""
return self.__IOCalls[name]