diff demos/rpg/scripts/objects/baseobject.py @ 546:8fee2d2286e9

Rewrote the object serializing routines to use a "template" idea for loading an object from disk. This allows for multiple objects to load the same base object template but be unique on the scene AND have different values. Useful for say more than one gold stack on the ground with different gold values. TODO: fix the "spawn" console command.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 03 Jun 2010 21:35:06 +0000
parents cb7ec12214a9
children e59ece21ab3e
line wrap: on
line diff
--- a/demos/rpg/scripts/objects/baseobject.py	Thu Jun 03 02:40:05 2010 +0000
+++ b/demos/rpg/scripts/objects/baseobject.py	Thu Jun 03 21:35:06 2010 +0000
@@ -67,7 +67,7 @@
 
 
 class BaseGameObject(object):
-	def __init__(self, gamecontroller, layer, typename, instancename, instanceid=None, createInstance=False):
+	def __init__(self, gamecontroller, layer, typename, baseobjectname, instancename, instanceid=None, createInstance=False):
 		"""
 		@param gamecontroller: A reference to the master game controller
 		@param instancename: The name of the object to load.  The object's XML file must
@@ -81,7 +81,9 @@
 		self._gamecontroller = gamecontroller
 		self._fifeobject = None
 		
-		self._typename = typename	
+		self._typename = typename
+		self._baseobjectname = baseobjectname
+		
 		self._name = instancename
 		if instanceid:
 			self._id = instanceid
@@ -128,23 +130,19 @@
 		curloc.setExactLayerCoordinates(self._position)
 		self.location = curloc
 		
-	def serialize(self, settings):
+	def serialize(self):
 		lvars = {}
-		lvars['posx'] = self._position.x
-		lvars['posy'] = self._position.y
-		lvars['typename'] = self._typename
-		
-		module = getModuleByType(self._type)
+		(x,y) = self.position
+		lvars['posx'] = x
+		lvars['posy'] = y
+		lvars['type'] = self._typename
+		lvars['objectname'] = self._baseobjectname
 		
-		settings.set(module, self._id, lvars)
-
-	def deserialize(self, settings):
-		module = getModuleByType(self._type)	
+		return lvars
 
-		lvars = settings.get(module, self._id, {})
-		
-		x = float(lvars['posx'])
-		y = float(lvars['posy'])
+	def deserialize(self, valuedict):	
+		x = float(valuedict['posx'])
+		y = float(valuedict['posy'])
 		
 		self.setMapPosition(x,y)