evennia/src/scheduler.py
Griatch 1d4f075ca7 * Updated and expanded the State system; the API changed a bit. You now have to first *create* the state using
GLOBAL_STATE_TABLE.add_state() before adding commands to it. The state can now be much more configured by including as much or as
little of the normal default commands into it as wanted (so you can now have states which are almost as normal, except some
commands are missing or change their behaviour ... illness or darkness comes to mind). The possibilities here are limitless.
* States now also optionally allow traversing exits as well as using command tables defined on objects.
* States now better handle error messages (so if you try 'look' in a state which does not contain a look command you will no
longer get the 'Huh?' but will be told that the command is not available at the moment).
* All examples in commands/examples/ have been updated to use the new State system. Also added a @test_state function for trying out
the functionality.
* Added hooks at_before_move() and at_after_move(), useful for character based move-restrictions and checks (e.g. movement speed)
* Minor tweaks to the event system; avoiding the counters to go negative should they hit an uncaught traceback.
* Small fixes of typos and minor extra safety checks.
/Griatch
2009-08-16 01:18:58 +00:00

30 lines
945 B
Python

"""
This file contains the event scheduler system.
ADDING AN EVENT:
* Create an event sub-class from the IntervalEvent class in events.py.
* Call src.scheduler.add_event() with your IntervalEvent subclass as the arg.
* Make sure that the module where your add_event() call resides is either
imported, or that add_event() is called by a command or some kind of action.
* Profit.
"""
# List of IntervalEvent sub-classed objects.
schedule = []
def add_event(event):
"""
Adds an event instance to the scheduled event list. Call this any time you
need to add a custom event to the global scheduler.
Args:
* event: (IntervalEvent) The event to add to the scheduler.
"""
#don't add multiple instances of the same event, instead replace
if event in schedule:
schedule[schedule.index(event)] = event
return
else:
schedule.append(event)
event.start_event_loop()