Add key:typeclass support for scripts command

This commit is contained in:
Griatch 2024-08-11 20:03:11 +02:00
parent bb751ad2ff
commit 310a895bb5
4 changed files with 42 additions and 18 deletions

View file

@ -2,6 +2,9 @@
## Main branch ## Main branch
Feat: Support `scripts key:typeclass` form to create global scripts
with dynamic keys (rather than just relying on typeclass' key). Support
searching using the same syntax (Griatch)
[Fix][issue3556]: Better error if trying to treat ObjectDB as a typeclass (Griatch) [Fix][issue3556]: Better error if trying to treat ObjectDB as a typeclass (Griatch)
[Fix][issue3590]: Make `examine` command properly show `strattr` type [Fix][issue3590]: Make `examine` command properly show `strattr` type
Attribute values (Griatch) Attribute values (Griatch)

View file

@ -1,5 +1,25 @@
# Changelog # Changelog
## Main branch
Feat: Support `scripts key:typeclass` form to create global scripts
with dynamic keys (rather than just relying on typeclass' key). Support
searching using the same syntax (Griatch)
[Fix][issue3556]: Better error if trying to treat ObjectDB as a typeclass (Griatch)
[Fix][issue3590]: Make `examine` command properly show `strattr` type
Attribute values (Griatch)
[Fix][issue3519]: `GLOBAL_SCRIPTS` container didn't list global scripts not
defined explicitly to be restarted/recrated in settings.py (Griatch)
Fix: Passing an already instantiated Script to `obj.scripts.add` (`ScriptHandler.add`)
did not add it to the handler's object (Griatch)
[Docs][issue3591]: Fix of NPC reaction tutorial code (Griatch)
[issue3591]: https://github.com/evennia/evennia/issues/3591
[issue3590]: https://github.com/evennia/evennia/issues/3590
[issue3556]: https://github.com/evennia/evennia/issues/3556
[issue3519]: https://github.com/evennia/evennia/issues/3519
## Evennia 4.3.0 ## Evennia 4.3.0
Aug 11, 2024 Aug 11, 2024

View file

@ -3521,16 +3521,22 @@ class CmdScripts(COMMAND_DEFAULT_CLASS):
hide_script_paths = ("evennia.prototypes.prototypes.DbPrototype",) hide_script_paths = ("evennia.prototypes.prototypes.DbPrototype",)
def _search_script(self): def _search_script(self):
# test first if this is a script match
print("search:", self.key_query, self.typeclass_query) # see if a dbref was provided
if self.key_query: if dbref(self.typeclass_query):
scripts = ScriptDB.objects.filter( scripts = ScriptDB.objects.get_all_scripts(self.typeclass_query)
db_key__iexact=self.key_query, db_typeclass_path__iendswith=self.typeclass_query
).exclude(db_typeclass_path__in=self.hide_script_paths)
if scripts: if scripts:
return scripts return scripts
self.caller.msg(f"No script found with dbref {self.typeclass_query}")
raise InterruptCommand
# try typeclass path # if we provided a key, we must find an exact match, otherwise we're creating that anew
if self.key_query:
return ScriptDB.objects.filter(
db_key__iexact=self.key_query, db_typeclass_path__iendswith=self.typeclass_query
).exclude(db_typeclass_path__in=self.hide_script_paths)
# the more general case - try typeclass path
scripts = ( scripts = (
ScriptDB.objects.filter(db_typeclass_path__iendswith=self.typeclass_query) ScriptDB.objects.filter(db_typeclass_path__iendswith=self.typeclass_query)
.exclude(db_typeclass_path__in=self.hide_script_paths) .exclude(db_typeclass_path__in=self.hide_script_paths)
@ -3539,11 +3545,6 @@ class CmdScripts(COMMAND_DEFAULT_CLASS):
if scripts: if scripts:
return scripts return scripts
# try dbref
scripts = ScriptDB.objects.get_all_scripts(self.typeclass_query)
if scripts:
return scripts
args = self.typeclass_query args = self.typeclass_query
if "-" in args: if "-" in args:
# may be a dbref-range # may be a dbref-range

View file

@ -1653,17 +1653,17 @@ class TestBuilding(BaseEvenniaCommandTest):
) )
def test_script_multi_delete(self): def test_script_multi_delete(self):
script1 = create.create_script() script1 = create.create_script(key="script1")
script2 = create.create_script() script2 = create.create_script(key="script2")
script3 = create.create_script() script3 = create.create_script(key="script3")
self.call( self.call(
building.CmdScripts(), building.CmdScripts(),
"/delete #{}-#{}".format(script1.id, script3.id), "/delete #{}-#{}".format(script1.id, script3.id),
( (
f"Global Script Deleted - #{script1.id} (evennia.scripts.scripts.DefaultScript)|" f"Global Script Deleted - script1 (evennia.scripts.scripts.DefaultScript)|"
f"Global Script Deleted - #{script2.id} (evennia.scripts.scripts.DefaultScript)|" f"Global Script Deleted - script2 (evennia.scripts.scripts.DefaultScript)|"
f"Global Script Deleted - #{script3.id} (evennia.scripts.scripts.DefaultScript)" f"Global Script Deleted - script3 (evennia.scripts.scripts.DefaultScript)"
), ),
inputs=["y"], inputs=["y"],
) )