Mercurial > fife-parpg
annotate engine/python/fife/extensions/loaders.py @ 664:61a5f86a0db3
* Fixed the warnings that were introduced by the light branch merge.
author | helios2000@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 08 Nov 2010 15:46:48 +0000 |
parents | e3140f01749d |
children |
rev | line source |
---|---|
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
2 # #################################################################### |
661
e3140f01749d
* Merged the light branch back into trunk.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
644
diff
changeset
|
3 # Copyright (C) 2005-2010 by the FIFE team |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
4 # http://www.fifengine.de |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
5 # This file is part of FIFE. |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
6 # |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
7 # FIFE is free software; you can redistribute it and/or |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
8 # modify it under the terms of the GNU Lesser General Public |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
9 # License as published by the Free Software Foundation; either |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
10 # version 2.1 of the License, or (at your option) any later version. |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
11 # |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
12 # This library is distributed in the hope that it will be useful, |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
15 # Lesser General Public License for more details. |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
16 # |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Lesser General Public |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
18 # License along with this library; if not, write to the |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
19 # Free Software Foundation, Inc., |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
21 # #################################################################### |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
22 |
661
e3140f01749d
* Merged the light branch back into trunk.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
644
diff
changeset
|
23 """ Loader interface for FIFE's native xml format """ |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
24 |
644
b84dbc4665b0
loaders extension can now handle multiple loaders for different filetypes. A difference between map and object files is now being made!
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
585
diff
changeset
|
25 import os.path |
b84dbc4665b0
loaders extension can now handle multiple loaders for different filetypes. A difference between map and object files is now being made!
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
585
diff
changeset
|
26 |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
27 from fife import fife |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
28 from fife.extensions.serializers.xmlmap import XMLMapLoader |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
29 |
644
b84dbc4665b0
loaders extension can now handle multiple loaders for different filetypes. A difference between map and object files is now being made!
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
585
diff
changeset
|
30 mapFileMapping = { 'xml' : XMLMapLoader} |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
31 fileExtensions = ('xml',) |
644
b84dbc4665b0
loaders extension can now handle multiple loaders for different filetypes. A difference between map and object files is now being made!
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
585
diff
changeset
|
32 mapFileExtensions = ('xml',) |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
33 |
661
e3140f01749d
* Merged the light branch back into trunk.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
644
diff
changeset
|
34 def loadMapFile(path, engine, callback=None, debug=True, extensions={}): |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
35 """ load map file and get (an optional) callback if major stuff is done: |
661
e3140f01749d
* Merged the light branch back into trunk.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
644
diff
changeset
|
36 |
e3140f01749d
* Merged the light branch back into trunk.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
644
diff
changeset
|
37 - map creation |
e3140f01749d
* Merged the light branch back into trunk.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
644
diff
changeset
|
38 - parsed imports |
e3140f01749d
* Merged the light branch back into trunk.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
644
diff
changeset
|
39 - parsed layers |
e3140f01749d
* Merged the light branch back into trunk.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
644
diff
changeset
|
40 - parsed cameras |
e3140f01749d
* Merged the light branch back into trunk.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
644
diff
changeset
|
41 |
e3140f01749d
* Merged the light branch back into trunk.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
644
diff
changeset
|
42 the callback will send both a string and a float (which shows |
e3140f01749d
* Merged the light branch back into trunk.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
644
diff
changeset
|
43 the overall process), callback(string, float) |
e3140f01749d
* Merged the light branch back into trunk.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
644
diff
changeset
|
44 |
585
c2de5aafe788
- added debug flag to loaders to enable/disable annoying print spam on maploading
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
45 @type engine: object |
c2de5aafe788
- added debug flag to loaders to enable/disable annoying print spam on maploading
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
46 @param engine: FIFE engine instance |
c2de5aafe788
- added debug flag to loaders to enable/disable annoying print spam on maploading
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
47 @type callback: function |
c2de5aafe788
- added debug flag to loaders to enable/disable annoying print spam on maploading
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
48 @param callback: callback for maploading progress |
c2de5aafe788
- added debug flag to loaders to enable/disable annoying print spam on maploading
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
49 @type debug: bool |
c2de5aafe788
- added debug flag to loaders to enable/disable annoying print spam on maploading
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
50 @param debug: flag to activate / deactivate print statements |
661
e3140f01749d
* Merged the light branch back into trunk.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
644
diff
changeset
|
51 |
585
c2de5aafe788
- added debug flag to loaders to enable/disable annoying print spam on maploading
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
52 @type map: object |
c2de5aafe788
- added debug flag to loaders to enable/disable annoying print spam on maploading
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
53 @return map: FIFE map object |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
54 """ |
644
b84dbc4665b0
loaders extension can now handle multiple loaders for different filetypes. A difference between map and object files is now being made!
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
585
diff
changeset
|
55 (filename, extension) = os.path.splitext(path) |
661
e3140f01749d
* Merged the light branch back into trunk.
helios2000@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
644
diff
changeset
|
56 map_loader = mapFileMapping[extension[1:]](engine, callback, debug, extensions) |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
57 map = map_loader.loadResource(fife.ResourceLocation(path)) |
585
c2de5aafe788
- added debug flag to loaders to enable/disable annoying print spam on maploading
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
378
diff
changeset
|
58 if debug: print "--- Loading map took: ", map_loader.time_to_load, " seconds." |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
59 return map |
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.
vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
60 |
644
b84dbc4665b0
loaders extension can now handle multiple loaders for different filetypes. A difference between map and object files is now being made!
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
585
diff
changeset
|
61 def addMapLoader(fileExtension, loaderClass): |
b84dbc4665b0
loaders extension can now handle multiple loaders for different filetypes. A difference between map and object files is now being made!
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
585
diff
changeset
|
62 """Add a new loader for fileextension |
b84dbc4665b0
loaders extension can now handle multiple loaders for different filetypes. A difference between map and object files is now being made!
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
585
diff
changeset
|
63 @type fileExtension: string |
b84dbc4665b0
loaders extension can now handle multiple loaders for different filetypes. A difference between map and object files is now being made!
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
585
diff
changeset
|
64 @param fileExtension: The file extension the loader is registered for |
b84dbc4665b0
loaders extension can now handle multiple loaders for different filetypes. A difference between map and object files is now being made!
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
585
diff
changeset
|
65 @type loaderClass: object |
b84dbc4665b0
loaders extension can now handle multiple loaders for different filetypes. A difference between map and object files is now being made!
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
585
diff
changeset
|
66 @param loaderClass: A fife.ResourceLoader implementation that loads maps |
b84dbc4665b0
loaders extension can now handle multiple loaders for different filetypes. A difference between map and object files is now being made!
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
585
diff
changeset
|
67 from files with the given fileExtension |
b84dbc4665b0
loaders extension can now handle multiple loaders for different filetypes. A difference between map and object files is now being made!
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
585
diff
changeset
|
68 """ |
b84dbc4665b0
loaders extension can now handle multiple loaders for different filetypes. A difference between map and object files is now being made!
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
585
diff
changeset
|
69 mapFileMapping[fileExtension] = loaderClass |
b84dbc4665b0
loaders extension can now handle multiple loaders for different filetypes. A difference between map and object files is now being made!
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
585
diff
changeset
|
70 _updateMapFileExtensions() |
b84dbc4665b0
loaders extension can now handle multiple loaders for different filetypes. A difference between map and object files is now being made!
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
585
diff
changeset
|
71 |
b84dbc4665b0
loaders extension can now handle multiple loaders for different filetypes. A difference between map and object files is now being made!
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
585
diff
changeset
|
72 def _updateMapFileExtensions(): |
b84dbc4665b0
loaders extension can now handle multiple loaders for different filetypes. A difference between map and object files is now being made!
nihathrael@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
585
diff
changeset
|
73 mapFileExtensions = set(mapFileMapping.keys()) |