From f6255caadece8c8c44470d79a514108967c453d8 Mon Sep 17 00:00:00 2001 From: Vincent Le Goff Date: Tue, 25 Jul 2017 22:40:27 +0200 Subject: [PATCH 1/2] Allow contrib.ingame_python.scripts.EventHandler.get_events to work with typeclasses --- evennia/contrib/ingame_python/scripts.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/evennia/contrib/ingame_python/scripts.py b/evennia/contrib/ingame_python/scripts.py index 11a1b9e24a..af74853ffb 100644 --- a/evennia/contrib/ingame_python/scripts.py +++ b/evennia/contrib/ingame_python/scripts.py @@ -10,7 +10,7 @@ import traceback from django.conf import settings from evennia import DefaultObject, DefaultScript, ChannelDB, ScriptDB -from evennia import logger +from evennia import logger, ObjectDB from evennia.utils.ansi import raw from evennia.utils.create import create_channel from evennia.utils.dbserialize import dbserialize @@ -101,7 +101,7 @@ class EventHandler(DefaultScript): Return a dictionary of events on this object. Args: - obj (Object): the connected object. + obj (Object or typeclass): the connected object or typeclass. Returns: A dictionary of the object's events. @@ -115,7 +115,11 @@ class EventHandler(DefaultScript): events = {} all_events = self.ndb.events classes = Queue() - classes.put(type(obj)) + if isinstance(obj, ObjectDB): + classes.put(type(obj)) + else: + classes.put(obj) + invalid = [] while not classes.empty(): typeclass = classes.get() From 32ad83d51c2875719578c5e36243ced3ad378e5f Mon Sep 17 00:00:00 2001 From: Vincent Le Goff Date: Thu, 10 Aug 2017 11:59:04 +0200 Subject: [PATCH 2/2] Fix documentation in the new option of the event handler --- evennia/contrib/ingame_python/scripts.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/evennia/contrib/ingame_python/scripts.py b/evennia/contrib/ingame_python/scripts.py index af74853ffb..cf538a7846 100644 --- a/evennia/contrib/ingame_python/scripts.py +++ b/evennia/contrib/ingame_python/scripts.py @@ -101,24 +101,28 @@ class EventHandler(DefaultScript): Return a dictionary of events on this object. Args: - obj (Object or typeclass): the connected object or typeclass. + obj (Object or typeclass): the connected object or a general typeclass. Returns: A dictionary of the object's events. - Note: + Notes: Events would define what the object can have as callbacks. Note, however, that chained callbacks will not appear in events and are handled separately. + You can also request the events of a typeclass, not a + connected object. This is useful to get the global list + of events for a typeclass that has no object yet. + """ events = {} all_events = self.ndb.events classes = Queue() - if isinstance(obj, ObjectDB): - classes.put(type(obj)) - else: + if isinstance(obj, type): classes.put(obj) + else: + classes.put(type(obj)) invalid = [] while not classes.empty():