Renamed GLOBAL_HANDLER to GLOBAL_SCRIPTS and cleaned up to PEP8
This commit is contained in:
parent
857c6d53f2
commit
f1c7471691
3 changed files with 17 additions and 15 deletions
|
|
@ -109,7 +109,7 @@ TASK_HANDLER = None
|
||||||
TICKER_HANDLER = None
|
TICKER_HANDLER = None
|
||||||
MONITOR_HANDLER = None
|
MONITOR_HANDLER = None
|
||||||
CHANNEL_HANDLER = None
|
CHANNEL_HANDLER = None
|
||||||
GLOBAL_HANDLER = None
|
GLOBAL_SCRIPTS = None
|
||||||
|
|
||||||
|
|
||||||
def _create_version():
|
def _create_version():
|
||||||
|
|
@ -153,7 +153,7 @@ def _init():
|
||||||
global search_object, search_script, search_account, search_channel, search_help, search_tag, search_message
|
global search_object, search_script, search_account, search_channel, search_help, search_tag, search_message
|
||||||
global create_object, create_script, create_account, create_channel, create_message, create_help_entry
|
global create_object, create_script, create_account, create_channel, create_message, create_help_entry
|
||||||
global settings, lockfuncs, logger, utils, gametime, ansi, spawn, managers
|
global settings, lockfuncs, logger, utils, gametime, ansi, spawn, managers
|
||||||
global contrib, TICKER_HANDLER, MONITOR_HANDLER, SESSION_HANDLER, CHANNEL_HANDLER, TASK_HANDLER, GLOBAL_HANDLER
|
global contrib, TICKER_HANDLER, MONITOR_HANDLER, SESSION_HANDLER, CHANNEL_HANDLER, TASK_HANDLER, GLOBAL_SCRIPTS
|
||||||
global EvMenu, EvTable, EvForm, EvMore, EvEditor
|
global EvMenu, EvTable, EvForm, EvMore, EvEditor
|
||||||
global ANSIString
|
global ANSIString
|
||||||
|
|
||||||
|
|
@ -214,7 +214,7 @@ def _init():
|
||||||
from .server.sessionhandler import SESSION_HANDLER
|
from .server.sessionhandler import SESSION_HANDLER
|
||||||
from .comms.channelhandler import CHANNEL_HANDLER
|
from .comms.channelhandler import CHANNEL_HANDLER
|
||||||
from .scripts.monitorhandler import MONITOR_HANDLER
|
from .scripts.monitorhandler import MONITOR_HANDLER
|
||||||
from .scripts.globalhandler import GLOBAL_HANDLER
|
from .scripts.globalhandler import GLOBAL_SCRIPTS
|
||||||
|
|
||||||
# initialize the doc string
|
# initialize the doc string
|
||||||
global __doc__
|
global __doc__
|
||||||
|
|
|
||||||
|
|
@ -6,23 +6,23 @@ class GlobalHandler(object):
|
||||||
"""
|
"""
|
||||||
Simple Handler object loaded by the Evennia API to contain and manage a game's Global Scripts.
|
Simple Handler object loaded by the Evennia API to contain and manage a game's Global Scripts.
|
||||||
|
|
||||||
This is accessed like a dictionary.
|
This is accessed like a dictionary. Alternatively you can access Properties on it.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
import evennia
|
import evennia
|
||||||
evennia.GLOBAL_HANDLER['key']
|
evennia.GLOBAL_SCRIPTS['key']
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.typeclass_storage = dict()
|
self.typeclass_storage = dict()
|
||||||
self.script_storage = dict()
|
self.script_storage = dict()
|
||||||
for k, v in settings.GLOBAL_SCRIPTS.items():
|
for key, typeclass_path in settings.GLOBAL_SCRIPTS.items():
|
||||||
self.typeclass_storage[k] = class_from_module(v)
|
self.typeclass_storage[key] = class_from_module(typeclass_path)
|
||||||
for k, v in self.typeclass_storage.items():
|
for key, typeclass in self.typeclass_storage.items():
|
||||||
found = v.objects.filter_family(db_key=k).first()
|
found = typeclass.objects.filter(db_key=key).first()
|
||||||
if not found:
|
if not found:
|
||||||
found = v.create(key=k, typeclass=v, persistent=True)
|
found = typeclass.create(key=key, typeclass=typeclass, persistent=True)
|
||||||
self.script_storage[k] = found
|
self.script_storage[key] = found
|
||||||
|
|
||||||
def __getitem__(self, item):
|
def __getitem__(self, item):
|
||||||
|
|
||||||
|
|
@ -40,6 +40,9 @@ class GlobalHandler(object):
|
||||||
self.script_storage[item] = reloaded
|
self.script_storage[item] = reloaded
|
||||||
return reloaded
|
return reloaded
|
||||||
|
|
||||||
|
def __getattr__(self, item):
|
||||||
|
return self[item]
|
||||||
|
|
||||||
|
|
||||||
# Create singleton of the GlobalHandler for the API.
|
# Create singleton of the GlobalHandler for the API.
|
||||||
GLOBAL_HANDLER = GlobalHandler()
|
GLOBAL_SCRIPTS = GlobalHandler()
|
||||||
|
|
|
||||||
|
|
@ -549,9 +549,8 @@ PROTOTYPEFUNC_MODULES = ["evennia.utils.prototypefuncs",
|
||||||
# this for Scripts that absolutely MUST be running for your game as a
|
# this for Scripts that absolutely MUST be running for your game as a
|
||||||
# simple way to get them launched.
|
# simple way to get them launched.
|
||||||
|
|
||||||
# One limitation with this system is that each Script must be have a
|
# The 'key' is a way to quickly index them, and it will also be the
|
||||||
# unique Typeclass. The 'key' is a way to quickly index them but is
|
# Script Typeclasss's key so it can be quickly retrieved.
|
||||||
# not necessarily the Script Typeclasss's key.
|
|
||||||
|
|
||||||
GLOBAL_SCRIPTS = {
|
GLOBAL_SCRIPTS = {
|
||||||
# 'key': 'typeclass.path.here',
|
# 'key': 'typeclass.path.here',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue