mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
issue #2243 -- prefer f-strings over %-interpolation
edited docs to prefer f-strings, then str.format(), and remove %-interpolation additional ad-hoc documentation fixes, as opportunities seen: - replace Built-In Function (BIF) "min" variable with "mins" - prefer BIF str(var) over "%s" % var - reformat some code examples to clarify multiple args passed to functions - change some single-quote strings to double-quotes for consistency - fix mismatched parens misc edits: - add .vscode/ to gitignore
This commit is contained in:
parent
f45051050e
commit
851ca30be5
30 changed files with 207 additions and 193 deletions
|
|
@ -150,7 +150,7 @@ class CmdSetPower(Command):
|
|||
return
|
||||
# at this point the argument is tested as valid. Let's set it.
|
||||
self.caller.db.power = power
|
||||
self.caller.msg("Your Power was set to %i." % power)
|
||||
self.caller.msg(f"Your Power was set to {power}.")
|
||||
```
|
||||
This is a pretty straightforward command. We do some error checking, then set the power on ourself.
|
||||
We use a `help_category` of "mush" for all our commands, just so they are easy to find and separate
|
||||
|
|
@ -295,11 +295,17 @@ class CmdAttack(Command):
|
|||
caller.db.combat_score = combat_score
|
||||
|
||||
# announce
|
||||
message = "%s +attack%s with a combat score of %s!"
|
||||
caller.msg(message % ("You", "", combat_score))
|
||||
caller.location.msg_contents(message %
|
||||
(caller.key, "s", combat_score),
|
||||
exclude=caller)
|
||||
message_template = "{attacker} +attack{s} with a combat score of {c_score}!"
|
||||
caller.msg(message_template.format(
|
||||
attacker="You",
|
||||
s="",
|
||||
c_score=combat_score,
|
||||
))
|
||||
caller.location.msg_contents(message_template.format(
|
||||
attacker=caller.key,
|
||||
s="s",
|
||||
c_score=combat_score,
|
||||
), exclude=caller)
|
||||
```
|
||||
|
||||
What we do here is simply to generate a "combat score" using Python's inbuilt `random.randint()`
|
||||
|
|
@ -359,7 +365,7 @@ class Character(DefaultCharacter):
|
|||
looker sees when looking at this object.
|
||||
"""
|
||||
text = super().return_appearance(looker)
|
||||
cscore = " (combat score: %s)" % self.db.combat_score
|
||||
cscore = f" (combat score: {self.db.combat_score})"
|
||||
if "\n" in text:
|
||||
# text is multi-line, add score after first line
|
||||
first_line, rest = text.split("\n", 1)
|
||||
|
|
@ -435,12 +441,17 @@ class CmdCreateNPC(Command):
|
|||
npc = create_object("characters.Character",
|
||||
key=name,
|
||||
location=caller.location,
|
||||
locks="edit:id(%i) and perm(Builders);call:false()" % caller.id)
|
||||
locks=f"edit:id({caller.id}) and perm(Builders);call:false()")
|
||||
# announce
|
||||
message = "%s created the NPC '%s'."
|
||||
caller.msg(message % ("You", name))
|
||||
caller.location.msg_contents(message % (caller.key, name),
|
||||
exclude=caller)
|
||||
message_template = "{creator} created the NPC '{npc}'."
|
||||
caller.msg(message_template.format(
|
||||
creator="You",
|
||||
npc=name,
|
||||
))
|
||||
caller.location.msg_contents(message_template.format(
|
||||
creator=caller.key,
|
||||
npt=name,
|
||||
), exclude=caller)
|
||||
```
|
||||
Here we define a `+createnpc` (`+createNPC` works too) that is callable by everyone *not* having the
|
||||
`nonpcs` "[permission](../../../Components/Locks#Permissions)" (in Evennia, a "permission" can just as well be used to
|
||||
|
|
@ -532,10 +543,10 @@ class CmdEditNPC(Command):
|
|||
return
|
||||
if not self.propname:
|
||||
# this means we just list the values
|
||||
output = "Properties of %s:" % npc.key
|
||||
output = f"Properties of {npc.key}:"
|
||||
for propname in allowed_propnames:
|
||||
propvalue = npc.attributes.get(propname, default="N/A")
|
||||
output += "\n %s = %s" % (propname, propvalue)
|
||||
output += f"\n {propname} = {propvalue}"
|
||||
caller.msg(output)
|
||||
elif self.propname not in allowed_propnames:
|
||||
caller.msg("You may only change %s." %
|
||||
|
|
@ -619,7 +630,7 @@ class CmdNPC(Command):
|
|||
return
|
||||
# send the command order
|
||||
npc.execute_cmd(self.cmdname)
|
||||
caller.msg("You told %s to do '%s'." % (npc.key, self.cmdname))
|
||||
caller.msg(f"You told {npc.key} to do '{self.cmdname}'.")
|
||||
```
|
||||
|
||||
Note that if you give an erroneous command, you will not see any error message, since that error
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue