Make script obj= required for targeting obj-based scripts. Resolve #3096

This commit is contained in:
Griatch 2023-02-26 00:09:44 +01:00
parent 93a149011f
commit 67294b7b15
4 changed files with 78 additions and 55 deletions

View file

@ -2,6 +2,8 @@
## Main branch (git)
- Bug fix: Change so `script obj = [scriptname|id]` is required to manipulate scripts
on objects; `script scriptname|id` only works on global scripts.
- Doc: Add warning about `Django-wiki` (in wiki tutorial) only supporting Django <4.0.
- Doc: Expanded `XYZGrid` docstring to clarify `MapLink` class will not itself
spawn anything, children must define their prototypes explicitly.

View file

@ -2,6 +2,8 @@
## Main branch (git)
- Bug fix: Change so `script obj = [scriptname|id]` is required to manipulate scripts
on objects; `script scriptname|id` only works on global scripts.
- Doc: Add warning about `Django-wiki` (in wiki tutorial) only supporting Django <4.0.
- Doc: Expanded `XYZGrid` docstring to clarify `MapLink` class will not itself
spawn anything, children must define their prototypes explicitly.

View file

@ -3304,8 +3304,8 @@ class CmdScripts(COMMAND_DEFAULT_CLASS):
scripts.
Usage:
script[/switches] [script-#dbref, key, script.path or <obj>]
script[/start||stop] <obj> = <script.path or script-key>
script[/switches] [script-#dbref, key, script.path]
script[/start||stop] <obj> = [<script.path or script-key>]
Switches:
start - start/unpause an existing script's timer.
@ -3314,19 +3314,21 @@ class CmdScripts(COMMAND_DEFAULT_CLASS):
delete - deletes script. This will also stop the timer as needed
Examples:
script - list scripts
script myobj - list all scripts on object
script foo.bar.Script - create a new global Script
script scriptname - examine named existing global script
script myobj = foo.bar.Script - create and assign script to object
script/stop myobj = scriptname - stop script on object
script/pause foo.Bar.Script - pause global script
script/delete myobj - delete ALL scripts on object
script/delete #dbref[-#dbref] - delete script or range by dbref
script - list all scripts
script foo.bar.Script - create a new global Script
script/pause foo.bar.Script - pause global script
script scriptname|#dbref - examine named existing global script
script/delete #dbref[-#dbref] - delete script or range by #dbref
script myobj = - list all scripts on object
script myobj = foo.bar.Script - create and assign script to object
script/stop myobj = name|#dbref - stop named script on object
script/delete myobj = name|#dbref - delete script on object
script/delete myobj = - delete ALL scripts on object
When given with an `<obj>` as left-hand-side, this creates and
assigns a new script to that object. Without an `<obj>`, this
manages and inspects global scripts
manages and inspects global scripts.
If no switches are given, this command just views all active
scripts. The argument can be either an object, at which point it
@ -3403,11 +3405,16 @@ class CmdScripts(COMMAND_DEFAULT_CLASS):
if self.rhs:
obj_query = self.lhs
script_query = self.rhs
elif self.rhs is not None:
# an empty "="
obj_query = self.lhs
script_query = None
else:
obj_query = script_query = self.args
obj_query = None
script_query = self.args
scripts = self._search_script(script_query)
objects = caller.search(obj_query, quiet=True)
scripts = self._search_script(script_query) if script_query else None
objects = caller.search(obj_query, quiet=True) if obj_query else None
obj = objects[0] if objects else None
if not self.switches:

View file

@ -17,9 +17,6 @@ from unittest.mock import MagicMock, Mock, patch
from anything import Anything
from django.conf import settings
from django.test import override_settings
from parameterized import parameterized
from twisted.internet import task
from evennia import (
DefaultCharacter,
DefaultExit,
@ -41,6 +38,8 @@ from evennia.server.sessionhandler import SESSIONS
from evennia.utils import create, gametime, utils
from evennia.utils.test_resources import BaseEvenniaCommandTest # noqa
from evennia.utils.test_resources import BaseEvenniaTest, EvenniaCommandTest
from parameterized import parameterized
from twisted.internet import task
# ------------------------------------------------------------
# Command testing
@ -199,33 +198,41 @@ class TestHelp(BaseEvenniaCommandTest):
[
(
"test", # main help entry
"Help for test\n\n"
"Main help text\n\n"
"Subtopics:\n"
" test/creating extra stuff"
" test/something else"
" test/more",
(
"Help for test\n\n"
"Main help text\n\n"
"Subtopics:\n"
" test/creating extra stuff"
" test/something else"
" test/more"
),
),
(
"test/creating extra stuff", # subtopic, full match
"Help for test/creating extra stuff\n\n"
"Help on creating extra stuff.\n\n"
"Subtopics:\n"
" test/creating extra stuff/subsubtopic\n",
(
"Help for test/creating extra stuff\n\n"
"Help on creating extra stuff.\n\n"
"Subtopics:\n"
" test/creating extra stuff/subsubtopic\n"
),
),
(
"test/creating", # startswith-match
"Help for test/creating extra stuff\n\n"
"Help on creating extra stuff.\n\n"
"Subtopics:\n"
" test/creating extra stuff/subsubtopic\n",
(
"Help for test/creating extra stuff\n\n"
"Help on creating extra stuff.\n\n"
"Subtopics:\n"
" test/creating extra stuff/subsubtopic\n"
),
),
(
"test/extra", # partial match
"Help for test/creating extra stuff\n\n"
"Help on creating extra stuff.\n\n"
"Subtopics:\n"
" test/creating extra stuff/subsubtopic\n",
(
"Help for test/creating extra stuff\n\n"
"Help on creating extra stuff.\n\n"
"Subtopics:\n"
" test/creating extra stuff/subsubtopic\n"
),
),
(
"test/extra/subsubtopic", # partial subsub-match
@ -242,19 +249,23 @@ class TestHelp(BaseEvenniaCommandTest):
),
(
"test/More/Second-more",
"Help for test/more/second-more\n\n"
"The Second More text.\n\n"
"Subtopics:\n"
" test/more/second-more/more again"
" test/more/second-more/third more",
(
"Help for test/more/second-more\n\n"
"The Second More text.\n\n"
"Subtopics:\n"
" test/more/second-more/more again"
" test/more/second-more/third more"
),
),
(
"test/More/-more", # partial match
"Help for test/more/second-more\n\n"
"The Second More text.\n\n"
"Subtopics:\n"
" test/more/second-more/more again"
" test/more/second-more/third more",
(
"Help for test/more/second-more\n\n"
"The Second More text.\n\n"
"Subtopics:\n"
" test/more/second-more/more again"
" test/more/second-more/third more"
),
),
(
"test/more/second/more again",
@ -1506,7 +1517,7 @@ class TestBuilding(BaseEvenniaCommandTest):
self.call(building.CmdFind(), f"=#{id1}-{id2}", f"{mdiff} Matches(#{id1}-#{id2}):")
def test_script(self):
self.call(building.CmdScripts(), "Obj", "No scripts defined on Obj")
self.call(building.CmdScripts(), "Obj =", "No scripts defined on Obj")
self.call(
building.CmdScripts(),
"Obj = scripts.scripts.DefaultScript",
@ -1518,12 +1529,12 @@ class TestBuilding(BaseEvenniaCommandTest):
"evennia.scripts.scripts.DoNothing",
"Global Script Created - sys_do_nothing ",
)
self.call(building.CmdScripts(), "Obj ", "dbref ")
self.call(building.CmdScripts(), "Obj =", "dbref ")
self.call(
building.CmdScripts(), "/start Obj", "Script on Obj Started "
building.CmdScripts(), "/start Obj = ", "Script on Obj Started "
) # we allow running start again; this should still happen
self.call(building.CmdScripts(), "/stop Obj", "Script on Obj Stopped - ")
self.call(building.CmdScripts(), "/stop Obj =", "Script on Obj Stopped - ")
self.call(
building.CmdScripts(),
@ -1586,9 +1597,8 @@ class TestBuilding(BaseEvenniaCommandTest):
self.call(
building.CmdTeleport(),
"Obj = Room2",
"Obj(#{}) is leaving Room(#{}), heading for Room2(#{}).|Teleported Obj -> Room2.".format(
oid, rid, rid2
),
"Obj(#{}) is leaving Room(#{}), heading for Room2(#{}).|Teleported Obj -> Room2."
.format(oid, rid, rid2),
)
self.call(building.CmdTeleport(), "NotFound = Room", "Could not find 'NotFound'.")
self.call(
@ -1704,7 +1714,8 @@ class TestBuilding(BaseEvenniaCommandTest):
self.call(
building.CmdSpawn(),
"{'prototype_key':'GOBLIN', 'typeclass':'evennia.objects.objects.DefaultCharacter', "
"'key':'goblin', 'location':'%s'}" % spawnLoc.dbref,
"'key':'goblin', 'location':'%s'}"
% spawnLoc.dbref,
"Spawned goblin",
)
goblin = get_object(self, "goblin")
@ -1752,7 +1763,8 @@ class TestBuilding(BaseEvenniaCommandTest):
self.call(
building.CmdSpawn(),
"/noloc {'prototype_parent':'TESTBALL', 'key': 'Ball', 'prototype_key': 'foo',"
" 'location':'%s'}" % spawnLoc.dbref,
" 'location':'%s'}"
% spawnLoc.dbref,
"Spawned Ball",
)
ball = get_object(self, "Ball")