comparison engine/extensions/serializers/xmlobject.py @ 129:9a1529f9625e

* Indentation patch by GreyGhost
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 07 Aug 2008 15:46:46 +0000
parents 4a0efb7baf70
children 3fddb45c0304
comparison
equal deleted inserted replaced
128:6e1fd3571440 129:9a1529f9625e
26 self.node = location.node 26 self.node = location.node
27 else: 27 else:
28 isobjectfile = True 28 isobjectfile = True
29 f = self.vfs.open(self.filename) 29 f = self.vfs.open(self.filename)
30 f.thisown = 1 30 f.thisown = 1
31 31
32 obj_identifier = '<?fife type="object"?>' 32 obj_identifier = '<?fife type="object"?>'
33 try: 33 try:
34 s = f.readString(len(obj_identifier)) 34 s = f.readString(len(obj_identifier))
35 except fife.IndexOverflow: 35 except fife.IndexOverflow:
36 isobjectfile = False 36 isobjectfile = False
37 37
38 if isobjectfile and s != obj_identifier: 38 if isobjectfile and s != obj_identifier:
39 isobjectfile = False 39 isobjectfile = False
40 40
41 if not isobjectfile: 41 if not isobjectfile:
42 raise WrongFileType('Tried to open non-object file %s with XMLObjectLoader.' % self.filename) 42 raise WrongFileType('Tried to open non-object file %s with XMLObjectLoader.' % self.filename)
43 self.do_load_resource(f) 43 self.do_load_resource(f)
44 44
45 def do_load_resource(self, file): 45 def do_load_resource(self, file):
49 self.parse_object(self.node) 49 self.parse_object(self.node)
50 50
51 def parse_object(self, object): 51 def parse_object(self, object):
52 if self.node.tag != 'object': 52 if self.node.tag != 'object':
53 raise InvalidFormat('Expected <object> tag, but found <%s>.' % self.node.tag) 53 raise InvalidFormat('Expected <object> tag, but found <%s>.' % self.node.tag)
54 54
55 id = object.get('id') 55 id = object.get('id')
56 if not id: 56 if not id:
57 raise InvalidFormat('<object> declared without an id attribute.') 57 raise InvalidFormat('<object> declared without an id attribute.')
58 58
59 nspace = object.get('namespace') 59 nspace = object.get('namespace')
60 if not nspace: 60 if not nspace:
61 raise InvalidFormat('<object> %s declared without a namespace attribute.' % str(id)) 61 raise InvalidFormat('<object> %s declared without a namespace attribute.' % str(id))
62 62
63 obj = None 63 obj = None
64 parent = object.get('parent', None) 64 parent = object.get('parent', None)
65 if parent: 65 if parent:
66 query = self.metamodel.getObjects('id', str(parent)) 66 query = self.metamodel.getObjects('id', str(parent))
67 if len(query) == 0: 67 if len(query) == 0:
79 79
80 obj.setResourceLocation(self.source) 80 obj.setResourceLocation(self.source)
81 fife.ObjectVisual.create(obj) 81 fife.ObjectVisual.create(obj)
82 obj.setBlocking(bool( object.get('blocking', False) )) 82 obj.setBlocking(bool( object.get('blocking', False) ))
83 obj.setStatic(bool( object.get('static', False) )) 83 obj.setStatic(bool( object.get('static', False) ))
84 84
85 pather = object.get('pather', 'RoutePather') 85 pather = object.get('pather', 'RoutePather')
86 obj.setPather( self.model.getPather(pather) ) 86 obj.setPather( self.model.getPather(pather) )
87 87
88 self.parse_images(object, obj) 88 self.parse_images(object, obj)
89 self.parse_actions(object, obj) 89 self.parse_actions(object, obj)
108 def parse_actions(self, objelt, object): 108 def parse_actions(self, objelt, object):
109 for action in objelt.findall('action'): 109 for action in objelt.findall('action'):
110 id = action.get('id') 110 id = action.get('id')
111 if not id: 111 if not id:
112 raise InvalidFormat('<action> declared without an id attribute.') 112 raise InvalidFormat('<action> declared without an id attribute.')
113 113
114 act_obj = object.createAction(str(id)) 114 act_obj = object.createAction(str(id))
115 fife.ActionVisual.create(act_obj) 115 fife.ActionVisual.create(act_obj)
116 self.parse_animations(action, act_obj) 116 self.parse_animations(action, act_obj)
117 117
118 def parse_animations(self, actelt, action): 118 def parse_animations(self, actelt, action):
128 128
129 anim_id = self.anim_pool.addResourceFromFile('/'.join(path)) 129 anim_id = self.anim_pool.addResourceFromFile('/'.join(path))
130 animation = self.anim_pool.getAnimation(anim_id) 130 animation = self.anim_pool.getAnimation(anim_id)
131 action.get2dGfxVisual().addAnimation(int( anim.get('direction', 0) ), anim_id) 131 action.get2dGfxVisual().addAnimation(int( anim.get('direction', 0) ), anim_id)
132 action.setDuration(animation.getDuration()) 132 action.setDuration(animation.getDuration())
133