Make numbered_names use get_display_name; make dbref display separate method
This commit is contained in:
parent
d893cfd46e
commit
cbe3d4c738
14 changed files with 242 additions and 122 deletions
|
|
@ -183,7 +183,7 @@ class TestEvscaperoomCommands(BaseEvenniaCommandTest):
|
|||
self.call(
|
||||
commands.CmdEmote(),
|
||||
"/me smiles to /obj",
|
||||
f"Char(#{self.char1.id}) smiles to Obj(#{self.obj1.id})",
|
||||
f"Char smiles to Obj.",
|
||||
)
|
||||
|
||||
def test_focus_interaction(self):
|
||||
|
|
|
|||
|
|
@ -77,7 +77,15 @@ from collections import defaultdict
|
|||
from django.conf import settings
|
||||
from evennia import DefaultCharacter, DefaultObject, default_cmds
|
||||
from evennia.commands.default.muxcommand import MuxCommand
|
||||
from evennia.utils import at_search_result, crop, evtable, inherits_from, int2str, iter_to_str
|
||||
from evennia.utils import (
|
||||
at_search_result,
|
||||
crop,
|
||||
evtable,
|
||||
group_objects_by_key_and_desc,
|
||||
inherits_from,
|
||||
int2str,
|
||||
iter_to_str,
|
||||
)
|
||||
from evennia.utils.ansi import raw as raw_ansi
|
||||
|
||||
# Options start here.
|
||||
|
|
@ -660,11 +668,10 @@ class CmdInventory(MuxCommand):
|
|||
carried = [obj for obj in items if not obj.db.worn]
|
||||
carry_table = self.styled_table(border="header")
|
||||
|
||||
for item in carried:
|
||||
singular, _ = item.get_numbered_name(1, self.caller)
|
||||
for key, desc, _ in group_objects_by_key_and_desc(carried, caller=self.caller):
|
||||
carry_table.add_row(
|
||||
f"{singular}|n",
|
||||
"{}|n".format(crop(raw_ansi(item.db.desc or ""), width=50) or ""),
|
||||
f"{key}|n",
|
||||
"{}|n".format(crop(raw_ansi(desc or ""), width=50) or ""),
|
||||
)
|
||||
message_list.extend(
|
||||
["|wYou are carrying:|n", str(carry_table) if carry_table.nrows > 0 else " Nothing."]
|
||||
|
|
@ -674,18 +681,17 @@ class CmdInventory(MuxCommand):
|
|||
worn = [obj for obj in items if obj.db.worn]
|
||||
wear_table = self.styled_table(border="header")
|
||||
|
||||
for item in worn:
|
||||
singular, _ = item.get_numbered_name(1, self.caller)
|
||||
for key, desc, _ in group_objects_by_key_and_desc(worn, caller=self.caller):
|
||||
wear_table.add_row(
|
||||
f"{singular}|n",
|
||||
"{}|n".format(crop(raw_ansi(item.db.desc or ""), width=50) or ""),
|
||||
f"{key}|n",
|
||||
"{}|n".format(crop(raw_ansi(desc or ""), width=50) or ""),
|
||||
)
|
||||
message_list.extend(
|
||||
["You are wearing:|n", str(wear_table) if wear_table.nrows > 0 else " Nothing."]
|
||||
)
|
||||
|
||||
# return the composite message
|
||||
self.caller.msg("\n".join(message_list))
|
||||
self.caller.msg(text=("\n".join(message_list), {"type": "inventory"}))
|
||||
|
||||
|
||||
class ClothedCharacterCmdSet(default_cmds.CharacterCmdSet):
|
||||
|
|
|
|||
|
|
@ -19,9 +19,11 @@ class TestClothingCmd(BaseEvenniaCommandTest):
|
|||
self.wearer.location = self.room
|
||||
# Make a test hat
|
||||
self.test_hat = create_object(clothing.ContribClothing, key="test hat")
|
||||
self.test_hat.db.desc = "A test hat."
|
||||
self.test_hat.db.clothing_type = "hat"
|
||||
# Make a test scarf
|
||||
self.test_scarf = create_object(clothing.ContribClothing, key="test scarf")
|
||||
self.test_scarf.db.desc = "A test scarf."
|
||||
self.test_scarf.db.clothing_type = "accessory"
|
||||
|
||||
def test_clothingcommands(self):
|
||||
|
|
@ -40,7 +42,10 @@ class TestClothingCmd(BaseEvenniaCommandTest):
|
|||
self.call(
|
||||
clothing.CmdInventory(),
|
||||
"",
|
||||
"You are carrying:\n a test scarf \n a test hat \nYou are wearing:\n Nothing.",
|
||||
(
|
||||
"You are carrying:\n a test hat A test hat. \n a test scarf A test"
|
||||
" scarf. \nYou are wearing:\n Nothing."
|
||||
),
|
||||
caller=self.wearer,
|
||||
use_assertequal=True,
|
||||
)
|
||||
|
|
@ -71,7 +76,10 @@ class TestClothingCmd(BaseEvenniaCommandTest):
|
|||
self.call(
|
||||
clothing.CmdInventory(),
|
||||
"",
|
||||
"You are carrying:\n Nothing.\nYou are wearing:\n a test scarf \n a test hat ",
|
||||
(
|
||||
"You are carrying:\n Nothing.\nYou are wearing:\n a test hat A test hat. \n"
|
||||
" a test scarf A test scarf. "
|
||||
),
|
||||
caller=self.wearer,
|
||||
use_assertequal=True,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
from evennia import create_object
|
||||
from evennia.utils.test_resources import BaseEvenniaCommandTest, BaseEvenniaTest # noqa
|
||||
from evennia.utils.test_resources import BaseEvenniaCommandTest # noqa
|
||||
from evennia.utils.test_resources import BaseEvenniaTest
|
||||
|
||||
from .containers import CmdContainerGet, CmdContainerLook, CmdPut, ContribContainer
|
||||
|
||||
|
|
@ -40,9 +41,17 @@ class TestContainerCmds(BaseEvenniaCommandTest):
|
|||
# get normally
|
||||
self.call(CmdContainerGet(), "Obj", "You pick up an Obj.")
|
||||
# put in the container
|
||||
self.call(CmdPut(), "obj in box", "You put an Obj in a Box.")
|
||||
self.call(
|
||||
CmdPut(),
|
||||
"obj in box",
|
||||
"You put an Obj in a Box.",
|
||||
)
|
||||
# get from the container
|
||||
self.call(CmdContainerGet(), "obj from box", "You get an Obj from a Box.")
|
||||
self.call(
|
||||
CmdContainerGet(),
|
||||
"obj from box",
|
||||
"You get an Obj from a Box.",
|
||||
)
|
||||
|
||||
def test_locked_get_put(self):
|
||||
# lock container
|
||||
|
|
|
|||
|
|
@ -6,11 +6,10 @@ Testing of ExtendedRoom contrib
|
|||
import datetime
|
||||
|
||||
from django.conf import settings
|
||||
from mock import Mock, patch
|
||||
from parameterized import parameterized
|
||||
|
||||
from evennia import create_object
|
||||
from evennia.utils.test_resources import BaseEvenniaCommandTest, EvenniaTestCase
|
||||
from mock import Mock, patch
|
||||
from parameterized import parameterized
|
||||
|
||||
from . import extended_room
|
||||
|
||||
|
|
@ -195,7 +194,7 @@ class TestExtendedRoomCommands(BaseEvenniaCommandTest):
|
|||
extended_room.CmdExtendedRoomDesc(),
|
||||
"",
|
||||
f"""
|
||||
Room Room(#{self.room1.id}) Season: autumn. Time: afternoon. States: None
|
||||
Room Room Season: autumn. Time: afternoon. States: None
|
||||
|
||||
Room state (default) (active):
|
||||
Base room description.
|
||||
|
|
@ -218,7 +217,7 @@ Base room description.
|
|||
extended_room.CmdExtendedRoomDesc(),
|
||||
"",
|
||||
f"""
|
||||
Room Room(#{self.room1.id}) Season: autumn. Time: afternoon. States: None
|
||||
Room Room Season: autumn. Time: afternoon. States: None
|
||||
|
||||
Room state burning:
|
||||
Burning description.
|
||||
|
|
@ -235,8 +234,10 @@ Base room description.
|
|||
self.call(
|
||||
extended_room.CmdExtendedRoomDesc(),
|
||||
"/del/burning/spring",
|
||||
"The burning-description was deleted, if it existed.|The spring-description was"
|
||||
" deleted, if it existed",
|
||||
(
|
||||
"The burning-description was deleted, if it existed.|The spring-description was"
|
||||
" deleted, if it existed"
|
||||
),
|
||||
)
|
||||
# add autumn, which should be active
|
||||
self.call(
|
||||
|
|
@ -248,7 +249,7 @@ Base room description.
|
|||
extended_room.CmdExtendedRoomDesc(),
|
||||
"",
|
||||
f"""
|
||||
Room Room(#{self.room1.id}) Season: autumn. Time: afternoon. States: None
|
||||
Room Room Season: autumn. Time: afternoon. States: None
|
||||
|
||||
Room state autumn (active):
|
||||
Autumn description.
|
||||
|
|
@ -285,8 +286,8 @@ test: Test detail.
|
|||
self.call(
|
||||
extended_room.CmdExtendedRoomDetail(),
|
||||
"",
|
||||
f"""
|
||||
The room Room(#{self.room1.id}) doesn't have any details.
|
||||
"""
|
||||
The room Room doesn't have any details.
|
||||
""".strip(),
|
||||
)
|
||||
|
||||
|
|
@ -306,7 +307,7 @@ The room Room(#{self.room1.id}) doesn't have any details.
|
|||
self.call(
|
||||
extended_room.CmdExtendedRoomState(),
|
||||
"",
|
||||
f"Room states (not counting automatic time/season) on Room(#{self.room1.id}):\n None",
|
||||
"Room states (not counting automatic time/season) on Room:\n None",
|
||||
)
|
||||
|
||||
# add room states
|
||||
|
|
@ -323,8 +324,7 @@ The room Room(#{self.room1.id}) doesn't have any details.
|
|||
self.call(
|
||||
extended_room.CmdExtendedRoomState(),
|
||||
"",
|
||||
f"Room states (not counting automatic time/season) on Room(#{self.room1.id}):\n "
|
||||
"'burning' and 'windy'",
|
||||
f"Room states (not counting automatic time/season) on Room:\n 'burning' and 'windy'",
|
||||
)
|
||||
# toggle windy
|
||||
self.call(
|
||||
|
|
@ -335,8 +335,7 @@ The room Room(#{self.room1.id}) doesn't have any details.
|
|||
self.call(
|
||||
extended_room.CmdExtendedRoomState(),
|
||||
"",
|
||||
f"Room states (not counting automatic time/season) on Room(#{self.room1.id}):\n "
|
||||
"'burning'",
|
||||
f"Room states (not counting automatic time/season) on Room:\n 'burning'",
|
||||
)
|
||||
# add a autumn state and make sure we override it
|
||||
self.room1.add_desc("Autumn description.", room_state="autumn")
|
||||
|
|
@ -387,13 +386,17 @@ The room Room(#{self.room1.id}) doesn't have any details.
|
|||
self.call(
|
||||
extended_room.CmdExtendedRoomLook(),
|
||||
"",
|
||||
f"Room(#{self.room1.id})\nThis is a nice autumnal forest. The afternoon sun is"
|
||||
" shining through the trees.",
|
||||
(
|
||||
f"Room(#{self.room1.id})\nThis is a nice autumnal forest. The afternoon sun is"
|
||||
" shining through the trees."
|
||||
),
|
||||
)
|
||||
self.room1.add_room_state("burning")
|
||||
self.call(
|
||||
extended_room.CmdExtendedRoomLook(),
|
||||
"",
|
||||
f"Room(#{self.room1.id})\nThis is a nice autumnal forest. The afternoon sun is"
|
||||
" shining through the trees and this place is on fire!",
|
||||
(
|
||||
f"Room(#{self.room1.id})\nThis is a nice autumnal forest. The afternoon sun is"
|
||||
" shining through the trees and this place is on fire!"
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -154,18 +154,12 @@ from string import punctuation
|
|||
|
||||
import inflect
|
||||
from django.conf import settings
|
||||
|
||||
from evennia.commands.cmdset import CmdSet
|
||||
from evennia.commands.command import Command
|
||||
from evennia.objects.models import ObjectDB
|
||||
from evennia.objects.objects import DefaultCharacter, DefaultObject
|
||||
from evennia.utils import ansi, logger
|
||||
from evennia.utils.utils import (
|
||||
iter_to_str,
|
||||
lazy_property,
|
||||
make_iter,
|
||||
variable_from_module,
|
||||
)
|
||||
from evennia.utils.utils import iter_to_str, lazy_property, make_iter, variable_from_module
|
||||
|
||||
_INFLECT = inflect.engine()
|
||||
|
||||
|
|
@ -1343,13 +1337,15 @@ class ContribRPObject(DefaultObject):
|
|||
# in eventual error reporting later (not their keys). Doing
|
||||
# it like this e.g. allows for use of the typeclass kwarg
|
||||
# limiter.
|
||||
results.extend([obj for obj in search_obj(candidate.key) if obj not in results])
|
||||
results.extend(
|
||||
[obj for obj in search_obj(candidate.key, **kwargs) if obj not in results]
|
||||
)
|
||||
|
||||
if not results and is_builder:
|
||||
# builders get a chance to search only by key+alias
|
||||
results = search_obj(searchdata, candidates=candidates, **kwargs)
|
||||
# builders get to do a global search by key+alias
|
||||
results = search_obj(searchdata, **kwargs)
|
||||
else:
|
||||
# global searches / #drefs end up here. Global searches are
|
||||
# global searches with #drefs end up here. Global searches are
|
||||
# only done in code, so is controlled, #dbrefs are turned off
|
||||
# for non-Builders.
|
||||
results = search_obj(searchdata, **kwargs)
|
||||
|
|
@ -1409,10 +1405,6 @@ class ContribRPObject(DefaultObject):
|
|||
# use own sdesc as a fallback
|
||||
sdesc = self.sdesc.get()
|
||||
|
||||
# add dbref is looker has control access and `noid` is not set
|
||||
if self.access(looker, access_type="control") and not kwargs.get("noid", False):
|
||||
sdesc = f"{sdesc}(#{self.id})"
|
||||
|
||||
return self.get_posed_sdesc(sdesc) if kwargs.get("pose", False) else sdesc
|
||||
|
||||
def get_display_characters(self, looker, pose=True, **kwargs):
|
||||
|
|
@ -1545,10 +1537,6 @@ class ContribRPCharacter(DefaultCharacter, ContribRPObject):
|
|||
# use own sdesc as a fallback
|
||||
sdesc = self.sdesc.get()
|
||||
|
||||
# add dbref is looker has control access and `noid` is not set
|
||||
if self.access(looker, access_type="control") and not kwargs.get("noid", False):
|
||||
sdesc = f"{sdesc}(#{self.id})"
|
||||
|
||||
return self.get_posed_sdesc(sdesc) if kwargs.get("pose", False) else sdesc
|
||||
|
||||
def at_object_creation(self):
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ Tests for RP system
|
|||
import time
|
||||
|
||||
from anything import Anything
|
||||
|
||||
from evennia import DefaultObject, create_object, default_cmds
|
||||
from evennia.commands.default.tests import BaseEvenniaCommandTest
|
||||
from evennia.utils.test_resources import BaseEvenniaTest
|
||||
|
|
@ -414,14 +413,14 @@ class TestRPSystemCommands(BaseEvenniaCommandTest):
|
|||
|
||||
expected_first_call = [
|
||||
"More than one match for 'Mushroom' (please narrow target):",
|
||||
f" Mushroom({mushroom1.dbref})-1 []",
|
||||
f" Mushroom({mushroom2.dbref})-2 []",
|
||||
f" Mushroom-1 []",
|
||||
f" Mushroom-2 []",
|
||||
]
|
||||
|
||||
self.call(default_cmds.CmdLook(), "Mushroom", "\n".join(expected_first_call)) # PASSES
|
||||
|
||||
expected_second_call = f"Mushroom({mushroom1.dbref})\nThe first mushroom is brown."
|
||||
expected_second_call = f"Mushroom(#{mushroom1.id})\nThe first mushroom is brown."
|
||||
self.call(default_cmds.CmdLook(), "Mushroom-1", expected_second_call) # FAILS
|
||||
|
||||
expected_third_call = f"Mushroom({mushroom2.dbref})\nThe second mushroom is red."
|
||||
expected_third_call = f"Mushroom(#{mushroom2.id})\nThe second mushroom is red."
|
||||
self.call(default_cmds.CmdLook(), "Mushroom-2", expected_third_call) # FAILS
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue