Moved the object's 'description' into an attribute, as suggested in the code. This means that get_description() and set_description() should no longer be used; instead use set_attribute('desc',value) and get_attribute('desc') as you would any attribute. 'desc' is used by the default look command, but apart from that, desc has no special status anymore.

/Griatch
This commit is contained in:
Griatch 2009-05-03 16:55:42 +00:00
parent e7d7284d5c
commit 05554e290a
7 changed files with 45 additions and 49 deletions

View file

@ -35,7 +35,6 @@ from src.statetable import GLOBAL_STATE_TABLE
#the name of our state, to make sure it's the same everywhere
STATENAME = 'menu'
#
# 'entry' command
#

View file

@ -68,7 +68,7 @@ class RedButton(BasicObject):
#get stored object related to this class
obj = self.scripted_obj
obj.set_description("This is your standard big red button.")
obj.set_attribute('desc', "This is your standard big red button.")
obj.set_attribute("breakpoint", 10)
obj.set_attribute("count", 0)

View file

@ -282,7 +282,7 @@ def cmd_examine(command):
s += str(target_obj.get_name(fullname=True)) + newl
s += str("Type: %s Flags: %s" % (target_obj.get_type(),
target_obj.get_flags())) + newl
s += str("Desc: %s" % target_obj.get_description(no_parsing=True)) + newl
#s += str("Desc: %s" % target_obj.get_attribute_value('desc')) + newl
s += str("Owner: %s " % target_obj.get_owner()) + newl
s += str("Zone: %s" % target_obj.get_zone()) + newl
s += str("Parent: %s " % target_obj.get_script_parent()) + newl

View file

@ -296,7 +296,7 @@ def cmd_create(command):
"location": source_object,
"owner": source_object}
new_object = Object.objects.create_object(odat)
new_object.set_attribute('desc', 'Nothing special.')
if len(eq_args)>1:
parent_str = eq_args[1]
if parent_str and new_object.set_script_parent(parent_str):
@ -797,12 +797,12 @@ def cmd_description(command):
return
new_desc = eq_args[1]
if new_desc == '':
source_object.emit_to("%s - DESCRIPTION cleared." % target_obj)
target_obj.set_description(None)
if not new_desc:
source_object.emit_to("%s - description cleared." % target_obj)
target_obj.set_attribute('desc', 'Nothing special.')
else:
source_object.emit_to("%s - DESCRIPTION set." % target_obj)
target_obj.set_description(new_desc)
source_object.emit_to("%s - description set." % target_obj)
target_obj.set_attribute('desc', new_desc)
GLOBAL_CMD_TABLE.add_command("@describe", cmd_description)
def cmd_recover(command):

View file

@ -33,6 +33,7 @@ def create_objects():
# Create the matching PLAYER object in the object DB.
god_user_obj = Object(id=1, type=defines_global.OTYPE_PLAYER)
god_user_obj.set_name(god_user.username)
god_user_obj.set_attribute('desc', 'You are Player #1.')
god_user_obj.scriptlink.at_player_creation()
god_user_obj.save()
@ -40,7 +41,7 @@ def create_objects():
limbo_obj = Object(id=2, type=defines_global.OTYPE_ROOM)
limbo_obj.set_owner(god_user_obj)
limbo_obj.set_name('%ch%ccLimbo%cn')
limbo_obj.set_description("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.")
limbo_obj.set_attribute('desc',"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.")
limbo_obj.scriptlink.at_object_creation()
limbo_obj.save()

View file

@ -113,8 +113,10 @@ class Object(models.Model):
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.
description = models.TextField(blank=True, null=True)
#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)
@ -128,7 +130,6 @@ class Object(models.Model):
#state system can set a particular command table to be used.
state = None
def __cmp__(self, other):
"""
Used to figure out if one object is the same as another.
@ -409,39 +410,34 @@ class Object(models.Model):
return "%s%s" % (parse_ansi(name_string.split(';')[0],
strip_ansi=no_ansi), dbref_string)
def set_description(self, new_desc):
"""
Set an objects description
"""
if new_desc == '':
self.description = None
else:
self.description = new_desc
self.save()
## def set_description(self, new_desc=''):
## """
## Set an objects description
## """
## if not new_desc:
## self.set_attribute('desc', 'Nothing special')
## #self.description = None
## else:
## self.set_attribute('desc', new_desc)
## #self.description = new_desc
## self.save()
def get_description(self, no_parsing=False, wrap_text=False):
"""
Returns an object's ANSI'd description or None if description is not
set.
"""
try:
# If no description is set, return None
if self.description is None:
return None
# Evaluate ANSI and stuff?
if no_parsing:
retval = self.description
else:
retval = parse_ansi(self.description)
# Default to a 78 character wrap.
if wrap_text:
return functions_general.word_wrap(retval)
else:
return retval
except:
# No description attribute present, return empty string.
return None
## def get_description(self, no_parsing=False, wrap_text=False):
## """
## Returns an object's ANSI'd description or None if description is not
## set.
## """
## desc = self.get_attribute_value('desc')
## if desc:
## if not no_parsing:
## desc = parse_ansi(desc)
## if wrap_text:
## return functions_general.word_wrap(desc)
## else:
## return desc
## else:
## # No description attribute present, return empty string.
## return ""
def get_flags(self):
"""
@ -580,13 +576,13 @@ class Object(models.Model):
attrib_obj = \
Attribute.objects.filter(attr_object=self).filter(attr_name__iexact=attribute)[0]
if new_value:
if new_value != None:
#pickle if anything else than str
if type(new_value) != type(str()):
new_value = pickle.dumps(new_value)#,pickle.HIGHEST_PROTOCOL)
ispickled = True
else:
new_value = new_value.strip()
new_value = new_value
ispickled = False
if attrib_obj:
@ -605,7 +601,7 @@ class Object(models.Model):
new_attrib.save()
elif attrib_obj:
# If you do something like @set me=attrib: , destroy the attrib.
# If you do something like @set me=attrib: , destroy the attrib.
attrib_obj.delete()

View file

@ -98,11 +98,11 @@ class EvenniaBasicObject(object):
else:
show_dbrefs = False
description = target_obj.get_description()
description = target_obj.get_attribute_value('desc')
if description is not None:
retval = "%s\r\n%s" % (
target_obj.get_name(show_dbref=show_dbrefs),
target_obj.get_description(),
target_obj.get_attribute_value('desc'),
)
else:
retval = "%s" % (