diff --git a/src/scripts/__init__.py b/game/gamesrc/parents/base/__init__.py similarity index 100% rename from src/scripts/__init__.py rename to game/gamesrc/parents/base/__init__.py diff --git a/game/gamesrc/parents/base/basicobject.py b/game/gamesrc/parents/base/basicobject.py new file mode 100644 index 0000000000..e193375f2c --- /dev/null +++ b/game/gamesrc/parents/base/basicobject.py @@ -0,0 +1,22 @@ +""" +This is the base object type/interface that all parents are derived from by +default. Each object type sub-classes this class and over-rides methods as +needed. + +NOTE: This file should NOT be directly modified. Sub-class the BasicObject +class in game/gamesrc/parents/base/basicobject.py and change the +SCRIPT_DEFAULT_OBJECT variable in settings.py to point to the new class. +""" +from src.script_parents.basicobject import EvenniaBasicObject + +class BasicObject(EvenniaBasicObject): + pass + +def class_factory(source_obj): + """ + This method is called any script you retrieve (via the scripthandler). It + creates an instance of the class and returns it transparently. + + source_obj: (Object) A reference to the object being scripted (the child). + """ + return BasicObject(source_obj) \ No newline at end of file diff --git a/game/gamesrc/parents/base/basicplayer.py b/game/gamesrc/parents/base/basicplayer.py new file mode 100644 index 0000000000..e5e90cec2c --- /dev/null +++ b/game/gamesrc/parents/base/basicplayer.py @@ -0,0 +1,21 @@ +""" +This is the basic Evennia-standard player parent. + +NOTE: This file should NOT be directly modified. Sub-class the BasicPlayer +class in game/gamesrc/parents/base/basicplayer.py and change the +SCRIPT_DEFAULT_PLAYER variable in settings.py to point to the new class. +""" +from src.script_parents.basicobject import EvenniaBasicObject +from src.script_parents.basicplayer import EvenniaBasicPlayer + +class BasicPlayer(EvenniaBasicObject, EvenniaBasicPlayer): + pass + +def class_factory(source_obj): + """ + This method is called any script you retrieve (via the scripthandler). It + creates an instance of the class and returns it transparently. + + source_obj: (Object) A reference to the object being scripted (the child). + """ + return BasicPlayer(source_obj) \ No newline at end of file diff --git a/src/config_defaults.py b/src/config_defaults.py index 1229d2a5a3..63a92aa07c 100644 --- a/src/config_defaults.py +++ b/src/config_defaults.py @@ -37,9 +37,14 @@ GAME_DIR = os.path.join(BASE_PATH, 'game') # Example: "/home/media/media.lawrence.com" MEDIA_ROOT = os.path.join(GAME_DIR, 'web', 'media') -# Absolute path to the directory that has the script tree in it. (no trailing slash) -# Example: "/home/evennia/src/scripts" -SCRIPT_ROOT = os.path.join(BASE_PATH, 'src', 'scripts') +# Import style path to the script parent module. Must be in the import path. +SCRIPT_IMPORT_PATH = 'game.gamesrc.parents' +# Default parent associated with non-player objects. This starts from where +# the SCRIPT_IMPORT_PATH left off. +SCRIPT_DEFAULT_OBJECT = 'base.basicobject' +# Default parent associated with player objects. This starts from where +# the SCRIPT_IMPORT_PATH left off. +SCRIPT_DEFAULT_PLAYER = 'base.basicplayer' # 'postgresql', 'mysql', 'mysql_old', 'sqlite3' or 'ado_mssql'. DATABASE_ENGINE = 'sqlite3' diff --git a/src/objects/models.py b/src/objects/models.py index 18055f5eea..4cb2ebbc04 100755 --- a/src/objects/models.py +++ b/src/objects/models.py @@ -1,7 +1,11 @@ +""" +This is where all of the crucial, core object models reside. +""" import re from django.db import models from django.contrib.auth.models import User, Group from django.contrib import admin +from django.conf import settings from src.config.models import ConfigValue from src.objects.util import object as util_object from src.objects.managers.commchannel import CommChannelManager @@ -650,16 +654,18 @@ class Object(models.Model): """ if not self.scriptlink_cached: if self.is_player(): - script_to_load = 'player.basicplayer' + script_to_load = settings.SCRIPT_DEFAULT_PLAYER else: - script_to_load = 'basicobject' - self.scriptlink_cached = scripthandler.scriptlink(self, self.get_attribute_value('__parent', script_to_load)) + script_to_load = settings.SCRIPT_DEFAULT_OBJECT + self.scriptlink_cached = scripthandler.scriptlink(self, + self.get_attribute_value('__parent', script_to_load)) if self.scriptlink_cached: # If the scriptlink variable can't be populated, this will fail # silently and let the exception hit in the scripthandler. return self.scriptlink_cached return None + # Set a property to make accessing the scriptlink more transparent. scriptlink = property(fget=get_scriptlink) def get_attribute_value(self, attrib, default=False): diff --git a/src/scripts/exit/__init__.py b/src/script_parents/__init__.py similarity index 100% rename from src/scripts/exit/__init__.py rename to src/script_parents/__init__.py diff --git a/src/scripts/basicobject.py b/src/script_parents/basicobject.py similarity index 87% rename from src/scripts/basicobject.py rename to src/script_parents/basicobject.py index 8d6b15b023..3146a9ef09 100644 --- a/src/scripts/basicobject.py +++ b/src/script_parents/basicobject.py @@ -1,10 +1,15 @@ """ -This will be the base object type/interface that all scripts are derived from by -default. It will have the necessary outline for developers to sub-class and override. +This is the base object type/interface that all parents are derived from by +default. Each object type sub-classes this class and over-rides methods as +needed. + +NOTE: This file should NOT be directly modified. Sub-class the BasicObject +class in game/gamesrc/parents/base/basicobject.py and change the +SCRIPT_DEFAULT_OBJECT variable in settings.py to point to the new class. """ from src import ansi -class BasicObject(object): +class EvenniaBasicObject(object): def __init__(self, source_obj): """ Get our ducks in a row. @@ -128,15 +133,4 @@ class BasicObject(object): * pobject: The object requesting the action. """ # Assume everyone passes the enter lock by default. - return True - -def class_factory(source_obj): - """ - This method is called any script you retrieve (via the scripthandler). It - creates an instance of the class and returns it transparently. I'm not - sure how well this will scale, but we'll find out. We may need to - re-factor this eventually. - - source_obj: (Object) A reference to the object being scripted (the child). - """ - return BasicObject(source_obj) + return True diff --git a/src/scripts/player/basicplayer.py b/src/script_parents/basicplayer.py similarity index 80% rename from src/scripts/player/basicplayer.py rename to src/script_parents/basicplayer.py index 84fafebe23..0ae1e17105 100644 --- a/src/scripts/player/basicplayer.py +++ b/src/script_parents/basicplayer.py @@ -1,12 +1,14 @@ """ -The basic Player object script parent. +This is the basic Evennia-standard player parent. + +NOTE: This file should NOT be directly modified. Sub-class the BasicPlayer +class in game/gamesrc/parents/base/basicplayer.py and change the +SCRIPT_DEFAULT_PLAYER variable in settings.py to point to the new class. """ import time - from src import comsys -from src.scripts.basicobject import BasicObject -class BasicPlayer(BasicObject): +class EvenniaBasicPlayer(object): def at_pre_login(self): """ Everything done here takes place before the player is actually @@ -34,6 +36,3 @@ class BasicPlayer(BasicObject): pobject.get_location().emit_to_contents("%s has connected." % (pobject.get_name(show_dbref=False),), exclude=pobject) session.execute_cmd("look") - -def class_factory(source_obj): - return BasicPlayer(source_obj) diff --git a/src/scripts/npc/__init__.py b/src/script_parents/exit/__init__.py similarity index 100% rename from src/scripts/npc/__init__.py rename to src/script_parents/exit/__init__.py diff --git a/src/scripts/player/__init__.py b/src/script_parents/npc/__init__.py similarity index 100% rename from src/scripts/player/__init__.py rename to src/script_parents/npc/__init__.py diff --git a/src/scripts/thing/__init__.py b/src/script_parents/player/__init__.py similarity index 100% rename from src/scripts/thing/__init__.py rename to src/script_parents/player/__init__.py diff --git a/src/script_parents/thing/__init__.py b/src/script_parents/thing/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/scripthandler.py b/src/scripthandler.py index 98ebc5fba0..4f582ad442 100644 --- a/src/scripthandler.py +++ b/src/scripthandler.py @@ -6,7 +6,6 @@ interaction with actual script methods should happen via calls to Objects. """ import os from traceback import format_exc - from django.conf import settings from src import logger @@ -32,15 +31,15 @@ def scriptlink(source_obj, scriptname): if retval: return retval.class_factory(source_obj) - ## - ## NOTE: Only go past here when the script isn't already cached. - ## + """ + NOTE: Only go past here when the script isn't already cached. + """ # Split the script name up by periods to give us the directory we need # to change to. I really wish we didn't have to do this, but there's some # strange issue with __import__ and more than two directories worth of # nesting. - full_script = "src.scripts.%s" % (scriptname,) + full_script = "%s.%s" % (settings.SCRIPT_IMPORT_PATH, scriptname) script_name = full_script.split('.')[-1] try: