Changeset 235:831e4f6b3d18


Ignore:
Timestamp:
Sep 4, 2013, 7:16:09 PM (7 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Message:

Add hints for the level editor

Location:
nagslang
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • nagslang/enemies.py

    r229 r235  
    99from nagslang.mutators import FLIP_H
    1010from nagslang.resources import resources
     11
     12
     13def get_editable_enemies():
     14    classes = []
     15    for cls_name, cls in globals().iteritems():
     16        if isinstance(cls, type) and issubclass(cls, Enemy):
     17            if hasattr(cls, 'requires'):
     18                classes.append((cls_name, cls))
     19    return classes
    1120
    1221
     
    3342    def attack(self):
    3443        raise NotImplementedError
     44
     45    @classmethod
     46    def requires(cls):
     47        return [("name", "string"), ("position", "coordinates")]
    3548
    3649
     
    113126        self.set_direction(x_step, y_step)
    114127        super(PatrollingAlien, self).animate()
     128
     129    @classmethod
     130    def requires(cls):
     131        return [("name", "string"), ("position", "coordinates"),
     132                ("end_position", "coordinates")]
  • nagslang/game_object.py

    r229 r235  
    99from nagslang.resources import resources
    1010from nagslang.events import DoorEvent
     11
     12
     13def get_editable_game_objects():
     14    classes = []
     15    for cls_name, cls in globals().iteritems():
     16        if isinstance(cls, type) and hasattr(cls, 'requires'):
     17            classes.append((cls_name, cls))
     18    return classes
    1119
    1220
     
    137145        return True
    138146
     147    @classmethod
     148    def requires(cls):
     149        """Hints for the level editor"""
     150        return [("name", "string")]
     151
    139152
    140153class FloorSwitch(GameObject):
     
    155168        )
    156169
     170    @classmethod
     171    def requires(cls):
     172        return [("name", "string"), ("position", "coordinates")]
     173
    157174
    158175class Note(GameObject):
     
    169186            render.TextOverlay(message),
    170187        )
     188
     189    @classmethod
     190    def requires(cls):
     191        return [("name", "string"), ("position", "coordinates"),
     192                ("message", "text")]
    171193
    172194
     
    187209            puzzle.StateProxyPuzzler(state_source),
    188210        )
     211
     212    @classmethod
     213    def requires(cls):
     214        return [("name", "string"), ("position", "coordinates"),
     215                ("state_source", "puzzler")]
    189216
    190217
     
    201228        )
    202229
     230    @classmethod
     231    def requires(cls):
     232        return [("name", "string"), ("position", "coordinates"),
     233                ("state_source", "puzzler")]
     234
    203235
    204236class Door(GameObject):
     
    226258        if self.puzzler.get_state():
    227259            DoorEvent.post(self.destination, self.dest_pos)
     260
     261    @classmethod
     262    def requires(cls):
     263        return [("name", "string"), ("position", "coordinates"),
     264                ("destination", "level name"), ("dest_pos", "coordinate"),
     265                ("key_state", "puzzler")]
    228266
    229267
     
    250288            return False
    251289        return True
     290
     291    @classmethod
     292    def requires(cls):
     293        return [("name", "string"), ("end1", "coordinates"),
     294                ("end2", "coordinates"), ("key_state", "puzzler")]
  • nagslang/puzzle.py

    r201 r235  
    11from nagslang.constants import COLLISION_TYPE_PLAYER
     2
     3
     4def get_editable_puzzlers():
     5    classes = []
     6    for cls_name, cls in globals().iteritems():
     7        if isinstance(cls, type) and hasattr(cls, 'requires'):
     8            classes.append((cls_name, cls))
     9    return classes
    210
    311
     
    3038        raise NotImplementedError()
    3139
     40    @classmethod
     41    def requires(cls):
     42        """Tell the level editor the arguments we require
     43
     44           Format is a list of name: type hint tuples"""
     45        return [("name", "string")]
     46
    3247
    3348class YesPuzzler(Puzzler):
     
    5873        return False
    5974
     75    @classmethod
     76    def requires(cls):
     77        return [("name", "string"), ("collision_types", "list of ints")]
     78
    6079
    6180class StateProxyPuzzler(Puzzler):
     
    6584    def get_state(self):
    6685        return self.glue.get_state_of(self._state_source)
     86
     87    @classmethod
     88    def requires(cls):
     89        return [("name", "string"), ("sources", "list of names")]
    6790
    6891
     
    7699                return False
    77100        return True
     101
     102    @classmethod
     103    def requires(cls):
     104        return [("name", "string"), ("sources", "list of names")]
Note: See TracChangeset for help on using the changeset viewer.