Ran black on branc

This commit is contained in:
Griatch 2019-12-16 20:31:42 +01:00
parent 6effb6f456
commit 4ea6209123
230 changed files with 7108 additions and 2395 deletions

View file

@ -234,7 +234,9 @@ class CmdGiveUp(CmdEvscapeRoom):
self.room.log(f"QUIT: {self.caller.key} used the quit command")
# manually call move hooks
self.room.msg_room(self.caller, f"|r{self.caller.key} gave up and was whisked away!|n")
self.room.msg_room(
self.caller, f"|r{self.caller.key} gave up and was whisked away!|n"
)
self.room.at_object_leave(self.caller, self.caller.home)
self.caller.move_to(self.caller.home, quiet=True, move_hooks=False)
@ -313,7 +315,9 @@ class CmdWho(CmdEvscapeRoom, default_cmds.CmdWho):
for obj in self.room.get_all_characters()
if obj != caller
]
chars = "\n".join([f"{caller.key} - {caller.db.desc.strip()} (you)"] + chars)
chars = "\n".join(
[f"{caller.key} - {caller.db.desc.strip()} (you)"] + chars
)
txt = f"|cPlayers in this room (room-name '{self.room.name}')|n:\n {chars}"
caller.msg(txt)
@ -389,7 +393,9 @@ class CmdEmote(Command):
emote = self.args.strip()
if not emote:
self.caller.msg('Usage: emote /me points to /door, saying "look over there!"')
self.caller.msg(
'Usage: emote /me points to /door, saying "look over there!"'
)
return
speech_clr = "|c"
@ -429,7 +435,9 @@ class CmdEmote(Command):
if target == self.caller:
txt = [f"{self_clr}{self.caller.get_display_name(target)}|n "] + txt
else:
txt = [f"{player_clr}{self.caller.get_display_name(target)}|n "] + txt
txt = [
f"{player_clr}{self.caller.get_display_name(target)}|n "
] + txt
txt = "".join(txt).strip() + ("." if add_period else "")
if not logged and hasattr(self.caller.location, "log"):
self.caller.location.log(f"emote: {txt}")
@ -531,7 +539,10 @@ class CmdRerouter(default_cmds.MuxCommand):
from evennia.commands import cmdhandler
cmdhandler.cmdhandler(
self.session, self.raw_string, cmdobj=CmdFocusInteraction(), cmdobj_key=self.cmdname
self.session,
self.raw_string,
cmdobj=CmdFocusInteraction(),
cmdobj_key=self.cmdname,
)
@ -603,7 +614,9 @@ class CmdStand(CmdEvscapeRoom):
obj, position = pos
self.caller.attributes.remove("position", category=self.room.tagcategory)
del obj.db.positions[self.caller]
self.room.msg_room(self.caller, "~You ~are back standing on the floor again.")
self.room.msg_room(
self.caller, "~You ~are back standing on the floor again."
)
else:
self.caller.msg("You are already standing.")
@ -679,7 +692,9 @@ class CmdCreateObj(CmdEvscapeRoom):
else:
name = args.strip()
obj = create_evscaperoom_object(typeclass=typeclass, key=name, location=self.room)
obj = create_evscaperoom_object(
typeclass=typeclass, key=name, location=self.room
)
caller.msg(f"Created new object {name} ({obj.typeclass_path}).")

View file

