Mercurial > fife-parpg
comparison engine/python/fife/extensions/serializers/xmlmap.py @ 585:c2de5aafe788
- added debug flag to loaders to enable/disable annoying print spam on maploading
author | chewie@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 08 Aug 2010 15:56:19 +0000 |
parents | c9113e23b004 |
children | e3140f01749d |
comparison
equal
deleted
inserted
replaced
584:a2dde16ddc62 | 585:c2de5aafe788 |
---|---|
32 import time | 32 import time |
33 | 33 |
34 FORMAT = '1.0' | 34 FORMAT = '1.0' |
35 | 35 |
36 class XMLMapLoader(fife.ResourceLoader): | 36 class XMLMapLoader(fife.ResourceLoader): |
37 def __init__(self, engine, callback): | 37 def __init__(self, engine, callback, debug): |
38 """ The XMLMapLoader parses the xml map using several section. | 38 """ The XMLMapLoader parses the xml map using several section. |
39 Each section fires a callback (if given) which can e. g. be | 39 Each section fires a callback (if given) which can e. g. be |
40 used to show a progress bar. | 40 used to show a progress bar. |
41 | 41 |
42 The callback sends two values, a string and a float (which shows | 42 The callback sends two values, a string and a float (which shows |
43 the overall process): callback(string, float) | 43 the overall process): callback(string, float) |
44 | 44 |
45 @param engine : a pointer to fife.engine | 45 @type engine: object |
46 @param engine: a pointer to fife.engine | |
47 @type callback: function | |
46 @param callback: a callback with two arguments, optional | 48 @param callback: a callback with two arguments, optional |
49 @type debug: bool | |
50 @param debug: flag to activate / deactivate print statements | |
47 """ | 51 """ |
48 fife.ResourceLoader.__init__(self) | 52 fife.ResourceLoader.__init__(self) |
49 self.thisown = 0 | 53 self.thisown = 0 |
50 | 54 |
51 self.callback = callback | 55 self.callback = callback |
56 self.debug = debug | |
52 | 57 |
53 self.engine = engine | 58 self.engine = engine |
54 self.vfs = self.engine.getVFS() | 59 self.vfs = self.engine.getVFS() |
55 self.model = self.engine.getModel() | 60 self.model = self.engine.getModel() |
56 self.pool = self.engine.getImagePool() | 61 self.pool = self.engine.getImagePool() |
122 if dir: | 127 if dir: |
123 dir = reverse_root_subfile(self.source, dir) | 128 dir = reverse_root_subfile(self.source, dir) |
124 | 129 |
125 # Don't parse duplicate imports | 130 # Don't parse duplicate imports |
126 if (dir,file) in parsedImports: | 131 if (dir,file) in parsedImports: |
127 print "Duplicate import:" ,(dir,file) | 132 if self.debug: print "Duplicate import:" ,(dir,file) |
128 continue | 133 continue |
129 parsedImports[(dir,file)] = 1 | 134 parsedImports[(dir,file)] = 1 |
130 | 135 |
131 if file and dir: | 136 if file and dir: |
132 loaders.loadImportFile('/'.join(dir, file), self.engine) | 137 loaders.loadImportFile('/'.join(dir, file), self.engine, self.debug) |
133 elif file: | 138 elif file: |
134 loaders.loadImportFile(file, self.engine) | 139 loaders.loadImportFile(file, self.engine, self.debug) |
135 elif dir: | 140 elif dir: |
136 loaders.loadImportDirRec(dir, self.engine) | 141 loaders.loadImportDirRec(dir, self.engine, self.debug) |
137 map.importDirs.append(dir) | 142 map.importDirs.append(dir) |
138 else: | 143 else: |
139 print 'Empty import statement?' | 144 if self.debug: print 'Empty import statement?' |
140 | 145 |
141 if self.callback: | 146 if self.callback: |
142 i += 1 | 147 i += 1 |
143 self.callback('loaded imports', float( i / float(len(tmplist)) * 0.25 + 0.25 ) ) | 148 self.callback('loaded imports', float( i / float(len(tmplist)) * 0.25 + 0.25 ) ) |
144 | 149 |