Mercurial > fife-parpg
annotate engine/extensions/serializers/xmlmap.py @ 375:91e352f81f63
The serializers will now use the LogManager instead of printing directly to console
author | cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sat, 21 Nov 2009 15:15:55 +0000 |
parents | ab41334e8a57 |
children |
rev | line source |
---|---|
331
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
319
diff
changeset
|
1 # -*- coding: utf-8 -*- |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
319
diff
changeset
|
2 |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
319
diff
changeset
|
3 # #################################################################### |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
319
diff
changeset
|
4 # 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:
319
diff
changeset
|
5 # http://www.fifengine.de |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
319
diff
changeset
|
6 # This file is part of FIFE. |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
319
diff
changeset
|
7 # |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
319
diff
changeset
|
8 # 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:
319
diff
changeset
|
9 # 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:
319
diff
changeset
|
10 # 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:
319
diff
changeset
|
11 # 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:
319
diff
changeset
|
12 # |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
319
diff
changeset
|
13 # 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:
319
diff
changeset
|
14 # 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:
319
diff
changeset
|
15 # 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:
319
diff
changeset
|
16 # Lesser General Public License for more details. |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
319
diff
changeset
|
17 # |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
319
diff
changeset
|
18 # 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:
319
diff
changeset
|
19 # 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:
319
diff
changeset
|
20 # Free Software Foundation, Inc., |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
319
diff
changeset
|
21 # 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:
319
diff
changeset
|
22 # #################################################################### |
48c99636453e
Added Licence header to all pypthon modules in extension/
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
319
diff
changeset
|
23 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
24 import fife |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
25 try: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
26 import xml.etree.cElementTree as ET |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
27 except: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
28 import xml.etree.ElementTree as ET |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
29 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
30 import loaders |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
31 from serializers import * |
375
91e352f81f63
The serializers will now use the LogManager instead of printing directly to console
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
356
diff
changeset
|
32 from fife_utils import * |
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
|
33 import time |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
34 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
35 FORMAT = '1.0' |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
36 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
37 class XMLMapLoader(fife.ResourceLoader): |
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:
129
diff
changeset
|
38 def __init__(self, engine, callback): |
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:
129
diff
changeset
|
39 """ The XMLMapLoader parses the xml map using several section. |
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:
129
diff
changeset
|
40 Each section fires a callback (if given) which can e. g. be |
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:
129
diff
changeset
|
41 used to show a progress bar. |
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:
129
diff
changeset
|
42 |
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:
129
diff
changeset
|
43 The callback sends two values, 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:
129
diff
changeset
|
44 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:
129
diff
changeset
|
45 |
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:
129
diff
changeset
|
46 @param engine : a pointer to fife.engine |
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:
129
diff
changeset
|
47 @param callback: a callback with two arguments, optional |
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:
129
diff
changeset
|
48 """ |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
49 fife.ResourceLoader.__init__(self) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
50 self.thisown = 0 |
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:
129
diff
changeset
|
51 |
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:
129
diff
changeset
|
52 self.callback = callback |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
53 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
54 self.engine = engine |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
55 self.vfs = self.engine.getVFS() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
56 self.model = self.engine.getModel() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
57 self.pool = self.engine.getImagePool() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
58 self.anim_pool = self.engine.getAnimationPool() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
59 self.map = None |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
60 self.source = None |
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
|
61 self.time_to_load = 0 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
62 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
63 self.nspace = None |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
64 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
65 def _err(self, msg): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
66 raise SyntaxError(''.join(['File: ', self.source, ' . ', msg])) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
67 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
68 def loadResource(self, location): |
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
|
69 start_time = time.time() |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
70 self.source = location.getFilename() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
71 f = self.vfs.open(self.source) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
72 f.thisown = 1 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
73 tree = ET.parse(f) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
74 root = tree.getroot() |
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:
129
diff
changeset
|
75 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
76 map = self.parse_map(root) |
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
|
77 self.time_to_load = time.time() - start_time |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
78 return map |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
79 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
80 def parse_map(self, mapelt): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
81 if not mapelt: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
82 self._err('No <map> element found at top level of map file definition.') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
83 id,format = mapelt.get('id'),mapelt.get('format') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
84 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
85 if not format == FORMAT: self._err(''.join(['This file has format ', format, ' but this loader has format ', FORMAT])) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
86 if not id: self._err('Map declared without an identifier.') |
129
9a1529f9625e
* Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
106
diff
changeset
|
87 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
88 map = None |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
89 try: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
90 self.map = self.model.createMap(str(id)) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
91 self.map.setResourceFile(self.source) |
375
91e352f81f63
The serializers will now use the LogManager instead of printing directly to console
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
356
diff
changeset
|
92 except fife.Exception, e: |
91e352f81f63
The serializers will now use the LogManager instead of printing directly to console
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
356
diff
changeset
|
93 if is_fife_exc(fife.NameClash, e): |
91e352f81f63
The serializers will now use the LogManager instead of printing directly to console
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
356
diff
changeset
|
94 msg = e.getMessage()+" " |
91e352f81f63
The serializers will now use the LogManager instead of printing directly to console
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
356
diff
changeset
|
95 msg = msg + X+''.join(['File: ', self.source, '. The map ', str(id), ' already exists! Ignoring map definition.']) |
91e352f81f63
The serializers will now use the LogManager instead of printing directly to console
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
356
diff
changeset
|
96 logger.log(fife.LogManager.LEVEL_WARN, msg) |
91e352f81f63
The serializers will now use the LogManager instead of printing directly to console
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
356
diff
changeset
|
97 return None |
91e352f81f63
The serializers will now use the LogManager instead of printing directly to console
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
356
diff
changeset
|
98 raise |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
99 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
100 # xml-specific directory imports. This is used by xml savers. |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
101 self.map.importDirs = [] |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
102 |
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:
129
diff
changeset
|
103 if self.callback is not 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:
129
diff
changeset
|
104 self.callback('created map', float(0.25) ) |
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:
129
diff
changeset
|
105 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
106 self.parse_imports(mapelt, self.map) |
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:
129
diff
changeset
|
107 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
108 self.parse_layers(mapelt, self.map) |
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:
129
diff
changeset
|
109 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
110 self.parse_cameras(mapelt, self.map) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
111 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
112 return self.map |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
113 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
114 def parse_imports(self, mapelt, map): |
150
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
145
diff
changeset
|
115 parsedImports = {} |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
145
diff
changeset
|
116 |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
145
diff
changeset
|
117 if self.callback: |
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:
129
diff
changeset
|
118 tmplist = mapelt.findall('import') |
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:
129
diff
changeset
|
119 i = float(0) |
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:
129
diff
changeset
|
120 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
121 for item in mapelt.findall('import'): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
122 file = item.get('file') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
123 if file: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
124 file = reverse_root_subfile(self.source, file) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
125 dir = item.get('dir') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
126 if dir: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
127 dir = reverse_root_subfile(self.source, dir) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
128 |
150
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
145
diff
changeset
|
129 # Don't parse duplicate imports |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
145
diff
changeset
|
130 if (dir,file) in parsedImports: |
375
91e352f81f63
The serializers will now use the LogManager instead of printing directly to console
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
356
diff
changeset
|
131 logger.log(fife.LogManager.LEVEL_WARN, "Duplicate import:" + str((dir, file))) |
150
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
145
diff
changeset
|
132 continue |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
145
diff
changeset
|
133 parsedImports[(dir,file)] = 1 |
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
145
diff
changeset
|
134 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
135 if file and dir: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
136 loaders.loadImportFile('/'.join(dir, file), self.engine) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
137 elif file: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
138 loaders.loadImportFile(file, self.engine) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
139 elif dir: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
140 loaders.loadImportDirRec(dir, self.engine) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
141 map.importDirs.append(dir) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
142 else: |
375
91e352f81f63
The serializers will now use the LogManager instead of printing directly to console
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
356
diff
changeset
|
143 logger.log(fife.LogManager.LEVEL_WARN, 'Empty import statement?') |
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:
129
diff
changeset
|
144 |
150
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
145
diff
changeset
|
145 if self.callback: |
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:
129
diff
changeset
|
146 i += 1 |
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:
129
diff
changeset
|
147 self.callback('loaded imports', float( i / float(len(tmplist)) * 0.25 + 0.25 ) ) |
150
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
145
diff
changeset
|
148 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
149 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
150 def parse_layers(self, mapelt, map): |
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:
129
diff
changeset
|
151 if self.callback is not 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:
129
diff
changeset
|
152 tmplist = mapelt.findall('layer') |
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:
129
diff
changeset
|
153 i = float(0) |
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:
129
diff
changeset
|
154 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
155 for layer in mapelt.findall('layer'): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
156 id = layer.get('id') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
157 grid_type = layer.get('grid_type') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
158 x_scale = layer.get('x_scale') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
159 y_scale = layer.get('y_scale') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
160 rotation = layer.get('rotation') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
161 x_offset = layer.get('x_offset') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
162 y_offset = layer.get('y_offset') |
16
ca21a01f5b1e
* Fixed the xmlmap.py serializer so it correctly reads pathfinding settings from the map file.
joe_hegarty@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
163 pathing = layer.get('pathing') |
356
ab41334e8a57
Added or1andov's code with a few adjustments to fix instance transparencies fixed[t:378]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
354
diff
changeset
|
164 transparency = layer.get('transparency') |
ab41334e8a57
Added or1andov's code with a few adjustments to fix instance transparencies fixed[t:378]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
354
diff
changeset
|
165 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
166 if not x_scale: x_scale = 1.0 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
167 if not y_scale: y_scale = 1.0 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
168 if not rotation: rotation = 0.0 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
169 if not x_offset: x_offset = 0.0 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
170 if not y_offset: y_offset = 0.0 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
171 if not pathing: pathing = "cell_edges_only" |
356
ab41334e8a57
Added or1andov's code with a few adjustments to fix instance transparencies fixed[t:378]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
354
diff
changeset
|
172 if not transparency: |
ab41334e8a57
Added or1andov's code with a few adjustments to fix instance transparencies fixed[t:378]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
354
diff
changeset
|
173 transparency = 0 |
ab41334e8a57
Added or1andov's code with a few adjustments to fix instance transparencies fixed[t:378]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
354
diff
changeset
|
174 else: |
ab41334e8a57
Added or1andov's code with a few adjustments to fix instance transparencies fixed[t:378]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
354
diff
changeset
|
175 transparency = int(transparency) |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
176 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
177 if not id: self._err('<layer> declared with no id attribute.') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
178 if not grid_type: self._err(''.join(['Layer ', str(id), ' has no grid_type attribute.'])) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
179 |
33
112fc4af772d
moved grid ownership to model in similar way as with pathers
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
16
diff
changeset
|
180 cellgrid = self.model.getCellGrid(grid_type) |
112fc4af772d
moved grid ownership to model in similar way as with pathers
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
16
diff
changeset
|
181 if not cellgrid: self._err('<layer> declared with invalid cellgrid type. (%s)' % grid_type) |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
182 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
183 cellgrid.setRotation(float(rotation)) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
184 cellgrid.setXScale(float(x_scale)) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
185 cellgrid.setYScale(float(y_scale)) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
186 cellgrid.setXShift(float(x_offset)) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
187 cellgrid.setYShift(float(y_offset)) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
188 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
189 layer_obj = None |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
190 try: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
191 layer_obj = map.createLayer(str(id), cellgrid) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
192 except fife.Exception, e: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
193 print e.getMessage() |
375
91e352f81f63
The serializers will now use the LogManager instead of printing directly to console
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
356
diff
changeset
|
194 logger.log(fife.LogManager.LEVEL_WARN, 'The layer ' + str(id) + ' already exists! Ignoring this layer.') |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
195 continue |
129
9a1529f9625e
* Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
106
diff
changeset
|
196 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
197 strgy = fife.CELL_EDGES_ONLY |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
198 if pathing == "cell_edges_and_diagonals": |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
199 strgy = fife.CELL_EDGES_AND_DIAGONALS |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
200 if pathing == "freeform": |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
201 strgy = fife.FREEFORM |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
202 layer_obj.setPathingStrategy(strgy) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
203 |
356
ab41334e8a57
Added or1andov's code with a few adjustments to fix instance transparencies fixed[t:378]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
354
diff
changeset
|
204 layer_obj.setLayerTransparency(transparency) |
ab41334e8a57
Added or1andov's code with a few adjustments to fix instance transparencies fixed[t:378]
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
354
diff
changeset
|
205 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
206 self.parse_instances(layer, layer_obj) |
129
9a1529f9625e
* Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
106
diff
changeset
|
207 |
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:
129
diff
changeset
|
208 if self.callback is not 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:
129
diff
changeset
|
209 i += 1 |
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:
129
diff
changeset
|
210 self.callback('loaded layer :' + str(id), float( i / float(len(tmplist)) * 0.25 + 0.5 ) ) |
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:
129
diff
changeset
|
211 |
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:
129
diff
changeset
|
212 # cleanup |
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:
129
diff
changeset
|
213 if self.callback is not 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:
129
diff
changeset
|
214 del tmplist |
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:
129
diff
changeset
|
215 del i |
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:
129
diff
changeset
|
216 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
217 def parse_instances(self, layerelt, layer): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
218 instelt = layerelt.find('instances') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
219 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
220 instances = instelt.findall('i') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
221 instances.extend(instelt.findall('inst')) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
222 instances.extend(instelt.findall('instance')) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
223 for instance in instances: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
224 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
225 objectID = instance.get('object') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
226 if not objectID: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
227 objectID = instance.get('obj') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
228 if not objectID: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
229 objectID = instance.get('o') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
230 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
231 if not objectID: self._err('<instance> does not specify an object attribute.') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
232 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
233 nspace = instance.get('namespace') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
234 if not nspace: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
235 nspace = instance.get('ns') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
236 if not nspace: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
237 nspace = self.nspace |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
238 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
239 if not nspace: self._err('<instance> %s does not specify an object namespace, and no default is available.' % str(objectID)) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
240 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
241 self.nspace = nspace |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
242 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
243 object = self.model.getObject(str(objectID), str(nspace)) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
244 if not object: |
375
91e352f81f63
The serializers will now use the LogManager instead of printing directly to console
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
356
diff
changeset
|
245 msg = 'Object with id=' + str(objectID) + ' ns=' + str(nspace) + ' could not be found. Omitting...' |
91e352f81f63
The serializers will now use the LogManager instead of printing directly to console
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
356
diff
changeset
|
246 logger.log(fife.LogManager.LEVEL_WARN, msg) |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
247 continue |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
248 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
249 x = instance.get('x') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
250 y = instance.get('y') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
251 z = instance.get('z') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
252 stackpos = instance.get('stackpos') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
253 id = instance.get('id') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
254 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
255 if x: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
256 x = float(x) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
257 self.x = x |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
258 else: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
259 self.x = self.x + 1 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
260 x = self.x |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
261 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
262 if y: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
263 y = float(y) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
264 self.y = y |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
265 else: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
266 y = self.y |
129
9a1529f9625e
* Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
106
diff
changeset
|
267 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
268 if z: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
269 z = float(z) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
270 else: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
271 z = 0.0 |
129
9a1529f9625e
* Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
106
diff
changeset
|
272 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
273 if not id: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
274 id = '' |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
275 else: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
276 id = str(id) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
277 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
278 inst = layer.createInstance(object, fife.ExactModelCoordinate(x,y,z), str(id)) |
129
9a1529f9625e
* Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
106
diff
changeset
|
279 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
280 rotation = instance.get('r') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
281 if not rotation: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
282 rotation = instance.get('rotation') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
283 if not rotation: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
284 angles = object.get2dGfxVisual().getStaticImageAngles() |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
285 if angles: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
286 rotation = angles[0] |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
287 else: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
288 rotation = 0 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
289 else: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
290 rotation = int(rotation) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
291 inst.setRotation(rotation) |
129
9a1529f9625e
* Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
106
diff
changeset
|
292 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
293 fife.InstanceVisual.create(inst) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
294 if (stackpos): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
295 inst.get2dGfxVisual().setStackPosition(int(stackpos)) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
296 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
297 if (object.getAction('default')): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
298 target = fife.Location(layer) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
299 inst.act('default', target, True) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
300 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
301 def parse_cameras(self, mapelt, map): |
150
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
145
diff
changeset
|
302 if self.callback: |
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:
129
diff
changeset
|
303 tmplist = mapelt.findall('camera') |
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:
129
diff
changeset
|
304 i = float(0) |
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:
129
diff
changeset
|
305 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
306 for camera in mapelt.findall('camera'): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
307 id = camera.get('id') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
308 zoom = camera.get('zoom') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
309 tilt = camera.get('tilt') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
310 rotation = camera.get('rotation') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
311 ref_layer_id = camera.get('ref_layer_id') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
312 ref_cell_width = camera.get('ref_cell_width') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
313 ref_cell_height = camera.get('ref_cell_height') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
314 viewport = camera.get('viewport') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
315 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
316 if not zoom: zoom = 1 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
317 if not tilt: tilt = 0 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
318 if not rotation: rotation = 0 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
319 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
320 if not id: self._err('Camera declared without an id.') |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
321 if not ref_layer_id: self._err(''.join(['Camera ', str(id), ' declared with no reference layer.'])) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
322 if not (ref_cell_width and ref_cell_height): self._err(''.join(['Camera ', str(id), ' declared without reference cell dimensions.'])) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
323 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
324 try: |
106
1fa74d3229d5
Omission of a camera viewport in xml map files now indicates that the camera should use the full window.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
33
diff
changeset
|
325 if viewport: |
1fa74d3229d5
Omission of a camera viewport in xml map files now indicates that the camera should use the full window.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
33
diff
changeset
|
326 cam = self.engine.getView().addCamera(str(id), map.getLayer(str(ref_layer_id)),fife.Rect(*[int(c) for c in viewport.split(',')]),fife.ExactModelCoordinate(0,0,0)) |
1fa74d3229d5
Omission of a camera viewport in xml map files now indicates that the camera should use the full window.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
33
diff
changeset
|
327 else: |
1fa74d3229d5
Omission of a camera viewport in xml map files now indicates that the camera should use the full window.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
33
diff
changeset
|
328 screen = self.engine.getRenderBackend() |
1fa74d3229d5
Omission of a camera viewport in xml map files now indicates that the camera should use the full window.
jwt@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
33
diff
changeset
|
329 cam = self.engine.getView().addCamera(str(id), map.getLayer(str(ref_layer_id)),fife.Rect(0,0,screen.getScreenWidth(),screen.getScreenHeight()),fife.ExactModelCoordinate(0,0,0)) |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
330 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
331 cam.setCellImageDimensions(int(ref_cell_width), int(ref_cell_height)) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
332 cam.setRotation(float(rotation)) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
333 cam.setTilt(float(tilt)) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
334 cam.setZoom(float(zoom)) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
335 except fife.Exception, e: |
375
91e352f81f63
The serializers will now use the LogManager instead of printing directly to console
cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
356
diff
changeset
|
336 logger.log(fife.LogManager.LEVEL_WARN, "Error when parsing cameras: "+e.getMessage()) |
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:
129
diff
changeset
|
337 |
150
6e7d228def30
Lazy loading for animations.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
145
diff
changeset
|
338 if self.callback: |
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:
129
diff
changeset
|
339 i += 1 |
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:
129
diff
changeset
|
340 self.callback('loaded camera: ' + str(id), float( i / len(tmplist) * 0.25 + 0.75 ) ) |
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:
129
diff
changeset
|
341 |