Mercurial > fife-parpg
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a0efb7baf70 |
---|---|
1 #!/usr/bin/env python | |
2 # coding: utf-8 | |
3 # Plugin for the editor. See fifedit.py. MapLoader presents a directory browser for finding and loading xml maps. | |
4 | |
5 import plugin | |
6 import filebrowser | |
7 import loaders, savers | |
8 from loaders import loadMapFile | |
9 from savers import saveMapFile | |
10 | |
11 class MapLoader(plugin.Plugin): | |
12 def __init__(self, engine): | |
13 super(MapLoader,self).__init__() | |
14 self.engine = engine | |
15 | |
16 self.filebrowser = filebrowser.FileBrowser(engine,self.loadFile, extensions = loaders.fileExtensions) | |
17 | |
18 self.menu_items = { | |
19 'Load' : self.filebrowser.showBrowser, | |
20 } | |
21 self.newMap = None | |
22 | |
23 def loadFile(self, path, filename): | |
24 content = path.split('/') | |
25 self.newMap = loadMapFile('/'.join([path, filename]), self.engine, '/'.join(content) + '/') | |
26 | |
27 class MapSaver(plugin.Plugin): | |
28 def __init__(self, engine): | |
29 super(MapSaver,self).__init__() | |
30 self.engine = engine | |
31 | |
32 self.filebrowser = filebrowser.FileBrowser(engine,self._selectFile,savefile=True, extensions = savers.fileExtensions) | |
33 | |
34 self.menu_items = { | |
35 'Save' : self.save, | |
36 'Save As' : self.filebrowser.showBrowser, | |
37 } | |
38 | |
39 self.saveRequested = False | |
40 self._location = None | |
41 self.path = '.' | |
42 | |
43 def save(self): | |
44 self.saveRequested = True | |
45 | |
46 def saveMap(self, map, importList): | |
47 curname = None | |
48 try: | |
49 curname = map.getResourceLocation().getFilename() | |
50 except RuntimeError: | |
51 pass # no name set for map yet | |
52 if self._location: | |
53 fname = '/'.join([self.path, self._location]) | |
54 saveMapFile(fname, self.engine, map, importList) | |
55 print "map saved as " + fname | |
56 self._location = None | |
57 elif curname: | |
58 saveMapFile(curname, self.engine, map, importList) | |
59 print "map saved with old name " + curname | |
60 else: | |
61 print 'MapSaver: error, no file location specified.' | |
62 | |
63 def _selectFile(self,path,filename): | |
64 self._location = filename | |
65 self.path = path | |
66 self.saveRequested = True |