Add specifying filename to editor
authorNeil <neil@dip.sun.ac.za>
Sun, 14 Apr 2013 13:48:55 +0000 (15:48 +0200)
committerNeil <neil@dip.sun.ac.za>
Sun, 14 Apr 2013 13:48:55 +0000 (15:48 +0200)
erdslangetjie/editor/editor.py

index 2d635d57d2701e599991db1833044234b547859d..ffff296f3d235c6ff6a8931363807a96b7e6a566 100644 (file)
@@ -1,4 +1,7 @@
+import sys
+import os
 import kivy
+from erdslangetjie.data import filepath, load
 
 kivy.require('1.6.0')
 
@@ -6,18 +9,41 @@ from kivy.app import App
 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__':