Mercurial > fife-parpg
comparison engine/python/fife/extensions/loaders.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 | c2de5aafe788 |
comparison
equal
deleted
inserted
replaced
377:fe6fb0e0ed23 | 378:64738befdf3b |
---|---|
1 # -*- coding: utf-8 -*- | |
2 | |
3 # #################################################################### | |
4 # Copyright (C) 2005-2009 by the FIFE team | |
5 # http://www.fifengine.de | |
6 # This file is part of FIFE. | |
7 # | |
8 # FIFE is free software; you can redistribute it and/or | |
9 # modify it under the terms of the GNU Lesser General Public | |
10 # License as published by the Free Software Foundation; either | |
11 # version 2.1 of the License, or (at your option) any later version. | |
12 # | |
13 # This library is distributed in the hope that it will be useful, | |
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 # Lesser General Public License for more details. | |
17 # | |
18 # You should have received a copy of the GNU Lesser General Public | |
19 # License along with this library; if not, write to the | |
20 # Free Software Foundation, Inc., | |
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
22 # #################################################################### | |
23 | |
24 # Loader interface for FIFE's native xml format. | |
25 | |
26 from fife import fife | |
27 | |
28 from fife.extensions.serializers.xmlmap import XMLMapLoader | |
29 from fife.extensions.serializers import WrongFileType, NameClash | |
30 | |
31 from fife.extensions.serializers.xmlobject import XMLObjectLoader | |
32 | |
33 fileExtensions = ('xml',) | |
34 | |
35 def loadMapFile(path, engine, callback=None): | |
36 """ load map file and get (an optional) callback if major stuff is done: | |
37 - map creation | |
38 - parsed imports | |
39 - parsed layers | |
40 - parsed cameras | |
41 the callback will send both a string and a float (which shows | |
42 the overall process), callback(string, float) | |
43 | |
44 @return map : map object | |
45 """ | |
46 map_loader = XMLMapLoader(engine, callback) | |
47 map = map_loader.loadResource(fife.ResourceLocation(path)) | |
48 print "--- Loading map took: ", map_loader.time_to_load, " seconds." | |
49 return map | |
50 | |
51 | |
52 def loadImportFile(path, engine): | |
53 object_loader = XMLObjectLoader(engine.getImagePool(), engine.getAnimationPool(), engine.getModel(), engine.getVFS()) | |
54 res = None | |
55 try: | |
56 res = object_loader.loadResource(fife.ResourceLocation(path)) | |
57 print 'imported object file ' + path | |
58 except WrongFileType: | |
59 pass | |
60 # print 'ignored non-object file ' + path | |
61 except NameClash: | |
62 pass | |
63 # print 'ignored already loaded file ' + path | |
64 return res | |
65 | |
66 def loadImportDir(path, engine): | |
67 for file in filter(lambda f: f.split('.')[-1] == 'xml', engine.getVFS().listFiles(path)): | |
68 loadImportFile('/'.join([path, file]), engine) | |
69 | |
70 def loadImportDirRec(path, engine): | |
71 loadImportDir(path, engine) | |
72 | |
73 for dir in filter(lambda d: not d.startswith('.'), engine.getVFS().listDirectories(path)): | |
74 loadImportDirRec('/'.join([path, dir]), engine) |