New way of working with scriptlinks.
Scripts should be defined as '.' separated directory structures, starting in the base evennia directory.
This commit is contained in:
parent
6d1a8b8250
commit
3e57f49395
2 changed files with 5 additions and 14 deletions
|
|
@ -646,7 +646,7 @@ class Object(models.Model):
|
||||||
"""
|
"""
|
||||||
if not self.scriptlink:
|
if not self.scriptlink:
|
||||||
if self.is_player():
|
if self.is_player():
|
||||||
script_to_load = 'player/basicplayer'
|
script_to_load = 'player.basicplayer'
|
||||||
else:
|
else:
|
||||||
script_to_load = 'basicobject'
|
script_to_load = 'basicobject'
|
||||||
self.scriptlink = scripthandler.scriptlink(self, self.get_attribute_value('__parent', script_to_load))
|
self.scriptlink = scripthandler.scriptlink(self, self.get_attribute_value('__parent', script_to_load))
|
||||||
|
|
|
||||||
|
|
@ -40,19 +40,13 @@ def scriptlink(source_obj, scriptname):
|
||||||
# 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.
|
||||||
#path_split = scriptname.split('.')
|
full_script = "src.scripts.%s" % (scriptname,)
|
||||||
#newpath_str = '/'.join(path_split[:-1])
|
script_name = full_script.split('.')[-1]
|
||||||
# Lop the module name off the end.
|
|
||||||
#modname = path_split[-1]
|
|
||||||
path_split = scriptname.split('/')
|
|
||||||
script_name = path_split[-1]
|
|
||||||
script_path = '/'.join(path_split[:-1])
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Change the working directory to the location of the script and import.
|
# Change the working directory to the location of the script and import.
|
||||||
os.chdir('%s/%s/' % (settings.SCRIPT_ROOT, script_path))
|
logger.log_infomsg("SCRIPT: Caching and importing %s." % (scriptname))
|
||||||
logger.log_infomsg("SCRIPT: Caching and importing %s." % (script_name))
|
modreference = __import__(full_script, fromlist=[script_name])
|
||||||
modreference = __import__(script_name)
|
|
||||||
# Store the module reference for later fast retrieval.
|
# Store the module reference for later fast retrieval.
|
||||||
cached_scripts[scriptname] = modreference
|
cached_scripts[scriptname] = modreference
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
|
@ -64,8 +58,5 @@ def scriptlink(source_obj, scriptname):
|
||||||
os.chdir(settings.BASE_PATH)
|
os.chdir(settings.BASE_PATH)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Change back to the original working directory.
|
|
||||||
os.chdir(settings.BASE_PATH)
|
|
||||||
|
|
||||||
# The new script module has been cached, return the reference.
|
# The new script module has been cached, return the reference.
|
||||||
return modreference.class_factory(source_obj)
|
return modreference.class_factory(source_obj)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue