From 9a166ba024663b07bbbed98a2a04d00928dcad62 Mon Sep 17 00:00:00 2001 From: Greg Taylor Date: Tue, 16 Dec 2008 04:28:57 +0000 Subject: [PATCH] Moving script_parent to a field on the object model. This is critical enough to warrant it being there instead of in an attribute. Minor changes here and there. NOTE: This update adds a field, delete your evennia.db3 or manually add a NOT NULL 'script_link' charfield(255). --- src/commands/general.py | 10 ++++++---- src/commands/parents.py | 4 +++- src/objects/models.py | 16 ++++++++++++---- src/objects/sql/object.sql | 4 ++-- src/session.py | 1 + 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/commands/general.py b/src/commands/general.py index d92f2790ae..f48e6bf6f9 100644 --- a/src/commands/general.py +++ b/src/commands/general.py @@ -271,15 +271,17 @@ def cmd_examine(command): along with detailed information about said object. """ # Format the examine header area with general flag/type info. - session.msg("%s\r\n%s" % ( - target_obj.get_name(fullname=True), - target_obj.get_description(no_parsing=True), - )) + session.msg(target_obj.get_name(fullname=True)) session.msg("Type: %s Flags: %s" % (target_obj.get_type(), target_obj.get_flags())) + session.msg("Desc: %s" % target_obj.get_description(no_parsing=True)) session.msg("Owner: %s " % (target_obj.get_owner(),)) session.msg("Zone: %s" % (target_obj.get_zone(),)) + parent_str = target_obj.script_parent + if parent_str and parent_str != '': + session.msg("Parent: %s " % (parent_str,)) + for attribute in target_obj.get_all_attributes(): session.msg(attribute.get_attrline()) diff --git a/src/commands/parents.py b/src/commands/parents.py index 74ea2a354d..4e45081ae6 100644 --- a/src/commands/parents.py +++ b/src/commands/parents.py @@ -28,7 +28,7 @@ def show_cached_scripts(command): for script in cache_dict.keys(): retval += "\n " + script retval += "\n" + "-" * 78 + "\n" - retval += "%d cached parents." % len(cache_dict) + retval += "%d cached parents" % len(cache_dict) session.msg(retval) def cmd_parent(command): @@ -43,3 +43,5 @@ def cmd_parent(command): if "clearcache" in command.command_switches: clear_cached_scripts(command) return + + \ No newline at end of file diff --git a/src/objects/models.py b/src/objects/models.py index 4cb2ebbc04..8881439a80 100755 --- a/src/objects/models.py +++ b/src/objects/models.py @@ -106,6 +106,7 @@ class Object(models.Model): ansi_name = models.CharField(max_length=255) owner = models.ForeignKey('self', related_name="obj_owner", blank=True, null=True) zone = models.ForeignKey('self', related_name="obj_zone", blank=True, null=True) + script_parent = models.CharField(max_length=255, 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. @@ -653,12 +654,19 @@ class Object(models.Model): Returns an object's script parent. """ if not self.scriptlink_cached: - if self.is_player(): - script_to_load = settings.SCRIPT_DEFAULT_PLAYER + script_to_load = None + if not self.script_parent or self.script_parent.strip() == '': + # No parent value, assume the defaults based on type. + if self.is_player(): + script_to_load = settings.SCRIPT_DEFAULT_PLAYER + else: + script_to_load = settings.SCRIPT_DEFAULT_OBJECT else: - script_to_load = settings.SCRIPT_DEFAULT_OBJECT + # A parent has been set, load it from the field's value. + script_to_load = self.script_parent + # Load the script reference into the object's attribute. self.scriptlink_cached = scripthandler.scriptlink(self, - self.get_attribute_value('__parent', script_to_load)) + script_to_load) if self.scriptlink_cached: # If the scriptlink variable can't be populated, this will fail diff --git a/src/objects/sql/object.sql b/src/objects/sql/object.sql index 3d757c7b60..1b834063bc 100644 --- a/src/objects/sql/object.sql +++ b/src/objects/sql/object.sql @@ -1,5 +1,5 @@ -INSERT INTO objects_object VALUES(1,'Wizard','Wizard',1,0,2,1,'',2,'','CONNECTED','2007-04-25'); -INSERT INTO objects_object VALUES(2,'Limbo','Limbo',1,NULL,NULL,2,'Welcome to your new Evennia-based game. From here you are ready to begin development. If you should need help or would like to participate in community discussions, visit http://evennia.com.',NULL,'','','2007-04-25'); +INSERT INTO objects_object VALUES(1,'Wizard','Wizard',1,0,'',2,1,'',2,'','CONNECTED','2007-04-25'); +INSERT INTO objects_object VALUES(2,'Limbo','Limbo',1,NULL,'',NULL,2,'Welcome to your new Evennia-based game. From here you are ready to begin development. If you should need help or would like to participate in community discussions, visit http://evennia.com.',NULL,'','','2007-04-25'); INSERT INTO objects_commchannel VALUES(1,'Public','Public',1,'Public Discussion'); INSERT INTO objects_commchannel VALUES(2,'Errors','Errors',1,'Error Log'); INSERT INTO objects_commchannel VALUES(3,'Info','Info',1,'Info Log'); \ No newline at end of file diff --git a/src/session.py b/src/session.py index cd345067c5..af51acccd5 100755 --- a/src/session.py +++ b/src/session.py @@ -133,6 +133,7 @@ class SessionProtocol(StatefulTelnetProtocol): result = Object.objects.get(id=self.uid) return result except: + logger.log_errmsg("No session match for object: #%s" % self.uid) return None def game_connect_screen(self):