# HG changeset patch # User prock@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1275685294 0 # Node ID e59ece21ab3eada2a7a44074ce839cadeefbc8e2 # Parent 8fee2d2286e93c751f4f8ee62dacd295c64c37bf Item serialization will now assume some default values if they are not found in the save files. The 'spawn' console command can now spawn items with default values. Cleaned up some print statements. diff -r 8fee2d2286e9 -r e59ece21ab3e demos/rpg/scripts/actors/baseactor.py --- a/demos/rpg/scripts/actors/baseactor.py Thu Jun 03 21:35:06 2010 +0000 +++ b/demos/rpg/scripts/actors/baseactor.py Fri Jun 04 21:01:34 2010 +0000 @@ -152,7 +152,21 @@ if itemtoremove: self._inventory.remove(itemtoremove) + + def serialize(self): + lvars = super(Actor, self).serialize() + + lvars['gold'] = self._gold + return lvars + + def deserialize(self, valuedict): + super(Actor, self).deserialize(valuedict) + + if valuedict.has_key("gold"): + self._gold = int(valuedict['gold']) + else: + self._gold = 0 def _getState(self): return self._state diff -r 8fee2d2286e9 -r e59ece21ab3e demos/rpg/scripts/gamecontroller.py --- a/demos/rpg/scripts/gamecontroller.py Thu Jun 03 21:35:06 2010 +0000 +++ b/demos/rpg/scripts/gamecontroller.py Fri Jun 04 21:01:34 2010 +0000 @@ -24,7 +24,7 @@ # #################################################################### # This is the rio de hola client for FIFE. -import sys, os, re, math, random, shutil, glob +import sys, os, re, math, random, shutil, glob, uuid from fife import fife @@ -218,12 +218,14 @@ cmd.append(arg) if cmd[0] == "spawn": - result = "Usage: spawn [object template] [posx] [posy]" + result = "Usage: spawn [object template] [posx] [posy] " if len(cmd) != 4: return result else: try: - obj = self._scene.loadObject(cmd[1]) + id = str(uuid.uuid1()) + valdict = { "posx" : float(cmd[2]), "posy" : float(cmd[3]) } + obj = self._scene.loadObject(cmd[1], id, valdict) except ObjectNotFoundError, e: result = "Error: Cannot load [" + cmd[1] + "]. It could not be found!" obj = None diff -r 8fee2d2286e9 -r e59ece21ab3e demos/rpg/scripts/objects/baseobject.py --- a/demos/rpg/scripts/objects/baseobject.py Thu Jun 03 21:35:06 2010 +0000 +++ b/demos/rpg/scripts/objects/baseobject.py Fri Jun 04 21:01:34 2010 +0000 @@ -102,7 +102,7 @@ if createInstance: self._createFIFEInstance(self._layer) else: - self._instance = None + self._findFIFEInstance(self._layer) self._activated = True @@ -140,9 +140,16 @@ return lvars - def deserialize(self, valuedict): - x = float(valuedict['posx']) - y = float(valuedict['posy']) + def deserialize(self, valuedict): + if valuedict.has_key("posx"): + x = float(valuedict['posx']) + else: + x = 0 + + if valuedict.has_key("posy"): + y = float(valuedict['posy']) + else: + y = 0 self.setMapPosition(x,y) @@ -187,7 +194,10 @@ return self._name def _getPosition(self): - self._position = self.location.getExactLayerCoordinates() + #if there isn't a FIFE instance just return last known coordinates + if self._instance: + self._position = self.location.getExactLayerCoordinates() + return (self._position.x, self._position.y) def _setPosition(self, tuplexy): diff -r 8fee2d2286e9 -r e59ece21ab3e demos/rpg/scripts/objects/items.py --- a/demos/rpg/scripts/objects/items.py Thu Jun 03 21:35:06 2010 +0000 +++ b/demos/rpg/scripts/objects/items.py Fri Jun 04 21:01:34 2010 +0000 @@ -75,7 +75,10 @@ def deserialize(self, valuedict): super(GoldStack, self).deserialize(valuedict) - self._value = int(valuedict['value']) + if valuedict.has_key("value"): + self._value = int(valuedict['value']) + else: + self._value = 0 def _getValue(self): return self._value @@ -101,7 +104,10 @@ def deserialize(self, valuedict): super(Portal, self).deserialize(valuedict) - self._dest = valuedict['dest'] + if valuedict.has_key("dest"): + self._dest = valuedict['dest'] + else: + self._dest = "town" def _getDest(self): return self._dest diff -r 8fee2d2286e9 -r e59ece21ab3e demos/rpg/scripts/scene.py --- a/demos/rpg/scripts/scene.py Thu Jun 03 21:35:06 2010 +0000 +++ b/demos/rpg/scripts/scene.py Fri Jun 04 21:01:34 2010 +0000 @@ -61,16 +61,12 @@ if objectid: identifier = objectid else: - #identifier = uuid.uuid1() - identifier = "blkdjfkdj" - + identifier = str(uuid.uuid1()) + try: objdict = self._modelsettings.get("objects", objectname, {}) modeldict = self._modelsettings.get("models", objdict["modelname"], {}) - print objdict - print modeldict - loadImportFile(modeldict["file"], self._gamecontroller.engine) if objdict["type"] == "GOLD":