We now access the scriptlink by calling object.scriptlink instead of get_scriptlink. Shortens the typage a little and allows for some less complex fun possibilities down the road.
This commit is contained in:
parent
e6e5a889f5
commit
51a911d048
4 changed files with 16 additions and 13 deletions
|
|
@ -104,13 +104,15 @@ class Object(models.Model):
|
|||
zone = models.ForeignKey('self', related_name="obj_zone", blank=True, null=True)
|
||||
home = models.ForeignKey('self', related_name="obj_home", blank=True, null=True)
|
||||
type = models.SmallIntegerField(choices=defines_global.OBJECT_TYPES)
|
||||
# TODO: Move description to an attribute.s
|
||||
# TODO: Move description to an attribute.
|
||||
description = models.TextField(blank=True, null=True)
|
||||
location = models.ForeignKey('self', related_name="obj_location", blank=True, null=True)
|
||||
flags = models.TextField(blank=True, null=True)
|
||||
nosave_flags = models.TextField(blank=True, null=True)
|
||||
date_created = models.DateField(editable=False, auto_now_add=True)
|
||||
scriptlink = None
|
||||
# 'scriptlink' is a 'get' property for retrieving a reference to the correct
|
||||
# script object. Defined down by get_scriptlink()
|
||||
scriptlink_cached = None
|
||||
|
||||
objects = ObjectManager()
|
||||
|
||||
|
|
@ -644,18 +646,19 @@ class Object(models.Model):
|
|||
"""
|
||||
Returns an object's script parent.
|
||||
"""
|
||||
if not self.scriptlink:
|
||||
if not self.scriptlink_cached:
|
||||
if self.is_player():
|
||||
script_to_load = 'player.basicplayer'
|
||||
else:
|
||||
script_to_load = 'basicobject'
|
||||
self.scriptlink = 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:
|
||||
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
|
||||
return self.scriptlink_cached
|
||||
return None
|
||||
scriptlink = property(fget=get_scriptlink)
|
||||
|
||||
def get_attribute_value(self, attrib, default=False):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -239,7 +239,7 @@ def handle(cdat):
|
|||
cdat['uinput'] = parsed_input
|
||||
|
||||
# SCRIPT: See if the player can traverse the exit
|
||||
if not targ_exit.get_scriptlink().default_lock({
|
||||
if not targ_exit.scriptlink.default_lock({
|
||||
"pobject": pobject
|
||||
}):
|
||||
session.msg("You can't traverse that exit.")
|
||||
|
|
|
|||
|
|
@ -116,13 +116,13 @@ def cmd_look(cdat):
|
|||
return
|
||||
|
||||
# SCRIPT: Get the item's appearance from the scriptlink.
|
||||
session.msg(target_obj.get_scriptlink().return_appearance({
|
||||
session.msg(target_obj.scriptlink.return_appearance({
|
||||
"target_obj": target_obj,
|
||||
"pobject": pobject
|
||||
}))
|
||||
|
||||
# SCRIPT: Call the object's script's a_desc() method.
|
||||
target_obj.get_scriptlink().a_desc({
|
||||
target_obj.scriptlink.a_desc({
|
||||
"target_obj": pobject
|
||||
})
|
||||
|
||||
|
|
@ -161,7 +161,7 @@ def cmd_get(cdat):
|
|||
pobject.get_location().emit_to_contents("%s picks up %s." % (pobject.get_name(), target_obj.get_name()), exclude=pobject)
|
||||
|
||||
# SCRIPT: Call the object's script's a_get() method.
|
||||
target_obj.get_scriptlink().a_get({
|
||||
target_obj.scriptlink.a_get({
|
||||
"pobject": pobject
|
||||
})
|
||||
|
||||
|
|
@ -192,7 +192,7 @@ def cmd_drop(cdat):
|
|||
pobject.get_location().emit_to_contents("%s drops %s." % (pobject.get_name(), target_obj.get_name()), exclude=pobject)
|
||||
|
||||
# SCRIPT: Call the object's script's a_drop() method.
|
||||
target_obj.get_scriptlink().a_drop({
|
||||
target_obj.scriptlink.a_drop({
|
||||
"pobject": pobject
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -142,8 +142,8 @@ class SessionProtocol(StatefulTelnetProtocol):
|
|||
pobject = self.get_pobject()
|
||||
session_mgr.disconnect_duplicate_session(self)
|
||||
|
||||
pobject.get_scriptlink().at_pre_login()
|
||||
pobject.get_scriptlink().at_post_login()
|
||||
pobject.scriptlink.at_pre_login()
|
||||
pobject.scriptlink.at_post_login()
|
||||
|
||||
logger.log_infomsg("Login: %s" % (self,))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue