Convert percent formatting to f-strings

This commit is contained in:
Jared Miller 2026-02-12 19:50:51 -05:00
parent 804c09ec4e
commit 270f432229
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C
52 changed files with 416 additions and 347 deletions

63
art.py
View file

@ -107,8 +107,8 @@ class Art:
def __init__(self, filename, app, charset, palette, width, height): def __init__(self, filename, app, charset, palette, width, height):
"Creates a new, blank document with given parameters." "Creates a new, blank document with given parameters."
self.valid = False self.valid = False
if filename and not filename.endswith(".%s" % ART_FILE_EXTENSION): if filename and not filename.endswith(".{}".format(ART_FILE_EXTENSION)):
filename += ".%s" % ART_FILE_EXTENSION filename += ".{}".format(ART_FILE_EXTENSION)
self.filename = filename self.filename = filename
self.app = app self.app = app
# save "time loaded" for menu sorting # save "time loaded" for menu sorting
@ -162,11 +162,11 @@ class Art:
def log_init(self): def log_init(self):
self.app.log("created new document:") self.app.log("created new document:")
self.app.log(" character set: %s" % self.charset.name) self.app.log(" character set: {}".format(self.charset.name))
self.app.log(" palette: %s" % self.palette.name) self.app.log(" palette: {}".format(self.palette.name))
self.app.log(" width/height: %s x %s" % (self.width, self.height)) self.app.log(" width/height: {} x {}".format(self.width, self.height))
self.app.log(" frames: %s" % self.frames) self.app.log(" frames: {}".format(self.frames))
self.app.log(" layers: %s" % self.layers) self.app.log(" layers: {}".format(self.layers))
def init_layers(self): def init_layers(self):
self.layers = 1 self.layers = 1
@ -219,7 +219,7 @@ class Art:
if self.app.ui and self is self.app.ui.active_art: if self.app.ui and self is self.app.ui.active_art:
self.app.ui.set_active_frame(index) self.app.ui.set_active_frame(index)
if log: if log:
self.app.log("Created new frame at index %s" % str(index)) self.app.log("Created new frame at index {}".format(str(index)))
def add_frame_to_end(self, delay=DEFAULT_FRAME_DELAY, log=True): def add_frame_to_end(self, delay=DEFAULT_FRAME_DELAY, log=True):
"Add a blank frame at the end of the current animation." "Add a blank frame at the end of the current animation."
@ -246,7 +246,9 @@ class Art:
if self is self.app.ui.active_art: if self is self.app.ui.active_art:
self.app.ui.set_active_frame(dest_frame_index - 1) self.app.ui.set_active_frame(dest_frame_index - 1)
self.app.log( self.app.log(
"Duplicated frame %s at frame %s" % (src_frame_index + 1, dest_frame_index) "Duplicated frame {} at frame {}".format(
src_frame_index + 1, dest_frame_index
)
) )
def delete_frame_at(self, index): def delete_frame_at(self, index):
@ -306,7 +308,7 @@ class Art:
z = z if z is not None else self.layers_z[src_index] z = z if z is not None else self.layers_z[src_index]
self.layers_z.append(z) self.layers_z.append(z)
self.layers_visibility.append(True) self.layers_visibility.append(True)
new_name = new_name or "Copy of %s" % self.layer_names[src_index] new_name = new_name or "Copy of {}".format(self.layer_names[src_index])
self.layer_names.append(new_name) self.layer_names.append(new_name)
# rebuild geo with added verts for new layer # rebuild geo with added verts for new layer
self.geo_changed = True self.geo_changed = True
@ -315,7 +317,7 @@ class Art:
self.app.ui.set_active_layer(self.layers - 1) self.app.ui.set_active_layer(self.layers - 1)
# don't log new layers created on the fly in game mode # don't log new layers created on the fly in game mode
if not self.app.game_mode: if not self.app.game_mode:
self.app.log("Added new layer %s" % new_name) self.app.log("Added new layer {}".format(new_name))
self.set_unsaved_changes(True) self.set_unsaved_changes(True)
def clear_frame_layer(self, frame, layer, bg_color=0, fg_color=None): def clear_frame_layer(self, frame, layer, bg_color=0, fg_color=None):
@ -366,7 +368,7 @@ class Art:
self.geo_changed = True self.geo_changed = True
if log: if log:
self.app.ui.message_line.post_line( self.app.ui.message_line.post_line(
"Character set changed to %s" % self.charset.name "Character set changed to {}".format(self.charset.name)
) )
def set_charset_by_name(self, new_charset_name): def set_charset_by_name(self, new_charset_name):
@ -382,7 +384,7 @@ class Art:
self.set_unsaved_changes(True) self.set_unsaved_changes(True)
if log: if log:
self.app.ui.message_line.post_line( self.app.ui.message_line.post_line(
"Color palette changed to %s" % self.palette.name "Color palette changed to {}".format(self.palette.name)
) )
def set_palette_by_name(self, new_palette_name): def set_palette_by_name(self, new_palette_name):
@ -871,7 +873,7 @@ class Art:
end_time = time.time() end_time = time.time()
self.set_unsaved_changes(False) self.set_unsaved_changes(False)
# self.app.log('saved %s to disk in %.5f seconds' % (self.filename, end_time - start_time)) # self.app.log('saved %s to disk in %.5f seconds' % (self.filename, end_time - start_time))
self.app.log("saved %s" % self.filename) self.app.log("saved {}".format(self.filename))
# remove old thumbnail # remove old thumbnail
thumb_dir = self.app.cache_dir + THUMBNAIL_CACHE_DIR thumb_dir = self.app.cache_dir + THUMBNAIL_CACHE_DIR
if os.path.exists(self.filename): if os.path.exists(self.filename):
@ -936,8 +938,9 @@ class Art:
json.dump(d, open(self.filename + "2", "w"), sort_keys=True, indent=None) json.dump(d, open(self.filename + "2", "w"), sort_keys=True, indent=None)
end_time = time.time() end_time = time.time()
self.app.log( self.app.log(
"ALT saved %s to disk in %.5f seconds" "ALT saved {} to disk in {:.5f} seconds".format(
% (self.filename, end_time - start_time) self.filename, end_time - start_time
)
) )
def set_unsaved_changes(self, new_status): def set_unsaved_changes(self, new_status):
@ -985,13 +988,13 @@ class Art:
exec(open(script_filename).read()) exec(open(script_filename).read())
# (assume script changed art) # (assume script changed art)
self.unsaved_changes = True self.unsaved_changes = True
logline = "Executed %s" % script_filename logline = "Executed {}".format(script_filename)
if log: if log:
self.app.log(logline) self.app.log(logline)
error = False error = False
except Exception: except Exception:
error = True error = True
logline = "Error executing %s:" % script_filename logline = "Error executing {}:".format(script_filename)
self.app.log(logline) self.app.log(logline)
# skip first 3 lines of callstack before artscript exec # skip first 3 lines of callstack before artscript exec
for line in traceback.format_exc().split("\n")[3:]: for line in traceback.format_exc().split("\n")[3:]:
@ -1021,7 +1024,7 @@ class Art:
if not script_filename: if not script_filename:
return return
if script_filename in self.scripts: if script_filename in self.scripts:
self.app.log("script %s is already running." % script_filename) self.app.log("script {} is already running.".format(script_filename))
return return
# add to "scripts currently running" list # add to "scripts currently running" list
self.scripts.append(script_filename) self.scripts.append(script_filename)
@ -1037,7 +1040,7 @@ class Art:
if not script_filename: if not script_filename:
return return
if script_filename not in self.scripts: if script_filename not in self.scripts:
self.app.log("script %s exists but isn't running." % script_filename) self.app.log("script {} exists but isn't running.".format(script_filename))
return return
script_index = self.scripts.index(script_filename) script_index = self.scripts.index(script_filename)
self.scripts.pop(script_index) self.scripts.pop(script_index)
@ -1208,11 +1211,11 @@ class ArtFromDisk(Art):
height = d["height"] height = d["height"]
charset = app.load_charset(d["charset"]) charset = app.load_charset(d["charset"])
if not charset: if not charset:
app.log("Character set %s not found!" % d["charset"]) app.log("Character set {} not found!".format(d["charset"]))
return return
palette = app.load_palette(d["palette"]) palette = app.load_palette(d["palette"])
if not palette: if not palette:
app.log("Palette %s not found!" % d["palette"]) app.log("Palette {} not found!".format(d["palette"]))
return return
# store loaded data for init_layers/frames # store loaded data for init_layers/frames
self.loaded_data = d self.loaded_data = d
@ -1240,12 +1243,12 @@ class ArtFromDisk(Art):
self.valid = True self.valid = True
def log_init(self): def log_init(self):
self.app.log("Loaded %s from disk:" % filename) self.app.log("Loaded {} from disk:".format(filename))
self.app.log(" character set: %s" % self.charset.name) self.app.log(" character set: {}".format(self.charset.name))
self.app.log(" palette: %s" % self.palette.name) self.app.log(" palette: {}".format(self.palette.name))
self.app.log(" width/height: %s x %s" % (self.width, self.height)) self.app.log(" width/height: {} x {}".format(self.width, self.height))
self.app.log(" frames: %s" % self.frames) self.app.log(" frames: {}".format(self.frames))
self.app.log(" layers: %s" % self.layers) self.app.log(" layers: {}".format(self.layers))
def init_layers(self): def init_layers(self):
frames = self.loaded_data["frames"] frames = self.loaded_data["frames"]
@ -1256,7 +1259,7 @@ class ArtFromDisk(Art):
self.layers_z.append(layer["z"]) self.layers_z.append(layer["z"])
self.layers_visibility.append(bool(layer.get("visible", 1))) self.layers_visibility.append(bool(layer.get("visible", 1)))
layer_num = str(i + 1) layer_num = str(i + 1)
self.layer_names.append(layer.get("name", "Layer %s" % layer_num)) self.layer_names.append(layer.get("name", "Layer {}".format(layer_num)))
active_layer = self.loaded_data.get("active_layer", 0) active_layer = self.loaded_data.get("active_layer", 0)
self.set_active_layer(active_layer) self.set_active_layer(active_layer)
@ -1312,7 +1315,7 @@ class ArtInstance(Art):
def __init__(self, source): def __init__(self, source):
self.source = source self.source = source
# unique(?) filename # unique(?) filename
self.filename = "%s_Instance%i" % (source.filename, time.time()) self.filename = f"{source.filename}_Instance{time.time()}"
self.app = source.app self.app = source.app
self.instances = None self.instances = None
self.char_changed_frames, self.uv_changed_frames = {}, {} self.char_changed_frames, self.uv_changed_frames = {}, {}

View file

@ -24,9 +24,9 @@ class ArtExporter:
self.art = self.app.ui.active_art self.art = self.app.ui.active_art
# add file extension to output filename if not present # add file extension to output filename if not present
if self.file_extension and not out_filename.endswith( if self.file_extension and not out_filename.endswith(
".%s" % self.file_extension ".{}".format(self.file_extension)
): ):
out_filename += ".%s" % self.file_extension out_filename += ".{}".format(self.file_extension)
# output filename in documents/art dir # output filename in documents/art dir
if not out_filename.startswith(self.app.documents_dir + ART_DIR): if not out_filename.startswith(self.app.documents_dir + ART_DIR):
out_filename = self.app.documents_dir + ART_DIR + out_filename out_filename = self.app.documents_dir + ART_DIR + out_filename
@ -41,7 +41,7 @@ class ArtExporter:
if self.run_export(out_filename, options): if self.run_export(out_filename, options):
self.success = True self.success = True
else: else:
line = "%s failed to export %s, see console for errors" % ( line = "{} failed to export {}, see console for errors".format(
self.__class__.__name__, self.__class__.__name__,
out_filename, out_filename,
) )

View file

@ -32,7 +32,9 @@ class ArtImporter:
def __init__(self, app, in_filename, options={}): def __init__(self, app, in_filename, options={}):
self.app = app self.app = app
new_filename = "%s.%s" % (os.path.splitext(in_filename)[0], ART_FILE_EXTENSION) new_filename = "{}.{}".format(
os.path.splitext(in_filename)[0], ART_FILE_EXTENSION
)
self.art = self.app.new_art(new_filename) self.art = self.app.new_art(new_filename)
# use charset and palette of existing art # use charset and palette of existing art
charset = ( charset = (

View file

@ -313,4 +313,4 @@ class Camera:
self.mouse_panned = False self.mouse_panned = False
def log_loc(self): def log_loc(self):
self.app.log("camera x=%s, y=%s, z=%s" % (self.x, self.y, self.z)) self.app.log("camera x={}, y={}, z={}".format(self.x, self.y, self.z))

View file

@ -34,16 +34,23 @@ class CharacterSetLord:
success = charset.load_char_data() success = charset.load_char_data()
if success: if success:
self.app.log( self.app.log(
"CharacterSetLord: success reloading %s" % charset.filename "CharacterSetLord: success reloading {}".format(
charset.filename
)
) )
else: else:
self.app.log( self.app.log(
"CharacterSetLord: failed reloading %s" % charset.filename, "CharacterSetLord: failed reloading {}".format(
charset.filename
),
True, True,
) )
except: except:
self.app.log( self.app.log(
"CharacterSetLord: failed reloading %s" % charset.filename, True "CharacterSetLord: failed reloading {}".format(
charset.filename
),
True,
) )
@ -57,7 +64,7 @@ class CharacterSet:
src_filename, CHARSET_DIR, CHARSET_FILE_EXTENSION src_filename, CHARSET_DIR, CHARSET_FILE_EXTENSION
) )
if not self.filename: if not self.filename:
self.app.log("Couldn't find character set data %s" % self.filename) self.app.log("Couldn't find character set data {}".format(self.filename))
return return
self.name = os.path.basename(self.filename) self.name = os.path.basename(self.filename)
self.name = os.path.splitext(self.name)[0] self.name = os.path.splitext(self.name)[0]
@ -71,7 +78,9 @@ class CharacterSet:
return return
# report # report
if log and not self.app.game_mode: if log and not self.app.game_mode:
self.app.log("loaded charmap '%s' from %s:" % (self.name, self.filename)) self.app.log(
"loaded charmap '{}' from {}:".format(self.name, self.filename)
)
self.report() self.report()
self.init_success = True self.init_success = True
@ -90,7 +99,9 @@ class CharacterSet:
char_data.pop(0).strip(), CHARSET_DIR, "png" char_data.pop(0).strip(), CHARSET_DIR, "png"
) )
if not img_filename: if not img_filename:
self.app.log("Couldn't find character set image %s" % self.image_filename) self.app.log(
"Couldn't find character set image {}".format(self.image_filename)
)
return False return False
self.image_filename = img_filename self.image_filename = img_filename
# now that we know the image file's name, store its last modified time # now that we know the image file's name, store its last modified time
@ -167,16 +178,19 @@ class CharacterSet:
def report(self): def report(self):
self.app.log( self.app.log(
" source texture %s is %s x %s pixels" " source texture {} is {} x {} pixels".format(
% (self.image_filename, self.image_width, self.image_height) self.image_filename, self.image_width, self.image_height
)
) )
self.app.log( self.app.log(
" char pixel width/height is %s x %s" % (self.char_width, self.char_height) " char pixel width/height is {} x {}".format(
self.char_width, self.char_height
)
) )
self.app.log( self.app.log(
" char map width/height is %s x %s" % (self.map_width, self.map_height) " char map width/height is {} x {}".format(self.map_width, self.map_height)
) )
self.app.log(" last character index: %s" % self.last_index) self.app.log(" last character index: {}".format(self.last_index))
def has_updated(self): def has_updated(self):
"return True if source image file has changed since last check" "return True if source image file has changed since last check"

View file

@ -307,8 +307,9 @@ class Collideable:
frame = self.go.renderable.frame frame = self.go.renderable.frame
if self.go.col_layer_name not in self.go.art.layer_names: if self.go.col_layer_name not in self.go.art.layer_names:
self.go.app.dev_log( self.go.app.dev_log(
"%s: Couldn't find collision layer with name '%s'" "{}: Couldn't find collision layer with name '{}'".format(
% (self.go.name, self.go.col_layer_name) self.go.name, self.go.col_layer_name
)
) )
return return
layer = self.go.art.layer_names.index(self.go.col_layer_name) layer = self.go.art.layer_names.index(self.go.col_layer_name)
@ -442,8 +443,9 @@ class CollisionLord:
def report(self): def report(self):
print( print(
"%s: %s dynamic shapes, %s static shapes" "{}: {} dynamic shapes, {} static shapes".format(
% (self, len(self.dynamic_shapes), len(self.static_shapes)) self, len(self.dynamic_shapes), len(self.static_shapes)
)
) )
def reset(self): def reset(self):

View file

