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

Source Code for Module fife.extensions.savers

 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  """ Savers plugin manager  """ 
24  from __future__ import print_function 
25   
26  import os.path 
27   
28  from fife import fife 
29  from fife.extensions.serializers.xmlmapsaver import XMLMapSaver 
30   
31  mapFileMapping = { 'xml' : XMLMapSaver} 
32  fileExtensions = ('xml',) 
33   
34 -def saveMapFile(path, engine, map, importList=[], debug=True):
35 """ save map file 36 @type path: string 37 @param path: The fully qualified path to the file to save 38 @type engine: object 39 @param engine: FIFE engine instance 40 @type map: object 41 @param map: FIFE map object 42 @type importList: list 43 @param importList: A list of all imports 44 @type debug: boolean 45 @param debug: Enables debugging information 46 """ 47 (filename, extension) = os.path.splitext(path) 48 map.setFilename(path) 49 map_saver = mapFileMapping[extension[1:]](path, engine, map, importList) 50 51 map_saver.saveResource() 52 if debug: print("--- Saved Map.") 53 return map
54
55 -def addMapSaver(fileExtension, saverClass):
56 """Add a new saver for fileextension 57 @type fileExtension: string 58 @param fileExtension: The file extension the saver is registered for 59 @type saverClass: object 60 @param saverClass: A fife.ResourceLoader implementation that saves maps 61 from files with the given fileExtension 62 """ 63 mapFileMapping[fileExtension] = saverClass 64 _updateMapFileExtensions()
65
66 -def _updateMapFileExtensions():
67 global fileExtensions 68 fileExtensions = set(mapFileMapping.keys())
69