Mercurial > fife-parpg
annotate engine/extensions/loaders.py @ 331:48c99636453e
Added Licence header to all pypthon modules in extension/
Commit 3k, Yay :-)
author | phoku@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 24 Aug 2009 12:01:34 +0000 |
parents | 54b3984e1afc |
children | dfd48d49c044 |
rev | line source |
---|---|
331
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
1 #!/usr/bin/env python |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
2 # -*- coding: utf-8 -*- |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
3 |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
4 # #################################################################### |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
5 # Copyright (C) 2005-2009 by the FIFE team |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
6 # http://www.fifengine.de |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
7 # This file is part of FIFE. |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
8 # |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
9 # FIFE is free software; you can redistribute it and/or |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
10 # modify it under the terms of the GNU Lesser General Public |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
11 # License as published by the Free Software Foundation; either |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
12 # version 2.1 of the License, or (at your option) any later version. |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
13 # |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
14 # This library is distributed in the hope that it will be useful, |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
17 # Lesser General Public License for more details. |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
18 # |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
19 # You should have received a copy of the GNU Lesser General Public |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
20 # License along with this library; if not, write to the |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
21 # Free Software Foundation, Inc., |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
23 # #################################################################### |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
24 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
25 # Loader interface for FIFE's native xml format. |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
26 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
27 import fife |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
28 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
29 from serializers.xmlmap import XMLMapLoader |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
30 from serializers import WrongFileType, NameClash |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
31 |
141
5e85737281bc
- some modification to loaders and serializers/xmlmap, now you can set a callback which informs you about finished parts of the maploading process
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
10
diff
changeset
|
32 from serializers.xmlobject import XMLObjectLoader |
5e85737281bc
- some modification to loaders and serializers/xmlmap, now you can set a callback which informs you about finished parts of the maploading process
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
10
diff
changeset
|
33 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
34 fileExtensions = ('xml',) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
35 |
141
5e85737281bc
- some modification to loaders and serializers/xmlmap, now you can set a callback which informs you about finished parts of the maploading process
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
10
diff
changeset
|
36 def loadMapFile(path, engine, callback=None): |
5e85737281bc
- some modification to loaders and serializers/xmlmap, now you can set a callback which informs you about finished parts of the maploading process
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
10
diff
changeset
|
37 """ load map file and get (an optional) callback if major stuff is done: |
5e85737281bc
- some modification to loaders and serializers/xmlmap, now you can set a callback which informs you about finished parts of the maploading process
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
10
diff
changeset
|
38 - map creation |
5e85737281bc
- some modification to loaders and serializers/xmlmap, now you can set a callback which informs you about finished parts of the maploading process
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
10
diff
changeset
|
39 - parsed imports |
5e85737281bc
- some modification to loaders and serializers/xmlmap, now you can set a callback which informs you about finished parts of the maploading process
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
10
diff
changeset
|
40 - parsed layers |
5e85737281bc
- some modification to loaders and serializers/xmlmap, now you can set a callback which informs you about finished parts of the maploading process
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
10
diff
changeset
|
41 - parsed cameras |
5e85737281bc
- some modification to loaders and serializers/xmlmap, now you can set a callback which informs you about finished parts of the maploading process
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
10
diff
changeset
|
42 the callback will send both a string and a float (which shows |
5e85737281bc
- some modification to loaders and serializers/xmlmap, now you can set a callback which informs you about finished parts of the maploading process
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
10
diff
changeset
|
43 the overall process), callback(string, float) |
5e85737281bc
- some modification to loaders and serializers/xmlmap, now you can set a callback which informs you about finished parts of the maploading process
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
10
diff
changeset
|
44 |
5e85737281bc
- some modification to loaders and serializers/xmlmap, now you can set a callback which informs you about finished parts of the maploading process
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
10
diff
changeset
|
45 @return map : map object |
5e85737281bc
- some modification to loaders and serializers/xmlmap, now you can set a callback which informs you about finished parts of the maploading process
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
10
diff
changeset
|
46 """ |
5e85737281bc
- some modification to loaders and serializers/xmlmap, now you can set a callback which informs you about finished parts of the maploading process
chewie@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
10
diff
changeset
|
47 map_loader = XMLMapLoader(engine, callback) |
145
e7a431577c95
Cleaned the basic model up. Code is cleaner now and a bit faster.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
141
diff
changeset
|
48 map = map_loader.loadResource(fife.ResourceLocation(path)) |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
145
diff
changeset
|
49 print "--- Loading map took: ", map_loader.time_to_load, " seconds." |
145
e7a431577c95
Cleaned the basic model up. Code is cleaner now and a bit faster.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
141
diff
changeset
|
50 return map |
e7a431577c95
Cleaned the basic model up. Code is cleaner now and a bit faster.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
141
diff
changeset
|
51 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
52 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
53 def loadImportFile(path, engine): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
54 object_loader = XMLObjectLoader(engine.getImagePool(), engine.getAnimationPool(), engine.getModel(), engine.getVFS()) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
55 res = None |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
56 try: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
57 res = object_loader.loadResource(fife.ResourceLocation(path)) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
58 print 'imported object file ' + path |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
59 except WrongFileType: |
10
ab09325f901e
Camera was attached to instance on a different layer, resulting in strange scrolling. Fixed it, and added a check to prevent this happening again (attach-to-other-layer fails and logs a warning).
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
60 pass |
ab09325f901e
Camera was attached to instance on a different layer, resulting in strange scrolling. Fixed it, and added a check to prevent this happening again (attach-to-other-layer fails and logs a warning).
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
61 # print 'ignored non-object file ' + path |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
62 except NameClash: |
10
ab09325f901e
Camera was attached to instance on a different layer, resulting in strange scrolling. Fixed it, and added a check to prevent this happening again (attach-to-other-layer fails and logs a warning).
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
63 pass |
ab09325f901e
Camera was attached to instance on a different layer, resulting in strange scrolling. Fixed it, and added a check to prevent this happening again (attach-to-other-layer fails and logs a warning).
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
64 # print 'ignored already loaded file ' + path |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
65 return res |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
66 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
67 def loadImportDir(path, engine): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
68 for file in filter(lambda f: f.split('.')[-1] == 'xml', engine.getVFS().listFiles(path)): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
69 loadImportFile('/'.join([path, file]), engine) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
70 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
71 def loadImportDirRec(path, engine): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
72 loadImportDir(path, engine) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
73 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
74 for dir in filter(lambda d: not d.startswith('.'), engine.getVFS().listDirectories(path)): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
75 loadImportDirRec('/'.join([path, dir]), engine) |