Final f-string batch

some uses of str.format remain, but converting them would be more trouble than it's worth
This commit is contained in:
Gouvernathor 2024-03-26 21:58:22 +01:00
parent 04f76d2b54
commit f17cffa3ec
9 changed files with 49 additions and 50 deletions

View File

@ -331,15 +331,15 @@ init -1 python:
def get_store_menu_item(self, disabled=False):
if disabled:
return gui.menu_item('-{}-'.format(self.name), None, style="disabled")
return gui.menu_item(f'-{self.name}-', None, style="disabled")
else:
return gui.menu_item('-{}-'.format(self.name), self)
return gui.menu_item(f'-{self.name}-', self)
def get_craft_menu_item(self, disabled=False):
if disabled:
return gui.menu_item('-Craft: "{}"-'.format(self.name), self.ingredients, style="disabled")
return gui.menu_item(f'-Craft: "{self.name}"-', self.ingredients, style="disabled")
else:
return gui.menu_item('-Craft: "{}"-'.format(self.name), self.id)
return gui.menu_item(f'-Craft: "{self.name}"-', self.id)
def get_mix_text(self):
return ">You mix the {i}" + potion_lib.get_name_by_id(self.ingredients[0]) \

View File

@ -15,16 +15,16 @@ python early:
return "DirectX" if preferences.renderer == "angle2" else "OpenGL"
class stdcol:
PURPLE = '\033[1;35;48m'
CYAN = '\033[1;36;48m'
BOLD = '\033[1;37;48m'
BLUE = '\033[1;34;48m'
GREEN = '\033[1;32;48m'
YELLOW = '\033[1;33;48m'
RED = '\033[1;31;48m'
BLACK = '\033[1;30;48m'
UNDERLINE = '\033[4;37;48m'
END = '\033[1;37;0m'
PURPLE = '\033[1;35;48m'
CYAN = '\033[1;36;48m'
BOLD = '\033[1;37;48m'
BLUE = '\033[1;34;48m'
GREEN = '\033[1;32;48m'
YELLOW = '\033[1;33;48m'
RED = '\033[1;31;48m'
BLACK = '\033[1;30;48m'
UNDERLINE = '\033[4;37;48m'
END = '\033[1;37;0m'
if config.developer:
# Debug
@ -42,7 +42,7 @@ python early:
orphaned.append(i)
if orphaned:
raise Exception("Orphaned compiled scripts detected, please delete them before continuing:\n{}".format(orphaned))
raise Exception(f"Orphaned compiled scripts detected, please delete them before continuing:\n{orphaned}")
detect_orphaned_rpyc_files()
@ -91,7 +91,7 @@ init -2 python:
return Image(file + ".png")
if config.developer:
raise IOError("Missing image: {}".format(path))
raise IOError(f"Missing image: {path}")
return Image("images/blank.webp")
def missing_label_func(name):

View File

@ -86,7 +86,7 @@ init python:
elif what == "temp_attr":
setattr(node, "temporary_attributes", tuple(contents))
else:
raise TypeError("Type {!r} is not implemented.".format(what))
raise TypeError(f"Type {what!r} is not implemented.")
def replace_expression(self, expr, val):
node = self.node
@ -97,14 +97,14 @@ init python:
# We need to make sure not to add quotes
# to expressions or variables.
if isinstance(val, str):
val = "\"{}\"".format(val)
val = repr(val)
# Insert new expression
d = self.get_expressions_active(who)
d[expr] = val
# Convert to list of tuples
# l = [(k, "\"{}\"".format(v)) for k, v in d.items() if not v is None] # This is faster, but not robust enough.
# l = [(k, repr(v)) for k, v in d.items() if not v is None] # This is faster, but not robust enough.
l = _list()
l2 = _list()

View File

@ -39,13 +39,13 @@ init python:
if cache_size >= cache_limit:
if config.developer:
print("Cache limit reached, purging cache... ({}/{})\n{}".format(cache_size, cache_limit, renpy.get_filename_line()))
print(f"Cache limit reached, purging cache... ({cache_size}/{cache_limit})\n{renpy.get_filename_line()}")
cache.clear()
if renpy.game.interface is not None:
if config.developer:
print("Statements limit reached, cleaning textures... ({})\n{}".format(self.limit, renpy.get_filename_line()))
print(f"Statements limit reached, cleaning textures... ({self.limit})\n{renpy.get_filename_line()}")
renpy.game.interface.full_redraw = True
renpy.game.interface.restart_interaction = True

View File

@ -137,7 +137,7 @@ init -1 python:
renpy.lint.report_node = node
has_failed = True
msg = "{!r} requires an integer, or a pre-defined named position, not {!r}".format(key, val)
msg = f"{key!r} requires an integer, or a pre-defined named position, not {val!r}"
renpy.lint.report(msg)
# This would require fixing hundreds of calls. Might postpone it...
@ -161,7 +161,7 @@ init -1 python:
if key == "emote":
msg = repr(key)
fn = "characters/{}/emote/{}.webp".format(SAYERS.get(who), val)
fn = f"characters/{SAYERS.get(who)}/emote/{val}.webp"
if not has_failed:
# Avoid repeating node destination

View File