@ -151,7 +151,9 @@ def node_set_desc(caller, raw_string, **kwargs):
current_desc = kwargs.get("desc", caller.db.desc)
text = (
"Your current description is\n\n " f' "{current_desc}"' "\n\nEnter your new description!"
"Your current description is\n\n "
f' "{current_desc}"'
"\n\nEnter your new description!"
)
def _temp_description(caller, raw_string, **kwargs):
@ -169,7 +171,10 @@ def node_set_desc(caller, raw_string, **kwargs):
options = (
{"key": "_default", "goto": _temp_description},
{"key": ("|g[a]ccept", "a"), "goto": (_set_description, {"desc": current_desc})},
{
"key": ("|g[a]ccept", "a"),
"goto": (_set_description, {"desc": current_desc}),
},
{"key": ("|r[c]ancel", "c"), "goto": "node_start"},
)
return text, options
@ -180,7 +185,10 @@ def node_create_room(caller, raw_string, **kwargs):
text = _CREATE_ROOM_TEXT
options = (
{"key": ("|g[c]reate new room and start game|n", "c"), "goto": _create_new_room},
{
"key": ("|g[c]reate new room and start game|n", "c"),
"goto": _create_new_room,
},
{"key": ("|r[a]bort and go back|n", "a"), "goto": "node_start"},
)
@ -221,7 +229,10 @@ def node_quit(caller, raw_string, **kwargs):
from evennia import default_cmds
cmdhandler.cmdhandler(
caller.ndb._menutree._session, "", cmdobj=default_cmds.CmdQuit(), cmdobj_key="@quit"
caller.ndb._menutree._session,
"",
cmdobj=default_cmds.CmdQuit(),
cmdobj_key="@quit",
)
return text, None # empty options exit the menu
@ -248,7 +259,9 @@ class EvscaperoomMenu(EvMenu):
main_options.append(key)
main_options = " | ".join(main_options)
room_choices = super().options_formatter(room_choices)
return "{}{}{}".format(main_options, "\n\n" if room_choices else "", room_choices)
return "{}{}{}".format(
main_options, "\n\n" if room_choices else "", room_choices
)
# access function
@ -265,7 +278,9 @@ def run_evscaperoom_menu(caller):
"node_join_room": node_join_room,
}
EvscaperoomMenu(caller, menutree, startnode="node_start", cmd_on_exit=None, auto_quit=True)
EvscaperoomMenu(
caller, menutree, startnode="node_start", cmd_on_exit=None, auto_quit=True
)
# ------------------------------------------------------------
@ -285,7 +300,9 @@ def _toggle_screen_reader(caller, raw_string, **kwargs):
session = kwargs["session"]
# flip old setting
session.protocol_flags["SCREENREADER"] = not session.protocol_flags.get("SCREENREADER", False)
session.protocol_flags["SCREENREADER"] = not session.protocol_flags.get(
"SCREENREADER", False
)
# sync setting with portal
session.sessionhandler.session_portal_sync(session)
return None, kwargs # rerun node

View file

@ -64,7 +64,12 @@ class EvscaperoomObject(DefaultObject):
# this mapping allows for prettier descriptions of our current
# position
position_prep_map = {"sit": "sitting", "kneel": "kneeling", "lie": "lying", "climb": "standing"}
position_prep_map = {
"sit": "sitting",
"kneel": "kneeling",
"lie": "lying",
"climb": "standing",
}
def at_object_creation(self):
"""
@ -161,7 +166,9 @@ class EvscaperoomObject(DefaultObject):
you = caller.key if caller else "they"
first_person, third_person = parse_for_perspectives(string, you=you)
for char in self.room.get_all_characters():
options = char.attributes.get("options", category=self.room.tagcategory, default={})
options = char.attributes.get(
"options", category=self.room.tagcategory, default={}
)
style = options.get("things_style", 2)
if char == caller:
if not skip_caller:
@ -178,7 +185,9 @@ class EvscaperoomObject(DefaultObject):
"""
# we must clean away markers
first_person, _ = parse_for_perspectives(string)
options = caller.attributes.get("options", category=self.room.tagcategory, default={})
options = caller.attributes.get(
"options", category=self.room.tagcategory, default={}
)
style = options.get("things_style", 2)
txt = parse_for_things(first_person, things_style=style)
caller.msg((txt, {"type": client_type}))
@ -276,7 +285,9 @@ class EvscaperoomObject(DefaultObject):
"""
args = re.sub(
r"|".join(r"^{}\s".format(prep) for prep in self.action_prepositions), "", args
r"|".join(r"^{}\s".format(prep) for prep in self.action_prepositions),
"",
args,
)
return args
@ -307,7 +318,8 @@ class EvscaperoomObject(DefaultObject):
helpstr = f"It looks like {self.key} may be " "suitable to {callsigns}."
else:
helpstr = (
f"At first glance, it looks like {self.key} might be " "suitable to {callsigns}."
f"At first glance, it looks like {self.key} might be "
"suitable to {callsigns}."
)
return command_signatures, helpstr
@ -330,10 +342,14 @@ class EvscaperoomObject(DefaultObject):
# custom-created signatures. We don't sort these
command_signatures, helpstr = self.get_cmd_signatures()
callsigns = list_to_string(["*" + sig for sig in command_signatures], endsep="or")
callsigns = list_to_string(
["*" + sig for sig in command_signatures], endsep="or"
)
# parse for *thing markers (use these as items)
options = caller.attributes.get("options", category=self.room.tagcategory, default={})
options = caller.attributes.get(
"options", category=self.room.tagcategory, default={}
)
style = options.get("things_style", 2)
helpstr = helpstr.format(callsigns=callsigns)
@ -521,7 +537,11 @@ class IndexReadable(Readable):
"""
# keys should be lower-key
index = {"page1": "This is page1", "page2": "This is page2", "page two": "page2"} # alias
index = {
"page1": "This is page1",
"page2": "This is page2",
"page two": "page2",
} # alias
def at_focus_read(self, caller, **kwargs):
@ -800,7 +820,8 @@ class Combinable(BaseApplicable):
new_obj = create_evscaperoom_object(**create_dict)
if new_obj and self.destroy_components:
self.msg_char(
caller, f"You combine *{self.key} with {other_obj.key} to make {new_obj.key}!"
caller,
f"You combine *{self.key} with {other_obj.key} to make {new_obj.key}!",
)
other_obj.delete()
self.delete()
@ -1020,7 +1041,8 @@ class BasePositionable(EvscaperoomObject):
def at_again_position(self, caller, position):
self.msg_char(
caller, f"But you are already {self.position_prep_map[position]} on *{self.key}?"
caller,
f"But you are already {self.position_prep_map[position]} on *{self.key}?",
)
def at_position(self, caller, position):

