Splitting the scripted parent system out into the gamesrc directory. There will be more explanation of this later.

This commit is contained in:
Greg Taylor 2008-12-15 05:55:04 +00:00
parent 00297d336a
commit 122bf4e3ff
13 changed files with 79 additions and 33 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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'

View file

@ -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):

View file

@ -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

View file

@ -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)

View file

View file

@ -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: