Mercurial > fife-parpg
diff clients/editor/plugins/maploader.py @ 0:4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 29 Jun 2008 18:44:17 +0000 |
parents | |
children | 816b17db2bec |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/clients/editor/plugins/maploader.py Sun Jun 29 18:44:17 2008 +0000 @@ -0,0 +1,66 @@ +#!/usr/bin/env python +# coding: utf-8 +# Plugin for the editor. See fifedit.py. MapLoader presents a directory browser for finding and loading xml maps. + +import plugin +import filebrowser +import loaders, savers +from loaders import loadMapFile +from savers import saveMapFile + +class MapLoader(plugin.Plugin): + def __init__(self, engine): + super(MapLoader,self).__init__() + self.engine = engine + + self.filebrowser = filebrowser.FileBrowser(engine,self.loadFile, extensions = loaders.fileExtensions) + + self.menu_items = { + 'Load' : self.filebrowser.showBrowser, + } + self.newMap = None + + def loadFile(self, path, filename): + content = path.split('/') + self.newMap = loadMapFile('/'.join([path, filename]), self.engine, '/'.join(content) + '/') + +class MapSaver(plugin.Plugin): + def __init__(self, engine): + super(MapSaver,self).__init__() + self.engine = engine + + self.filebrowser = filebrowser.FileBrowser(engine,self._selectFile,savefile=True, extensions = savers.fileExtensions) + + self.menu_items = { + 'Save' : self.save, + 'Save As' : self.filebrowser.showBrowser, + } + + self.saveRequested = False + self._location = None + self.path = '.' + + def save(self): + self.saveRequested = True + + def saveMap(self, map, importList): + curname = None + try: + curname = map.getResourceLocation().getFilename() + except RuntimeError: + pass # no name set for map yet + if self._location: + fname = '/'.join([self.path, self._location]) + saveMapFile(fname, self.engine, map, importList) + print "map saved as " + fname + self._location = None + elif curname: + saveMapFile(curname, self.engine, map, importList) + print "map saved with old name " + curname + else: + print 'MapSaver: error, no file location specified.' + + def _selectFile(self,path,filename): + self._location = filename + self.path = path + self.saveRequested = True