Package fife :: Package extensions :: Module loaders
[hide private]
[frames] | no frames]

Source Code for Module fife.extensions.loaders

 1  # -*- coding: utf-8 -*- 
 2  # #################################################################### 
 3  #  Copyright (C) 2005-2019 by the FIFE team 
 4  #  http://www.fifengine.net 
 5  #  This file is part of FIFE. 
 6  # 
 7  #  FIFE is free software; you can redistribute it and/or 
 8  #  modify it under the terms of the GNU Lesser General Public 
 9  #  License as published by the Free Software Foundation; either 
10  #  version 2.1 of the License, or (at your option) any later version. 
11  # 
12  #  This library is distributed in the hope that it will be useful, 
13  #  but WITHOUT ANY WARRANTY; without even the implied warranty of 
14  #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
15  #  Lesser General Public License for more details. 
16  # 
17  #  You should have received a copy of the GNU Lesser General Public 
18  #  License along with this library; if not, write to the 
19  #  Free Software Foundation, Inc., 
20  #  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA 
21  # #################################################################### 
22   
23  """ Loaders plugin manager """ 
24  from __future__ import print_function 
25   
26  import os.path 
27   
28  from fife import fife 
29  from fife.extensions.serializers.xmlmap import XMLMapLoader 
30   
31  mapFileMapping = { 'xml' : XMLMapLoader} 
32  fileExtensions = set(['xml']) 
33   
34 -def loadMapFile(path, engine, callback=None, debug=True, extensions={}):
35 """ load map file and get (an optional) callback if major stuff is done: 36 37 - map creation 38 - parsed imports 39 - parsed layers 40 - parsed cameras 41 42 the callback will send both a string and a float (which shows 43 the overall process), callback(string, float) 44 45 @type engine: object 46 @param engine: FIFE engine instance 47 @type callback: function 48 @param callback: callback for maploading progress 49 @type debug: bool 50 @param debug: flag to activate / deactivate print statements 51 @rtype object 52 @return FIFE map object 53 """ 54 (filename, extension) = os.path.splitext(path) 55 map_loader = mapFileMapping[extension[1:]](engine, callback, debug, extensions) 56 map = map_loader.loadResource(path) 57 if debug: print("--- Loading map took: ", map_loader.time_to_load, " seconds.") 58 return map
59
60 -def addMapLoader(fileExtension, loaderClass):
61 """Add a new loader for fileextension 62 @type fileExtension: string 63 @param fileExtension: The file extension the loader is registered for 64 @type loaderClass: object 65 @param loaderClass: A fife.ResourceLoader implementation that loads maps 66 from files with the given fileExtension 67 """ 68 mapFileMapping[fileExtension] = loaderClass 69 _updateMapFileExtensions()
70
71 -def _updateMapFileExtensions():
72 global fileExtensions 73 fileExtensions = set(mapFileMapping.keys())
74