mirror of
https://github.com/evennia/evennia.git
synced 2026-03-29 03:57:17 +02:00
OBS: You need to resync your database! Moved cmdsets into the database rather than being dependent on scripts. Moved the creation of the cmdset- and cmdset-handlers into ObjectDB.__init__ rather than bootstrapping it from the typeclass. Added some more script functionality for testing, includong the @script command for assigning a script to an object.
This commit is contained in:
parent
e965830735
commit
126e2ea61f
17 changed files with 370 additions and 216 deletions
|
|
@ -20,14 +20,14 @@ class ScriptManager(TypedObjectManager):
|
|||
return []
|
||||
scripts = self.filter(db_obj=obj)
|
||||
if key:
|
||||
return [script for script in scripts if script.key == key]
|
||||
return scripts.filter(db_key=key)
|
||||
return scripts
|
||||
|
||||
@returns_typeclass_list
|
||||
def get_all_scripts(self, key=None):
|
||||
"""
|
||||
Return all scripts, alternative only
|
||||
scripts with a certain key/dbref.
|
||||
scripts with a certain key/dbref or path.
|
||||
"""
|
||||
if key:
|
||||
dbref = self.dbref(key)
|
||||
|
|
@ -39,7 +39,7 @@ class ScriptManager(TypedObjectManager):
|
|||
# not a dbref. Normal key search
|
||||
scripts = self.filter(db_key=key)
|
||||
else:
|
||||
scripts = self.all()
|
||||
scripts = list(self.all())
|
||||
return scripts
|
||||
|
||||
def delete_script(self, dbref):
|
||||
|
|
@ -120,7 +120,7 @@ class ScriptManager(TypedObjectManager):
|
|||
elif obj:
|
||||
scripts = self.get_all_scripts_on_obj(obj, key=key)
|
||||
else:
|
||||
scripts = self.get_all_scripts(key=key)
|
||||
scripts = self.model.get_all_cached_instances()#get_all_scripts(key=key)
|
||||
if not scripts:
|
||||
VALIDATE_ITERATION -= 1
|
||||
return None, None
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ from django.conf import settings
|
|||
from django.db import models
|
||||
from src.typeclasses.models import Attribute, TypedObject
|
||||
from src.scripts.manager import ScriptManager
|
||||
#from src.locks.lockhandler import LockHandler
|
||||
|
||||
#------------------------------------------------------------
|
||||
#
|
||||
|
|
|
|||
|
|
@ -24,22 +24,6 @@ class ScriptHandler(object):
|
|||
"""
|
||||
self.obj = obj
|
||||
|
||||
# this is required to stop a nasty loop in some situations that
|
||||
# has the handler infinitely recursively re-added to its object.
|
||||
self.obj.scripts = self
|
||||
|
||||
scripts = ScriptDB.objects.get_all_scripts_on_obj(self.obj)
|
||||
#print "starting scripthandler. %s has scripts %s" % (self.obj, scripts)
|
||||
if scripts:
|
||||
okscripts = [script for script in scripts if script.persistent == True]
|
||||
delscripts = [script for script in scripts if script not in okscripts]
|
||||
for script in delscripts:
|
||||
#print "stopping script %s" % script
|
||||
script.stop()
|
||||
for script in okscripts:
|
||||
#print "starting script %s" % script
|
||||
script.start()
|
||||
|
||||
def __str__(self):
|
||||
"List the scripts tied to this object"
|
||||
scripts = ScriptDB.objects.get_all_scripts_on_obj(self.obj)
|
||||
|
|
@ -72,39 +56,51 @@ class ScriptHandler(object):
|
|||
script = create.create_script(scriptclass, key=key, obj=self.obj, autostart=autostart)
|
||||
if not script:
|
||||
logger.log_errmsg("Script %s failed to be created/start." % scriptclass)
|
||||
return False
|
||||
return True
|
||||
|
||||
def start(self, scriptkey):
|
||||
def start(self, scriptid):
|
||||
"""
|
||||
Find an already added script and force-start it
|
||||
"""
|
||||
scripts = ScriptDB.objects.get_all_scripts_on_obj(self.obj, key=scriptkey)
|
||||
scripts = ScriptDB.objects.get_all_scripts_on_obj(self.obj, key=scriptid)
|
||||
num = 0
|
||||
for script in scripts:
|
||||
script.start()
|
||||
num += script.start()
|
||||
return num
|
||||
|
||||
def delete(self, scriptkey):
|
||||
def delete(self, scriptid):
|
||||
"""
|
||||
Forcibly delete a script from this object.
|
||||
|
||||
scriptid can be a script key or the path to a script (in the
|
||||
latter case all scripts with this path will be deleted!)
|
||||
|
||||
"""
|
||||
delscripts = ScriptDB.objects.get_all_scripts_on_obj(self.obj, key=scriptkey)
|
||||
delscripts = ScriptDB.objects.get_all_scripts_on_obj(self.obj, key=scriptid)
|
||||
if not delscripts:
|
||||
delscripts = [script for script in ScriptDB.objects.get_all_scripts_on_obj(self.obj) if script.path == scriptid]
|
||||
num = 0
|
||||
for script in delscripts:
|
||||
script.stop()
|
||||
num += script.stop()
|
||||
return num
|
||||
|
||||
def stop(self, scriptkey):
|
||||
def stop(self, scriptid):
|
||||
"""
|
||||
Alias for delete.
|
||||
Alias for delete. scriptid can be a script key or a script path string.
|
||||
"""
|
||||
self.delete(scriptkey)
|
||||
return self.delete(scriptid)
|
||||
|
||||
def all(self, scriptkey=None):
|
||||
def all(self, scriptid=None):
|
||||
"""
|
||||
Get all scripts stored in the handler, alternatively all matching a key.
|
||||
"""
|
||||
return ScriptDB.objects.get_all_scripts_on_obj(self.obj, key=scriptkey)
|
||||
return ScriptDB.objects.get_all_scripts_on_obj(self.obj, key=scriptid)
|
||||
|
||||
def validate(self):
|
||||
def validate(self, init_mode=False):
|
||||
"""
|
||||
Runs a validation on this object's scripts only.
|
||||
This should be called regularly to crank the wheels.
|
||||
"""
|
||||
ScriptDB.objects.validate(obj=self.obj)
|
||||
ScriptDB.objects.validate(obj=self.obj, init_mode=init_mode)
|
||||
|
||||
|
|
|
|||
|
|
@ -142,7 +142,8 @@ class ScriptClass(TypeClass):
|
|||
try:
|
||||
self.delete()
|
||||
except AssertionError:
|
||||
pass
|
||||
return 0
|
||||
return 1
|
||||
|
||||
def is_valid(self):
|
||||
"placeholder"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue