Adding a new API system to Evennia. This centralizes all access of the evennia driver through a single module "ev". Importing ev one should be able to access (and also importantly, easily explore) Evennia's API much easier. This API goes a long way to "flatten" the structure so that one doesn't need to remember how to find some method in a deeply nested subdirectory.

As part of this work, I have also written full listings of all available properties on Typeclassed objects (including those inherited in various ways). Should hopefully make things easier to find.
One can of course still import things directly from src/ as before. But this is a first step towards removing the "base" objects in game/gamesrc and instead making those accessible through the core API.
This commit is contained in:
Griatch 2012-03-24 23:02:45 +01:00
parent 7a2cdd3842
commit 0d01462077
24 changed files with 519 additions and 93 deletions

View file

@ -20,9 +20,8 @@ from src.utils import logger
#
class ScriptClass(TypeClass):
"""
Base class for scripts
Base class for scripts. Don't inherit from this, inherit from Script instead.
"""
# private methods
def __eq__(self, other):
@ -253,31 +252,73 @@ class Script(ScriptClass):
the hooks called by the script machinery.
"""
## available properties
def __init__(self, dbobj):
"""
This is the base TypeClass for all Scripts. Scripts describe events, timers and states in game,
they can have a time component or describe a state that changes under certain conditions.
# key (string) - name of object
# name (string)- same as key
# aliases (list of strings) - aliases to the object. Will be saved to database as AliasDB entries but returned as strings.
# dbref (int, read-only) - unique #id-number. Also "id" can be used.
# dbobj (Object, read-only) - link to database model. dbobj.typeclass points back to this class
# typeclass (Object, read-only) - this links back to this class as an identified only. Use self.swap_typeclass() to switch.
# date_created (string) - time stamp of object creation
# permissions (list of strings) - list of permission strings
Script API:
# desc (string) - optional description of script, shown in listings
# obj (Object) - optional object that this script is connected to and acts on (set automatically by obj.scripts.add())
# interval (int) - how often script should run, in seconds. <0 turns off ticker
# start_delay (bool) - if the script should start repeating right away or wait self.interval seconds
# repeats (int) - how many times the script should repeat before stopping. 0 means infinite repeats
# persistent (bool) - if script should survive a server shutdown or not
# is_active (bool) - if script is currently running
* Available properties (only available on initiated Typeclass objects)
## Handlers
key (string) - name of object
name (string)- same as key
aliases (list of strings) - aliases to the object. Will be saved to database as AliasDB entries but returned as strings.
dbref (int, read-only) - unique #id-number. Also "id" can be used.
dbobj (Object, read-only) - link to database model. dbobj.typeclass points back to this class
typeclass (Object, read-only) - this links back to this class as an identified only. Use self.swap_typeclass() to switch.
date_created (string) - time stamp of object creation
permissions (list of strings) - list of permission strings
# locks - lock-handler: use locks.add() to add new lock strings
# db - attribute-handler: store/retrieve database attributes on this self.db.myattr=val, val=self.db.myattr
# ndb - non-persistent attribute handler: same as db but does not create a database entry when storing data
desc (string) - optional description of script, shown in listings
obj (Object) - optional object that this script is connected to and acts on (set automatically by obj.scripts.add())
interval (int) - how often script should run, in seconds. <0 turns off ticker
start_delay (bool) - if the script should start repeating right away or wait self.interval seconds
repeats (int) - how many times the script should repeat before stopping. 0 means infinite repeats
persistent (bool) - if script should survive a server shutdown or not
is_active (bool) - if script is currently running
* Handlers
locks - lock-handler: use locks.add() to add new lock strings
db - attribute-handler: store/retrieve database attributes on this self.db.myattr=val, val=self.db.myattr
ndb - non-persistent attribute handler: same as db but does not create a database entry when storing data
* Helper methods
start() - start script (this usually happens automatically at creation and obj.script.add() etc)
stop() - stop script, and delete it
pause() - put the script on hold, until unpause() is called. If script is persistent, the pause state will survive a shutdown.
unpause() - restart a previously paused script. The script will continue as if it was never paused.
time_until_next_repeat() - if a timed script (interval>0), returns time until next tick
* Hook methods
at_script_creation() - called only once, when an object of this
class is first created.
is_valid() - is called to check if the script is valid to be running
at the current time. If is_valid() returns False, the running
script is stopped and removed from the game. You can use this
to check state changes (i.e. an script tracking some combat
stats at regular intervals is only valid to run while there is
actual combat going on).
at_start() - Called every time the script is started, which for persistent
scripts is at least once every server start. Note that this is
unaffected by self.delay_start, which only delays the first call
to at_repeat().
at_repeat() - Called every self.interval seconds. It will be called immediately
upon launch unless self.delay_start is True, which will delay
the first call of this method by self.interval seconds. If
self.interval==0, this method will never be called.
at_stop() - Called as the script object is stopped and is about to be removed from
the game, e.g. because is_valid() returned False.
at_server_reload() - Called when server reloads. Can be used to save temporary
variables you want should survive a reload.
at_server_shutdown() - called at a full server shutdown.
"""
super(Script, self).__init__(dbobj)
def at_script_creation(self):
"""