Changeset 216:023eea4ad4a5


Ignore:
Timestamp:
04/06/11 22:47:02 (12 years ago)
Author:
Simon Cross <hodgestar@…>
Branch:
default
Phase:
public
Message:

Add support for trigger world changes when entering and exiting dialog states.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/dialogue.py

    r196 r216  
    4141        next_state = state.event(my_locals)
    4242        if next_state.name in self.states:
     43            self.states[self.state].leave(my_locals)
    4344            self.state = next_state.name
     45            self.states[self.state].enter(my_locals)
    4446
    4547    def choice(self, i):
     
    9395            self.triggers.append(Trigger("""True""", auto_next, pseudo_path))
    9496
     97        on_entry = state_src.get("on_entry", None)
     98        if on_entry is not None:
     99            self.on_entry = compile(on_entry,
     100                                    "<%s>" % ":".join(base_path + ["on_entry"]),
     101                                    "exec")
     102
     103        on_exit = state_src.get("on_exit", None)
     104        if on_exit is not None:
     105            self.on_exit = compile(on_exit,
     106                                   "<%s>" % ":".join(base_path + ["on_exit"]),
     107                                   "exec")
     108
    95109    def __repr__(self):
    96110        return "<%r name=%r>" % (self.__class__.__name__, self.name)
     
    101115            if next_state is not None:
    102116                return next_state
     117
     118    def enter(self, my_locals):
     119        self.on_entry(my_locals, {}, my_locals.copy())
     120
     121    def leave(self, my_locals):
     122        self.on_exit(my_locals, {}, my_locals.copy())
    103123
    104124
Note: See TracChangeset for help on using the changeset viewer.