Mercurial > fife-parpg
comparison engine/extensions/serializers/xmlanimation.py @ 0:4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 29 Jun 2008 18:44:17 +0000 |
parents | |
children | 9a1529f9625e |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a0efb7baf70 |
---|---|
1 import fife | |
2 from serializers import * | |
3 | |
4 class XMLAnimationLoader(fife.ResourceLoader): | |
5 def __init__(self, imagepool, vfs): | |
6 fife.ResourceLoader.__init__(self) | |
7 self.imagepool = imagepool | |
8 self.vfs = vfs | |
9 self.thisown = 0 | |
10 self.filename = '' | |
11 self.node = None | |
12 | |
13 def loadResource(self, location): | |
14 self.filename = location.getFilename() | |
15 return self.do_load_resource() | |
16 | |
17 def do_load_resource(self): | |
18 f = self.vfs.open(self.filename) | |
19 f.thisown = 1 | |
20 tree = ET.parse(f) | |
21 self.node = tree.getroot() | |
22 | |
23 animation = fife.Animation() | |
24 common_frame_delay = int(self.node.get('delay', 0)) | |
25 x_offset = int(self.node.get('x_offset', 0)) | |
26 y_offset = int(self.node.get('y_offset', 0)) | |
27 animation.setActionFrame(int(self.node.get('action', 0))) | |
28 | |
29 frames = self.node.findall('frame') | |
30 if not frames: | |
31 raise InvalidFormat('animation without <frame>s') | |
32 | |
33 for frame in frames: | |
34 source = frame.get('source') | |
35 if not source: | |
36 raise InvalidFormat('animation without <frame>s') | |
37 | |
38 frame_x_offset = int(frame.get('x_offset', x_offset)) | |
39 frame_y_offset = int(frame.get('y_offset', y_offset)) | |
40 frame_delay = int(frame.get('delay', common_frame_delay)) | |
41 | |
42 # xml paths are relative to the directory of the file they're used in. | |
43 path = self.filename.split('/') | |
44 path.pop() | |
45 path.append(str(source)) | |
46 | |
47 image = self.imagepool.getImage(self.imagepool.addResourceFromFile('/'.join(path))) | |
48 image.setXShift(frame_x_offset) | |
49 image.setYShift(frame_y_offset) | |
50 animation.addFrame(image, frame_delay); | |
51 | |
52 animation.thisown = 0 | |
53 return animation |