Continuing work on API, making local-use class properties _private to make things easier to explore.

This commit is contained in:
Griatch 2012-03-31 13:06:29 +02:00
parent 1ce5c6b84a
commit fc156b5a54
5 changed files with 308 additions and 328 deletions

View file

@ -11,7 +11,7 @@ handled by Scripts.
Scripts have to check for themselves that they should be applied at a
particular moment of time; this is handled by the is_valid() hook.
Scripts can also implement at_start and at_end hooks for preparing and
cleaning whatever effect they have had on the game object.
cleaning whatever effect they have had on the game object.
Common examples of uses of Scripts:
- load the default cmdset to the player object's cmdhandler
@ -20,8 +20,8 @@ Common examples of uses of Scripts:
start combat or enter a dark room.
- Weather patterns in-game
- merge a new cmdset with the default one for changing which
commands are available at a particular time
- give the player/object a time-limited bonus/effect
commands are available at a particular time
- give the player/object a time-limited bonus/effect
"""
from django.conf import settings
@ -45,7 +45,7 @@ class ScriptAttribute(Attribute):
verbose_name = "Script Attribute"
verbose_name_plural = "Script Attributes"
#------------------------------------------------------------
#
# ScriptDB
@ -54,7 +54,7 @@ class ScriptAttribute(Attribute):
class ScriptDB(TypedObject):
"""
The Script database representation.
The Script database representation.
The TypedObject supplies the following (inherited) properties:
key - main name
@ -62,10 +62,10 @@ class ScriptDB(TypedObject):
typeclass_path - the path to the decorating typeclass
typeclass - auto-linked typeclass
date_created - time stamp of object creation
permissions - perm strings
dbref - #id of object
permissions - perm strings
dbref - #id of object
db - persistent attribute storage
ndb - non-persistent attribute storage
ndb - non-persistent attribute storage
The ScriptDB adds the following properties:
desc - optional description of script
@ -74,21 +74,21 @@ class ScriptDB(TypedObject):
start_delay - if the script should start repeating right away
repeats - how many times the script should repeat
persistent - if script should survive a server reboot
is_active - bool if script is currently running
is_active - bool if script is currently running
"""
#
#
# ScriptDB Database Model setup
#
# These databse fields are all set using their corresponding properties,
# named same as the field, but withtou the db_* prefix.
# inherited fields (from TypedObject):
# inherited fields (from TypedObject):
# db_key, db_typeclass_path, db_date_created, db_permissions
# optional description.
# optional description.
db_desc = models.CharField('desc', max_length=255, blank=True)
# A reference to the database object affected by this Script, if any.
db_obj = models.ForeignKey("objects.ObjectDB", null=True, blank=True, verbose_name='scripted object',
@ -106,7 +106,7 @@ class ScriptDB(TypedObject):
# Database manager
objects = ScriptManager()
class Meta:
"Define Django meta options"
verbose_name = "Script"
@ -115,8 +115,8 @@ class ScriptDB(TypedObject):
# @property decorators that allows to access these fields using
# normal python operations (without having to remember to save()
# etc). So e.g. a property 'attr' has a get/set/del decorator
# defined that allows the user to do self.attr = value,
# value = self.attr and del self.attr respectively (where self
# defined that allows the user to do self.attr = value,
# value = self.attr and del self.attr respectively (where self
# is the script in question).
# desc property (wraps db_desc)
@ -186,7 +186,7 @@ class ScriptDB(TypedObject):
self.db_start_delay = False
self.save()
start_delay = property(start_delay_get, start_delay_set, start_delay_del)
# repeats property (wraps db_repeats)
#@property
def repeats_get(self):
@ -221,7 +221,7 @@ class ScriptDB(TypedObject):
self.save()
persistent = property(persistent_get, persistent_set, persistent_del)
# is_active property (wraps db_is_active)
# is_active property (wraps db_is_active)
#@property
def is_active_get(self):
"Getter. Allows for value = self.is_active"
@ -245,33 +245,26 @@ class ScriptDB(TypedObject):
#
# this is required to properly handle attributes and typeclass loading
#attribute_model_path = "src.scripts.models"
#attribute_model_name = "ScriptAttribute"
typeclass_paths = settings.SCRIPT_TYPECLASS_PATHS
attribute_class = ScriptAttribute
db_model_name = "scriptdb" # used by attributes to safely store objects
# this is used by all typedobjects as a fallback
try:
default_typeclass_path = settings.BASE_SCRIPT_TYPECLASS
except:
default_typeclass_path = "src.scripts.scripts.DoNothing"
_typeclass_paths = settings.SCRIPT_TYPECLASS_PATHS
_attribute_class = ScriptAttribute
_db_model_name = "scriptdb" # used by attributes to safely store objects
_default_typeclass_path = settings.BASE_SCRIPT_TYPECLASS or "src.scripts.scripts.DoNothing"
def at_typeclass_error(self):
"""
If this is called, it means the typeclass has a critical
If this is called, it means the typeclass has a critical
error and cannot even be loaded. We don't allow a script
to be created under those circumstances. Already created,
permanent scripts are set to already be active so they
won't get activated now (next reboot the bug might be fixed)
"""
# By setting is_active=True, we trick the script not to run "again".
self.is_active = True
self.is_active = True
return super(ScriptDB, self).at_typeclass_error()
delete_iter = 0
def delete(self):
if self.delete_iter > 0:
return
return
self.delete_iter += 1
super(ScriptDB, self).delete()