Mercurial > fife-parpg
comparison utils/animation_generator.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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a0efb7baf70 |
---|---|
1 #!/usr/bin/python | |
2 from util_scripts.path import path | |
3 import os, sys | |
4 | |
5 DIRNAME = 'clients/rio_de_hola/objects/items/common/crates/empty_lid/open' | |
6 DELAY = 130 | |
7 NAMESPACE = 'http://www.fifengine.de/xml/rio_de_hola' | |
8 ACTIONFRAME = -1 | |
9 X_OFFSET = 0 | |
10 Y_OFFSET = 0 | |
11 | |
12 _sep = os.path.sep | |
13 p = path(DIRNAME) | |
14 files = p.walkfiles('*.png') | |
15 | |
16 dir2anim = {} | |
17 for f in files: | |
18 curdir = _sep.join(str(f).split(_sep)[:-1]) | |
19 if not dir2anim.has_key(curdir): | |
20 dir2anim[curdir] = [] | |
21 dir2anim[curdir].append(f) | |
22 | |
23 ANIM_HEADER = '<animation delay="%d" namespace="%s" id="%s" x_offset="%d" y_offset="%d">' | |
24 ANIM_ACTION_HEADER = '<animation delay="%d" namespace="%s" id="%s" x_offset="%d" y_offset="%d" action="%d">' | |
25 ANIM_LINE = '<frame source="%s" />' | |
26 ANIM_FOOTER = '</animation>\n' | |
27 | |
28 for d in sorted(dir2anim.keys()): | |
29 anim = [] | |
30 animation_id = ':'.join(d.split(_sep)[-3:]) | |
31 if ACTIONFRAME < 0: | |
32 anim.append(ANIM_HEADER % (DELAY, NAMESPACE, animation_id, X_OFFSET, Y_OFFSET)) | |
33 else: | |
34 anim.append(ANIM_ACTION_HEADER % (DELAY, NAMESPACE, animation_id, X_OFFSET, Y_OFFSET, ACTIONFRAME)) | |
35 | |
36 for f in sorted(dir2anim[d]): | |
37 filename = f.split(_sep)[-1] | |
38 anim.append('\t' + ANIM_LINE % filename) | |
39 anim.append(ANIM_FOOTER) | |
40 | |
41 outfile = _sep.join([d, 'animation.xml']) | |
42 contents = '\n'.join(anim) | |
43 print outfile | |
44 print contents | |
45 print '' | |
46 open(outfile, 'w').write(contents) | |
47 | |
48 print "all done" |