@ -141,8 +141,9 @@ class Cursor:
self.app.keyboard_editing = True self.app.keyboard_editing = True
if self.logg: if self.logg:
self.app.log( self.app.log(
"Cursor: %s,%s,%s scale %.2f,%.2f" "Cursor: {},{},{} scale {:.2f},{:.2f}".format(
% (self.x, self.y, self.z, self.scale_x, self.scale_y) self.x, self.y, self.z, self.scale_x, self.scale_y
)
) )
def set_scale(self, new_scale): def set_scale(self, new_scale):
@ -185,7 +186,7 @@ class Cursor:
x0, y0 = self.x, -self.y x0, y0 = self.x, -self.y
x1, y1 = self.last_x, -self.last_y x1, y1 = self.last_x, -self.last_y
tiles = vector.get_tiles_along_line(x0, y0, x1, y1) tiles = vector.get_tiles_along_line(x0, y0, x1, y1)
print("drag from %s,%s to %s,%s:" % (x0, y0, x1, y1)) print("drag from {},{} to {},{}:".format(x0, y0, x1, y1))
print(tiles) print(tiles)
return tiles return tiles

View file

@ -23,7 +23,7 @@ class EditCommand:
# get unique-ish ID from memory address # get unique-ish ID from memory address
addr = self.__repr__() addr = self.__repr__()
addr = addr[addr.find("0") : -1] addr = addr[addr.find("0") : -1]
s = "EditCommand_%s: %s tiles, time %s" % ( s = "EditCommand_{}: {} tiles, time {}".format(
addr, addr,
self.get_number_of_commands(), self.get_number_of_commands(),
self.finish_time, self.finish_time,
@ -95,7 +95,7 @@ class EntireArtCommand:
for atype in self.array_types: for atype in self.array_types:
# save list as eg "b_chars" for "character data before operation" # save list as eg "b_chars" for "character data before operation"
src_data = getattr(self.art, atype) src_data = getattr(self.art, atype)
var_name = "%s_%s" % (prefix, atype) var_name = "{}_{}".format(prefix, atype)
# deep copy each frame's data, else before == after # deep copy each frame's data, else before == after
new_data = [] new_data = []
for frame in src_data: for frame in src_data:
@ -145,15 +145,17 @@ class EditCommandTile:
self.a_char = self.a_fg = self.a_bg = self.a_xform = None self.a_char = self.a_fg = self.a_bg = self.a_xform = None
def __str__(self): def __str__(self):
s = "F%s L%s %s,%s @ %.2f: " % ( s = "F{} L{} {},{} @ {:.2f}: ".format(
self.frame, self.frame,
self.layer, self.layer,
str(self.x).rjust(2, "0"), str(self.x).rjust(2, "0"),
str(self.y).rjust(2, "0"), str(self.y).rjust(2, "0"),
self.creation_time, self.creation_time,
) )
s += "c%s f%s b%s x%s -> " % (self.b_char, self.b_fg, self.b_bg, self.b_xform) s += "c{} f{} b{} x{} -> ".format(
s += "c%s f%s b%s x%s" % (self.a_char, self.a_fg, self.a_bg, self.a_xform) self.b_char, self.b_fg, self.b_bg, self.b_xform
)
s += "c{} f{} b{} x{}".format(self.a_char, self.a_fg, self.a_bg, self.a_xform)
return s return s
def __eq__(self, value): def __eq__(self, value):
@ -259,7 +261,7 @@ class CommandStack:
self.undo_commands, self.redo_commands = [], [] self.undo_commands, self.redo_commands = [], []
def __str__(self): def __str__(self):
s = "stack for %s:\n" % self.art.filename s = "stack for {}:\n".format(self.art.filename)
s += "===\nundo:\n" s += "===\nundo:\n"
for cmd in self.undo_commands: for cmd in self.undo_commands:
s += str(cmd) + "\n" s += str(cmd) + "\n"

View file

@ -100,13 +100,13 @@ class ConvertImageOptionsDialog(ImportOptionsDialog):
# can't assume any art is open, use defaults if needed # can't assume any art is open, use defaults if needed
w = self.ui.active_art.width if self.ui.active_art else DEFAULT_WIDTH w = self.ui.active_art.width if self.ui.active_art else DEFAULT_WIDTH
h = self.ui.active_art.height if self.ui.active_art else DEFAULT_HEIGHT h = self.ui.active_art.height if self.ui.active_art else DEFAULT_HEIGHT
label %= "%s x %s" % (w, h) label %= "{} x {}".format(w, h)
elif field_index == 7: elif field_index == 7:
# scale # might not be valid # scale # might not be valid
valid, _ = self.is_input_valid() valid, _ = self.is_input_valid()
if not valid: if not valid:
return label % "???" return label % "???"
label %= "%s x %s" % self.get_tile_scale() label %= "{} x {}".format(*self.get_tile_scale())
return label return label
def get_tile_scale(self): def get_tile_scale(self):

View file

@ -50,7 +50,7 @@ class ImageSequenceConverter:
self.app.update_window_title() self.app.update_window_title()
def fail(self): def fail(self):
self.app.log("Bad frame %s" % self.image_filenames[0], error=True) self.app.log("Bad frame {}".format(self.image_filenames[0]), error=True)
self.finish(True) self.finish(True)
def update(self): def update(self):
@ -65,8 +65,9 @@ class ImageSequenceConverter:
time_taken = time.time() - self.start_time time_taken = time.time() - self.start_time
(verb, error) = ("cancelled", True) if cancelled else ("finished", False) (verb, error) = ("cancelled", True) if cancelled else ("finished", False)
self.app.log( self.app.log(
"Conversion of image sequence %s %s after %.3f seconds" "Conversion of image sequence {} {} after {:.3f} seconds".format(
% (self.image_name, verb, time_taken), self.image_name, verb, time_taken
),
error, error,
) )
self.app.converter = None self.app.converter = None
@ -96,7 +97,7 @@ image chosen.
bicubic_scale = options["bicubic_scale"] bicubic_scale = options["bicubic_scale"]
# get dir listing with full pathname # get dir listing with full pathname
in_dir = os.path.dirname(in_filename) in_dir = os.path.dirname(in_filename)
in_files = ["%s/%s" % (in_dir, f) for f in os.listdir(in_dir)] in_files = ["{}/{}".format(in_dir, f) for f in os.listdir(in_dir)]
in_files.sort() in_files.sort()
# assume numeric sequence starts from chosen file # assume numeric sequence starts from chosen file
in_files = in_files[in_files.index(in_filename) :] in_files = in_files[in_files.index(in_filename) :]

View file

@ -37,7 +37,7 @@ class PNGExportOptionsDialog(ExportOptionsDialog):
scale = int(self.field_texts[0]) scale = int(self.field_texts[0])
width = art.charset.char_width * art.width * scale width = art.charset.char_width * art.width * scale
height = art.charset.char_height * art.height * scale height = art.charset.char_height * art.height * scale
label %= "%s x %s" % (width, height) label %= "{} x {}".format(width, height)
return label return label
def is_input_valid(self): def is_input_valid(self):

View file

@ -22,14 +22,14 @@ def get_full_filename(
base_filename = os.path.splitext(base_filename)[0] base_filename = os.path.splitext(base_filename)[0]
fn = base_filename fn = base_filename
if use_frame: if use_frame:
fn += "_%s" % (str(frame).rjust(4, "0")) fn += "_{}".format(str(frame).rjust(4, "0"))
if use_layer: if use_layer:
fn += "_%s" % layer_name fn += "_{}".format(layer_name)
# strip unfriendly chars from output filename # strip unfriendly chars from output filename
for forbidden_char in ["\\", "/", "*", ":"]: for forbidden_char in ["\\", "/", "*", ":"]:
fn = fn.replace(forbidden_char, "") fn = fn.replace(forbidden_char, "")
# add path and extension for final mutated filename # add path and extension for final mutated filename
return "%s/%s.%s" % (dirname, fn, FILE_EXTENSION) return "{}/{}.{}".format(dirname, fn, FILE_EXTENSION)
class PNGSetExportOptionsDialog(ExportOptionsDialog): class PNGSetExportOptionsDialog(ExportOptionsDialog):
@ -78,7 +78,7 @@ class PNGSetExportOptionsDialog(ExportOptionsDialog):
scale = int(self.field_texts[0]) scale = int(self.field_texts[0])
width = art.charset.char_width * art.width * scale width = art.charset.char_width * art.width * scale
height = art.charset.char_height * art.height * scale height = art.charset.char_height * art.height * scale
label %= "%s x %s" % (width, height) label %= "{} x {}".format(width, height)
# show how many images exported set will be # show how many images exported set will be
elif field_index == 4: elif field_index == 4:
export_frames = bool(self.field_texts[2].strip()) export_frames = bool(self.field_texts[2].strip())

View file

@ -243,7 +243,9 @@ class GameObject:
if v not in obj_data: if v not in obj_data:
if self.log_load: if self.log_load:
self.app.dev_log( self.app.dev_log(
"Serialized property '%s' not found for %s" % (v, self.name) "Serialized property '{}' not found for {}".format(
v, self.name
)
) )
continue continue
# if value is in data and serialized list but undeclared, do so # if value is in data and serialized list but undeclared, do so
@ -286,7 +288,7 @@ class GameObject:
"Dict of all Arts this object can reference, eg for states" "Dict of all Arts this object can reference, eg for states"
# if art_src not specified, create a new art according to dimensions # if art_src not specified, create a new art according to dimensions
if self.generate_art: if self.generate_art:
self.art_src = "%s_art" % self.name self.art_src = "{}_art".format(self.name)
self.art = self.app.new_art( self.art = self.app.new_art(
self.art_src, self.art_src,
self.art_width, self.art_width,
@ -306,7 +308,7 @@ class GameObject:
self.art = self.arts[art] self.art = self.arts[art]
break break
if not self.art: if not self.art:
self.app.log("Couldn't spawn GameObject with art %s" % self.art_src) self.app.log("Couldn't spawn GameObject with art {}".format(self.art_src))
return return
self.renderable = GameObjectRenderable(self.app, self.art, self) self.renderable = GameObjectRenderable(self.app, self.art, self)
self.renderable.alpha = self.alpha self.renderable.alpha = self.alpha
@ -343,14 +345,15 @@ class GameObject:
self.start_animating() self.start_animating()
if self.log_spawn: if self.log_spawn:
self.app.log( self.app.log(
"Spawned %s with Art %s" "Spawned {} with Art {}".format(
% (self.name, os.path.basename(self.art.filename)) self.name, os.path.basename(self.art.filename)
)
) )
def get_unique_name(self): def get_unique_name(self):
"Generate and return a somewhat human-readable unique name for object" "Generate and return a somewhat human-readable unique name for object"
name = str(self) name = str(self)
return "%s_%s" % (type(self).__name__, name[name.rfind("x") + 1 : -1]) return "{}_{}".format(type(self).__name__, name[name.rfind("x") + 1 : -1])
def _rename(self, new_name): def _rename(self, new_name):
# pass thru to world, this method exists for edit set method # pass thru to world, this method exists for edit set method
@ -376,13 +379,13 @@ class GameObject:
if self.facing_changes_art: if self.facing_changes_art:
# load each facing for each state # load each facing for each state
for facing in FACINGS.values(): for facing in FACINGS.values():
art_name = "%s_%s_%s" % (self.art_src, state, facing) art_name = "{}_{}_{}".format(self.art_src, state, facing)
art = self.app.load_art(art_name, False) art = self.app.load_art(art_name, False)
if art: if art:
self.arts[art_name] = art self.arts[art_name] = art
else: else:
# load each state # load each state
art_name = "%s_%s" % (self.art_src, state) art_name = "{}_{}".format(self.art_src, state)
art = self.app.load_art(art_name, False) art = self.app.load_art(art_name, False)
if art: if art:
self.arts[art_name] = art self.arts[art_name] = art
@ -664,14 +667,14 @@ class GameObject:
"Return Art (and 'flip X' bool) that best represents current state" "Return Art (and 'flip X' bool) that best represents current state"
# use current state if none specified # use current state if none specified
state = self.state if state is None else state state = self.state if state is None else state
art_state_name = "%s_%s" % (self.art_src, self.state) art_state_name = "{}_{}".format(self.art_src, self.state)
# simple case: no facing, just state # simple case: no facing, just state
if not self.facing_changes_art: if not self.facing_changes_art:
# return art for current state, use default if not available # return art for current state, use default if not available
if art_state_name in self.arts: if art_state_name in self.arts:
return self.arts[art_state_name], False return self.arts[art_state_name], False
else: else:
default_name = "%s_%s" % (self.art_src, self.state or DEFAULT_STATE) default_name = "{}_{}".format(self.art_src, self.state or DEFAULT_STATE)
# assert(default_name in self.arts # assert(default_name in self.arts
# don't assert - if base+state name available, use that # don't assert - if base+state name available, use that
if default_name in self.arts: if default_name in self.arts:
@ -682,7 +685,7 @@ class GameObject:
# more complex case: art determined by both state and facing # more complex case: art determined by both state and facing
facing_suffix = FACINGS[self.facing] facing_suffix = FACINGS[self.facing]
# first see if anim exists for this exact state, skip subsequent logic # first see if anim exists for this exact state, skip subsequent logic
exact_name = "%s_%s" % (art_state_name, facing_suffix) exact_name = "{}_{}".format(art_state_name, facing_suffix)
if exact_name in self.arts: if exact_name in self.arts:
return self.arts[exact_name], False return self.arts[exact_name], False
# see what anims are available and try to choose best for facing # see what anims are available and try to choose best for facing
@ -693,12 +696,12 @@ class GameObject:
break break
# if NO anims for current state, fall back to default # if NO anims for current state, fall back to default
if not has_state: if not has_state:
default_name = "%s_%s" % (self.art_src, DEFAULT_STATE) default_name = "{}_{}".format(self.art_src, DEFAULT_STATE)
art_state_name = default_name art_state_name = default_name
front_name = "%s_%s" % (art_state_name, FACINGS[GOF_FRONT]) front_name = "{}_{}".format(art_state_name, FACINGS[GOF_FRONT])
left_name = "%s_%s" % (art_state_name, FACINGS[GOF_LEFT]) left_name = "{}_{}".format(art_state_name, FACINGS[GOF_LEFT])
right_name = "%s_%s" % (art_state_name, FACINGS[GOF_RIGHT]) right_name = "{}_{}".format(art_state_name, FACINGS[GOF_RIGHT])
back_name = "%s_%s" % (art_state_name, FACINGS[GOF_BACK]) back_name = "{}_{}".format(art_state_name, FACINGS[GOF_BACK])
has_front = front_name in self.arts has_front = front_name in self.arts
has_left = left_name in self.arts has_left = left_name in self.arts
has_right = right_name in self.arts has_right = right_name in self.arts
@ -991,7 +994,7 @@ class GameObject:
) )
if not timer: if not timer:
self.app.log( self.app.log(
"Timer named %s not found on object %s" % (timer_name, self.name) "Timer named {} not found on object {}".format(timer_name, self.name)
) )
d = [ d = [
self.timer_functions_pre_update, self.timer_functions_pre_update,
@ -1119,8 +1122,9 @@ class GameObject:
or abs(self.y) > self.kill_distance_from_origin or abs(self.y) > self.kill_distance_from_origin
): ):
self.app.log( self.app.log(
"%s reached %s from origin, destroying." "{} reached {} from origin, destroying.".format(
% (self.name, self.kill_distance_from_origin) self.name, self.kill_distance_from_origin
)
) )
self.destroy() self.destroy()

View file

@ -44,7 +44,9 @@ class GameRoom:
for v in self.serialized: for v in self.serialized:
if v not in room_data: if v not in room_data:
self.world.app.dev_log( self.world.app.dev_log(
"Serialized property '%s' not found for room %s" % (v, self.name) "Serialized property '{}' not found for room {}".format(
v, self.name
)
) )
continue continue
if not hasattr(self, v): if not hasattr(self, v):
@ -90,7 +92,9 @@ class GameRoom:
def set_camera_marker_name(self, marker_name): def set_camera_marker_name(self, marker_name):
if marker_name not in self.world.objects: if marker_name not in self.world.objects:
self.world.app.log("Couldn't find camera marker with name %s" % marker_name) self.world.app.log(
"Couldn't find camera marker with name {}".format(marker_name)
)
return return
self.camera_marker_name = marker_name self.camera_marker_name = marker_name
if self is self.world.current_room: if self is self.world.current_room:
@ -105,7 +109,7 @@ class GameRoom:
def entered(self, old_room): def entered(self, old_room):
"Run when the player enters this room." "Run when the player enters this room."
if self.log_changes: if self.log_changes:
self.world.app.log('Room "%s" entered' % self.name) self.world.app.log('Room "{}" entered'.format(self.name))
# set camera if marker is set # set camera if marker is set
if self.world.room_camera_changes_enabled: if self.world.room_camera_changes_enabled:
self.use_camera_marker() self.use_camera_marker()
@ -120,7 +124,7 @@ class GameRoom:
def exited(self, new_room): def exited(self, new_room):
"Run when the player exits this room." "Run when the player exits this room."
if self.log_changes: if self.log_changes:
self.world.app.log('Room "%s" exited' % self.name) self.world.app.log('Room "{}" exited'.format(self.name))
# tell objects in this room player has exited # tell objects in this room player has exited
for obj in self.objects.values(): for obj in self.objects.values():
obj.room_exited(self, new_room) obj.room_exited(self, new_room)
@ -129,7 +133,7 @@ class GameRoom:
"Add object with given name to this room." "Add object with given name to this room."
obj = self.world.objects.get(obj_name, None) obj = self.world.objects.get(obj_name, None)
if not obj: if not obj:
self.world.app.log("Couldn't find object named %s" % obj_name) self.world.app.log("Couldn't find object named {}".format(obj_name))
return return
self.add_object(obj) self.add_object(obj)
@ -142,7 +146,7 @@ class GameRoom:
"Remove object with given name from this room." "Remove object with given name from this room."
obj = self.world.objects.get(obj_name, None) obj = self.world.objects.get(obj_name, None)
if not obj: if not obj:
self.world.app.log("Couldn't find object named %s" % obj_name) self.world.app.log("Couldn't find object named {}".format(obj_name))
return return
self.remove_object(obj) self.remove_object(obj)
@ -152,13 +156,13 @@ class GameRoom:
self.objects.pop(obj.name) self.objects.pop(obj.name)
else: else:
self.world.app.log( self.world.app.log(
"GameRoom %s doesn't contain GameObject %s" % (self.name, obj.name) "GameRoom {} doesn't contain GameObject {}".format(self.name, obj.name)
) )
if self.name in obj.rooms: if self.name in obj.rooms:
obj.rooms.pop(self.name) obj.rooms.pop(self.name)
else: else:
self.world.app.log( self.world.app.log(
"GameObject %s not found in GameRoom %s" % (obj.name, self.name) "GameObject {} not found in GameRoom {}".format(obj.name, self.name)
) )
def get_dict(self): def get_dict(self):

View file

@ -369,8 +369,9 @@ class WarpTrigger(StaticTileTrigger):
marker = self.world.objects.get(self.destination_marker_name, None) marker = self.world.objects.get(self.destination_marker_name, None)
if not marker: if not marker:
self.app.log( self.app.log(
"Warp destination object %s not found" "Warp destination object {} not found".format(
% self.destination_marker_name self.destination_marker_name
)
) )
return return
other.set_loc(marker.x, marker.y, marker.z) other.set_loc(marker.x, marker.y, marker.z)
@ -383,8 +384,9 @@ class WarpTrigger(StaticTileTrigger):
and room.name != self.destination_room_name and room.name != self.destination_room_name
): ):
self.app.log( self.app.log(
"Marker %s's room differs from destination room %s" "Marker {}'s room differs from destination room {}".format(
% (marker.name, self.destination_room_name) marker.name, self.destination_room_name
)
) )
self.world.change_room(room.name) self.world.change_room(room.name)
other.last_warp_update = self.world.updates other.last_warp_update = self.world.updates
@ -502,8 +504,9 @@ class SoundBlaster(LocationMarker):
self.sound_filenames[self.sound_name] = filename self.sound_filenames[self.sound_name] = filename
return return
self.world.app.log( self.world.app.log(
"Couldn't find sound file %s for SoundBlaster %s" "Couldn't find sound file {} for SoundBlaster {}".format(
% (self.sound_name, self.name) self.sound_name, self.name
)
) )
def room_entered(self, room, old_room): def room_entered(self, room, old_room):

View file

@ -220,7 +220,7 @@ class GameWorld:
new_obj = self.spawn_object_of_class(self.classname_to_spawn, x, y) new_obj = self.spawn_object_of_class(self.classname_to_spawn, x, y)
if self.current_room: if self.current_room:
self.current_room.add_object(new_obj) self.current_room.add_object(new_obj)
self.app.ui.message_line.post_line("Spawned %s" % new_obj.name) self.app.ui.message_line.post_line("Spawned {}".format(new_obj.name))
return return
objects = self.get_objects_at(x, y) objects = self.get_objects_at(x, y)
next_obj = self.pick_next_object_at(x, y) next_obj = self.pick_next_object_at(x, y)
@ -408,7 +408,7 @@ class GameWorld:
self.unload_game() self.unload_game()
new_dir = self.app.documents_dir + TOP_GAME_DIR + new_game_dir + "/" new_dir = self.app.documents_dir + TOP_GAME_DIR + new_game_dir + "/"
if os.path.exists(new_dir): if os.path.exists(new_dir):
self.app.log("Game dir %s already exists!" % new_game_dir) self.app.log("Game dir {} already exists!".format(new_game_dir))
return False return False
os.mkdir(new_dir) os.mkdir(new_dir)
os.mkdir(new_dir + ART_DIR) os.mkdir(new_dir + ART_DIR)
@ -514,7 +514,7 @@ class GameWorld:
self.game_name = dir_name self.game_name = dir_name
if not d.endswith("/"): if not d.endswith("/"):
self.game_dir += "/" self.game_dir += "/"
self.app.log("Game data folder is now %s" % self.game_dir) self.app.log("Game data folder is now {}".format(self.game_dir))
# set sounds dir before loading state; some obj inits depend on it # set sounds dir before loading state; some obj inits depend on it
self.sounds_dir = self.game_dir + SOUNDS_DIR self.sounds_dir = self.game_dir + SOUNDS_DIR
if reset: if reset:
@ -526,7 +526,7 @@ class GameWorld:
self.classes = self._get_all_loaded_classes() self.classes = self._get_all_loaded_classes()
break break
if not self.game_dir: if not self.game_dir:
self.app.log("Couldn't find game directory %s" % dir_name) self.app.log("Couldn't find game directory {}".format(dir_name))
def _remove_non_current_game_modules(self): def _remove_non_current_game_modules(self):
""" """
@ -535,7 +535,7 @@ class GameWorld:
""" """
modules_to_remove = [] modules_to_remove = []
games_dir_prefix = TOP_GAME_DIR.replace("/", "") games_dir_prefix = TOP_GAME_DIR.replace("/", "")
this_game_dir_prefix = "%s.%s" % (games_dir_prefix, self.game_name) this_game_dir_prefix = "{}.{}".format(games_dir_prefix, self.game_name)
for module_name in sys.modules: for module_name in sys.modules:
# remove any module that isn't for this game or part of its path # remove any module that isn't for this game or part of its path
if ( if (
@ -555,7 +555,7 @@ class GameWorld:
# build list of module files # build list of module files
modules_list = self.builtin_module_names[:] modules_list = self.builtin_module_names[:]
# create appropriately-formatted python import path # create appropriately-formatted python import path
module_path_prefix = "%s.%s.%s." % ( module_path_prefix = "{}.{}.{}.".format(
TOP_GAME_DIR.replace("/", ""), TOP_GAME_DIR.replace("/", ""),
self.game_name, self.game_name,
GAME_SCRIPTS_DIR.replace("/", ""), GAME_SCRIPTS_DIR.replace("/", ""),
@ -603,7 +603,7 @@ class GameWorld:
if not self.allow_pause: if not self.allow_pause:
return return
self.paused = not self.paused self.paused = not self.paused
s = "Game %spaused." % ["un", ""][self.paused] s = "Game {}paused.".format(["un", ""][self.paused])
self.app.ui.message_line.post_line(s) self.app.ui.message_line.post_line(s)
def get_elapsed_time(self): def get_elapsed_time(self):
@ -758,7 +758,7 @@ class GameWorld:
and line.strip() != "method()" and line.strip() != "method()"
): ):
self.app.log(line.rstrip()) self.app.log(line.rstrip())
s = "Error in %s.%s! See console." % (obj.name, method.__name__) s = "Error in {}.{}! See console.".format(obj.name, method.__name__)
self.app.ui.message_line.post_line(s, 10, True) self.app.ui.message_line.post_line(s, 10, True)
def pre_update(self): def pre_update(self):
@ -938,14 +938,14 @@ class GameWorld:
if filename and filename != "": if filename and filename != "":
if not filename.endswith(STATE_FILE_EXTENSION): if not filename.endswith(STATE_FILE_EXTENSION):
filename += "." + STATE_FILE_EXTENSION filename += "." + STATE_FILE_EXTENSION
filename = "%s%s" % (self.game_dir, filename) filename = "{}{}".format(self.game_dir, filename)
else: else:
# state filename example: # state filename example:
# games/mytestgame2/1431116386.gs # games/mytestgame2/1431116386.gs
timestamp = int(time.time()) timestamp = int(time.time())
filename = "%s%s.%s" % (self.game_dir, timestamp, STATE_FILE_EXTENSION) filename = "{}{}.{}".format(self.game_dir, timestamp, STATE_FILE_EXTENSION)
json.dump(d, open(filename, "w"), sort_keys=True, indent=1) json.dump(d, open(filename, "w"), sort_keys=True, indent=1)
self.app.log("Saved game state %s to disk." % filename) self.app.log("Saved game state {} to disk.".format(filename))
self.app.update_window_title() self.app.update_window_title()
def _get_all_loaded_classes(self): def _get_all_loaded_classes(self):
@ -982,7 +982,7 @@ class GameWorld:
obj_class = obj.__class__.__name__ obj_class = obj.__class__.__name__
spawned = self.spawn_object_of_class(obj_class, x, y) spawned = self.spawn_object_of_class(obj_class, x, y)
if spawned: if spawned:
self.app.log("%s reset to class defaults" % obj.name) self.app.log("{} reset to class defaults".format(obj.name))
if obj is self.player: if obj is self.player:
self.player = spawned self.player = spawned
obj.destroy() obj.destroy()
@ -994,9 +994,9 @@ class GameWorld:
new_objects.append(self.duplicate_object(obj)) new_objects.append(self.duplicate_object(obj))
# report on objects created # report on objects created
if len(new_objects) == 1: if len(new_objects) == 1:
self.app.log("%s created from %s" % (new_objects[0].name, obj.name)) self.app.log("{} created from {}".format(new_objects[0].name, obj.name))
elif len(new_objects) > 1: elif len(new_objects) > 1:
self.app.log("%s new objects created" % len(new_objects)) self.app.log("{} new objects created".format(len(new_objects)))
def duplicate_object(self, obj): def duplicate_object(self, obj):
"Create a duplicate of given object." "Create a duplicate of given object."
@ -1025,7 +1025,9 @@ class GameWorld:
for other_obj in self.objects.values(): for other_obj in self.objects.values():
if other_obj is not self and other_obj.name == new_name: if other_obj is not self and other_obj.name == new_name:
self.app.ui.message_line.post_line( self.app.ui.message_line.post_line(
"Can't rename %s to %s, name already in use" % (obj.name, new_name) "Can't rename {} to {}, name already in use".format(
obj.name, new_name
)
) )
return return
self.objects.pop(obj.name) self.objects.pop(obj.name)
@ -1066,7 +1068,7 @@ class GameWorld:
def add_room(self, new_room_name, new_room_classname="GameRoom"): def add_room(self, new_room_name, new_room_classname="GameRoom"):
"Add a new Room with given name of (optional) given class." "Add a new Room with given name of (optional) given class."
if new_room_name in self.rooms: if new_room_name in self.rooms:
self.log("Room called %s already exists!" % new_room_name) self.log("Room called {} already exists!".format(new_room_name))
return return
new_room_class = self.classes[new_room_classname] new_room_class = self.classes[new_room_classname]
new_room = new_room_class(self, new_room_name) new_room = new_room_class(self, new_room_name)
@ -1084,7 +1086,7 @@ class GameWorld:
def change_room(self, new_room_name): def change_room(self, new_room_name):
"Set world's current active room to Room with given name." "Set world's current active room to Room with given name."
if new_room_name not in self.rooms: if new_room_name not in self.rooms:
self.app.log("Couldn't change to missing room %s" % new_room_name) self.app.log("Couldn't change to missing room {}".format(new_room_name))
return return
old_room = self.current_room old_room = self.current_room
self.current_room = self.rooms[new_room_name] self.current_room = self.rooms[new_room_name]
@ -1122,7 +1124,7 @@ class GameWorld:
d = json.load(open(filename)) d = json.load(open(filename))
# self.app.log('Loading game state %s...' % filename) # self.app.log('Loading game state %s...' % filename)
except: except:
self.app.log("Couldn't load game state from %s" % filename) self.app.log("Couldn't load game state from {}".format(filename))
# self.app.log(sys.exc_info()) # self.app.log(sys.exc_info())
return return
errors = False errors = False
@ -1159,7 +1161,7 @@ class GameWorld:
self.hud = hud_class(self) self.hud = hud_class(self)
self.hud_class_name = hud_class.__name__ self.hud_class_name = hud_class.__name__
if not errors and self.app.init_success: if not errors and self.app.init_success:
self.app.log("Loaded game state from %s" % filename) self.app.log("Loaded game state from {}".format(filename))
self.last_state_loaded = filename self.last_state_loaded = filename
self.set_for_all_objects("show_collision", self.show_collision_all) self.set_for_all_objects("show_collision", self.show_collision_all)
self.set_for_all_objects("show_bounds", self.show_bounds_all) self.set_for_all_objects("show_bounds", self.show_bounds_all)
@ -1170,13 +1172,13 @@ class GameWorld:
def report(self): def report(self):
"Print (not log) information about current world state." "Print (not log) information about current world state."
print("--------------\n%s report:" % self) print("--------------\n{} report:".format(self))
obj_arts, obj_rends, obj_dbg_rends, obj_cols, obj_col_rends = 0, 0, 0, 0, 0 obj_arts, obj_rends, obj_dbg_rends, obj_cols, obj_col_rends = 0, 0, 0, 0, 0
attachments = 0 attachments = 0
# create merged dict of existing and just-spawned objects # create merged dict of existing and just-spawned objects
all_objects = self.objects.copy() all_objects = self.objects.copy()
all_objects.update(self.new_objects) all_objects.update(self.new_objects)
print("%s objects:" % len(all_objects)) print("{} objects:".format(len(all_objects)))
for obj in all_objects.values(): for obj in all_objects.values():
obj_arts += len(obj.arts) obj_arts += len(obj.arts)
if obj.renderable is not None: if obj.renderable is not None:
@ -1191,12 +1193,11 @@ class GameWorld:
attachments += len(obj.attachments) attachments += len(obj.attachments)
print( print(
""" """
%s arts in objects, %s arts loaded, {} arts in objects, {} arts loaded,
%s HUD arts, %s HUD renderables, {} HUD arts, {} HUD renderables,
%s renderables, %s debug renderables, {} renderables, {} debug renderables,
%s collideables, %s collideable viz renderables, {} collideables, {} collideable viz renderables,
%s attachments""" {} attachments""".format(
% (
obj_arts, obj_arts,
len(self.art_loaded), len(self.art_loaded),
len(self.hud.arts), len(self.hud.arts),
@ -1210,10 +1211,11 @@ class GameWorld:
) )
self.cl.report() self.cl.report()
print( print(
"%s charsets loaded, %s palettes" "{} charsets loaded, {} palettes".format(
% (len(self.app.charsets), len(self.app.palettes)) len(self.app.charsets), len(self.app.palettes)
)
) )
print("%s arts loaded for edit" % len(self.app.art_loaded_for_edit)) print("{} arts loaded for edit".format(len(self.app.art_loaded_for_edit)))
def toggle_all_origin_viz(self): def toggle_all_origin_viz(self):
"Toggle visibility of XYZ markers for all object origins." "Toggle visibility of XYZ markers for all object origins."

View file

@ -55,7 +55,7 @@ class CrawlPlayer(Player):
if key == "up" if key == "up"
else DIR_NAMES[OPPOSITE_DIRS[self.direction]] else DIR_NAMES[OPPOSITE_DIRS[self.direction]]
) )
self.app.log("can't go %s!" % dir_name) self.app.log("can't go {}!".format(dir_name))
else: else:
self.x, self.y = self.maze.x + new_x, self.maze.y - new_y self.x, self.y = self.maze.x + new_x, self.maze.y - new_y
# update art to show facing # update art to show facing

View file

@ -79,7 +79,7 @@ class Fireplace(GameObject):
self.credit_screen = None self.credit_screen = None
self.music_exists = False self.music_exists = False
if os.path.exists(self.world.sounds_dir + MUSIC_FILENAME): if os.path.exists(self.world.sounds_dir + MUSIC_FILENAME):
self.app.log("%s found in %s" % (MUSIC_FILENAME, self.world.sounds_dir)) self.app.log("{} found in {}".format(MUSIC_FILENAME, self.world.sounds_dir))
self.world.play_music(MUSIC_FILENAME) self.world.play_music(MUSIC_FILENAME)
self.music_paused = False self.music_paused = False
self.music_exists = True self.music_exists = True
@ -88,7 +88,9 @@ class Fireplace(GameObject):
self.credit_screen.z = 1.1 self.credit_screen.z = 1.1
self.credit_screen.set_scale(0.75, 0.75, 1) self.credit_screen.set_scale(0.75, 0.75, 1)
else: else:
self.app.log("No %s found in %s" % (MUSIC_FILENAME, self.world.sounds_dir)) self.app.log(
"No {} found in {}".format(MUSIC_FILENAME, self.world.sounds_dir)
)
self.set_new_message_time() self.set_new_message_time()
def update(self): def update(self):
@ -190,14 +192,14 @@ class Fireplace(GameObject):
elif key == "=" or key == "+": elif key == "=" or key == "+":
self.target_particles += 10 self.target_particles += 10
self.art.write_string( self.art.write_string(
0, 0, 0, 0, "Embers: %s" % self.target_particles, 15, 1 0, 0, 0, 0, "Embers: {}".format(self.target_particles), 15, 1
) )
elif key == "-": elif key == "-":
if self.target_particles <= 10: if self.target_particles <= 10:
return return
self.target_particles -= 10 self.target_particles -= 10
self.art.write_string( self.art.write_string(
0, 0, 0, 0, "Embers: %s" % self.target_particles, 15, 1 0, 0, 0, 0, "Embers: {}".format(self.target_particles), 15, 1
) )

View file

@ -79,7 +79,7 @@ class Board(GameObject):
self.reset() self.reset()
return return
# get list of valid keys from length of tile_colors # get list of valid keys from length of tile_colors
valid_keys = ["%s" % str(i + 1) for i in range(len(TILE_COLORS))] valid_keys = ["{}".format(str(i + 1)) for i in range(len(TILE_COLORS))]
if key not in valid_keys: if key not in valid_keys:
return return
key = int(key) - 1 key = int(key) - 1

View file

@ -88,7 +88,7 @@ class MazePickup(GameObject):
def picked_up(self, new_holder): def picked_up(self, new_holder):
self.holder = new_holder self.holder = new_holder
self.world.hud.post_msg("got %s!" % self.display_name) self.world.hud.post_msg("got {}!".format(self.display_name))
self.disable_collision() self.disable_collision()
self.play_sound("pickup") self.play_sound("pickup")
@ -167,7 +167,9 @@ class MazeLock(StaticTileBG):
if other.held_object and type(other.held_object) is self.key_type: if other.held_object and type(other.held_object) is self.key_type:
self.unlocked(other) self.unlocked(other)
else: else:
self.world.hud.post_msg("blocked - need %s!" % self.key_type.display_name) self.world.hud.post_msg(
"blocked - need {}!".format(self.key_type.display_name)
)
def unlocked(self, other): def unlocked(self, other):
self.disable_collision() self.disable_collision()

View file

@ -90,7 +90,7 @@ class FlowerObject(GameObject):
# track # of growth updates we've had # track # of growth updates we've had
self.grows = 0 self.grows = 0
# create an art document we can add frames to and later export # create an art document we can add frames to and later export
self.export_filename = "%s%swildflower_%s" % ( self.export_filename = "{}{}wildflower_{}".format(
self.app.documents_dir, self.app.documents_dir,
ART_DIR, ART_DIR,
self.seed, self.seed,

View file

@ -81,12 +81,11 @@ class Frond:
if self.life <= 0 or self.color == self.ramp.end: if self.life <= 0 or self.color == self.ramp.end:
self.finished_growing = True self.finished_growing = True
if self.debug: if self.debug:
print(" frond %i finished." % self.index) print(f" frond {self.index} finished.")
return painted return painted
if self.debug: if self.debug:
print( print(
" frond %i at (%i, %i) using %s" f" frond {self.index} at ({self.x}, {self.y}) using {self.get_grow_dir.__name__}"
% (self.index, self.x, self.y, self.get_grow_dir.__name__)
) )
# if we're out of bounds, simply don't paint; # if we're out of bounds, simply don't paint;
# we might go back in bounds next grow # we might go back in bounds next grow

View file

@ -68,14 +68,7 @@ class Petal:
return return
if self.debug: if self.debug:
print( print(
" petal %i at (%i, %i) at radius %i using %s" f" petal {self.index} at ({self.x}, {self.y}) at radius {self.radius} using {self.get_ring_tiles.__name__}"
% (
self.index,
self.x,
self.y,
self.radius,
self.get_ring_tiles.__name__,
)
) )
self.paint_ring() self.paint_ring()
# grow and change # grow and change

View file

@ -69,7 +69,7 @@ class FlowerGlobals(WorldGlobalsObject):
scale=4, scale=4,
bg_color=self.world.bg_color, bg_color=self.world.bg_color,
) )
self.app.log("Exported %s.png" % self.flower.export_filename) self.app.log("Exported {}.png".format(self.flower.export_filename))
class SeedDisplay(GameObject): class SeedDisplay(GameObject):

View file

@ -38,7 +38,7 @@ class ImageConverter:
self.init_success = False self.init_success = False
image_filename = app.find_filename_path(image_filename) image_filename = app.find_filename_path(image_filename)
if not image_filename or not os.path.exists(image_filename): if not image_filename or not os.path.exists(image_filename):
app.log("ImageConverter: Couldn't find image %s" % image_filename) app.log("ImageConverter: Couldn't find image {}".format(image_filename))
app.converter = None app.converter = None
return return
self.app = app self.app = app
@ -266,8 +266,9 @@ class ImageConverter:
time_taken = time.time() - self.start_time time_taken = time.time() - self.start_time
verb = "cancelled" if cancelled else "finished" verb = "cancelled" if cancelled else "finished"
self.app.log( self.app.log(
"Conversion of image %s %s after %.3f seconds" "Conversion of image {} {} after {:.3f} seconds".format(
% (self.image_filename, verb, time_taken) self.image_filename, verb, time_taken
)
) )
self.app.converter = None self.app.converter = None
self.preview_sprite = None self.preview_sprite = None

View file

@ -14,8 +14,9 @@ def get_frame_image(app, art, frame, allow_crt=True, scale=1, bg_color=(0, 0, 0,
# error out if over max texture size # error out if over max texture size
if w > app.max_texture_size or h > app.max_texture_size: if w > app.max_texture_size or h > app.max_texture_size:
app.log( app.log(
"ERROR: Image output size (%s x %s) exceeds your hardware's max supported texture size (%s x %s)!" "ERROR: Image output size ({} x {}) exceeds your hardware's max supported texture size ({} x {})!".format(
% (w, h, app.max_texture_size, app.max_texture_size), w, h, app.max_texture_size, app.max_texture_size
),
error=True, error=True,
) )
app.log( app.log(

View file

@ -89,13 +89,13 @@ class InputLord:
) < os.path.getmtime(BINDS_TEMPLATE_FILENAME) ) < os.path.getmtime(BINDS_TEMPLATE_FILENAME)
if not binds_outdated and os.path.exists(binds_filename): if not binds_outdated and os.path.exists(binds_filename):
exec(open(binds_filename).read()) exec(open(binds_filename).read())
self.app.log("Loaded key binds from %s" % binds_filename) self.app.log("Loaded key binds from {}".format(binds_filename))
else: else:
default_data = open(BINDS_TEMPLATE_FILENAME).readlines()[1:] default_data = open(BINDS_TEMPLATE_FILENAME).readlines()[1:]
new_binds = open(binds_filename, "w") new_binds = open(binds_filename, "w")
new_binds.writelines(default_data) new_binds.writelines(default_data)
new_binds.close() new_binds.close()
self.app.log("Created new key binds file %s" % binds_filename) self.app.log("Created new key binds file {}".format(binds_filename))
exec("".join(default_data)) exec("".join(default_data))
if not self.edit_bind_src: if not self.edit_bind_src:
self.app.log("No bind data found, Is binds.cfg.default present?") self.app.log("No bind data found, Is binds.cfg.default present?")
@ -109,9 +109,9 @@ class InputLord:
# bind data could be a single item (string) or a list/tuple # bind data could be a single item (string) or a list/tuple
bind_data = self.edit_bind_src[bind_string] bind_data = self.edit_bind_src[bind_string]
if type(bind_data) is str: if type(bind_data) is str:
bind_fnames = ["BIND_%s" % bind_data] bind_fnames = ["BIND_{}".format(bind_data)]
else: else:
bind_fnames = ["BIND_%s" % s for s in bind_data] bind_fnames = ["BIND_{}".format(s) for s in bind_data]
bind_functions = [] bind_functions = []
for bind_fname in bind_fnames: for bind_fname in bind_fnames:
if not hasattr(self, bind_fname): if not hasattr(self, bind_fname):
@ -123,7 +123,7 @@ class InputLord:
js_init = sdl2.SDL_InitSubSystem(sdl2.SDL_INIT_JOYSTICK) js_init = sdl2.SDL_InitSubSystem(sdl2.SDL_INIT_JOYSTICK)
if js_init != 0: if js_init != 0:
self.app.log( self.app.log(
"SDL2: Couldn't initialize joystick subsystem, code %s" % js_init "SDL2: Couldn't initialize joystick subsystem, code {}".format(js_init)
) )
return return
sticks = sdl2.SDL_NumJoysticks() sticks = sdl2.SDL_NumJoysticks()
@ -137,8 +137,9 @@ class InputLord:
pad_axes = sdl2.SDL_JoystickNumAxes(pad) pad_axes = sdl2.SDL_JoystickNumAxes(pad)
pad_buttons = sdl2.SDL_JoystickNumButtons(pad) pad_buttons = sdl2.SDL_JoystickNumButtons(pad)
self.app.log( self.app.log(
"Gamepad found: %s with %s axes, %s buttons" "Gamepad found: {} with {} axes, {} buttons".format(
% (pad_name, pad_axes, pad_buttons) pad_name, pad_axes, pad_buttons
)
) )
self.gamepad = pad self.gamepad = pad
# before main loop begins, set initial mouse position - # before main loop begins, set initial mouse position -
@ -204,7 +205,7 @@ class InputLord:
if not hasattr(button, "menu_data"): if not hasattr(button, "menu_data"):
continue continue
for item in button.menu_data.items: for item in button.menu_data.items:
if function.__name__ == "BIND_%s" % item.command: if function.__name__ == "BIND_{}".format(item.command):
items.append(item) items.append(item)
return items return items
@ -1224,10 +1225,14 @@ class InputLord:
for obj in self.app.gw.selected_objects: for obj in self.app.gw.selected_objects:
if obj.orig_collision_type and obj.collision_type == CT_NONE: if obj.orig_collision_type and obj.collision_type == CT_NONE:
obj.enable_collision() obj.enable_collision()
self.ui.message_line.post_line("Collision enabled for %s" % obj.name) self.ui.message_line.post_line(
"Collision enabled for {}".format(obj.name)
)
elif obj.collision_type != CT_NONE: elif obj.collision_type != CT_NONE:
obj.disable_collision() obj.disable_collision()
self.ui.message_line.post_line("Collision disabled for %s" % obj.name) self.ui.message_line.post_line(
"Collision disabled for {}".format(obj.name)
)
def BIND_toggle_game_edit_ui(self): def BIND_toggle_game_edit_ui(self):
self.ui.toggle_game_edit_ui() self.ui.toggle_game_edit_ui()

View file

@ -34,10 +34,13 @@ class PaletteLord:
changed = palette.filename changed = palette.filename
try: try:
palette.load_image() palette.load_image()
self.app.log("PaletteLord: success reloading %s" % palette.filename) self.app.log(
"PaletteLord: success reloading {}".format(palette.filename)
)
except: except:
self.app.log( self.app.log(
"PaletteLord: failed reloading %s" % palette.filename, True "PaletteLord: failed reloading {}".format(palette.filename),
True,
) )
@ -49,7 +52,7 @@ class Palette:
src_filename, PALETTE_DIR, PALETTE_EXTENSIONS src_filename, PALETTE_DIR, PALETTE_EXTENSIONS
) )
if self.filename is None: if self.filename is None:
self.app.log("Couldn't find palette image %s" % src_filename) self.app.log("Couldn't find palette image {}".format(src_filename))
return return
self.last_image_change = os.path.getmtime(self.filename) self.last_image_change = os.path.getmtime(self.filename)
self.name = os.path.basename(self.filename) self.name = os.path.basename(self.filename)
@ -57,10 +60,12 @@ class Palette:
self.load_image() self.load_image()
self.base_filename = os.path.splitext(os.path.basename(self.filename))[0] self.base_filename = os.path.splitext(os.path.basename(self.filename))[0]
if log and not self.app.game_mode: if log and not self.app.game_mode:
self.app.log("loaded palette '%s' from %s:" % (self.name, self.filename)) self.app.log(
self.app.log(" unique colors found: %s" % int(len(self.colors) - 1)) "loaded palette '{}' from {}:".format(self.name, self.filename)
self.app.log(" darkest color index: %s" % self.darkest_index) )
self.app.log(" lightest color index: %s" % self.lightest_index) self.app.log(" unique colors found: {}".format(int(len(self.colors) - 1)))
self.app.log(" darkest color index: {}".format(self.darkest_index))
self.app.log(" lightest color index: {}".format(self.lightest_index))
self.init_success = True self.init_success = True
def load_image(self): def load_image(self):
@ -219,7 +224,7 @@ class PaletteFromList(Palette):
self.init_success = False self.init_success = False
self.app = app self.app = app
# generate a unique non-user-facing palette name # generate a unique non-user-facing palette name
name = "PaletteFromList_%s" % time.time() name = "PaletteFromList_{}".format(time.time())
self.filename = self.name = self.base_filename = name self.filename = self.name = self.base_filename = name
colors = [] colors = []
for color in src_color_list: for color in src_color_list:
@ -247,10 +252,10 @@ class PaletteFromList(Palette):
x += 1 x += 1
self.texture = Texture(img.tobytes(), MAX_COLORS, 1) self.texture = Texture(img.tobytes(), MAX_COLORS, 1)
if log and not self.app.game_mode: if log and not self.app.game_mode:
self.app.log("generated new palette '%s'" % (self.name)) self.app.log("generated new palette '{}'".format(self.name))
self.app.log(" unique colors: %s" % int(len(self.colors) - 1)) self.app.log(" unique colors: {}".format(int(len(self.colors) - 1)))
self.app.log(" darkest color index: %s" % self.darkest_index) self.app.log(" darkest color index: {}".format(self.darkest_index))
self.app.log(" lightest color index: %s" % self.lightest_index) self.app.log(" lightest color index: {}".format(self.lightest_index))
def has_updated(self): def has_updated(self):
"No bitmap source for this type of palette, so no hot-reload" "No bitmap source for this type of palette, so no hot-reload"
@ -262,7 +267,7 @@ class PaletteFromFile(Palette):
self.init_success = False self.init_success = False
src_filename = app.find_filename_path(src_filename) src_filename = app.find_filename_path(src_filename)
if not src_filename: if not src_filename:
app.log("Couldn't find palette source image %s" % src_filename) app.log("Couldn't find palette source image {}".format(src_filename))
return return
# dither source image, re-save it, use that as the source for a palette # dither source image, re-save it, use that as the source for a palette
src_img = Image.open(src_filename) src_img = Image.open(src_filename)
@ -281,7 +286,7 @@ class PaletteFromFile(Palette):
if os.path.exists(palette_path + palette_filename + ".png"): if os.path.exists(palette_path + palette_filename + ".png"):
i = 0 i = 0
while os.path.exists( while os.path.exists(
"%s%s%s.png" % (palette_path, palette_filename, str(i)) "{}{}{}.png".format(palette_path, palette_filename, str(i))
): ):
i += 1 i += 1
palette_filename += str(i) palette_filename += str(i)

View file

@ -284,7 +284,7 @@ class Application:
gpu_renderer = GL.glGetString(GL.GL_RENDERER).decode("utf-8") gpu_renderer = GL.glGetString(GL.GL_RENDERER).decode("utf-8")
except: except:
gpu_renderer = "[couldn't detect renderer]" gpu_renderer = "[couldn't detect renderer]"
self.log(" GPU: %s - %s" % (gpu_vendor, gpu_renderer)) self.log(" GPU: {} - {}".format(gpu_vendor, gpu_renderer))
try: try:
# try single-argument GL2.0 version first # try single-argument GL2.0 version first
gl_ver = GL.glGetString(GL.GL_VERSION) gl_ver = GL.glGetString(GL.GL_VERSION)
@ -293,7 +293,7 @@ class Application:
gl_ver = gl_ver.decode("utf-8") gl_ver = gl_ver.decode("utf-8")
except: except:
gl_ver = "[couldn't detect GL version]" gl_ver = "[couldn't detect GL version]"
self.log(" OpenGL detected: %s" % gl_ver) self.log(" OpenGL detected: {}".format(gl_ver))
# GL 1.1 doesn't even habla shaders, quit if we fail GLSL version check # GL 1.1 doesn't even habla shaders, quit if we fail GLSL version check
try: try:
glsl_ver = GL.glGetString(GL.GL_SHADING_LANGUAGE_VERSION) glsl_ver = GL.glGetString(GL.GL_SHADING_LANGUAGE_VERSION)
@ -306,14 +306,16 @@ class Application:
self.should_quit = True self.should_quit = True
return return
glsl_ver = glsl_ver.decode("utf-8") if glsl_ver != None else None glsl_ver = glsl_ver.decode("utf-8") if glsl_ver != None else None
self.log(" GLSL detected: %s" % glsl_ver or "[unknown]") self.log(" GLSL detected: {}".format(glsl_ver) or "[unknown]")
# verify that we got at least a 2.1 context # verify that we got at least a 2.1 context
majorv, minorv = ctypes.c_int(0), ctypes.c_int(0) majorv, minorv = ctypes.c_int(0), ctypes.c_int(0)
video.SDL_GL_GetAttribute(video.SDL_GL_CONTEXT_MAJOR_VERSION, majorv) video.SDL_GL_GetAttribute(video.SDL_GL_CONTEXT_MAJOR_VERSION, majorv)
video.SDL_GL_GetAttribute(video.SDL_GL_CONTEXT_MINOR_VERSION, minorv) video.SDL_GL_GetAttribute(video.SDL_GL_CONTEXT_MINOR_VERSION, minorv)
context_version = majorv.value + (minorv.value * 0.1) context_version = majorv.value + (minorv.value * 0.1)
self.use_vao = bool(GL.glGenVertexArrays) self.use_vao = bool(GL.glGenVertexArrays)
self.log(" Vertex Array Object support %sfound." % ["NOT ", ""][self.use_vao]) self.log(
" Vertex Array Object support {}found.".format(["NOT ", ""][self.use_vao])
)
if not self.context: if not self.context:
self.log("No OpenGL context found!") self.log("No OpenGL context found!")
# enforce GL version requirement # enforce GL version requirement
@ -341,41 +343,43 @@ class Application:
GL.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE, mts) GL.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE, mts)
self.max_texture_size = mts.value self.max_texture_size = mts.value
self.log( self.log(
" Maximum supported texture size: %s x %s" " Maximum supported texture size: {} x {}".format(
% (self.max_texture_size, self.max_texture_size) self.max_texture_size, self.max_texture_size
)
) )
self.log( self.log(
" Detected screen resolution: %.0f x %.0f, window: %s x %s" " Detected screen resolution: {:.0f} x {:.0f}, window: {} x {}".format(
% (screen_width, screen_height, self.window_width, self.window_height) screen_width, screen_height, self.window_width, self.window_height
)
) )
self.log("Detecting software environment...") self.log("Detecting software environment...")
self.log(" OS: %s" % platform.platform()) self.log(" OS: {}".format(platform.platform()))
py_version = " ".join(sys.version.split("\n")) py_version = " ".join(sys.version.split("\n"))
# report 32 vs 64 bit as it's not clear from sys.version or OS # report 32 vs 64 bit as it's not clear from sys.version or OS
bitness = platform.architecture()[0] bitness = platform.architecture()[0]
# on linux, report whether we're running x11 or wayland # on linux, report whether we're running x11 or wayland
if platform.system() == "Linux": if platform.system() == "Linux":
driver = sdl2.SDL_GetCurrentVideoDriver().decode("utf-8") driver = sdl2.SDL_GetCurrentVideoDriver().decode("utf-8")
self.log(' Linux SDL2 "video driver": %s' % driver) self.log(' Linux SDL2 "video driver": {}'.format(driver))
self.log(" Python: %s (%s)" % (py_version, bitness)) self.log(" Python: {} ({})".format(py_version, bitness))
module_versions = "PySDL2 %s, " % sdl2.__version__ module_versions = "PySDL2 {}, ".format(sdl2.__version__)
module_versions += "numpy %s, " % numpy.__version__ module_versions += "numpy {}, ".format(numpy.__version__)
module_versions += "PyOpenGL %s, " % OpenGL.__version__ module_versions += "PyOpenGL {}, ".format(OpenGL.__version__)
module_versions += "appdirs %s, " % appdirs.__version__ module_versions += "appdirs {}, ".format(appdirs.__version__)
module_versions += "PIL %s" % PIL.__version__ module_versions += "PIL {}".format(PIL.__version__)
self.log(" Modules: %s" % module_versions) self.log(" Modules: {}".format(module_versions))
sdl_version = "%s.%s.%s " % ( sdl_version = "{}.{}.{} ".format(
sdl2.version.SDL_MAJOR_VERSION, sdl2.version.SDL_MAJOR_VERSION,
sdl2.version.SDL_MINOR_VERSION, sdl2.version.SDL_MINOR_VERSION,
sdl2.version.SDL_PATCHLEVEL, sdl2.version.SDL_PATCHLEVEL,
) )
sdl_version += sdl2.version.SDL_GetRevision().decode("utf-8") sdl_version += sdl2.version.SDL_GetRevision().decode("utf-8")
sdl_version += ", SDLmixer: %s.%s.%s" % ( sdl_version += ", SDLmixer: {}.{}.{}".format(
sdlmixer.SDL_MIXER_MAJOR_VERSION, sdlmixer.SDL_MIXER_MAJOR_VERSION,
sdlmixer.SDL_MIXER_MINOR_VERSION, sdlmixer.SDL_MIXER_MINOR_VERSION,
sdlmixer.SDL_MIXER_PATCHLEVEL, sdlmixer.SDL_MIXER_PATCHLEVEL,
) )
self.log(" SDL: %s" % sdl_version) self.log(" SDL: {}".format(sdl_version))
# draw black screen while doing other init # draw black screen while doing other init
GL.glClearColor(0.0, 0.0, 0.0, 1.0) GL.glClearColor(0.0, 0.0, 0.0, 1.0)
GL.glClear(GL.GL_COLOR_BUFFER_BIT) GL.glClear(GL.GL_COLOR_BUFFER_BIT)
@ -562,7 +566,7 @@ class Application:
and "_bootstrap._gcd_import" not in line and "_bootstrap._gcd_import" not in line
): ):
self.log(line.rstrip()) self.log(line.rstrip())
s = "Error importing module %s! See console." % module_name s = "Error importing module {}! See console.".format(module_name)
if self.ui: if self.ui:
self.ui.message_line.post_line(s, 10, True) self.ui.message_line.post_line(s, 10, True)
@ -585,7 +589,7 @@ class Application:
art = None art = None
if not valid_filename: if not valid_filename:
if autocreate: if autocreate:
self.log("Creating new art %s" % filename) self.log("Creating new art {}".format(filename))
return self.new_art(filename) return self.new_art(filename)
else: else:
# self.log("Couldn't find art %s" % filename) # self.log("Couldn't find art %s" % filename)
@ -637,7 +641,7 @@ class Application:
self.edit_renderables.remove(r) self.edit_renderables.remove(r)
if art is self.ui.active_art: if art is self.ui.active_art:
self.ui.active_art = None self.ui.active_art = None
self.log("Unloaded %s" % art.filename) self.log("Unloaded {}".format(art.filename))
if len(self.art_loaded_for_edit) > 0: if len(self.art_loaded_for_edit) > 0:
self.ui.set_active_art(self.art_loaded_for_edit[0]) self.ui.set_active_art(self.art_loaded_for_edit[0])
self.update_window_title() self.update_window_title()
@ -694,7 +698,7 @@ class Application:
extensions = [extensions] extensions = [extensions]
for dirname in dirnames: for dirname in dirnames:
for ext in extensions: for ext in extensions:
f = "%s%s" % (dirname, filename) f = "{}{}".format(dirname, filename)
# filename passed in might already have intended extension, # filename passed in might already have intended extension,
# eg from a directory listing # eg from a directory listing
if ext and ext != "" and not filename.endswith(ext): if ext and ext != "" and not filename.endswith(ext):
@ -723,7 +727,7 @@ class Application:
if basename in self.converter_modules: if basename in self.converter_modules:
m = importlib.reload(self.converter_modules[basename]) m = importlib.reload(self.converter_modules[basename])
else: else:
m = importlib.import_module("formats.%s" % basename) m = importlib.import_module("formats.{}".format(basename))
self.converter_modules[basename] = m self.converter_modules[basename] = m
except Exception as e: except Exception as e:
self.log_import_exception(e, basename) self.log_import_exception(e, basename)
@ -778,7 +782,7 @@ class Application:
def set_window_title(self, text=None): def set_window_title(self, text=None):
# if editing is locked, don't even show Playscii name # if editing is locked, don't even show Playscii name
new_title = "%s - %s" % (APP_NAME, text) if self.can_edit else str(text) new_title = "{} - {}".format(APP_NAME, text) if self.can_edit else str(text)
new_title = bytes(new_title, "utf-8") new_title = bytes(new_title, "utf-8")
sdl2.SDL_SetWindowTitle(self.window, new_title) sdl2.SDL_SetWindowTitle(self.window, new_title)
@ -833,7 +837,7 @@ class Application:
def screenshot(self): def screenshot(self):
"saves a date + time-stamped screenshot" "saves a date + time-stamped screenshot"
timestamp = time.strftime("%Y-%m-%d_%H-%M-%S") timestamp = time.strftime("%Y-%m-%d_%H-%M-%S")
output_filename = "playscii_%s.png" % timestamp output_filename = "playscii_{}.png".format(timestamp)
w, h = self.window_width, self.window_height w, h = self.window_width, self.window_height
pixels = GL.glReadPixels( pixels = GL.glReadPixels(
0, 0, w, h, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, outputType=None 0, 0, w, h, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, outputType=None
@ -841,8 +845,8 @@ class Application:
pixel_bytes = pixels.flatten().tobytes() pixel_bytes = pixels.flatten().tobytes()
img = Image.frombytes(mode="RGBA", size=(w, h), data=pixel_bytes) img = Image.frombytes(mode="RGBA", size=(w, h), data=pixel_bytes)
img = img.transpose(Image.FLIP_TOP_BOTTOM) img = img.transpose(Image.FLIP_TOP_BOTTOM)
img.save("%s%s" % (self.documents_dir + SCREENSHOT_DIR, output_filename)) img.save("{}{}".format(self.documents_dir + SCREENSHOT_DIR, output_filename))
self.log("Saved screenshot %s" % output_filename) self.log("Saved screenshot {}".format(output_filename))
def enter_game_mode(self): def enter_game_mode(self):
self.game_mode = True self.game_mode = True
@ -960,12 +964,12 @@ class Application:
def debug_onion_frames(self): def debug_onion_frames(self):
"debug function to log onion renderable state" "debug function to log onion renderable state"
# TODO: remove this once it's served its purpose # TODO: remove this once it's served its purpose
debug = ["current frame: %s" % self.ui.active_art.active_frame, ""] debug = ["current frame: {}".format(self.ui.active_art.active_frame), ""]
debug.append("onion_renderables_prev:") debug.append("onion_renderables_prev:")
def get_onion_info(i, r): def get_onion_info(i, r):
visible = "VISIBLE" if r.visible else "" visible = "VISIBLE" if r.visible else ""
return "%s: %s frame %s %s" % ( return "{}: {} frame {} {}".format(
i, i,
r.art.filename.ljust(20), r.art.filename.ljust(20),
r.frame, r.frame,
@ -991,7 +995,7 @@ class Application:
if line.strip(): if line.strip():
self.log(line.rstrip()) self.log(line.rstrip())
return return
self.log("Using %s as overlay image." % image_filename) self.log("Using {} as overlay image.".format(image_filename))
self.overlay_renderable = r self.overlay_renderable = r
self.ui.size_and_position_overlay_image() self.ui.size_and_position_overlay_image()
self.draw_overlay = True self.draw_overlay = True
@ -1058,7 +1062,7 @@ class Application:
# setting already found, remove this redundant line # setting already found, remove this redundant line
self.config_lines.remove(line) self.config_lines.remove(line)
# get current value from top-level scope and write it to end of cfg # get current value from top-level scope and write it to end of cfg
self.config_lines += "%s = %s\n" % (setting_name, setting_value) self.config_lines += "{} = {}\n".format(setting_name, setting_value)
def save_persistent_config(self): def save_persistent_config(self):
"write options we want to persist across sessions to config file" "write options we want to persist across sessions to config file"
@ -1126,7 +1130,7 @@ class Application:
editor_bin = os.environ.get("EDITOR", None) editor_bin = os.environ.get("EDITOR", None)
if not editor_bin: if not editor_bin:
return return
cmd = '%s "%s"' % (editor_bin, cfg_path) cmd = '{} "{}"'.format(editor_bin, cfg_path)
os.system(cmd) os.system(cmd)
# update resident cfg file lines, which will be saved out on exit # update resident cfg file lines, which will be saved out on exit
self.config_lines = open(cfg_path).readlines() self.config_lines = open(cfg_path).readlines()
@ -1136,7 +1140,7 @@ class Application:
def open_local_url(self, url): def open_local_url(self, url):
"opens given local (this file system) URL in a cross-platform way" "opens given local (this file system) URL in a cross-platform way"
webbrowser.open("file://%s/%s" % (os.getcwd(), url)) webbrowser.open("file://{}/{}".format(os.getcwd(), url))
def open_help_docs(self): def open_help_docs(self):
self.open_local_url(WEBSITE_HELP_URL) self.open_local_url(WEBSITE_HELP_URL)
@ -1202,7 +1206,7 @@ def get_paths():
if os.path.exists(documents_dir + DOCUMENTS_SUBDIR): if os.path.exists(documents_dir + DOCUMENTS_SUBDIR):
documents_dir += DOCUMENTS_SUBDIR documents_dir += DOCUMENTS_SUBDIR
# add Playscii/ to documents path # add Playscii/ to documents path
documents_dir += "/%s/" % APP_NAME documents_dir += "/{}/".format(APP_NAME)
# create Playscii dir AND subdirs for user art, charsets etc if not present # create Playscii dir AND subdirs for user art, charsets etc if not present
for subdir in [ for subdir in [
"", "",
@ -1242,7 +1246,7 @@ class Logger:
self.log_file = open(config_dir + LOG_FILENAME, "w", bufsize) self.log_file = open(config_dir + LOG_FILENAME, "w", bufsize)
def log(self, new_line): def log(self, new_line):
self.log_file.write("%s\n" % new_line) self.log_file.write("{}\n".format(new_line))
self.lines.append(str(new_line)) self.lines.append(str(new_line))
print(new_line) print(new_line)
@ -1257,7 +1261,7 @@ def get_app():
# start logger even before Application has initialized so we can write to it # start logger even before Application has initialized so we can write to it
# startup message: application and version # # startup message: application and version #
logger = Logger(config_dir) logger = Logger(config_dir)
logger.log("%s v%s" % (APP_NAME, get_version())) logger.log("{} v{}".format(APP_NAME, get_version()))
# see if "autoplay this game" file exists and has anything in it # see if "autoplay this game" file exists and has anything in it
autoplay_game = None autoplay_game = None
if os.path.exists(AUTOPLAY_GAME_FILENAME): if os.path.exists(AUTOPLAY_GAME_FILENAME):
@ -1267,7 +1271,7 @@ def get_app():
# load in config - may change above values and submodule class defaults # load in config - may change above values and submodule class defaults
cfg_filename = config_dir + CONFIG_FILENAME cfg_filename = config_dir + CONFIG_FILENAME
if os.path.exists(cfg_filename): if os.path.exists(cfg_filename):
logger.log("Loading config from %s..." % cfg_filename) logger.log("Loading config from {}...".format(cfg_filename))
# execute cfg line by line so we can continue past lines with errors. # execute cfg line by line so we can continue past lines with errors.
# this does mean that commenting out blocks with triple-quotes fails, # this does mean that commenting out blocks with triple-quotes fails,
# but that's not a good practice anyway. # but that's not a good practice anyway.
@ -1287,7 +1291,7 @@ def get_app():
if "Error" in el: if "Error" in el:
error = el error = el
break break
logger.log(" Removing line %s with %s" % (i, error)) logger.log(" Removing line {} with {}".format(i, error))
new_cfg = open(cfg_filename, "w") new_cfg = open(cfg_filename, "w")
new_cfg.writelines(new_cfg_lines) new_cfg.writelines(new_cfg_lines)
new_cfg.close() new_cfg.close()
@ -1300,7 +1304,7 @@ def get_app():
new_cfg.writelines(default_data) new_cfg.writelines(default_data)
new_cfg.close() new_cfg.close()
exec("".join(default_data)) exec("".join(default_data))
logger.log("Created new config file %s" % cfg_filename) logger.log("Created new config file {}".format(cfg_filename))
art_to_load, game_dir_to_load, state_to_load = None, None, None art_to_load, game_dir_to_load, state_to_load = None, None, None
# usage: # usage:
# playscii.py [artfile] | [-game gamedir [-state statefile | artfile]] # playscii.py [artfile] | [-game gamedir [-state statefile | artfile]]

View file

@ -97,14 +97,14 @@ class TileRenderable:
if self.app.use_vao: if self.app.use_vao:
GL.glBindVertexArray(0) GL.glBindVertexArray(0)
if self.log_create_destroy: if self.log_create_destroy:
self.app.log("created: %s" % self) self.app.log("created: {}".format(self))
def __str__(self): def __str__(self):
"for debug purposes, return a concise unique name" "for debug purposes, return a concise unique name"
for i, r in enumerate(self.art.renderables): for i, r in enumerate(self.art.renderables):
if r is self: if r is self:
break break
return "%s %s %s" % (self.art.get_simple_name(), self.__class__.__name__, i) return "{} {} {}".format(self.art.get_simple_name(), self.__class__.__name__, i)
def create_buffers(self): def create_buffers(self):
# vertex positions and elements # vertex positions and elements
@ -229,8 +229,7 @@ class TileRenderable:
): ):
if self.log_buffer_updates: if self.log_buffer_updates:
self.app.log( self.app.log(
"update_buffer: %s, %s, %s, %s, %s, %s, %s" "update_buffer: {}, {}, {}, {}, {}, {}, {}".format(
% (
buffer_index, buffer_index,
array, array,
target, target,
@ -268,7 +267,7 @@ class TileRenderable:
self.update_tile_buffers(True, True, True, True) self.update_tile_buffers(True, True, True, True)
if self.log_animation: if self.log_animation:
self.app.log( self.app.log(
"%s animating from frames %s to %s" % (self, old_frame, self.frame) "{} animating from frames {} to {}".format(self, old_frame, self.frame)
) )
def start_animating(self): def start_animating(self):
@ -320,7 +319,9 @@ class TileRenderable:
self.goal_x, self.goal_y, self.goal_z = x, y, z self.goal_x, self.goal_y, self.goal_z = x, y, z
if self.log_animation: if self.log_animation:
self.app.log( self.app.log(
"%s will move to %s,%s" % (self.art.filename, self.goal_x, self.goal_y) "{} will move to {},{}".format(
self.art.filename, self.goal_x, self.goal_y
)
) )
def snap_to(self, x, y, z): def snap_to(self, x, y, z):
@ -409,7 +410,7 @@ class TileRenderable:
if self.art and self in self.art.renderables: if self.art and self in self.art.renderables:
self.art.renderables.remove(self) self.art.renderables.remove(self)
if self.log_create_destroy: if self.log_create_destroy:
self.app.log("destroyed: %s" % self) self.app.log("destroyed: {}".format(self))
def get_projection_matrix(self): def get_projection_matrix(self):
""" """

View file

@ -27,7 +27,7 @@ class LineRenderable:
self.app = app self.app = app
# we may be attached to a game object # we may be attached to a game object
self.go = game_object self.go = game_object
self.unique_name = "%s_%s" % (int(time.time()), self.__class__.__name__) self.unique_name = "{}_{}".format(int(time.time()), self.__class__.__name__)
self.quad_size_ref = quad_size_ref self.quad_size_ref = quad_size_ref
self.x, self.y, self.z = 0, 0, 0 self.x, self.y, self.z = 0, 0, 0
self.scale_x, self.scale_y = 1, 1 self.scale_x, self.scale_y = 1, 1
@ -94,7 +94,7 @@ class LineRenderable:
if self.app.use_vao: if self.app.use_vao:
GL.glBindVertexArray(0) GL.glBindVertexArray(0)
if self.log_create_destroy: if self.log_create_destroy:
self.app.log("created: %s" % self) self.app.log("created: {}".format(self))
def __str__(self): def __str__(self):
"for debug purposes, return a unique name" "for debug purposes, return a unique name"
@ -178,7 +178,7 @@ class LineRenderable:
GL.glDeleteVertexArrays(1, [self.vao]) GL.glDeleteVertexArrays(1, [self.vao])
GL.glDeleteBuffers(3, [self.vert_buffer, self.elem_buffer, self.color_buffer]) GL.glDeleteBuffers(3, [self.vert_buffer, self.elem_buffer, self.color_buffer])
if self.log_create_destroy: if self.log_create_destroy:
self.app.log("destroyed: %s" % self) self.app.log("destroyed: {}".format(self))
def render(self): def render(self):
if not self.visible: if not self.visible:

View file

@ -23,7 +23,7 @@ class SpriteRenderable:
def __init__(self, app, texture_filename=None, image_data=None): def __init__(self, app, texture_filename=None, image_data=None):
self.app = app self.app = app
self.unique_name = "%s_%s" % (int(time.time()), self.__class__.__name__) self.unique_name = "{}_{}".format(int(time.time()), self.__class__.__name__)
self.x, self.y, self.z = self.get_initial_position() self.x, self.y, self.z = self.get_initial_position()
self.scale_x, self.scale_y, self.scale_z = self.get_initial_scale() self.scale_x, self.scale_y, self.scale_z = self.get_initial_scale()
if self.app.use_vao: if self.app.use_vao:

View file

@ -65,28 +65,34 @@ class Shader:
self.last_vert_change = time.time() self.last_vert_change = time.time()
vert_source = self.get_shader_source(self.vert_source_file) vert_source = self.get_shader_source(self.vert_source_file)
if self.log_compile: if self.log_compile:
self.sl.app.log("Compiling vertex shader %s..." % self.vert_source_file) self.sl.app.log(
"Compiling vertex shader {}...".format(self.vert_source_file)
)
self.vert_shader = self.try_compile_shader( self.vert_shader = self.try_compile_shader(
vert_source, GL.GL_VERTEX_SHADER, self.vert_source_file vert_source, GL.GL_VERTEX_SHADER, self.vert_source_file
) )
if self.log_compile and self.vert_shader: if self.log_compile and self.vert_shader:
self.sl.app.log( self.sl.app.log(
"Compiled vertex shader %s in %.6f seconds" "Compiled vertex shader {} in {:.6f} seconds".format(
% (self.vert_source_file, time.time() - self.last_vert_change) self.vert_source_file, time.time() - self.last_vert_change
)
) )
# fragment shader # fragment shader
self.frag_source_file = frag_source_file self.frag_source_file = frag_source_file
self.last_frag_change = time.time() self.last_frag_change = time.time()
frag_source = self.get_shader_source(self.frag_source_file) frag_source = self.get_shader_source(self.frag_source_file)
if self.log_compile: if self.log_compile:
self.sl.app.log("Compiling fragment shader %s..." % self.frag_source_file) self.sl.app.log(
"Compiling fragment shader {}...".format(self.frag_source_file)
)
self.frag_shader = self.try_compile_shader( self.frag_shader = self.try_compile_shader(
frag_source, GL.GL_FRAGMENT_SHADER, self.frag_source_file frag_source, GL.GL_FRAGMENT_SHADER, self.frag_source_file
) )
if self.log_compile and self.frag_shader: if self.log_compile and self.frag_shader:
self.sl.app.log( self.sl.app.log(
"Compiled fragment shader %s in %.6f seconds" "Compiled fragment shader {} in {:.6f} seconds".format(
% (self.frag_source_file, time.time() - self.last_frag_change) self.frag_source_file, time.time() - self.last_frag_change
)
) )
# shader program # shader program
if self.vert_shader and self.frag_shader: if self.vert_shader and self.frag_shader:
@ -103,7 +109,7 @@ class Shader:
shader_version = self.glsl_version_macos shader_version = self.glsl_version_macos
else: else:
shader_version = self.glsl_version_unix shader_version = self.glsl_version_unix
version_string = "#version %s\n" % shader_version version_string = "#version {}\n".format(shader_version)
src = bytes(version_string, "utf-8") + src src = bytes(version_string, "utf-8") + src
return src return src
@ -112,7 +118,7 @@ class Shader:
try: try:
shader = shaders.compileShader(source, shader_type) shader = shaders.compileShader(source, shader_type)
except Exception as e: except Exception as e:
self.sl.app.log("%s: " % source_filename) self.sl.app.log("{}: ".format(source_filename))
lines = e.args[0].split("\\n") lines = e.args[0].split("\\n")
# salvage block after "shader compile failure" enclosed in b"" # salvage block after "shader compile failure" enclosed in b""
pre = lines.pop(0).split('b"') pre = lines.pop(0).split('b"')
@ -142,9 +148,9 @@ class Shader:
try: try:
new_shader = shaders.compileShader(new_shader_source, shader_type) new_shader = shaders.compileShader(new_shader_source, shader_type)
# TODO: use try_compile_shader instead here, make sure exception passes thru ok # TODO: use try_compile_shader instead here, make sure exception passes thru ok
self.sl.app.log("ShaderLord: success reloading %s" % file_to_reload) self.sl.app.log("ShaderLord: success reloading {}".format(file_to_reload))
except: except:
self.sl.app.log("ShaderLord: failed reloading %s" % file_to_reload) self.sl.app.log("ShaderLord: failed reloading {}".format(file_to_reload))
return return
# recompile program with new shader # recompile program with new shader
if shader_type == GL.GL_VERTEX_SHADER: if shader_type == GL.GL_VERTEX_SHADER:

17
ui.py
View file

@ -120,7 +120,7 @@ class UI:
# create tools # create tools
for t in self.tool_classes: for t in self.tool_classes:
new_tool = t(self) new_tool = t(self)
tool_name = "%s_tool" % new_tool.name tool_name = "{}_tool".format(new_tool.name)
setattr(self, tool_name, new_tool) setattr(self, tool_name, new_tool)
# stick in a list for popup tool tab # stick in a list for popup tool tab
self.tools.append(new_tool) self.tools.append(new_tool)
@ -208,8 +208,9 @@ class UI:
self.set_elements_scale() self.set_elements_scale()
if self.scale != old_scale: if self.scale != old_scale:
self.message_line.post_line( self.message_line.post_line(
"UI scale is now %s (%.3f x %.3f)" "UI scale is now {} ({:.3f} x {:.3f})".format(
% (self.scale, self.width_tiles, self.height_tiles) self.scale, self.width_tiles, self.height_tiles
)
) )
def set_elements_scale(self): def set_elements_scale(self):
@ -282,7 +283,7 @@ class UI:
self.app.update_window_title() self.app.update_window_title()
if self.app.can_edit: if self.app.can_edit:
self.message_line.post_line( self.message_line.post_line(
"%s %s" % (self.art_selected_log, self.active_art.filename) "{} {}".format(self.art_selected_log, self.active_art.filename)
) )
def set_active_art_by_filename(self, art_filename): def set_active_art_by_filename(self, art_filename):
@ -345,7 +346,9 @@ class UI:
if self.menu_bar.active_menu_name and not cycled_fill: if self.menu_bar.active_menu_name and not cycled_fill:
self.menu_bar.close_active_menu() self.menu_bar.close_active_menu()
self.message_line.post_line( self.message_line.post_line(
"%s %s" % (self.selected_tool.get_button_caption(), self.tool_selected_log) "{} {}".format(
self.selected_tool.get_button_caption(), self.tool_selected_log
)
) )
def cycle_fill_tool_mode(self): def cycle_fill_tool_mode(self):
@ -374,7 +377,7 @@ class UI:
self.selected_xform = new_xform self.selected_xform = new_xform
self.popup.set_xform(new_xform) self.popup.set_xform(new_xform)
self.tool_settings_changed = True self.tool_settings_changed = True
line = "%s %s" % (self.xform_selected_log, uv_names[self.selected_xform]) line = "{} {}".format(self.xform_selected_log, uv_names[self.selected_xform])
self.message_line.post_line(line) self.message_line.post_line(line)
def cycle_selected_xform(self, back=False): def cycle_selected_xform(self, back=False):
@ -592,7 +595,7 @@ class UI:
command = EntireArtCommand(art, min_x, min_y) command = EntireArtCommand(art, min_x, min_y)
command.save_tiles(before=True) command.save_tiles(before=True)
art.resize(w, h, min_x, min_y) art.resize(w, h, min_x, min_y)
self.app.log("Resized %s to %s x %s" % (art.filename, w, h)) self.app.log("Resized {} to {} x {}".format(art.filename, w, h))
art.set_unsaved_changes(True) art.set_unsaved_changes(True)
# clear selection to avoid having tiles we know are OoB selected # clear selection to avoid having tiles we know are OoB selected
self.select_tool.selected_tiles = {} self.select_tool.selected_tiles = {}

View file

@ -74,7 +74,7 @@ class NewArtDialog(BaseFileDialog):
def get_initial_field_text(self, field_number): def get_initial_field_text(self, field_number):
if field_number == 0: if field_number == 0:
return "new%s" % len(self.ui.app.art_loaded_for_edit) return "new{}".format(len(self.ui.app.art_loaded_for_edit))
elif field_number == 2: elif field_number == 2:
return str(DEFAULT_WIDTH) return str(DEFAULT_WIDTH)
elif field_number == 4: elif field_number == 4:
@ -116,7 +116,7 @@ class NewArtDialog(BaseFileDialog):
name = self.field_texts[0] name = self.field_texts[0]
w, h = int(self.field_texts[2]), int(self.field_texts[4]) w, h = int(self.field_texts[2]), int(self.field_texts[4])
self.ui.app.new_art_for_edit(name, w, h) self.ui.app.new_art_for_edit(name, w, h)
self.ui.app.log("Created %s.psci with size %s x %s" % (name, w, h)) self.ui.app.log("Created {}.psci with size {} x {}".format(name, w, h))
self.dismiss() self.dismiss()
@ -266,7 +266,7 @@ class ImportOptionsDialog(UIDialog):
importer = app.importer(app, filename, options) importer = app.importer(app, filename, options)
if importer.success: if importer.success:
if app.importer.completes_instantly: if app.importer.completes_instantly:
app.log("Imported %s successfully." % filename) app.log("Imported {} successfully.".format(filename))
app.importer = None app.importer = None
@ -280,7 +280,7 @@ class ExportOptionsDialog(UIDialog):
# if importer needs no options, run it # if importer needs no options, run it
exporter = app.exporter(app, filename, options) exporter = app.exporter(app, filename, options)
if exporter.success: if exporter.success:
app.log("Exported %s successfully." % exporter.out_filename) app.log("Exported {} successfully.".format(exporter.out_filename))
class ExportFileDialog(ConvertFileDialog): class ExportFileDialog(ConvertFileDialog):
@ -606,7 +606,7 @@ class AddLayerDialog(UIDialog):
def get_initial_field_text(self, field_number): def get_initial_field_text(self, field_number):
if field_number == 0: if field_number == 0:
return "Layer %s" % str(self.ui.active_art.layers + 1) return "Layer {}".format(str(self.ui.active_art.layers + 1))
elif field_number == 1: elif field_number == 1:
return str( return str(
self.ui.active_art.layers_z[self.ui.active_art.active_layer] self.ui.active_art.layers_z[self.ui.active_art.active_layer]
@ -761,7 +761,7 @@ class SetCameraZoomDialog(UIDialog):
def get_initial_field_text(self, field_number): def get_initial_field_text(self, field_number):
if field_number == 0: if field_number == 0:
return "%.1f" % self.ui.app.camera.get_current_zoom_pct() return "{:.1f}".format(self.ui.app.camera.get_current_zoom_pct())
return "" return ""
def is_input_valid(self): def is_input_valid(self):

View file

@ -52,15 +52,17 @@ class UIButton:
"common code for button event logging" "common code for button event logging"
if self.element.ui.logg: if self.element.ui.logg:
self.element.ui.app.log( self.element.ui.app.log(
"UIButton: %s's %s %s" "UIButton: {}'s {} {}".format(
% (self.element.__class__.__name__, self.__class__.__name__, event_type) self.element.__class__.__name__, self.__class__.__name__, event_type
)
) )
def set_state(self, new_state): def set_state(self, new_state):
if new_state not in BUTTON_STATES: if new_state not in BUTTON_STATES:
self.element.ui.app.log( self.element.ui.app.log(
"Unrecognized state for button %s: %s" "Unrecognized state for button {}: {}".format(
% (self.__class__.__name__, new_state) self.__class__.__name__, new_state
)
) )
return return
self.dimmed = new_state == "dimmed" self.dimmed = new_state == "dimmed"
@ -68,8 +70,8 @@ class UIButton:
self.set_state_colors() self.set_state_colors()
def get_state_colors(self, state): def get_state_colors(self, state):
fg = getattr(self, "%s_fg_color" % state) fg = getattr(self, "{}_fg_color".format(state))
bg = getattr(self, "%s_bg_color" % state) bg = getattr(self, "{}_bg_color".format(state))
return fg, bg return fg, bg
def set_state_colors(self): def set_state_colors(self):

View file

@ -178,7 +178,7 @@ class ChooserDialog(UIDialog):
try: try:
l = os.listdir(new_dir) l = os.listdir(new_dir)
except PermissionError: except PermissionError:
line = "No permission to access %s!" % os.path.abspath(new_dir) line = "No permission to access {}!".format(os.path.abspath(new_dir))
self.ui.message_line.post_line(line, error=True) self.ui.message_line.post_line(line, error=True)
return False return False
self.current_dir = new_dir self.current_dir = new_dir

View file

@ -138,9 +138,11 @@ class ImportCommand(ConsoleCommand):
if c.__name__ == importer_classname: if c.__name__ == importer_classname:
importer_class = c importer_class = c
if not importer_class: if not importer_class:
console.ui.app.log("Couldn't find importer class %s" % importer_classname) console.ui.app.log(
"Couldn't find importer class {}".format(importer_classname)
)
if not os.path.exists(filename): if not os.path.exists(filename):
console.ui.app.log("Couldn't find file %s" % filename) console.ui.app.log("Couldn't find file {}".format(filename))
importer = importer_class(console.ui.app, filename) importer = importer_class(console.ui.app, filename)
@ -157,7 +159,9 @@ class ExportCommand(ConsoleCommand):
if c.__name__ == exporter_classname: if c.__name__ == exporter_classname:
exporter_class = c exporter_class = c
if not exporter_class: if not exporter_class:
console.ui.app.log("Couldn't find exporter class %s" % exporter_classname) console.ui.app.log(
"Couldn't find exporter class {}".format(exporter_classname)
)
exporter = exporter_class(console.ui.app, filename) exporter = exporter_class(console.ui.app, filename)
@ -227,7 +231,7 @@ class CommandListCommand(ConsoleCommand):
command_list.sort() command_list.sort()
for command in command_list: for command in command_list:
desc = commands[command].description desc = commands[command].description
console.ui.app.log(" %s - %s" % (command, desc)) console.ui.app.log(" {} - {}".format(command, desc))
class RunArtScriptCommand(ConsoleCommand): class RunArtScriptCommand(ConsoleCommand):
@ -417,7 +421,7 @@ class ConsoleUI(UIElement):
"draw current user input on second to last line, with >_ prompt" "draw current user input on second to last line, with >_ prompt"
# clear entire user line first # clear entire user line first
self.art.write_string(0, 0, 0, -2, " " * self.width, self.text_color) self.art.write_string(0, 0, 0, -2, " " * self.width, self.text_color)
self.art.write_string(0, 0, 0, -2, "%s " % self.prompt, self.text_color) self.art.write_string(0, 0, 0, -2, "{} ".format(self.prompt), self.text_color)
# if first item of line is a valid command, change its color # if first item of line is a valid command, change its color
items = self.current_line.split() items = self.current_line.split()
if len(items) > 0 and items[0] in commands: if len(items) > 0 and items[0] in commands:
@ -487,7 +491,7 @@ class ConsoleUI(UIElement):
self.toggle() self.toggle()
return return
elif keystr == "Return": elif keystr == "Return":
line = "%s %s" % (self.prompt, self.current_line) line = "{} {}".format(self.prompt, self.current_line)
self.ui.app.log(line) self.ui.app.log(line)
# if command is same as last, don't repeat it # if command is same as last, don't repeat it
if len(self.command_history) == 0 or ( if len(self.command_history) == 0 or (
@ -579,7 +583,7 @@ class ConsoleUI(UIElement):
output = str(eval(line)) output = str(eval(line))
except Exception as e: except Exception as e:
# try to output useful error text # try to output useful error text
output = "%s: %s" % (e.__class__.__name__, str(e)) output = "{}: {}".format(e.__class__.__name__, str(e))
# commands CAN return None, so only log if there's something # commands CAN return None, so only log if there's something
if output and output != "None": if output and output != "None":
self.ui.app.log(output) self.ui.app.log(output)

View file

@ -296,7 +296,7 @@ class EditListPanel(GamePanel):
self.list_scroll_index = min(self.list_scroll_index, len(self.items)) self.list_scroll_index = min(self.list_scroll_index, len(self.items))
def get_label(self): def get_label(self):
label = "%s (%s)" % ( label = "{} ({})".format(
self.list_operation_labels[self.list_operation], self.list_operation_labels[self.list_operation],
self.cancel_tip, self.cancel_tip,
) )
@ -475,7 +475,7 @@ class EditListPanel(GamePanel):
items = self.list_rooms() items = self.list_rooms()
# prefix room names with "ROOM:" # prefix room names with "ROOM:"
for i, item in enumerate(items): for i, item in enumerate(items):
item.name = "ROOM: %s" % item.name item.name = "ROOM: {}".format(item.name)
items += self.list_objects() items += self.list_objects()
return items return items

View file

@ -37,7 +37,7 @@ class UIElement:
self.ui = ui self.ui = ui
self.hovered_buttons = [] self.hovered_buttons = []
# generate a unique name # generate a unique name
art_name = "%s_%s" % (int(time.time()), self.__class__.__name__) art_name = "{}_{}".format(int(time.time()), self.__class__.__name__)
self.art = UIArt( self.art = UIArt(
art_name, art_name,
self.ui.app, self.ui.app,
@ -135,8 +135,9 @@ class UIElement:
mouse_button = mouse_button or "[n/a]" mouse_button = mouse_button or "[n/a]"
if self.ui.logg: if self.ui.logg:
self.ui.app.log( self.ui.app.log(
"UIElement: %s %s with mouse button %s" "UIElement: {} {} with mouse button {}".format(
% (self.__class__.__name__, event_type, mouse_button) self.__class__.__name__, event_type, mouse_button
)
) )
def is_visible(self): def is_visible(self):
@ -303,11 +304,11 @@ class FPSCounterUI(UIElement):
color = self.ui.colors.yellow color = self.ui.colors.yellow
if self.ui.app.fps < 10: if self.ui.app.fps < 10:
color = self.ui.colors.red color = self.ui.colors.red
text = "%.1f fps" % self.ui.app.fps text = "{:.1f} fps".format(self.ui.app.fps)
x = self.tile_width - 1 x = self.tile_width - 1
self.art.write_string(0, 0, x, 0, text, color, None, True) self.art.write_string(0, 0, x, 0, text, color, None, True)
# display last tick time; frame_time includes delay, is useless # display last tick time; frame_time includes delay, is useless
text = "%.1f ms " % self.ui.app.frame_time text = "{:.1f} ms ".format(self.ui.app.frame_time)
self.art.write_string(0, 0, x, 1, text, color, None, True) self.art.write_string(0, 0, x, 1, text, color, None, True)
def render(self): def render(self):

View file

@ -144,15 +144,15 @@ class ArtChooserItem(BaseFileChooserItem):
return [] return []
mod_time = time.gmtime(self.art_mod_time) mod_time = time.gmtime(self.art_mod_time)
mod_time = time.strftime("%Y-%m-%d %H:%M:%S", mod_time) mod_time = time.strftime("%Y-%m-%d %H:%M:%S", mod_time)
lines = ["last change: %s" % mod_time] lines = ["last change: {}".format(mod_time)]
line = "%s x %s, " % (self.art_width, self.art_height) line = "{} x {}, ".format(self.art_width, self.art_height)
line += "%s frame" % self.art_frames line += "{} frame".format(self.art_frames)
# pluralize properly # pluralize properly
line += "s" if self.art_frames > 1 else "" line += "s" if self.art_frames > 1 else ""
line += ", %s layer" % self.art_layers line += ", {} layer".format(self.art_layers)
line += "s" if self.art_layers > 1 else "" line += "s" if self.art_layers > 1 else ""
lines += [line] lines += [line]
lines += ["char: %s, pal: %s" % (self.art_charset, self.art_palette)] lines += ["char: {}, pal: {}".format(self.art_charset, self.art_palette)]
return lines return lines
def get_preview_texture(self, app): def get_preview_texture(self, app):
@ -312,7 +312,7 @@ class PaletteChooserItem(BaseFileChooserItem):
def get_description_lines(self): def get_description_lines(self):
colors = len(self.palette.colors) colors = len(self.palette.colors)
return ["Unique colors: %s" % str(colors - 1)] return ["Unique colors: {}".format(str(colors - 1))]
def get_preview_texture(self, app): def get_preview_texture(self, app):
return self.palette.src_texture return self.palette.src_texture
@ -370,7 +370,7 @@ class CharsetChooserItem(BaseFileChooserItem):
if line.startswith("//"): if line.startswith("//"):
lines.append(line[2:]) lines.append(line[2:])
break break
lines.append("Characters: %s" % str(self.charset.last_index)) lines.append("Characters: {}".format(str(self.charset.last_index)))
return lines return lines
def get_preview_texture(self, app): def get_preview_texture(self, app):

View file

@ -443,7 +443,7 @@ class GameRoomMenuData(PulldownMenuData):
item = TempMenuItemClass item = TempMenuItemClass
# leave spaces for mark # leave spaces for mark
item.label = " %s" % room_name item.label = " {}".format(room_name)
# pad, put Z depth on far right # pad, put Z depth on far right
item.label = item.label.ljust(longest_line) item.label = item.label.ljust(longest_line)
# trim to keep below a max length # trim to keep below a max length

View file

@ -131,5 +131,5 @@ class AboutDialog(PagedInfoDialog):
all_modes_visible = True all_modes_visible = True
def __init__(self, ui, options): def __init__(self, ui, options):
self.title += " %s" % ui.app.version self.title += " {}".format(ui.app.version)
PagedInfoDialog.__init__(self, ui, options) PagedInfoDialog.__init__(self, ui, options)

View file

@ -217,7 +217,7 @@ class MenuBar(UIElement):
button.width = len(button.caption) + 2 button.width = len(button.caption) + 2
button.x = x button.x = x
x += button.width + self.button_padding x += button.width + self.button_padding
setattr(self, "%s_button" % button.name, button) setattr(self, "{}_button".format(button.name), button)
# NOTE: callback already defined in MenuButton class, # NOTE: callback already defined in MenuButton class,
# menu data for pulldown with set in MenuButton subclass # menu data for pulldown with set in MenuButton subclass
button.pulldown = self.ui.pulldown button.pulldown = self.ui.pulldown

View file

@ -173,7 +173,7 @@ class PulldownMenu(UIElement):
for bind_tuple in binds: for bind_tuple in binds:
command_functions = binds[bind_tuple] command_functions = binds[bind_tuple]
for f in command_functions: for f in command_functions:
if f.__name__ == "BIND_%s" % menu_item.command: if f.__name__ == "BIND_{}".format(menu_item.command):
shortcut = "" shortcut = ""
# shift, alt, ctrl # shift, alt, ctrl
if bind_tuple[1]: if bind_tuple[1]:
@ -187,5 +187,5 @@ class PulldownMenu(UIElement):
if not (bind_tuple[0].startswith("_") and len(bind_tuple[0]) > 1): if not (bind_tuple[0].startswith("_") and len(bind_tuple[0]) > 1):
shortcut += bind_tuple[0] shortcut += bind_tuple[0]
return shortcut, f return shortcut, f
self.ui.app.log("Shortcut/command not found: %s" % menu_item.command) self.ui.app.log("Shortcut/command not found: {}".format(menu_item.command))
return "", null return "", null

View file

@ -229,7 +229,9 @@ class ToolTogglePickerHoldItem(ArtModePulldownMenuItem):
command = "toggle_picker_hold" command = "toggle_picker_hold"
def get_label(app): def get_label(app):
return "Picker toggle key: %s" % ["press", "hold"][app.ui.popup_hold_to_show] return "Picker toggle key: {}".format(
["press", "hold"][app.ui.popup_hold_to_show]
)
class ToolSwapSelectedColors(ArtModePulldownMenuItem): class ToolSwapSelectedColors(ArtModePulldownMenuItem):
@ -247,42 +249,42 @@ class ToolToggleArtToolbar(ArtModePulldownMenuItem):
class ToolPaintItem(ArtModePulldownMenuItem): class ToolPaintItem(ArtModePulldownMenuItem):
# two spaces in front of each label to leave room for mark # two spaces in front of each label to leave room for mark
label = " %s" % PencilTool.button_caption label = " {}".format(PencilTool.button_caption)
command = "select_pencil_tool" command = "select_pencil_tool"
class ToolEraseItem(ArtModePulldownMenuItem): class ToolEraseItem(ArtModePulldownMenuItem):
label = " %s" % EraseTool.button_caption label = " {}".format(EraseTool.button_caption)
command = "select_erase_tool" command = "select_erase_tool"
class ToolRotateItem(ArtModePulldownMenuItem): class ToolRotateItem(ArtModePulldownMenuItem):
label = " %s" % RotateTool.button_caption label = " {}".format(RotateTool.button_caption)
command = "select_rotate_tool" command = "select_rotate_tool"
class ToolGrabItem(ArtModePulldownMenuItem): class ToolGrabItem(ArtModePulldownMenuItem):
label = " %s" % GrabTool.button_caption label = " {}".format(GrabTool.button_caption)
command = "select_grab_tool" command = "select_grab_tool"
class ToolTextItem(ArtModePulldownMenuItem): class ToolTextItem(ArtModePulldownMenuItem):
label = " %s" % TextTool.button_caption label = " {}".format(TextTool.button_caption)
command = "select_text_tool" command = "select_text_tool"
class ToolSelectItem(ArtModePulldownMenuItem): class ToolSelectItem(ArtModePulldownMenuItem):
label = " %s" % SelectTool.button_caption label = " {}".format(SelectTool.button_caption)
command = "select_select_tool" command = "select_select_tool"
class ToolPasteItem(ArtModePulldownMenuItem): class ToolPasteItem(ArtModePulldownMenuItem):
label = " %s" % PasteTool.button_caption label = " {}".format(PasteTool.button_caption)
command = "select_paste_tool" command = "select_paste_tool"
class ToolFillItem(ArtModePulldownMenuItem): class ToolFillItem(ArtModePulldownMenuItem):
label = " %s" % FillTool.button_caption label = " {}".format(FillTool.button_caption)
command = "select_fill_tool" command = "select_fill_tool"
@ -299,7 +301,7 @@ class ToolIncreaseBrushSizeItem(ArtModePulldownMenuItem):
if not app.ui.selected_tool.brush_size: if not app.ui.selected_tool.brush_size:
return "Increase brush size" return "Increase brush size"
size = app.ui.selected_tool.brush_size + 1 size = app.ui.selected_tool.brush_size + 1
return "Increase brush size to %s" % size return "Increase brush size to {}".format(size)
class ToolDecreaseBrushSizeItem(ArtModePulldownMenuItem): class ToolDecreaseBrushSizeItem(ArtModePulldownMenuItem):
@ -315,7 +317,7 @@ class ToolDecreaseBrushSizeItem(ArtModePulldownMenuItem):
if not app.ui.selected_tool.brush_size: if not app.ui.selected_tool.brush_size:
return "Decrease brush size" return "Decrease brush size"
size = app.ui.selected_tool.brush_size - 1 size = app.ui.selected_tool.brush_size - 1
return "Decrease brush size to %s" % size return "Decrease brush size to {}".format(size)
class ToolSettingsItem(ArtModePulldownMenuItem): class ToolSettingsItem(ArtModePulldownMenuItem):
@ -366,9 +368,8 @@ class ToolSetFillBoundariesItem(ArtModePulldownMenuItem):
return type(app.ui.selected_tool) is not FillTool return type(app.ui.selected_tool) is not FillTool
def get_label(app): def get_label(app):
return ( return "Fill tool bounded by: {}".format(
"Fill tool bounded by: %s" app.ui.fill_tool.boundary_mode_names[app.ui.fill_tool.boundary_mode]
% app.ui.fill_tool.boundary_mode_names[app.ui.fill_tool.boundary_mode]
) )
@ -467,9 +468,8 @@ class ViewSetOverlayImageScalingItem(ArtModePulldownMenuItem):
command = "set_overlay_image_scaling" command = "set_overlay_image_scaling"
def get_label(app): def get_label(app):
return ( return "Overlay image scaling: {}".format(
"Overlay image scaling: %s" ["width", "height", "fill"][app.overlay_scale_type]
% ["width", "height", "fill"][app.overlay_scale_type]
) )
def should_dim(app): def should_dim(app):
@ -588,7 +588,7 @@ class FrameToggleOnionItem(ArtModePulldownMenuItem):
return not app.ui.active_art or app.ui.active_art.frames < 2 return not app.ui.active_art or app.ui.active_art.frames < 2
def get_label(app): def get_label(app):
l = "%s onion skin frames" % ["Show", "Hide"][app.onion_frames_visible] l = "{} onion skin frames".format(["Show", "Hide"][app.onion_frames_visible])
return l return l
@ -600,7 +600,7 @@ class FrameCycleOnionFramesItem(ArtModePulldownMenuItem):
return not app.ui.active_art or app.ui.active_art.frames < 2 return not app.ui.active_art or app.ui.active_art.frames < 2
def get_label(app): def get_label(app):
return "Number of onion frames: %s" % app.onion_show_frames return "Number of onion frames: {}".format(app.onion_show_frames)
class FrameCycleOnionDisplayItem(ArtModePulldownMenuItem): class FrameCycleOnionDisplayItem(ArtModePulldownMenuItem):
@ -617,7 +617,7 @@ class FrameCycleOnionDisplayItem(ArtModePulldownMenuItem):
display = "Previous" display = "Previous"
else: else:
display = "Next" display = "Next"
return "Onion frames show: %s" % display return "Onion frames show: {}".format(display)
class FrameAddFrameItem(ArtModePulldownMenuItem): class FrameAddFrameItem(ArtModePulldownMenuItem):
@ -872,7 +872,7 @@ class ToolMenuData(PulldownMenuData):
# if it's a tool setting toggle, use its own mark check function # if it's a tool setting toggle, use its own mark check function
if item.__bases__[0] is ToolSettingsItem or hasattr(item, "should_mark"): if item.__bases__[0] is ToolSettingsItem or hasattr(item, "should_mark"):
return item.should_mark(ui) return item.should_mark(ui)
return item.label == " %s" % ui.selected_tool.button_caption return item.label == " {}".format(ui.selected_tool.button_caption)
class ViewMenuData(PulldownMenuData): class ViewMenuData(PulldownMenuData):
@ -933,7 +933,7 @@ class ArtMenuData(PulldownMenuData):
item = TempMenuItemClass item = TempMenuItemClass
# leave spaces for mark # leave spaces for mark
item.label = " %s" % art.filename item.label = " {}".format(art.filename)
item.command = "art_switch_to" item.command = "art_switch_to"
item.cb_arg = art.filename item.cb_arg = art.filename
# order list by art's time loaded # order list by art's time loaded
@ -1008,7 +1008,7 @@ class LayerMenuData(PulldownMenuData):
item = TempMenuItemClass item = TempMenuItemClass
# leave spaces for mark # leave spaces for mark
item.label = " %s" % layer_name item.label = " {}".format(layer_name)
if not app.ui.active_art.layers_visibility[i]: if not app.ui.active_art.layers_visibility[i]:
item.label += " (hidden)" item.label += " (hidden)"
# pad, put Z depth on far right # pad, put Z depth on far right
@ -1016,7 +1016,7 @@ class LayerMenuData(PulldownMenuData):
# trim to keep below a max length # trim to keep below a max length
item.label = item.label[:longest_line] item.label = item.label[:longest_line]
# spaces between layer name and z depth # spaces between layer name and z depth
item.label += "z:%.2f" % app.ui.active_art.layers_z[i] item.label += "z:{:.2f}".format(app.ui.active_art.layers_z[i])
# tell PulldownMenu's button creation process not to auto-pad # tell PulldownMenu's button creation process not to auto-pad
item.no_pad = True item.no_pad = True
item.command = "layer_switch_to" item.command = "layer_switch_to"

View file

@ -64,7 +64,7 @@ class PropertyItem:
def set_value(self, value): def set_value(self, value):
# convert value to a button-friendly string # convert value to a button-friendly string
if type(value) is float: if type(value) is float:
valstr = "%.3f" % value valstr = "{:.3f}".format(value)
# non-fixed decimal version may be shorter, if so use it # non-fixed decimal version may be shorter, if so use it
if len(str(value)) < len(valstr): if len(str(value)) < len(valstr):
valstr = str(value) valstr = str(value)
@ -178,7 +178,7 @@ class EditObjectPanel(GamePanel):
elif selected == 1 and self.world.selected_objects[0]: elif selected == 1 and self.world.selected_objects[0]:
return self.world.selected_objects[0].name return self.world.selected_objects[0].name
else: else:
return "[%s selected]" % selected return "[{} selected]".format(selected)
def refresh_items(self): def refresh_items(self):
if len(self.world.selected_objects) == 0: if len(self.world.selected_objects) == 0:
@ -222,14 +222,14 @@ class EditObjectPanel(GamePanel):
button.can_hover = False button.can_hover = False
return return
# set button caption, width, x based on value # set button caption, width, x based on value
button.caption = "%s " % item.prop_value button.caption = "{} ".format(item.prop_value)
button.width = len(button.caption) + 1 button.width = len(button.caption) + 1
button.x = self.tile_width - button.width button.x = self.tile_width - button.width
button.cb_arg = item button.cb_arg = item
button.can_hover = True button.can_hover = True
# set non-button text to the left correctly # set non-button text to the left correctly
x = button.x + 1 x = button.x + 1
label = "%s: " % item.prop_name label = "{}: ".format(item.prop_name)
self.art.write_string(0, 0, x, y, label, UIColors.darkgrey, None, True) self.art.write_string(0, 0, x, y, label, UIColors.darkgrey, None, True)
def update(self): def update(self):

View file

@ -261,10 +261,10 @@ class ToolPopup(UIElement):
for tool in self.ui.tools: for tool in self.ui.tools:
tool_button = ToolButton(self) tool_button = ToolButton(self)
# caption: 1-space padding from left # caption: 1-space padding from left
tool_button.caption = " %s" % tool.button_caption tool_button.caption = " {}".format(tool.button_caption)
tool_button_name = "%s_tool_button" % tool.name tool_button_name = "{}_tool_button".format(tool.name)
setattr(self, tool_button_name, tool_button) setattr(self, tool_button_name, tool_button)
cb_name = "%s_pressed" % tool_button_name cb_name = "{}_pressed".format(tool_button_name)
tool_button.callback = getattr(self, cb_name) tool_button.callback = getattr(self, cb_name)
# set a special property UI can refer to # set a special property UI can refer to
tool_button.tool_name = tool.name tool_button.tool_name = tool.name
@ -280,9 +280,9 @@ class ToolPopup(UIElement):
buttons = [] buttons = []
for button_class in button_dict: for button_class in button_dict:
button = button_class(self) button = button_class(self)
button_name = "%s_button" % button_dict[button_class] button_name = "{}_button".format(button_dict[button_class])
setattr(self, button_name, button) setattr(self, button_name, button)
cb_name = "%s_pressed" % button_name cb_name = "{}_pressed".format(button_name)
button.callback = getattr(self, cb_name) button.callback = getattr(self, cb_name)
buttons.append(button) buttons.append(button)
return buttons return buttons
@ -439,13 +439,13 @@ class ToolPopup(UIElement):
# position & caption charset button # position & caption charset button
y = self.tab_height + 1 y = self.tab_height + 1
self.choose_charset_button.y = y self.choose_charset_button.y = y
self.choose_charset_button.caption = " %s %s " % ( self.choose_charset_button.caption = " {} {} ".format(
CharSetChooserButton.caption, CharSetChooserButton.caption,
charset.name, charset.name,
) )
self.choose_charset_button.width = len(self.choose_charset_button.caption) self.choose_charset_button.width = len(self.choose_charset_button.caption)
# charset scale # charset scale
charset_scale = "%.2fx" % self.charset_swatch.char_scale charset_scale = "{:.2f}x".format(self.charset_swatch.char_scale)
x = -self.scale_charset_up_button.width * 2 x = -self.scale_charset_up_button.width * 2
self.art.write_string(0, 0, x, y, charset_scale, None, None, True) self.art.write_string(0, 0, x, y, charset_scale, None, None, True)
# transform labels and buttons, eg # transform labels and buttons, eg
@ -460,7 +460,7 @@ class ToolPopup(UIElement):
pal_caption_y = (cqh * charset.map_height) / self.art.quad_height pal_caption_y = (cqh * charset.map_height) / self.art.quad_height
pal_caption_y += self.tab_height + 5 pal_caption_y += self.tab_height + 5
self.choose_palette_button.y = int(pal_caption_y) self.choose_palette_button.y = int(pal_caption_y)
self.choose_palette_button.caption = " %s %s " % ( self.choose_palette_button.caption = " {} {} ".format(
PaletteChooserButton.caption, PaletteChooserButton.caption,
palette.name, palette.name,
) )
@ -495,7 +495,7 @@ class ToolPopup(UIElement):
# draw current tool settings # draw current tool settings
x = TOOL_PANE_WIDTH + 1 x = TOOL_PANE_WIDTH + 1
y = self.tab_height + 1 y = self.tab_height + 1
label = "%s %s" % ( label = "{} {}".format(
self.ui.selected_tool.button_caption, self.ui.selected_tool.button_caption,
self.tool_settings_label, self.tool_settings_label,
) )
@ -510,7 +510,7 @@ class ToolPopup(UIElement):
# calculate X of + and - buttons based on size string # calculate X of + and - buttons based on size string
self.brush_size_down_button.x = TOOL_PANE_WIDTH + len(label) + 2 self.brush_size_down_button.x = TOOL_PANE_WIDTH + len(label) + 2
label += " " * (self.brush_size_down_button.width + 1) label += " " * (self.brush_size_down_button.width + 1)
label += "%s" % self.ui.selected_tool.brush_size label += "{}".format(self.ui.selected_tool.brush_size)
self.brush_size_up_button.x = TOOL_PANE_WIDTH + len(label) + 3 self.brush_size_up_button.x = TOOL_PANE_WIDTH + len(label) + 3
self.art.write_string(0, 0, x, y, label) self.art.write_string(0, 0, x, y, label)
else: else:
@ -546,7 +546,7 @@ class ToolPopup(UIElement):
(self.affects_xform_label, self.ui.selected_tool.affects_xform) (self.affects_xform_label, self.ui.selected_tool.affects_xform)
] ]
for label, toggle in label_toggle_pairs: for label, toggle in label_toggle_pairs:
self.art.write_string(0, 0, x + w + 1, y, "%s" % label) self.art.write_string(0, 0, x + w + 1, y, "{}".format(label))
# self.art.set_tile_at(0, 0, x, y, get_affects_char(toggle), 4, 2) # self.art.set_tile_at(0, 0, x, y, get_affects_char(toggle), 4, 2)
self.art.set_char_index_at(0, 0, x + 1, y, get_affects_char(toggle)) self.art.set_char_index_at(0, 0, x + 1, y, get_affects_char(toggle))
y += 1 y += 1

View file

@ -29,7 +29,7 @@ class CharToggleButton(StatusBarToggleButton):
tooltip_on_hover = True tooltip_on_hover = True
def get_tooltip_text(self): def get_tooltip_text(self):
return "character index: %s" % self.element.ui.selected_char return "character index: {}".format(self.element.ui.selected_char)
def get_tooltip_location(self): def get_tooltip_location(self):
return 1, self.element.get_tile_y() - 1 return 1, self.element.get_tile_y() - 1
@ -54,7 +54,7 @@ class FGToggleButton(StatusBarToggleButton):
tooltip_on_hover = True tooltip_on_hover = True
def get_tooltip_text(self): def get_tooltip_text(self):
return "foreground color index: %s" % self.element.ui.selected_fg_color return "foreground color index: {}".format(self.element.ui.selected_fg_color)
def get_tooltip_location(self): def get_tooltip_location(self):
return 8, self.element.get_tile_y() - 1 return 8, self.element.get_tile_y() - 1
@ -78,7 +78,7 @@ class BGToggleButton(StatusBarToggleButton):
tooltip_on_hover = True tooltip_on_hover = True
def get_tooltip_text(self): def get_tooltip_text(self):
return "background color index: %s" % self.element.ui.selected_bg_color return "background color index: {}".format(self.element.ui.selected_bg_color)
def get_tooltip_location(self): def get_tooltip_location(self):
return 15, self.element.get_tile_y() - 1 return 15, self.element.get_tile_y() - 1
@ -188,7 +188,7 @@ class StatusBarUI(UIElement):
art = ui.active_art art = ui.active_art
self.ui = ui self.ui = ui
# create 3 custom Arts w/ source charset and palette, renderables for each # create 3 custom Arts w/ source charset and palette, renderables for each
art_name = "%s_%s" % (int(time.time()), self.__class__.__name__) art_name = "{}_{}".format(int(time.time()), self.__class__.__name__)
self.char_art = UIArt( self.char_art = UIArt(
art_name, ui.app, art.charset, art.palette, self.swatch_width, 1 art_name, ui.app, art.charset, art.palette, self.swatch_width, 1
) )
@ -225,7 +225,7 @@ class StatusBarUI(UIElement):
for button_class, button_name in self.button_names.items(): for button_class, button_name in self.button_names.items():
button = button_class(self) button = button_class(self)
setattr(self, button_name + "_button", button) setattr(self, button_name + "_button", button)
cb_name = "%s_button_pressed" % button_name cb_name = "{}_button_pressed".format(button_name)
button.callback = getattr(self, cb_name) button.callback = getattr(self, cb_name)
self.buttons.append(button) self.buttons.append(button)
# keep a mapping of button names to buttons, for eg tooltip updates # keep a mapping of button names to buttons, for eg tooltip updates
@ -436,15 +436,17 @@ class StatusBarUI(UIElement):
# NOTE: button X offsets will be set in write_right_elements # NOTE: button X offsets will be set in write_right_elements
null = "---" null = "---"
layers = art.layers if art else 0 layers = art.layers if art else 0
layer = "%s/%s" % (art.active_layer + 1, layers) if art else null layer = "{}/{}".format(art.active_layer + 1, layers) if art else null
self.layer_cycle_button.caption = layer self.layer_cycle_button.caption = layer
self.layer_cycle_button.width = len(self.layer_cycle_button.caption) self.layer_cycle_button.width = len(self.layer_cycle_button.caption)
frames = art.frames if art else 0 frames = art.frames if art else 0
frame = "%s/%s" % (art.active_frame + 1, frames) if art else null frame = "{}/{}".format(art.active_frame + 1, frames) if art else null
self.frame_cycle_button.caption = frame self.frame_cycle_button.caption = frame
self.frame_cycle_button.width = len(self.frame_cycle_button.caption) self.frame_cycle_button.width = len(self.frame_cycle_button.caption)
# zoom % # zoom %
zoom = "%.1f" % self.ui.app.camera.get_current_zoom_pct() if art else null zoom = (
"{:.1f}".format(self.ui.app.camera.get_current_zoom_pct()) if art else null
)
self.zoom_set_button.caption = zoom[:5] # maintain size self.zoom_set_button.caption = zoom[:5] # maintain size
def update(self): def update(self):
@ -512,7 +514,7 @@ class StatusBarUI(UIElement):
color = self.dim_color color = self.dim_color
tile_x = str(tile_x).rjust(3) tile_x = str(tile_x).rjust(3)
tile_y = str(tile_y).rjust(3) tile_y = str(tile_y).rjust(3)
tile = "%s,%s" % (tile_x, tile_y) tile = "{},{}".format(tile_x, tile_y)
self.art.write_string(0, 0, x, 0, tile, color, dark, True) self.art.write_string(0, 0, x, 0, tile, color, dark, True)
# tile label # tile label
x -= len(tile) x -= len(tile)

View file

@ -20,7 +20,7 @@ class UISwatch(UIElement):
self.tile_width, self.tile_height = self.get_size() self.tile_width, self.tile_height = self.get_size()
art = self.ui.active_art art = self.ui.active_art
# generate a unique name for debug purposes # generate a unique name for debug purposes
art_name = "%s_%s" % (int(time.time()), self.__class__.__name__) art_name = "{}_{}".format(int(time.time()), self.__class__.__name__)
self.art = UIArt( self.art = UIArt(
art_name, art_name,
self.ui.app, self.ui.app,
@ -405,7 +405,7 @@ class PaletteSwatch(UISwatch):
class ColorSelectionLabelArt(UIArt): class ColorSelectionLabelArt(UIArt):
def __init__(self, ui, letter): def __init__(self, ui, letter):
letter_index = ui.charset.get_char_index(letter) letter_index = ui.charset.get_char_index(letter)
art_name = "%s_%s" % (int(time.time()), self.__class__.__name__) art_name = "{}_{}".format(int(time.time()), self.__class__.__name__)
UIArt.__init__(self, art_name, ui.app, ui.charset, ui.palette, 1, 1) UIArt.__init__(self, art_name, ui.app, ui.charset, ui.palette, 1, 1)
label_color = ui.colors.white label_color = ui.colors.white
label_bg_color = 0 label_bg_color = 0

View file

@ -69,7 +69,7 @@ class UITool:
self.affects_char = not self.affects_char self.affects_char = not self.affects_char
self.ui.tool_settings_changed = True self.ui.tool_settings_changed = True
line = self.button_caption + " " line = self.button_caption + " "
line = "%s %s" % ( line = "{} {}".format(
self.button_caption, self.button_caption,
[self.ui.affects_char_off_log, self.ui.affects_char_on_log][ [self.ui.affects_char_off_log, self.ui.affects_char_on_log][
self.affects_char self.affects_char
@ -82,7 +82,7 @@ class UITool:
return return
self.affects_fg_color = not self.affects_fg_color self.affects_fg_color = not self.affects_fg_color
self.ui.tool_settings_changed = True self.ui.tool_settings_changed = True
line = "%s %s" % ( line = "{} {}".format(
self.button_caption, self.button_caption,
[self.ui.affects_fg_off_log, self.ui.affects_fg_on_log][ [self.ui.affects_fg_off_log, self.ui.affects_fg_on_log][
self.affects_fg_color self.affects_fg_color
@ -95,7 +95,7 @@ class UITool:
return return
self.affects_bg_color = not self.affects_bg_color self.affects_bg_color = not self.affects_bg_color
self.ui.tool_settings_changed = True self.ui.tool_settings_changed = True
line = "%s %s" % ( line = "{} {}".format(
self.button_caption, self.button_caption,
[self.ui.affects_bg_off_log, self.ui.affects_bg_on_log][ [self.ui.affects_bg_off_log, self.ui.affects_bg_on_log][
self.affects_bg_color self.affects_bg_color
@ -108,7 +108,7 @@ class UITool:
return return
self.affects_xform = not self.affects_xform self.affects_xform = not self.affects_xform
self.ui.tool_settings_changed = True self.ui.tool_settings_changed = True
line = "%s %s" % ( line = "{} {}".format(
self.button_caption, self.button_caption,
[self.ui.affects_xform_off_log, self.ui.affects_xform_on_log][ [self.ui.affects_xform_off_log, self.ui.affects_xform_on_log][
self.affects_xform self.affects_xform
@ -587,7 +587,7 @@ class FillTool(UITool):
] ]
def get_button_caption(self): def get_button_caption(self):
return "%s (%s bounded)" % ( return "{} ({} bounded)".format(
self.button_caption, self.button_caption,
self.boundary_mode_names[self.boundary_mode], self.boundary_mode_names[self.boundary_mode],
) )

View file

@ -11,7 +11,7 @@ class Vec3:
self.x, self.y, self.z = x, y, z self.x, self.y, self.z = x, y, z
def __str__(self): def __str__(self):
return "Vec3 %.4f, %.4f, %.4f" % (self.x, self.y, self.z) return "Vec3 {:.4f}, {:.4f}, {:.4f}".format(self.x, self.y, self.z)
def __sub__(self, b): def __sub__(self, b):
"Return a new vector subtracted from given other vector." "Return a new vector subtracted from given other vector."