Merge branch 'develop' of https://github.com/evennia/evennia into fix_multi_input_focus
This commit is contained in:
commit
4e58b70a06
8 changed files with 137 additions and 43 deletions
|
|
@ -2,6 +2,13 @@
|
|||
|
||||
Contrib by Griatch 2022
|
||||
|
||||
|
||||
```{warning}
|
||||
NOTE - this tutorial is WIP and NOT complete! It was put on hold to focus on
|
||||
releasing Evennia 1.0. You will still learn things from it, but don't expect
|
||||
perfection.
|
||||
```
|
||||
|
||||
A complete example MUD using Evennia. This is the final result of what is
|
||||
implemented if you follow the Getting-Started tutorial. It's recommended
|
||||
that you follow the tutorial step by step and write your own code. But if
|
||||
|
|
|
|||
|
|
@ -12,13 +12,14 @@ evennia.OPTION_CLASSES
|
|||
|
||||
|
||||
from pickle import dumps
|
||||
from django.db.utils import OperationalError, ProgrammingError
|
||||
from django.conf import settings
|
||||
from evennia.utils.utils import class_from_module, callables_from_module
|
||||
from evennia.utils import logger
|
||||
|
||||
from django.conf import settings
|
||||
from django.db.utils import OperationalError, ProgrammingError
|
||||
from evennia.utils import logger
|
||||
from evennia.utils.utils import callables_from_module, class_from_module
|
||||
|
||||
SCRIPTDB = None
|
||||
_BASE_SCRIPT_TYPECLASS = None
|
||||
|
||||
|
||||
class Container:
|
||||
|
|
@ -200,16 +201,25 @@ class GlobalScriptContainer(Container):
|
|||
initialized.
|
||||
|
||||
"""
|
||||
global _BASE_SCRIPT_TYPECLASS
|
||||
if not _BASE_SCRIPT_TYPECLASS:
|
||||
_BASE_SCRIPT_TYPECLASS = class_from_module(settings.BASE_SCRIPT_TYPECLASS)
|
||||
|
||||
if self.typeclass_storage is None:
|
||||
self.typeclass_storage = {}
|
||||
for key, data in self.loaded_data.items():
|
||||
for key, data in list(self.loaded_data.items()):
|
||||
try:
|
||||
typeclass = data.get("typeclass", settings.BASE_SCRIPT_TYPECLASS)
|
||||
self.typeclass_storage[key] = class_from_module(typeclass)
|
||||
script_typeclass = class_from_module(typeclass)
|
||||
assert issubclass(script_typeclass, _BASE_SCRIPT_TYPECLASS)
|
||||
self.typeclass_storage[key] = script_typeclass
|
||||
except Exception:
|
||||
logger.log_trace(
|
||||
f"GlobalScriptContainer could not start import global script {key}."
|
||||
f"GlobalScriptContainer could not start import global script {key}. "
|
||||
"It will be removed (skipped)."
|
||||
)
|
||||
# Let's remove this key/value. We want to let other scripts load.
|
||||
self.loaded_data.pop(key)
|
||||
|
||||
def get(self, key, default=None):
|
||||
"""
|
||||
|
|
|
|||
81
evennia/utils/tests/test_containers.py
Normal file
81
evennia/utils/tests/test_containers.py
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
import unittest
|
||||
|
||||
from evennia.utils import containers
|
||||
from django.conf import settings
|
||||
from django.test import override_settings
|
||||
from evennia.utils.utils import class_from_module
|
||||
|
||||
_BASE_SCRIPT_TYPECLASS = class_from_module(settings.BASE_SCRIPT_TYPECLASS)
|
||||
|
||||
class GoodScript(_BASE_SCRIPT_TYPECLASS):
|
||||
pass
|
||||
|
||||
class BadScript:
|
||||
"""Not subclass of _BASE_SCRIPT_TYPECLASS,"""
|
||||
pass
|
||||
|
||||
class WorseScript(_BASE_SCRIPT_TYPECLASS):
|
||||
"""objects will fail upon call"""
|
||||
@property
|
||||
def objects(self):
|
||||
from evennia import module_that_doesnt_exist
|
||||
|
||||
class TestGlobalScriptContainer(unittest.TestCase):
|
||||
|
||||
def test_init_with_no_scripts(self):
|
||||
gsc = containers.GlobalScriptContainer()
|
||||
|
||||
self.assertEqual(len(gsc.loaded_data), 0)
|
||||
|
||||
@override_settings(GLOBAL_SCRIPTS={'script_name': {}})
|
||||
def test_init_with_typeclassless_script(self):
|
||||
|
||||
gsc = containers.GlobalScriptContainer()
|
||||
|
||||
self.assertEqual(len(gsc.loaded_data), 1)
|
||||
self.assertIn('script_name', gsc.loaded_data)
|
||||
|
||||
def test_start_with_no_scripts(self):
|
||||
gsc = containers.GlobalScriptContainer()
|
||||
|
||||
gsc.start()
|
||||
|
||||
self.assertEqual(len(gsc.typeclass_storage), 0)
|
||||
|
||||
@override_settings(GLOBAL_SCRIPTS={'script_name': {}})
|
||||
def test_start_with_typeclassless_script_defaults_to_base(self):
|
||||
gsc = containers.GlobalScriptContainer()
|
||||
|
||||
gsc.start()
|
||||
|
||||
self.assertEqual(len(gsc.typeclass_storage), 1)
|
||||
self.assertIn('script_name', gsc.typeclass_storage)
|
||||
self.assertEqual(gsc.typeclass_storage['script_name'], _BASE_SCRIPT_TYPECLASS)
|
||||
|
||||
@override_settings(GLOBAL_SCRIPTS={'script_name': {'typeclass': 'evennia.utils.tests.test_containers.GoodScript'}})
|
||||
def test_start_with_typeclassed_script_loads_it(self):
|
||||
gsc = containers.GlobalScriptContainer()
|
||||
|
||||
gsc.start()
|
||||
|
||||
self.assertEqual(len(gsc.typeclass_storage), 1)
|
||||
self.assertIn('script_name', gsc.typeclass_storage)
|
||||
self.assertEqual(gsc.typeclass_storage['script_name'], GoodScript)
|
||||
|
||||
@override_settings(GLOBAL_SCRIPTS={'script_name': {'typeclass': 'evennia.utils.tests.test_containers.BadScript'}})
|
||||
def test_start_with_bad_typeclassed_script_skips_it(self):
|
||||
gsc = containers.GlobalScriptContainer()
|
||||
|
||||
gsc.start()
|
||||
|
||||
self.assertEqual(len(gsc.typeclass_storage), 0)
|
||||
self.assertNotIn('script_name', gsc.typeclass_storage)
|
||||
|
||||
@override_settings(GLOBAL_SCRIPTS={'script_name': {'typeclass': 'evennia.utils.tests.test_containers.WorstScript'}})
|
||||
def test_start_with_worst_typeclassed_script_skips_it(self):
|
||||
gsc = containers.GlobalScriptContainer()
|
||||
|
||||
gsc.start()
|
||||
|
||||
self.assertEqual(len(gsc.typeclass_storage), 0)
|
||||
self.assertNotIn('script_name', gsc.typeclass_storage)
|
||||
|
|
@ -335,9 +335,9 @@ let goldenlayout = (function () {
|
|||
//
|
||||
var onTabCreate = function (tab) {
|
||||
//HTML for the typeDropdown
|
||||
let renameDropdownControl = $("<span class='lm_title' style='font-size: 1.5em;width: 0.5em;'>🢒</span>");
|
||||
let typeDropdownControl = $("<span class='lm_title' style='font-size: 1.0em;width: 1em;'>⯁</span>");
|
||||
let updateDropdownControl = $("<span class='lm_title' style='font-size: 1.0em;width: 1em;'>⯈</span>");
|
||||
let renameDropdownControl = $("<span class='lm_title' style='font-size: 1.5em;width: 0.5em;'>▸</span>");
|
||||
let typeDropdownControl = $("<span class='lm_title' style='font-size: 1.0em;width: 1em;'>◆</span>");
|
||||
let updateDropdownControl = $("<span class='lm_title' style='font-size: 1.0em;width: 1em;'>▸</span>");
|
||||
let splitControl = $("<span class='lm_title' style='font-size: 1.5em;width: 1em;'>+</span>");
|
||||
// track dropdowns when the associated control is clicked
|
||||
renameDropdownControl.click( tab, renameDropdown );
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue