Commits

Daniel Pope  committed dabcc51 Draft

Fix: moving balloons between slots

  • Participants
  • Parent commits f70d89b

Comments (0)

Files changed (4)

File korovic/components/balloons.py

     LIFT = v(0, 20000)
     MASS = 3
     ALT_ATTENUATION = 0.00001  # how fast lift drops off with altitude
-    slot_mask = Slot.TOP
+    slot_mask = Slot.TOP | Slot.NOSE | Slot.TAIL
 
     def __init__(self, squid, attachment_point):
         super(Balloon, self).__init__(squid, attachment_point)
             bs.extend(self.tether.bodies_and_shapes())
         return bs
 
+    def attach_at_slot(self, slot):
+        super(Balloon, self).attach_at_slot(slot)
+        self.reset()
+
     def home_position(self):
         return Component.get_position(self) + v(0, 100)
 

File korovic/components/base.py

         self.sprite = pyglet.sprite.Sprite(self.image, 0, 0)
         self.body = None
 
+    def attach_at_slot(self, slot):
+        self.slot = slot
+        self.attachment_point = slot.pos
+
     def bodies_and_shapes(self):
         if self.body is None:
             return []

File korovic/components/squid.py

         self.slots[id].component = component
         self.components.append(component)
         self.components.sort(key=lambda c: bool(c.slot_mask & Slot.SIDE))
-        component.slot = self.slots[id]
-        component.attachment_point = self.slots[id].pos
+        component.attach_at_slot(self.slots[id])
 
     def attach_new(self, id, component_class):
         """Attach a new instance of component_class at id"""

File korovic/editor.py

         p = v(x, y)
         self.dragging = (p - self.component.position).length <= 70
         if self.dragging:
-            self.start_pos = self.component.position
+            self.start_pos = self.component.attachment_position()
             return EVENT_HANDLED
 
     def on_mouse_release(self, x, y, button, modifiers):
                 slots.attach(self.proposed_slot[0], self.component)
                 self.real_slot = self.component.slot
             else:
-                self.component.slot = self.real_slot
-                self.component.attachment_point = self.real_slot.pos
+                self.component.attach_at_slot(self.real_slot)
             self.proposed_slot = None
             self.display_offset = v(0, 0)
             self.dragging = False
 
         if slot is not None:
             self.proposed_slot = (slot, v(0, 0))
-            self.component.slot = slots.slots[slot]
-            self.component.attachment_point = slots.slots[slot].pos
+            self.component.attach_at_slot(slots.slots[slot])
         else:
             self.proposed_slot = None