source: trunk/game/local_loaders/loaders.py @ 264

Revision 264, 2.2 KB checked in by Kaydeth_parpg, 10 years ago (diff)

Ticket #72: Patch by Kaydeth. The separate objects file was merged back into the main map file that FIFE parses to load each Map. The Map, Engine, and World classes were all updated to allow game object creation to happen as the map file is loaded. loaders.py and xmlmap.py were copied from the FIFE code base and made local so that we can now customize how we pass the parsed map and object information to FIFE.

Line 
1#!/usr/bin/python
2
3#   This program is free software: you can redistribute it and/or modify
4#   it under the terms of the GNU General Public License as published by
5#   the Free Software Foundation, either version 3 of the License, or
6#   (at your option) any later version.
7
8#   This program is distributed in the hope that it will be useful,
9#   but WITHOUT ANY WARRANTY; without even the implied warranty of
10#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11#   GNU General Public License for more details.
12
13#   You should have received a copy of the GNU General Public License
14#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16# Most of this code was copied from the FIFE file loaders.py
17# It is part of the local code base now so we customize what happens as
18# we read map files
19import fife
20
21from xmlmap import XMLMapLoader
22from serializers import WrongFileType, NameClash
23
24from serializers.xmlobject import XMLObjectLoader
25
26fileExtensions = ('xml',)
27
28def loadMapFile(path, engine, data, callback=None):
29    """     load map file and get (an optional) callback if major stuff is done:
30    - map creation
31    - parsed impor0ts
32    - parsed layers
33    - parsed cameras
34    the callback will send both a string and a float (which shows
35    the overall process), callback(string, float)
36   
37    Inputs:
38        path = filename for map
39        engine = FIFE engine
40        data = Engine object for PARPG data
41       
42    @return    map    : map object
43    """
44    map_loader = XMLMapLoader(engine, data, callback)
45    map = map_loader.loadResource(fife.ResourceLocation(path))
46    print "--- Loading map took: ", map_loader.time_to_load, " seconds."
47    return map
48
49def loadImportFile(path, engine):
50    object_loader = XMLObjectLoader(engine.getImagePool(), engine.getAnimationPool(), engine.getModel(), engine.getVFS())
51    res = None
52    try:
53        res = object_loader.loadResource(fife.ResourceLocation(path))
54        print 'imported object file ' + path
55    except WrongFileType:
56        pass
57#        print 'ignored non-object file ' + path
58    except NameClash:
59        pass
60#        print 'ignored already loaded file ' + path
61    return res
Note: See TracBrowser for help on using the repository browser.