From 51a911d048034581b56faf721d68b148df55ef0d Mon Sep 17 00:00:00 2001 From: Greg Taylor Date: Sat, 21 Jun 2008 02:05:44 +0000 Subject: [PATCH] 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. --- apps/objects/models.py | 15 +++++++++------ src/cmdhandler.py | 2 +- src/commands/general.py | 8 ++++---- src/session.py | 4 ++-- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/apps/objects/models.py b/apps/objects/models.py index 416120c2de..6d878145c9 100755 --- a/apps/objects/models.py +++ b/apps/objects/models.py @@ -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): """ diff --git a/src/cmdhandler.py b/src/cmdhandler.py index d03c258b91..953be9c0b8 100755 --- a/src/cmdhandler.py +++ b/src/cmdhandler.py @@ -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.") diff --git a/src/commands/general.py b/src/commands/general.py index 13bb09720c..4abd395aee 100644 --- a/src/commands/general.py +++ b/src/commands/general.py @@ -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 }) diff --git a/src/session.py b/src/session.py index 682a2acada..41ff8c0bdc 100755 --- a/src/session.py +++ b/src/session.py @@ -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,))