Save levels
authorNeil <neil@dip.sun.ac.za>
Thu, 18 Apr 2013 12:07:10 +0000 (14:07 +0200)
committerNeil <neil@dip.sun.ac.za>
Thu, 18 Apr 2013 12:07:10 +0000 (14:07 +0200)
erdslangetjie/editor/editor.py

index 1606fd63bcd6f2d92a184ff197e6341941652716..a8737e14f9d9017ebf469c3ccd446ccc41282a92 100644 (file)
@@ -8,6 +8,7 @@ from kivy.uix.widget import Widget
 from kivy.uix.floatlayout import FloatLayout
 from kivy.graphics import Color, Rectangle
 from kivy.uix.label import Label
+from kivy.uix.popup import Popup
 from kivy.utils import platform
 from kivy.config import Config
 
@@ -110,7 +111,25 @@ class EditorWindow(FloatLayout):
         self.add_widget(save_label)
 
     def do_save(self, label, ref):
-        pass
+        try:
+            self.level_obj.validate()
+        except RuntimeError as err:
+            print err
+            popup = Popup(title='Error',
+                    content=Label(text='Level not valid: %s' % err),
+                    size_hint=(.5, .5))
+            popup.open()
+            return
+        save_data = self.level_obj.get_level_data()
+        savefile = file(filepath(self.level), 'w')
+        savefile.write(save_data)
+        savefile.write('\n')
+        savefile.close()
+        popup = Popup(title='Success',
+                content=Label(text='Level saved to %s' % self.level),
+                size_hint=(.5, .5))
+        popup.open()
+
 
     def change_tool(self, label, ref):
         self.tool = ref