comparison tools/animation_generator.py @ 378:64738befdf3b

bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
author vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 11 Jan 2010 23:34:52 +0000
parents
children 81641655bc38
comparison
equal deleted inserted replaced
377:fe6fb0e0ed23 378:64738befdf3b
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"