Global scripts not defined in settings wouldn't appear on GLOBAL_SCRIPTS container as documented. Resolves #3519

This commit is contained in:
Griatch 2024-08-11 15:47:03 +02:00
parent 1ad91fed2c
commit 4954fa1189
3 changed files with 27 additions and 9 deletions

View file

@ -5,11 +5,14 @@
[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)
[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

View file

@ -6,13 +6,12 @@ ability to run timers.
"""
from django.utils.translation import gettext as _
from twisted.internet.defer import Deferred, maybeDeferred
from twisted.internet.task import LoopingCall
from evennia.scripts.manager import ScriptManager
from evennia.scripts.models import ScriptDB
from evennia.typeclasses.models import TypeclassBase
from evennia.utils import create, logger
from twisted.internet.defer import Deferred, maybeDeferred
from twisted.internet.task import LoopingCall
__all__ = ["DefaultScript", "DoNothing", "Store"]
@ -423,7 +422,12 @@ class ScriptBase(ScriptDB, metaclass=TypeclassBase):
updates = []
if not cdict.get("key"):
if not self.db_key:
self.db_key = "#%i" % self.dbid
if hasattr(self, "key"):
# take key from the object typeclass
self.db_key = self.key
else:
# no key set anywhere, use class+dbid as key
self.db_key = f"{self.__class__.__name__}(#{self.dbid})"
updates.append("db_key")
elif self.db_key != cdict["key"]:
self.db_key = cdict["key"]

View file

@ -14,7 +14,7 @@ from pickle import dumps
from django.conf import settings
from django.db.utils import OperationalError, ProgrammingError
from evennia.scripts.models import ScriptDB
from evennia.utils import logger
from evennia.utils.utils import callables_from_module, class_from_module
@ -217,7 +217,7 @@ class GlobalScriptContainer(Container):
"""
if not self.loaded:
self.load_data()
out_value = default
script_found = None
if key in self.loaded_data:
if key not in self.typeclass_storage:
# this means we are trying to load in a loop
@ -230,8 +230,12 @@ class GlobalScriptContainer(Container):
script_found = self._load_script(key)
if script_found:
out_value = script_found
else:
# script not found in settings, see if one exists in database (not
# auto-started/recreated)
script_found = ScriptDB.objects.filter(db_key__iexact=key, db_obj__isnull=True).first()
return out_value
return script_found if script_found is not None else default
def all(self):
"""
@ -239,12 +243,19 @@ class GlobalScriptContainer(Container):
scripts defined in settings.
Returns:
scripts (list): All global script objects stored on the container.
list: All global script objects in game (both managed and unmanaged),
sorted alphabetically.
"""
if not self.loaded:
self.load_data()
return list(self.loaded_data.values())
managed_scripts = list(self.loaded_data.values())
unmanaged_scripts = list(
ScriptDB.objects.filter(db_obj__isnull=True).exclude(
id__in=[scr.id for scr in managed_scripts]
)
)
return list(sorted(managed_scripts + unmanaged_scripts, key=lambda scr: scr.db_key))
# Create all singletons