Splitting the scripted parent system out into the gamesrc directory. There will be more explanation of this later.
This commit is contained in:
parent
00297d336a
commit
122bf4e3ff
13 changed files with 79 additions and 33 deletions
22
game/gamesrc/parents/base/basicobject.py
Normal file
22
game/gamesrc/parents/base/basicobject.py
Normal 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)
|
||||||
21
game/gamesrc/parents/base/basicplayer.py
Normal file
21
game/gamesrc/parents/base/basicplayer.py
Normal 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)
|
||||||
|
|
@ -37,9 +37,14 @@ GAME_DIR = os.path.join(BASE_PATH, 'game')
|
||||||
# Example: "/home/media/media.lawrence.com"
|
# Example: "/home/media/media.lawrence.com"
|
||||||
MEDIA_ROOT = os.path.join(GAME_DIR, 'web', 'media')
|
MEDIA_ROOT = os.path.join(GAME_DIR, 'web', 'media')
|
||||||
|
|
||||||
# Absolute path to the directory that has the script tree in it. (no trailing slash)
|
# Import style path to the script parent module. Must be in the import path.
|
||||||
# Example: "/home/evennia/src/scripts"
|
SCRIPT_IMPORT_PATH = 'game.gamesrc.parents'
|
||||||
SCRIPT_ROOT = os.path.join(BASE_PATH, 'src', 'scripts')
|
# 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'.
|
# 'postgresql', 'mysql', 'mysql_old', 'sqlite3' or 'ado_mssql'.
|
||||||
DATABASE_ENGINE = 'sqlite3'
|
DATABASE_ENGINE = 'sqlite3'
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
|
"""
|
||||||
|
This is where all of the crucial, core object models reside.
|
||||||
|
"""
|
||||||
import re
|
import re
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.auth.models import User, Group
|
from django.contrib.auth.models import User, Group
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from django.conf import settings
|
||||||
from src.config.models import ConfigValue
|
from src.config.models import ConfigValue
|
||||||
from src.objects.util import object as util_object
|
from src.objects.util import object as util_object
|
||||||
from src.objects.managers.commchannel import CommChannelManager
|
from src.objects.managers.commchannel import CommChannelManager
|
||||||
|
|
@ -650,16 +654,18 @@ class Object(models.Model):
|
||||||
"""
|
"""
|
||||||
if not self.scriptlink_cached:
|
if not self.scriptlink_cached:
|
||||||
if self.is_player():
|
if self.is_player():
|
||||||
script_to_load = 'player.basicplayer'
|
script_to_load = settings.SCRIPT_DEFAULT_PLAYER
|
||||||
else:
|
else:
|
||||||
script_to_load = 'basicobject'
|
script_to_load = settings.SCRIPT_DEFAULT_OBJECT
|
||||||
self.scriptlink_cached = scripthandler.scriptlink(self, self.get_attribute_value('__parent', script_to_load))
|
self.scriptlink_cached = scripthandler.scriptlink(self,
|
||||||
|
self.get_attribute_value('__parent', script_to_load))
|
||||||
|
|
||||||
if self.scriptlink_cached:
|
if self.scriptlink_cached:
|
||||||
# If the scriptlink variable can't be populated, this will fail
|
# If the scriptlink variable can't be populated, this will fail
|
||||||
# silently and let the exception hit in the scripthandler.
|
# silently and let the exception hit in the scripthandler.
|
||||||
return self.scriptlink_cached
|
return self.scriptlink_cached
|
||||||
return None
|
return None
|
||||||
|
# Set a property to make accessing the scriptlink more transparent.
|
||||||
scriptlink = property(fget=get_scriptlink)
|
scriptlink = property(fget=get_scriptlink)
|
||||||
|
|
||||||
def get_attribute_value(self, attrib, default=False):
|
def get_attribute_value(self, attrib, default=False):
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,15 @@
|
||||||
"""
|
"""
|
||||||
This will be the base object type/interface that all scripts are derived from by
|
This is the base object type/interface that all parents are derived from by
|
||||||
default. It will have the necessary outline for developers to sub-class and override.
|
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
|
from src import ansi
|
||||||
|
|
||||||
class BasicObject(object):
|
class EvenniaBasicObject(object):
|
||||||
def __init__(self, source_obj):
|
def __init__(self, source_obj):
|
||||||
"""
|
"""
|
||||||
Get our ducks in a row.
|
Get our ducks in a row.
|
||||||
|
|
@ -129,14 +134,3 @@ class BasicObject(object):
|
||||||
"""
|
"""
|
||||||
# Assume everyone passes the enter lock by default.
|
# Assume everyone passes the enter lock by default.
|
||||||
return True
|
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)
|
|
||||||
|
|
@ -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
|
import time
|
||||||
|
|
||||||
from src import comsys
|
from src import comsys
|
||||||
from src.scripts.basicobject import BasicObject
|
|
||||||
|
|
||||||
class BasicPlayer(BasicObject):
|
class EvenniaBasicPlayer(object):
|
||||||
def at_pre_login(self):
|
def at_pre_login(self):
|
||||||
"""
|
"""
|
||||||
Everything done here takes place before the player is actually
|
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_location().emit_to_contents("%s has connected." %
|
||||||
(pobject.get_name(show_dbref=False),), exclude=pobject)
|
(pobject.get_name(show_dbref=False),), exclude=pobject)
|
||||||
session.execute_cmd("look")
|
session.execute_cmd("look")
|
||||||
|
|
||||||
def class_factory(source_obj):
|
|
||||||
return BasicPlayer(source_obj)
|
|
||||||
0
src/script_parents/thing/__init__.py
Normal file
0
src/script_parents/thing/__init__.py
Normal file
|
|
@ -6,7 +6,6 @@ interaction with actual script methods should happen via calls to Objects.
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
from traceback import format_exc
|
from traceback import format_exc
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from src import logger
|
from src import logger
|
||||||
|
|
||||||
|
|
@ -32,15 +31,15 @@ def scriptlink(source_obj, scriptname):
|
||||||
if retval:
|
if retval:
|
||||||
return retval.class_factory(source_obj)
|
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
|
# 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
|
# 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
|
# strange issue with __import__ and more than two directories worth of
|
||||||
# nesting.
|
# nesting.
|
||||||
full_script = "src.scripts.%s" % (scriptname,)
|
full_script = "%s.%s" % (settings.SCRIPT_IMPORT_PATH, scriptname)
|
||||||
script_name = full_script.split('.')[-1]
|
script_name = full_script.split('.')[-1]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue