diff tools/area_editor.py @ 535:5f7a44b0d330

Merge
author David Sharpe <decoydavid@gmail.com>
date Sat, 07 Sep 2013 21:00:56 +0200
parents 811481b20689
children 80264aee0af2
line wrap: on
line diff
--- a/tools/area_editor.py	Sat Sep 07 21:00:18 2013 +0200
+++ b/tools/area_editor.py	Sat Sep 07 21:00:56 2013 +0200
@@ -35,6 +35,7 @@
 from nagslang.yamlish import load_s
 import nagslang.enemies as ne
 import nagslang.game_object as ngo
+import nagslang.collectable as collectable
 import nagslang.puzzle as np
 
 # layout constants
@@ -200,9 +201,10 @@
         # Get the class given the classname
         modules = {
             'game_object': ngo,
+            'collectable': collectable,
             'enemies': ne,
             'puzzle': np,
-            }
+        }
         if '.' in classname:
             modname, classname = classname.split('.')
             mod = modules[modname]
@@ -388,7 +390,7 @@
         try:
             try:
                 index = int(self.poly_choice.get_text())
-            except TypeError:
+            except ValueError:
                 index = 0
             data = self.level_widget.level.polygons[index][:]
         except KeyError:
@@ -823,6 +825,9 @@
 
     def add_game_object(self):
         classes = ngo.get_editable_game_objects()
+        classes.extend(("collectable.%s" % cls_name, cls)
+                       for cls_name, cls
+                       in collectable.get_editable_game_objects())
         choose = self._make_choice_dialog(classes)
         res = choose.present()
         choice = choose.get_selection()
@@ -871,8 +876,18 @@
     def _update_pos(self, obj, new_pos):
         data = self.level.lookup[obj]
         new_coords = self.level.point_to_pymunk(new_pos)
-        data['args'][0][0] = new_coords[0]
-        data['args'][0][1] = new_coords[1]
+        args = data['args']
+        old_coords = list(args[0])
+        args[0][0] = new_coords[0]
+        args[0][1] = new_coords[1]
+        param_defs = obj.requires()[1:]  # chop off name
+        for i, (_key, key_type) in enumerate(param_defs):
+            if i > len(args):
+                break
+            if key_type == "polygon (convex)":
+                args[i] = self.level.translate_poly(
+                    args[i], old_coords, new_coords)
+                print args[i]
         self.level.reset_objs()
         self.invalidate()