View file

@ -102,7 +102,9 @@ class EvscapeRoom(EvscaperoomObject, DefaultRoom):
if achievement not in achievements:
self.log(f"achievement: {caller} earned '{achievement}' - {subtext}")
achievements[achievement] = subtext
caller.attributes.add("achievements", achievements, category=self.tagcategory)
caller.attributes.add(
"achievements", achievements, category=self.tagcategory
)
def get_all_characters(self):
"""
@ -224,7 +226,8 @@ class EvscapeRoom(EvscaperoomObject, DefaultRoom):
def return_appearance(self, looker, **kwargs):
obj, pos = self.get_position(looker)
pos = (
f"\n|x[{self.position_prep_map[pos]} on " f"{obj.get_display_name(looker)}]|n"
f"\n|x[{self.position_prep_map[pos]} on "
f"{obj.get_display_name(looker)}]|n"
if obj
else ""
)
@ -232,7 +235,9 @@ class EvscapeRoom(EvscaperoomObject, DefaultRoom):
admin_only = ""
if self.check_perm(looker, "Admin"):
# only for admins
objs = DefaultObject.objects.filter_family(db_location=self).exclude(id=looker.id)
objs = DefaultObject.objects.filter_family(db_location=self).exclude(
id=looker.id
)
admin_only = "\n|xAdmin only: " + list_to_string(
[obj.get_display_name(looker) for obj in objs]
)

View file

@ -58,7 +58,9 @@ class StateHandler(object):
except Exception as err:
logger.log_trace()
self.room.msg_room(None, f"|rBUG: Could not load state {statename}: {err}!")
self.room.msg_room(None, f"|rBUG: Falling back to {self.current_state_name}")
self.room.msg_room(
None, f"|rBUG: Falling back to {self.current_state_name}"
)
return
state = mod.State(self, self.room)
@ -202,7 +204,9 @@ class BaseState(object):
if cinematic:
message = msg_cinematic(message, borders=borders)
if target:
options = target.attributes.get("options", category=self.room.tagcategory, default={})
options = target.attributes.get(
"options", category=self.room.tagcategory, default={}
)
style = options.get("things_style", 2)
# we assume this is a char
target.msg(parse_for_things(message, things_style=style))

View file

@ -117,7 +117,9 @@ class HelpButton(objects.EvscaperoomObject):
self.msg_char(caller, "There are no more hints to be had.")
else:
self.msg_room(
caller, f"{caller.key} pushes *button and gets the " f'hint:\n "{hint.strip()}"|n'
caller,
f"{caller.key} pushes *button and gets the "
f'hint:\n "{hint.strip()}"|n',
)

View file

@ -18,7 +18,9 @@ from . import utils
class TestEvscaperoomCommands(CommandTest):
def setUp(self):
super().setUp()
self.room1 = utils.create_evscaperoom_object("evscaperoom.room.EvscapeRoom", key="Testroom")
self.room1 = utils.create_evscaperoom_object(
"evscaperoom.room.EvscapeRoom", key="Testroom"
)
self.char1.location = self.room1
self.obj1.location = self.room1
@ -151,19 +153,24 @@ class TestEvscaperoomCommands(CommandTest):
cmd.room = self.room1
cmd.focus = self.obj1
self.assertEqual(
self.char1.attributes.get("focus", category=self.room1.tagcategory), self.obj1
self.char1.attributes.get("focus", category=self.room1.tagcategory),
self.obj1,
)
def test_focus(self):
# don't focus on a non-room object
self.call(commands.CmdFocus(), "obj")
self.assertEqual(self.char1.attributes.get("focus", category=self.room1.tagcategory), None)
self.assertEqual(
self.char1.attributes.get("focus", category=self.room1.tagcategory), None
)
# should focus correctly
myobj = utils.create_evscaperoom_object(
objects.EvscaperoomObject, "mytestobj", location=self.room1
)
self.call(commands.CmdFocus(), "mytestobj")
self.assertEqual(self.char1.attributes.get("focus", category=self.room1.tagcategory), myobj)
self.assertEqual(
self.char1.attributes.get("focus", category=self.room1.tagcategory), myobj
)
def test_look(self):
self.call(commands.CmdLook(), "at obj", "Obj")
@ -173,13 +180,19 @@ class TestEvscaperoomCommands(CommandTest):
def test_speech(self):
self.call(commands.CmdSpeak(), "", "What do you want to say?", cmdstring="")
self.call(commands.CmdSpeak(), "Hello!", "You say: Hello!", cmdstring="")
self.call(commands.CmdSpeak(), "", "What do you want to whisper?", cmdstring="whisper")
self.call(
commands.CmdSpeak(), "", "What do you want to whisper?", cmdstring="whisper"
)
self.call(commands.CmdSpeak(), "Hi.", "You whisper: Hi.", cmdstring="whisper")
self.call(commands.CmdSpeak(), "Hi.", "You whisper: Hi.", cmdstring="whisper")
self.call(commands.CmdSpeak(), "HELLO!", "You shout: HELLO!", cmdstring="shout")
self.call(commands.CmdSpeak(), "Hello to obj", "You say: Hello", cmdstring="say")
self.call(commands.CmdSpeak(), "Hello to obj", "You shout: Hello", cmdstring="shout")
self.call(
commands.CmdSpeak(), "Hello to obj", "You say: Hello", cmdstring="say"
)
self.call(
commands.CmdSpeak(), "Hello to obj", "You shout: Hello", cmdstring="shout"
)
def test_emote(self):
self.call(
@ -194,7 +207,9 @@ class TestEvscaperoomCommands(CommandTest):
class TestUtils(EvenniaTest):
def test_overwrite(self):
room = utils.create_evscaperoom_object("evscaperoom.room.EvscapeRoom", key="Testroom")
room = utils.create_evscaperoom_object(
"evscaperoom.room.EvscapeRoom", key="Testroom"
)
obj1 = utils.create_evscaperoom_object(
objects.EvscaperoomObject, key="testobj", location=room
)
@ -212,11 +227,15 @@ class TestUtils(EvenniaTest):
def test_parse_for_perspectives(self):
second, third = utils.parse_for_perspectives("~You ~look at the nice book", "TestGuy")
second, third = utils.parse_for_perspectives(
"~You ~look at the nice book", "TestGuy"
)
self.assertTrue(second, "You look at the nice book")
self.assertTrue(third, "TestGuy looks at the nice book")
# irregular
second, third = utils.parse_for_perspectives("With a smile, ~you ~were gone", "TestGuy")
second, third = utils.parse_for_perspectives(
"With a smile, ~you ~were gone", "TestGuy"
)
self.assertTrue(second, "With a smile, you were gone")
self.assertTrue(third, "With a smile, TestGuy was gone")
@ -224,8 +243,12 @@ class TestUtils(EvenniaTest):
string = "Looking at *book and *key."
self.assertEqual(utils.parse_for_things(string, 0), "Looking at book and key.")
self.assertEqual(utils.parse_for_things(string, 1), "Looking at |ybook|n and |ykey|n.")
self.assertEqual(utils.parse_for_things(string, 2), "Looking at |y[book]|n and |y[key]|n.")
self.assertEqual(
utils.parse_for_things(string, 1), "Looking at |ybook|n and |ykey|n."
)
self.assertEqual(
utils.parse_for_things(string, 2), "Looking at |y[book]|n and |y[key]|n."
)
class TestEvScapeRoom(EvenniaTest):
@ -248,10 +271,14 @@ class TestEvScapeRoom(EvenniaTest):
self.assertEqual(list(room.get_all_characters()), [self.char1])
room.tag_character(self.char1, "opened_door")
self.assertEqual(self.char1.tags.get("opened_door", category=self.roomtag), "opened_door")
self.assertEqual(
self.char1.tags.get("opened_door", category=self.roomtag), "opened_door"
)
room.tag_all_characters("tagged_all")
self.assertEqual(self.char1.tags.get("tagged_all", category=self.roomtag), "tagged_all")
self.assertEqual(
self.char1.tags.get("tagged_all", category=self.roomtag), "tagged_all"
)
room.character_cleanup(self.char1)
self.assertEqual(self.char1.tags.get(category=self.roomtag), None)