Changeset 439:4c60df80b91b


Ignore:
Timestamp:
09/07/13 12:30:27 (8 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Phase:
public
Rebase:
32363033343833633963613832636433323564653839316231373564656136333261633132383132
Message:

Don't allow placing points outside the level

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/area_editor.py

    r436 r439  
    7474        self._move_poly = None
    7575
     76    def _in_bounds(self, pos):
     77        if pos[0] < 0 or pos[0] >= self.x:
     78            return False
     79        if pos[1] < 0 or pos[1] >= self.y:
     80            return False
     81        return True
     82
    7683    def load(self, space):
    7784        super(EditorLevel, self).load(space)
     
    8794    def add_point(self, poly_index, pos):
    8895        self.polygons.setdefault(poly_index, [])
     96        if not self._in_bounds(pos):
     97            return False
    8998        if not self.polygons[poly_index]:
    9099            point = self.point_to_pymunk(pos)
     
    93102            add_pos = self.point_to_pymunk(pos)
    94103            self.polygons[poly_index].append(add_pos)
     104        return True
    95105
    96106    def delete_point(self, index):
     
    107117            return False
    108118        first = self.polygons[index][0]
    109         self.add_point(index, self.point_to_pygame(first))
    110         return True
     119        if self.add_point(index, self.point_to_pygame(first)):
     120            return True
     121        return False
    111122
    112123    def add_line(self, start_pos, end_pos):
     
    600611        elif self.cur_poly and ev.button == 1:
    601612            # Add a point
    602             self.level.add_point(self.cur_poly, snapped_pos)
     613            if not self.level.add_point(self.cur_poly, snapped_pos):
     614                alert("Failed to place point")
    603615        elif ev.button == 3:
    604616            self._mouse_drag = True
Note: See TracChangeset for help on using the changeset viewer.