run black
This commit is contained in:
parent
371ec9f7fe
commit
85b0b3cca8
2 changed files with 95 additions and 51 deletions
|
|
@ -80,7 +80,7 @@ from evennia.utils import at_search_result, evtable, inherits_from, iter_to_str
|
||||||
|
|
||||||
# Options start here.
|
# Options start here.
|
||||||
# Maximum character length of 'wear style' strings, or None for unlimited.
|
# Maximum character length of 'wear style' strings, or None for unlimited.
|
||||||
WEARSTYLE_MAXLENGTH = getattr(settings, 'CLOTHING_WEARSTYLE_MAXLENGTH', 50)
|
WEARSTYLE_MAXLENGTH = getattr(settings, "CLOTHING_WEARSTYLE_MAXLENGTH", 50)
|
||||||
|
|
||||||
# The rest of these options have to do with clothing types. ContribClothing types are optional,
|
# The rest of these options have to do with clothing types. ContribClothing types are optional,
|
||||||
# but can be used to give better control over how different items of clothing behave. You
|
# but can be used to give better control over how different items of clothing behave. You
|
||||||
|
|
@ -89,7 +89,10 @@ WEARSTYLE_MAXLENGTH = getattr(settings, 'CLOTHING_WEARSTYLE_MAXLENGTH', 50)
|
||||||
|
|
||||||
# The order in which clothing types appear on the description. Untyped clothing or clothing
|
# The order in which clothing types appear on the description. Untyped clothing or clothing
|
||||||
# with a type not given in this list goes last.
|
# with a type not given in this list goes last.
|
||||||
CLOTHING_TYPE_ORDER = getattr(settings, 'CLOTHING_TYPE_ORDERED', [
|
CLOTHING_TYPE_ORDER = getattr(
|
||||||
|
settings,
|
||||||
|
"CLOTHING_TYPE_ORDERED",
|
||||||
|
[
|
||||||
"hat",
|
"hat",
|
||||||
"jewelry",
|
"jewelry",
|
||||||
"top",
|
"top",
|
||||||
|
|
@ -101,23 +104,30 @@ CLOTHING_TYPE_ORDER = getattr(settings, 'CLOTHING_TYPE_ORDERED', [
|
||||||
"socks",
|
"socks",
|
||||||
"shoes",
|
"shoes",
|
||||||
"accessory",
|
"accessory",
|
||||||
])
|
],
|
||||||
|
)
|
||||||
# The maximum number of each type of clothes that can be worn. Unlimited if untyped or not specified.
|
# The maximum number of each type of clothes that can be worn. Unlimited if untyped or not specified.
|
||||||
CLOTHING_TYPE_LIMIT = getattr(settings, 'CLOTHING_TYPE_LIMIT', {"hat": 1, "gloves": 1, "socks": 1, "shoes": 1})
|
CLOTHING_TYPE_LIMIT = getattr(
|
||||||
|
settings, "CLOTHING_TYPE_LIMIT", {"hat": 1, "gloves": 1, "socks": 1, "shoes": 1}
|
||||||
|
)
|
||||||
# The maximum number of clothing items that can be worn, or None for unlimited.
|
# The maximum number of clothing items that can be worn, or None for unlimited.
|
||||||
CLOTHING_OVERALL_LIMIT = getattr(settings, 'CLOTHING_OVERALL_LIMIT', 20)
|
CLOTHING_OVERALL_LIMIT = getattr(settings, "CLOTHING_OVERALL_LIMIT", 20)
|
||||||
# What types of clothes will automatically cover what other types of clothes when worn.
|
# What types of clothes will automatically cover what other types of clothes when worn.
|
||||||
# Note that clothing only gets auto-covered if it's already worn when you put something
|
# Note that clothing only gets auto-covered if it's already worn when you put something
|
||||||
# on that auto-covers it - for example, it's perfectly possible to have your underpants
|
# on that auto-covers it - for example, it's perfectly possible to have your underpants
|
||||||
# showing if you put them on after your pants!
|
# showing if you put them on after your pants!
|
||||||
CLOTHING_TYPE_AUTOCOVER = getattr(settings, 'CLOTHING_TYPE_AUTOCOVER', {
|
CLOTHING_TYPE_AUTOCOVER = getattr(
|
||||||
|
settings,
|
||||||
|
"CLOTHING_TYPE_AUTOCOVER",
|
||||||
|
{
|
||||||
"top": ["undershirt"],
|
"top": ["undershirt"],
|
||||||
"bottom": ["underpants"],
|
"bottom": ["underpants"],
|
||||||
"fullbody": ["undershirt", "underpants"],
|
"fullbody": ["undershirt", "underpants"],
|
||||||
"shoes": ["socks"],
|
"shoes": ["socks"],
|
||||||
})
|
},
|
||||||
|
)
|
||||||
# Types of clothes that can't be used to cover other clothes.
|
# Types of clothes that can't be used to cover other clothes.
|
||||||
CLOTHING_TYPE_CANT_COVER_WITH = getattr(settings, 'CLOTHING_TYPE_AUTOCOVER', ["jewelry"])
|
CLOTHING_TYPE_CANT_COVER_WITH = getattr(settings, "CLOTHING_TYPE_AUTOCOVER", ["jewelry"])
|
||||||
|
|
||||||
|
|
||||||
# HELPER FUNCTIONS START HERE
|
# HELPER FUNCTIONS START HERE
|
||||||
|
|
@ -248,7 +258,13 @@ class ContribClothing(DefaultObject):
|
||||||
to_cover = []
|
to_cover = []
|
||||||
if clothing_type := self.db.clothing_type:
|
if clothing_type := self.db.clothing_type:
|
||||||
if autocover_types := CLOTHING_TYPE_AUTOCOVER.get(clothing_type):
|
if autocover_types := CLOTHING_TYPE_AUTOCOVER.get(clothing_type):
|
||||||
to_cover.extend( [ garment for garment in get_worn_clothes(wearer) if garment.db.clothing_type in autocover_types ] )
|
to_cover.extend(
|
||||||
|
[
|
||||||
|
garment
|
||||||
|
for garment in get_worn_clothes(wearer)
|
||||||
|
if garment.db.clothing_type in autocover_types
|
||||||
|
]
|
||||||
|
)
|
||||||
for garment in to_cover:
|
for garment in to_cover:
|
||||||
garment.db.covered_by = self
|
garment.db.covered_by = self
|
||||||
|
|
||||||
|
|
@ -309,6 +325,7 @@ class ContribClothing(DefaultObject):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class ClothedCharacter(DefaultCharacter):
|
class ClothedCharacter(DefaultCharacter):
|
||||||
"""
|
"""
|
||||||
Character that displays worn clothing when looked at. You can also
|
Character that displays worn clothing when looked at. You can also
|
||||||
|
|
@ -339,7 +356,9 @@ class ClothedCharacter(DefaultCharacter):
|
||||||
|
|
||||||
# Create outfit string
|
# Create outfit string
|
||||||
if outfit_list:
|
if outfit_list:
|
||||||
outfit = f"{self.get_display_name(looker, **kwargs)} is wearing {iter_to_str(outfit_list)}."
|
outfit = (
|
||||||
|
f"{self.get_display_name(looker, **kwargs)} is wearing {iter_to_str(outfit_list)}."
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
outfit = f"{self.get_display_name(looker, **kwargs)} is wearing nothing."
|
outfit = f"{self.get_display_name(looker, **kwargs)} is wearing nothing."
|
||||||
|
|
||||||
|
|
@ -361,8 +380,13 @@ class ClothedCharacter(DefaultCharacter):
|
||||||
Returns:
|
Returns:
|
||||||
str: A string describing the things in object.
|
str: A string describing the things in object.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _filter_visible(obj_list):
|
def _filter_visible(obj_list):
|
||||||
return (obj for obj in obj_list if obj != looker and obj.access(looker, "view") and not obj.db.worn)
|
return (
|
||||||
|
obj
|
||||||
|
for obj in obj_list
|
||||||
|
if obj != looker and obj.access(looker, "view") and not obj.db.worn
|
||||||
|
)
|
||||||
|
|
||||||
# sort and handle same-named things
|
# sort and handle same-named things
|
||||||
things = _filter_visible(self.contents_get(content_type="object"))
|
things = _filter_visible(self.contents_get(content_type="object"))
|
||||||
|
|
@ -378,7 +402,12 @@ class ClothedCharacter(DefaultCharacter):
|
||||||
singular, plural = thing.get_numbered_name(nthings, looker, key=thingname)
|
singular, plural = thing.get_numbered_name(nthings, looker, key=thingname)
|
||||||
thing_names.append(singular if nthings == 1 else plural)
|
thing_names.append(singular if nthings == 1 else plural)
|
||||||
thing_names = iter_to_str(thing_names)
|
thing_names = iter_to_str(thing_names)
|
||||||
return f"\n{self.get_display_name(looker, **kwargs)} is carrying {thing_names}" if thing_names else ""
|
return (
|
||||||
|
f"\n{self.get_display_name(looker, **kwargs)} is carrying {thing_names}"
|
||||||
|
if thing_names
|
||||||
|
else ""
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# COMMANDS START HERE
|
# COMMANDS START HERE
|
||||||
|
|
||||||
|
|
@ -443,7 +472,9 @@ class CmdWear(MuxCommand):
|
||||||
else:
|
else:
|
||||||
# Adjust the wearstyle
|
# Adjust the wearstyle
|
||||||
clothing.db.worn = self.rhs
|
clothing.db.worn = self.rhs
|
||||||
self.caller.location.msg_contents(f"$You() $conj(wear) {clothing.name} {self.rhs}.", from_obj=self.caller)
|
self.caller.location.msg_contents(
|
||||||
|
f"$You() $conj(wear) {clothing.name} {self.rhs}.", from_obj=self.caller
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
already_worn = get_worn_clothes(self.caller)
|
already_worn = get_worn_clothes(self.caller)
|
||||||
|
|
@ -537,9 +568,7 @@ class CmdCover(MuxCommand):
|
||||||
self.caller.msg(f"{cover_with.name} is already covered by {covered_by.name}.")
|
self.caller.msg(f"{cover_with.name} is already covered by {covered_by.name}.")
|
||||||
return
|
return
|
||||||
if covered_by := to_cover.db.covered_by:
|
if covered_by := to_cover.db.covered_by:
|
||||||
self.caller.msg(
|
self.caller.msg(f"{to_cover.name} is already covered by {covered_by.name}.")
|
||||||
f"{to_cover.name} is already covered by {covered_by.name}."
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Put on the item to cover with if it's not on already
|
# Put on the item to cover with if it's not on already
|
||||||
|
|
@ -547,7 +576,9 @@ class CmdCover(MuxCommand):
|
||||||
cover_with.wear(self.caller, True)
|
cover_with.wear(self.caller, True)
|
||||||
to_cover.db.covered_by = cover_with
|
to_cover.db.covered_by = cover_with
|
||||||
|
|
||||||
self.caller.location.msg_contents(f"$You() $conj(cover) {to_cover.name} with {cover_with.name}.", from_obj=self.caller)
|
self.caller.location.msg_contents(
|
||||||
|
f"$You() $conj(cover) {to_cover.name} with {cover_with.name}.", from_obj=self.caller
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class CmdUncover(MuxCommand):
|
class CmdUncover(MuxCommand):
|
||||||
|
|
@ -583,7 +614,9 @@ class CmdUncover(MuxCommand):
|
||||||
self.caller.msg(f"{clothing.name} is under too many layers to uncover.")
|
self.caller.msg(f"{clothing.name} is under too many layers to uncover.")
|
||||||
return
|
return
|
||||||
clothing.db.covered_by = None
|
clothing.db.covered_by = None
|
||||||
self.caller.location.msg_contents(f"$You() $conj(uncover) {clothing.name}.", from_obj=self.caller)
|
self.caller.location.msg_contents(
|
||||||
|
f"$You() $conj(uncover) {clothing.name}.", from_obj=self.caller
|
||||||
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.caller.msg(f"{clothing.name} isn't covered by anything.")
|
self.caller.msg(f"{clothing.name} isn't covered by anything.")
|
||||||
|
|
@ -627,7 +660,9 @@ class CmdInventory(MuxCommand):
|
||||||
|
|
||||||
message_list.append("|wYou are carrying:|n")
|
message_list.append("|wYou are carrying:|n")
|
||||||
for item in carried:
|
for item in carried:
|
||||||
carry_table.add_row(item.get_display_name(self.caller), item.get_display_desc(self.caller))
|
carry_table.add_row(
|
||||||
|
item.get_display_name(self.caller), item.get_display_desc(self.caller)
|
||||||
|
)
|
||||||
if carry_table.nrows == 0:
|
if carry_table.nrows == 0:
|
||||||
carry_table.add_row("Nothing.", "")
|
carry_table.add_row("Nothing.", "")
|
||||||
message_list.append(str(carry_table))
|
message_list.append(str(carry_table))
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,10 @@ class TestClothingCmd(BaseEvenniaCommandTest):
|
||||||
def test_clothingcommands(self):
|
def test_clothingcommands(self):
|
||||||
# Test inventory command.
|
# Test inventory command.
|
||||||
self.call(
|
self.call(
|
||||||
clothing.CmdInventory(), "", "You are not carrying or wearing anything.", caller=self.wearer
|
clothing.CmdInventory(),
|
||||||
|
"",
|
||||||
|
"You are not carrying or wearing anything.",
|
||||||
|
caller=self.wearer,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Test wear command
|
# Test wear command
|
||||||
|
|
@ -57,7 +60,10 @@ class TestClothingCmd(BaseEvenniaCommandTest):
|
||||||
# Test remove command.
|
# Test remove command.
|
||||||
self.call(clothing.CmdRemove(), "", "Could not find ''.", caller=self.wearer)
|
self.call(clothing.CmdRemove(), "", "Could not find ''.", caller=self.wearer)
|
||||||
self.call(
|
self.call(
|
||||||
clothing.CmdRemove(), "hat", "You have to take off test scarf first.", caller=self.wearer
|
clothing.CmdRemove(),
|
||||||
|
"hat",
|
||||||
|
"You have to take off test scarf first.",
|
||||||
|
caller=self.wearer,
|
||||||
)
|
)
|
||||||
self.call(
|
self.call(
|
||||||
clothing.CmdRemove(),
|
clothing.CmdRemove(),
|
||||||
|
|
@ -68,7 +74,9 @@ class TestClothingCmd(BaseEvenniaCommandTest):
|
||||||
# Test uncover command.
|
# Test uncover command.
|
||||||
self.test_scarf.wear(self.wearer, True)
|
self.test_scarf.wear(self.wearer, True)
|
||||||
self.test_hat.db.covered_by = self.test_scarf
|
self.test_hat.db.covered_by = self.test_scarf
|
||||||
self.call(clothing.CmdUncover(), "", "Usage: uncover <worn clothing object>", caller=self.wearer)
|
self.call(
|
||||||
|
clothing.CmdUncover(), "", "Usage: uncover <worn clothing object>", caller=self.wearer
|
||||||
|
)
|
||||||
self.call(clothing.CmdUncover(), "hat", "You uncover test hat.", caller=self.wearer)
|
self.call(clothing.CmdUncover(), "hat", "You uncover test hat.", caller=self.wearer)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -108,7 +116,8 @@ class TestClothingFunc(BaseEvenniaTest):
|
||||||
|
|
||||||
clothes_list = [self.test_shirt, self.test_hat, self.test_pants]
|
clothes_list = [self.test_shirt, self.test_hat, self.test_pants]
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
clothing.order_clothes_list(clothes_list), [self.test_hat, self.test_shirt, self.test_pants]
|
clothing.order_clothes_list(clothes_list),
|
||||||
|
[self.test_hat, self.test_shirt, self.test_pants],
|
||||||
)
|
)
|
||||||
|
|
||||||
self.test_hat.wear(self.wearer, True)
|
self.test_hat.wear(self.wearer, True)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue