More cleanup of the RPsystem contrib's typeclass hierarchy.
This commit is contained in:
parent
45371289f4
commit
bac8f51401
1 changed files with 45 additions and 12 deletions
|
|
@ -922,8 +922,7 @@ class RecogHandler(object):
|
||||||
class RPObject(DefaultObject):
|
class RPObject(DefaultObject):
|
||||||
"""
|
"""
|
||||||
This class is meant as a mix-in or parent for objects in an
|
This class is meant as a mix-in or parent for objects in an
|
||||||
rp-heavy game. It implements the base functionality for sdescs,
|
rp-heavy game. It implements the base functionality for poses.
|
||||||
name replacement and look extensions.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def at_object_creation(self):
|
def at_object_creation(self):
|
||||||
|
|
@ -986,6 +985,9 @@ class RPObject(DefaultObject):
|
||||||
including the DBREF if this user is privileged to control
|
including the DBREF if this user is privileged to control
|
||||||
said object.
|
said object.
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
The RPObject version doesn't add color to its display.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
idstr = "(#%s)" % self.id if self.access(looker, access_type='control') else ""
|
idstr = "(#%s)" % self.id if self.access(looker, access_type='control') else ""
|
||||||
try:
|
try:
|
||||||
|
|
@ -994,8 +996,15 @@ class RPObject(DefaultObject):
|
||||||
recog = None
|
recog = None
|
||||||
sdesc = recog or (hasattr(self, "sdesc") and self.sdesc.get()) or self.key
|
sdesc = recog or (hasattr(self, "sdesc") and self.sdesc.get()) or self.key
|
||||||
pose = " %s" % self.db.pose or "" if kwargs.get("pose", False) else ""
|
pose = " %s" % self.db.pose or "" if kwargs.get("pose", False) else ""
|
||||||
return "{c%s{n%s%s" % (sdesc, idstr, pose)
|
return "%s%s%s" % (sdesc, idstr, pose)
|
||||||
|
|
||||||
|
|
||||||
|
class RPRoom(DefaultRoom):
|
||||||
|
"""
|
||||||
|
Rooms don't have sdescs nor poses of their own, so we just modify
|
||||||
|
`return_appearance` here to make sure it properly displays poses
|
||||||
|
of objects in the room.
|
||||||
|
"""
|
||||||
def return_appearance(self, looker):
|
def return_appearance(self, looker):
|
||||||
"""
|
"""
|
||||||
This formats a description. It is the hook a 'look' command
|
This formats a description. It is the hook a 'look' command
|
||||||
|
|
@ -1030,16 +1039,9 @@ class RPObject(DefaultObject):
|
||||||
return string
|
return string
|
||||||
|
|
||||||
|
|
||||||
class RPRoom(DefaultRoom):
|
|
||||||
"""
|
|
||||||
Rooms don't have sdescs nor poses of their own, so we
|
|
||||||
just borrow its return_appearance hook here.
|
|
||||||
"""
|
|
||||||
return_appearance = RPObject.__dict__["return_appearance"]
|
|
||||||
|
|
||||||
class RPCharacter(DefaultCharacter, RPObject):
|
class RPCharacter(DefaultCharacter, RPObject):
|
||||||
"""
|
"""
|
||||||
This is a character aware of RP systems.
|
This is a character class that has poses, sdesc and recog.
|
||||||
"""
|
"""
|
||||||
# Handlers
|
# Handlers
|
||||||
@lazy_property
|
@lazy_property
|
||||||
|
|
@ -1050,6 +1052,37 @@ class RPCharacter(DefaultCharacter, RPObject):
|
||||||
def recog(self):
|
def recog(self):
|
||||||
return RecogHandler(self)
|
return RecogHandler(self)
|
||||||
|
|
||||||
|
def get_display_name(self, looker, **kwargs):
|
||||||
|
"""
|
||||||
|
Displays the name of the object in a viewer-aware manner.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
looker (TypedObject): The object or player that is looking
|
||||||
|
at/getting inforamtion for this object.
|
||||||
|
|
||||||
|
Kwargs:
|
||||||
|
pose (bool): Include the pose (if available) in the return.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
name (str): A string of the sdesc containing the name of the object,
|
||||||
|
if this is defined.
|
||||||
|
including the DBREF if this user is privileged to control
|
||||||
|
said object.
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
The RPCharacter version of this method colors its display to make
|
||||||
|
characters stand out from other objects.
|
||||||
|
|
||||||
|
"""
|
||||||
|
idstr = "(#%s)" % self.id if self.access(looker, access_type='control') else ""
|
||||||
|
try:
|
||||||
|
recog = looker.recog.get(self)
|
||||||
|
except AttributeError:
|
||||||
|
recog = None
|
||||||
|
sdesc = recog or (hasattr(self, "sdesc") and self.sdesc.get()) or self.key
|
||||||
|
pose = " %s" % self.db.pose or "" if kwargs.get("pose", False) else ""
|
||||||
|
return "{c%s{n%s%s" % (sdesc, idstr, pose)
|
||||||
|
|
||||||
def at_object_creation(self):
|
def at_object_creation(self):
|
||||||
"""
|
"""
|
||||||
Called at initial creation.
|
Called at initial creation.
|
||||||
|
|
@ -1065,5 +1098,5 @@ class RPCharacter(DefaultCharacter, RPObject):
|
||||||
|
|
||||||
self.cmdset.add(RPSystemCmdSet, permanent=True)
|
self.cmdset.add(RPSystemCmdSet, permanent=True)
|
||||||
# initializing sdesc
|
# initializing sdesc
|
||||||
self.sdesc.add("A normal item")
|
self.sdesc.add("A normal person")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue