+import sys
+import os
import kivy
+from erdslangetjie.data import filepath, load
kivy.require('1.6.0')
from kivy.uix.widget import Widget
+
class EditorWindow(Widget):
- pass
+ def __init__(self, level):
+ if os.path.exists(filepath(level)):
+ self.level_data = load(level)
+ self.level = level
+ elif os.path.exists(filepath('levels/' + level)):
+ self.level_data = load('levels/' + level)
+ self.level = 'levels/' + level
+ else:
+ print 'Unable to find %s - treating this as a new level' % level
+ self.level_data = load('levels/blank.txt')
+ if 'levels/' in level:
+ self.level = level
+ else:
+ self.level = 'levels/' + level
+ super(EditorWindow, self).__init__()
class EditorApp(App):
+ def __init__(self, level):
+ self.level = level
+ super(EditorApp, self).__init__()
+
def build(self):
- return EditorWindow()
+ return EditorWindow(self.level)
def main():
- EditorApp().run()
+ if len(sys.argv) > 1:
+ level = sys.argv[1]
+ else:
+ level = 'level1.txt'
+ EditorApp(level).run()
if __name__ == '__main__':