comparison demos/rpg/scripts/objects/baseobject.py @ 560:69d50e751c9a

Lots of changes. - Added the Serializer class - Made exceptions a little more usable - Added actor attributes (not used yet but will be with the combat engine) - Made the quest dialogs more customizable - Many other small changes
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Wed, 23 Jun 2010 19:20:24 +0000
parents 718e154a43c8
children f85762e634c5
comparison
equal deleted inserted replaced
559:cccff9b04f57 560:69d50e751c9a
20 # You should have received a copy of the GNU Lesser General Public 20 # You should have received a copy of the GNU Lesser General Public
21 # License along with this library; if not, write to the 21 # License along with this library; if not, write to the
22 # Free Software Foundation, Inc., 22 # Free Software Foundation, Inc.,
23 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 # #################################################################### 24 # ####################################################################
25 # This is the rio de hola client for FIFE.
26 25
27 import sys, os, re, math, random, shutil 26 import sys, os, re, math, random, shutil
28 27
29 from fife import fife 28 from fife import fife
30 from fife.extensions.loaders import loadMapFile 29 from fife.extensions.loaders import loadMapFile
30
31 from scripts.misc.exceptions import *
32 from scripts.misc.serializer import Serializer
31 33
32 GameObjectTypes = { 34 GameObjectTypes = {
33 "DEFAULT": 0, 35 "DEFAULT": 0,
34 "ITEM":1, 36 "ITEM":1,
35 "QUESTGIVER":2, 37 "QUESTGIVER":2,
64 66
65 def onInstanceActionFinished(self, instance, action): 67 def onInstanceActionFinished(self, instance, action):
66 pass 68 pass
67 69
68 70
69 class BaseGameObject(object): 71 class BaseGameObject(Serializer):
70 def __init__(self, gamecontroller, layer, typename, baseobjectname, instancename, instanceid=None, createInstance=False): 72 def __init__(self, gamecontroller, layer, typename, baseobjectname, instancename, instanceid=None, createInstance=False):
71 """ 73 """
72 @param gamecontroller: A reference to the master game controller 74 @param gamecontroller: A reference to the master game controller
73 @param instancename: The name of the object to load. The object's XML file must 75 @param instancename: The name of the object to load. The object's XML file must
74 be part of the map file or added with fife.extensions.loaders.loadImportFile 76 be part of the map file or added with fife.extensions.loaders.loadImportFile
127 129
128 def spawn(self, x, y): 130 def spawn(self, x, y):
129 #This doesnt work 131 #This doesnt work
130 #self._instance.get2dGfxVisual().setVisible(True) 132 #self._instance.get2dGfxVisual().setVisible(True)
131 133
132 self._position.x = x 134 if self._instance:
133 self._position.y = y 135 self._setMapPostion(x,y)
134 self._createFIFEInstance(self, self._layer) 136 else:
137 self._position.x = x
138 self._position.y = y
139 self._createFIFEInstance(self, self._layer)
135 140
136 self._activated = True 141 self._activated = True
137 142
138 def setMapPosition(self, x, y): 143 def setMapPosition(self, x, y):
139 curloc = self.location 144 curloc = self.location
153 lvars['type'] = self._typename 158 lvars['type'] = self._typename
154 lvars['objectname'] = self._baseobjectname 159 lvars['objectname'] = self._baseobjectname
155 160
156 return lvars 161 return lvars
157 162
158 def deserialize(self, valuedict): 163 def deserialize(self, valuedict=None):
164 if not valuedict:
165 return
166
159 if valuedict.has_key("posx"): 167 if valuedict.has_key("posx"):
160 x = float(valuedict['posx']) 168 x = float(valuedict['posx'])
161 else: 169 else:
162 x = 0 170 x = 0
163 171
177 185
178 self._instance = layer.createInstance(self._fifeobject, fife.ExactModelCoordinate(self._position.x,self._position.y), self._id) 186 self._instance = layer.createInstance(self._fifeobject, fife.ExactModelCoordinate(self._position.x,self._position.y), self._id)
179 fife.InstanceVisual.create(self._instance) 187 fife.InstanceVisual.create(self._instance)
180 188
181 self._instance.thisown = 0 189 self._instance.thisown = 0
182 190
183 def _findFIFEInstance(self, layer): 191 def _findFIFEInstance(self, layer):
184 """ 192 """
185 @todo: throw InstanceNotFoundError 193 Throws InstanceNotFound if the instance was not found on the specified layer.
186 """ 194 """
187 self._instance = self._layer.getInstance(self._id) 195 self._instance = self._layer.getInstance(self._id)
188 if self._instance: 196 if self._instance:
189 self._instance.thisown = 0 197 self._instance.thisown = 0
198 else:
199 raise InstanceNotFoundError(self._id + " was not found on the layer!")
190 200
191 def _getLocation(self): 201 def _getLocation(self):
192 return self._instance.getLocation() 202 return self._instance.getLocation()
193 203
194 def _setLocation(self, loc): 204 def _setLocation(self, loc):