@ -75,7 +75,7 @@ init python in cli:
for i, s in enumerate(strings):
n = round(float(i)/(nstrings)*100)
print("\rGenerating strings for {} ... Total progress:{} % ... Stage 2/2".format(language, n), end="")
print(f"\rGenerating strings for {language} ... Total progress:{n} % ... Stage 2/2", end="")
tlfn = renpy.translation.generation.translation_filename(s)
@ -96,17 +96,17 @@ init python in cli:
tlfn = os.path.join(renpy.config.gamedir, renpy.config.tl_directory, language, tlfn)
f = open_tl_file(tlfn, mode="w")
f.write(u"translate {} strings:\n".format(language))
f.write(u"\n")
f.write(f"translate {language} strings:\n")
f.write("\n")
for s in sl:
original = s.text
translation = stl.translate(s.text) # Keeps translated strings
f.write(u" # {}:{}\n".format(elide_filename(s.filename), s.line))
f.write(u" old \"{}\"\n".format(quote_unicode(original)))
f.write(u" new \"{}\"\n".format(quote_unicode(translation)))
f.write(u"\n")
f.write(f" # {elide_filename(s.filename)}:{s.line}\n")
f.write(f" old \"{quote_unicode(original)}\"\n")
f.write(f" new \"{quote_unicode(translation)}\"\n")
f.write("\n")
def retranslate():
translator = renpy.game.script.translator
@ -135,7 +135,7 @@ init python in cli:
for language in translator.languages:
print("\rGenerating dialogues for {} ... Total progress:{} % ... Stage 1/2".format(language, n), end="")
print(f"\rGenerating dialogues for {language} ... Total progress:{n} % ... Stage 1/2", end="")
for _, trans in translator.file_translates[filepath]:
@ -159,9 +159,9 @@ init python in cli:
f = open_tl_file(fp, mode="w")
f.write(u"# {}:{}\n".format(trans.filename, trans.linenumber))
f.write(u"translate {} {}:\n".format(language, trans.identifier.replace(".", "_")))
f.write(u"\n")
f.write(f"# {trans.filename}:{trans.linenumber}\n")
f.write("translate {} {}:\n".format(language, trans.identifier.replace(".", "_")))
f.write("\n")
for n in trans.block:
f.write(u" # " + n.get_code() + "\n")
@ -196,7 +196,7 @@ init python in cli:
f.close()
if args.dry:
print("Removal required: {}".format(filepath))
print(f"Removal required: {filepath}")
else:
os.unlink(filepath)
os.unlink(filepath + "c")

View File

@ -214,7 +214,7 @@ init python:
delattr(store, "achievements_dict")
if current > latest:
raise Exception("Loaded save file is incompatible. (Save Version: {}, Game Version: {})".format(current, latest))
raise Exception(f"Loaded save file is incompatible. (Save Version: {current}, Game Version: {latest})")
if current < latest:
setattr(store, "version", latest)
@ -228,7 +228,7 @@ init python:
def version_logo():
url = UPDATE_URL
filename = "logo_{}.webp".format(UPDATE_VER)
filename = f"logo_{UPDATE_VER}.webp"
path = os.path.join(config.basedir, "update", filename)
# Read file if exists

View File

@ -203,7 +203,7 @@ screen studio():
$ bg_blur = studio.choices["background"]["blur"]
$ bg_matrix = bg_hue*bg_saturation*bg_brightness
$ bg_image = studio.choices["background"]["list"][studio.choices["background"]["image"]]
$ bg_image = "images/rooms/_bg_/{}.webp".format(bg_image)
$ bg_image = f"images/rooms/_bg_/{bg_image}.webp"
$ bg = Transform(bg_image, matrixcolor=bg_matrix, blur=bg_blur)
$ ov_hue = HueMatrix(studio.choices["overlay"]["hue"])
@ -214,9 +214,8 @@ screen studio():
$ ov_matrix = ov_hue*ov_saturation*ov_brightness
$ ov_image = studio.choices["overlay"]["list"][studio.choices["overlay"]["image"]]
if not ov_image is None:
$ ov_image = "images/rooms/overlays/{}.webp".format(ov_image)
$ ov = Transform(ov_image, matrixcolor=ov_matrix, blur=ov_blur, alpha=ov_alpha)
if ov_image is not None:
$ ov = Transform(f"images/rooms/overlays/{ov_image}.webp", matrixcolor=ov_matrix, blur=ov_blur, alpha=ov_alpha)
else:
$ ov = None
@ -337,7 +336,7 @@ screen studio():
selected v[1] text_color ("#009900" if active else "#f9d592")
text_hover_color "#fff"
text_first_indent 20
background Transform("interface/icons/head/{}.webp".format(k), size=(16, 16), offset=(22, 3))
background Transform(f"interface/icons/head/{k}.webp", size=(16, 16), offset=(22, 3))
vbox:
align (1.0, 1.0)

View File

@ -777,7 +777,7 @@ screen wardrobe_menuitem(xx, yy):
pos (12, 108)
for subcategory in category_items.keys():
$ icon = lock_wardrobe_icon("interface/wardrobe/icons/{}.webp".format(subcategory))
$ icon = lock_wardrobe_icon(f"interface/wardrobe/icons/{subcategory}.webp")
button:
focus_mask None
@ -830,7 +830,7 @@ screen wardrobe_outfit_menuitem(xx, yy):
pos (8, 108)
for subcategory in category_items.keys():
$ icon = lock_wardrobe_icon("interface/wardrobe/icons/{}.webp".format(subcategory))
$ icon = lock_wardrobe_icon(f"interface/wardrobe/icons/{subcategory}.webp")
$ action = Return(["subcategory", subcategory])
if subcategory == "schedule" and not get_character_scheduling(states.active_girl):
@ -903,7 +903,7 @@ screen wardrobe_schedule_menuitem(item):
spacing 0
for i in wardrobe_outfit_schedule:
$ boolean = "" if item.schedule[i] else "Not "
$ caption = "{}worn during the {}".format(boolean, i) if i in ("day", "night") else "{}worn in {} weather".format(boolean, i)
$ caption = f"{boolean}worn during the {i}" if i in ("day", "night") else f"{boolean}worn in {i} weather"
textbutton i:
style gui.theme("dropdown")
tooltip caption