From 5c521313d48ea7e5df72e8c1101d4ddcaae44a35 Mon Sep 17 00:00:00 2001 From: Griatch Date: Tue, 14 May 2019 10:33:31 +0200 Subject: [PATCH] Various fixes from game jam --- evennia/commands/cmdhandler.py | 1 + evennia/commands/command.py | 1 - evennia/commands/default/account.py | 2 +- evennia/locks/lockhandler.py | 8 ++++---- evennia/objects/objects.py | 10 ++++++---- evennia/settings_default.py | 2 +- evennia/typeclasses/attributes.py | 15 +++++++++++---- evennia/typeclasses/tags.py | 4 +++- evennia/utils/create.py | 6 +++--- evennia/utils/evmenu.py | 18 ++++++++++++------ evennia/utils/utils.py | 2 +- .../static/webclient/js/plugins/default_in.js | 4 ++-- 12 files changed, 45 insertions(+), 28 deletions(-) diff --git a/evennia/commands/cmdhandler.py b/evennia/commands/cmdhandler.py index 1f068e13e3..a8c23a97ff 100644 --- a/evennia/commands/cmdhandler.py +++ b/evennia/commands/cmdhandler.py @@ -647,6 +647,7 @@ def cmdhandler(called_by, raw_string, _testing=False, callertype="session", sess args = raw_string unformatted_raw_string = "%s%s" % (cmdname, args) cmdset = None + raw_cmdname = cmdname # session = session # account = account diff --git a/evennia/commands/command.py b/evennia/commands/command.py index fed6b0917e..96e619e83d 100644 --- a/evennia/commands/command.py +++ b/evennia/commands/command.py @@ -483,7 +483,6 @@ class Command(with_metaclass(CommandMeta, object)): h_line_char = kwargs.pop('header_line_char', '~') header_line_char = ANSIString(f'|{border_color}{h_line_char}|n') - c_char = kwargs.pop('corner_char', '+') corner_char = ANSIString(f'|{border_color}{c_char}|n') diff --git a/evennia/commands/default/account.py b/evennia/commands/default/account.py index 067bc6dd55..ab506b1935 100644 --- a/evennia/commands/default/account.py +++ b/evennia/commands/default/account.py @@ -415,7 +415,7 @@ class CmdWho(COMMAND_DEFAULT_CLASS): else: show_session_data = account.check_permstring("Developer") or account.check_permstring("Admins") - naccounts = (SESSIONS.account_count()) + naccounts = SESSIONS.account_count() if show_session_data: # privileged info table = self.style_table("|wAccount Name", diff --git a/evennia/locks/lockhandler.py b/evennia/locks/lockhandler.py index 1a43e7c65a..1a0cdd8d0f 100644 --- a/evennia/locks/lockhandler.py +++ b/evennia/locks/lockhandler.py @@ -618,7 +618,7 @@ class _ObjDummy: lock_storage = '' -def check_lockstring(self, accessing_obj, lockstring, no_superuser_bypass=False, +def check_lockstring(accessing_obj, lockstring, no_superuser_bypass=False, default=False, access_type=None): """ Do a direct check against a lockstring ('atype:func()..'), @@ -643,9 +643,9 @@ def check_lockstring(self, accessing_obj, lockstring, no_superuser_bypass=False, access (bool): If check is passed or not. """ - global _LOCKHANDLER - if not _LOCKHANDLER: - _LOCKHANDLER = LockHandler(_ObjDummy()) + global _LOCK_HANDLER + if not _LOCK_HANDLER: + _LOCK_HANDLER = LockHandler(_ObjDummy()) return _LOCK_HANDLER.check_lockstring( accessing_obj, lockstring, no_superuser_bypass=no_superuser_bypass, default=default, access_type=access_type) diff --git a/evennia/objects/objects.py b/evennia/objects/objects.py index c72fa72ac6..671342889a 100644 --- a/evennia/objects/objects.py +++ b/evennia/objects/objects.py @@ -1623,7 +1623,9 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)): commonly an object or the current location. It will be checked for the "view" type access. **kwargs (dict): Arbitrary, optional arguments for users - overriding the call (unused by default). + overriding the call. This will be passed into + return_appearance, get_display_name and at_desc but is not used + by default. Returns: lookstring (str): A ready-processed look string @@ -1632,15 +1634,15 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)): """ if not target.access(self, "view"): try: - return "Could not view '%s'." % target.get_display_name(self) + return "Could not view '%s'." % target.get_display_name(self, **kwargs) except AttributeError: return "Could not view '%s'." % target.key - description = target.return_appearance(self) + description = target.return_appearance(self, **kwargs) # the target's at_desc() method. # this must be the last reference to target so it may delete itself when acted on. - target.at_desc(looker=self) + target.at_desc(looker=self, **kwargs) return description diff --git a/evennia/settings_default.py b/evennia/settings_default.py index e1aa1c0c78..f681177776 100644 --- a/evennia/settings_default.py +++ b/evennia/settings_default.py @@ -493,7 +493,7 @@ TYPECLASS_AGGRESSIVE_CACHE = True # Options and validators ###################################################################### -# Options available on Accounts. Each such option is described by a +# Options available on Accounts. Each such option is described by a # class available from evennia.OPTION_CLASSES, in turn making use # of validators from evennia.VALIDATOR_FUNCS to validate input when # the user changes an option. The options are accessed through the diff --git a/evennia/typeclasses/attributes.py b/evennia/typeclasses/attributes.py index a6823221cf..278eff6a9e 100644 --- a/evennia/typeclasses/attributes.py +++ b/evennia/typeclasses/attributes.py @@ -677,11 +677,18 @@ class AttributeHandler(object): if not self._cache_complete: self._fullcache() - if accessing_obj: - [attr.delete() for attr in self._cache.values() - if attr and attr.access(accessing_obj, self._attredit, default=default_access)] + + if category is not None: + attrs = [attr for attr in self._cache.values() if attr.category == category] else: - [attr.delete() for attr in self._cache.values() if attr and attr.pk] + attrs = self._cache.values() + + if accessing_obj: + [attr.delete() for attr in attrs + if attr and + attr.access(accessing_obj, self._attredit, default=default_access)] + else: + [attr.delete() for attr in attrs if attr and attr.pk] self._cache = {} self._catcache = {} self._cache_complete = False diff --git a/evennia/typeclasses/tags.py b/evennia/typeclasses/tags.py index 97e92e2a2f..a486835e50 100644 --- a/evennia/typeclasses/tags.py +++ b/evennia/typeclasses/tags.py @@ -348,7 +348,9 @@ class TagHandler(object): """ if not self._cache_complete: self._fullcache() - query = {"%s__id" % self._model: self._objid, "tag__db_model": self._model, "tag__db_tagtype": self._tagtype} + query = {"%s__id" % self._model: self._objid, + "tag__db_model": self._model, + "tag__db_tagtype": self._tagtype} if category: query["tag__db_category"] = category.strip().lower() getattr(self.obj, self._m2m_fieldname).through.objects.filter(**query).delete() diff --git a/evennia/utils/create.py b/evennia/utils/create.py index 7403f1a8f3..fa934ca394 100644 --- a/evennia/utils/create.py +++ b/evennia/utils/create.py @@ -103,7 +103,6 @@ def create_object(typeclass=None, key=None, location=None, home=None, tags = make_iter(tags) if tags is not None else None attributes = make_iter(attributes) if attributes is not None else None - if isinstance(typeclass, str): # a path is given. Load the actual typeclass typeclass = class_from_module(typeclass, settings.TYPECLASS_PATHS) @@ -119,8 +118,9 @@ def create_object(typeclass=None, key=None, location=None, home=None, try: home = dbid_to_obj(settings.DEFAULT_HOME, _ObjectDB) if not nohome else None except _ObjectDB.DoesNotExist: - raise _ObjectDB.DoesNotExist("settings.DEFAULT_HOME (= '%s') does not exist, or the setting is malformed." % - settings.DEFAULT_HOME) + raise _ObjectDB.DoesNotExist( + "settings.DEFAULT_HOME (= '%s') does not exist, or the setting is malformed." % + settings.DEFAULT_HOME) # create new instance new_object = typeclass(db_key=key, db_location=location, diff --git a/evennia/utils/evmenu.py b/evennia/utils/evmenu.py index d86107dffa..3bb65be8da 100644 --- a/evennia/utils/evmenu.py +++ b/evennia/utils/evmenu.py @@ -318,6 +318,9 @@ class EvMenu(object): """ + # convenient helpers for easy overloading + node_border_char = "_" + def __init__(self, caller, menudata, startnode="start", cmdset_mergetype="Replace", cmdset_priority=1, auto_quit=True, auto_look=True, auto_help=True, @@ -1047,6 +1050,7 @@ class EvMenu(object): node (str): The formatted node to display. """ + sep = self.node_border_char if self._session: screen_width = self._session.protocol_flags.get( @@ -1057,8 +1061,8 @@ class EvMenu(object): nodetext_width_max = max(m_len(line) for line in nodetext.split("\n")) options_width_max = max(m_len(line) for line in optionstext.split("\n")) total_width = min(screen_width, max(options_width_max, nodetext_width_max)) - separator1 = "_" * total_width + "\n\n" if nodetext_width_max else "" - separator2 = "\n" + "_" * total_width + "\n\n" if total_width else "" + separator1 = sep * total_width + "\n\n" if nodetext_width_max else "" + separator2 = "\n" + sep * total_width + "\n\n" if total_width else "" return separator1 + "|n" + nodetext + "|n" + separator2 + "|n" + optionstext @@ -1079,10 +1083,12 @@ def list_node(option_generator, select=None, pagesize=10): that is called as option_generator(caller) to produce such a list. select (callable or str, optional): Node to redirect a selection to. Its `**kwargs` will contain the `available_choices` list and `selection` will hold one of the elements in - that list. If a callable, it will be called as select(caller, menuchoice) where - menuchoice is the chosen option as a string. Should return the target node to goto after - this selection (or None to repeat the list-node). Note that if this is not given, the - decorated node must itself provide a way to continue from the node! + that list. If a callable, it will be called as + select(caller, menuchoice, **kwargs) where menuchoice is the chosen option as a + string and `available_choices` is a kwarg mapping the option keys to the choices + offered by the option_generator. The callable whould return the name of the target node + to goto after this selection (or None to repeat the list-node). Note that if this is not + given, the decorated node must itself provide a way to continue from the node! pagesize (int): How many options to show per page. Example: diff --git a/evennia/utils/utils.py b/evennia/utils/utils.py index 263365a2a9..16a229d23c 100644 --- a/evennia/utils/utils.py +++ b/evennia/utils/utils.py @@ -256,7 +256,7 @@ def justify(text, width=None, align="f", indent=0): words = [] for ip, paragraph in enumerate(paragraphs): if ip > 0: - words.append(("\n\n", 0)) + words.append(("\n", 0)) words.extend((word, len(word)) for word in paragraph.split()) ngaps, wlen, line = 0, 0, [] diff --git a/evennia/web/webclient/static/webclient/js/plugins/default_in.js b/evennia/web/webclient/static/webclient/js/plugins/default_in.js index bdd2fc0c69..56e6dc6c8a 100644 --- a/evennia/web/webclient/static/webclient/js/plugins/default_in.js +++ b/evennia/web/webclient/static/webclient/js/plugins/default_in.js @@ -26,8 +26,8 @@ let defaultin_plugin = (function () { break; case 13: // Enter key - var outtext = inputfield.val(); // Grab the text from which-ever inputfield is focused - if ( outtext && !event.shiftKey ) { // Enter Key without shift --> send Mesg + var outtext = inputfield.val() || ""; // Grab the text from which-ever inputfield is focused + if ( !event.shiftKey ) { // Enter Key without shift --> send Mesg var lines = outtext.trim().replace(/[\r]+/,"\n").replace(/[\n]+/, "\n").split("\n"); for (var i = 0; i < lines.length; i++) { plugin_handler.onSend( lines[i].trim() );