Fix unused variables and loop variables

This commit is contained in:
Jared Miller 2026-02-12 19:58:15 -05:00
parent d47d1f6280
commit f0438812fc
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C
18 changed files with 26 additions and 28 deletions

View file

@ -475,7 +475,7 @@ class CollisionLord:
def update(self):
"Resolve overlaps between all relevant world objects."
for i in range(self.iterations):
for _ in range(self.iterations):
# filter shape lists for anything out of room etc
valid_dynamic_shapes = []
for shape in self.dynamic_shapes:

View file

@ -15,7 +15,7 @@ class EditCommand:
for frame in self.tile_commands.values():
for layer in frame.values():
for column in layer.values():
for tile in column.values():
for _tile in column.values():
commands += 1
return commands

View file

@ -1082,7 +1082,7 @@ class GameObject:
steps = int(total_move_dist / step_dist)
# start stepping from beginning of this frame's move distance
self.x, self.y = self.last_x, self.last_y
for i in range(steps):
for _ in range(steps):
self.x += dir_x * step_dist
self.y += dir_y * step_dist
collisions = self.get_collisions()

View file

@ -41,7 +41,7 @@ class CrawlTopDownView(GameObject):
# make a copy of original layer to color for visibility, hide original
self.art.duplicate_layer(0)
self.art.layers_visibility[0] = False
for frame, layer, x, y in TileIter(self.art):
for _frame, layer, x, y in TileIter(self.art):
if layer == 0:
continue
# set all tiles undiscovered

View file

@ -66,7 +66,7 @@ class Fireplace(GameObject):
self.weighted_chars = sorted(chars, key=weights.__getitem__)
# spawn initial particles
self.particles = []
for i in range(self.target_particles):
for _ in range(self.target_particles):
p = FireParticle(self)
self.particles.append(p)
# help screen

View file

@ -130,7 +130,7 @@ class Petal:
tiles = []
angle = 0
resolution = 30
for i in range(resolution):
for _ in range(resolution):
angle += math.radians(90.0 / resolution)
x = round(math.cos(angle) * self.radius)
y = round(math.sin(angle) * self.radius)

View file

@ -155,7 +155,7 @@ class ImageConverter:
def update(self):
if time.time() < self.start_time + self.start_delay:
return
for i in range(self.tiles_per_tick):
for _ in range(self.tiles_per_tick):
x_start, y_start = self.x * self.char_w, self.y * self.char_h
x_end, y_end = x_start + self.char_w, y_start + self.char_h
block = self.src_array[y_start:y_end, x_start:x_end]
@ -198,8 +198,8 @@ class ImageConverter:
color_counts += [(color, counts[i])]
color_counts.sort(key=lambda item: item[1], reverse=True)
combos = []
for color1, count1 in color_counts:
for color2, count2 in color_counts:
for color1, _count1 in color_counts:
for color2, _count2 in color_counts:
if color1 == color2:
continue
# fg/bg color swap SHOULD be allowed

View file

@ -143,7 +143,6 @@ def export_still_image(app, art, out_filename, crt=True, scale=1, bg_color=None)
if not src_img:
return False
src_img.save(out_filename, "PNG")
output_format = "32-bit w/ alpha"
else:
# else convert to current palette.
# as with aniGIF export, use arbitrary color for transparency

View file

@ -28,10 +28,8 @@ class PaletteLord:
):
return
self.last_check = self.app.get_elapsed_time()
changed = None
for palette in self.app.palettes:
if palette.has_updated():
changed = palette.filename
try:
palette.load_image()
self.app.log(

View file

@ -101,10 +101,12 @@ class TileRenderable:
def __str__(self):
"for debug purposes, return a concise unique name"
i = 0
for i, r in enumerate(self.art.renderables):
for idx, r in enumerate(self.art.renderables):
if r is self:
i = idx
break
else:
i = 0
return "{} {} {}".format(self.art.get_simple_name(), self.__class__.__name__, i)
def create_buffers(self):
@ -546,7 +548,6 @@ class TileRenderable:
if not self.app.show_hidden_layers and not self.art.layers_visibility[i]:
continue
layer_start = i * layer_size
layer_end = layer_start + layer_size
# for active art, dim all but active layer based on UI setting
if (
not self.app.game_mode

View file

@ -331,7 +331,6 @@ class DebugLineRenderable(WorldLineRenderable):
def add_lines(self, new_verts, new_colors=None):
"add lines to the current ones"
line_items = len(self.vert_array)
lines = int(line_items / self.vert_items)
# if new_verts is a list of tuples, unpack into flat list
if type(new_verts[0]) is tuple:
new_verts_unpacked = []

6
ui.py
View file

@ -287,10 +287,12 @@ class UI:
)
def set_active_art_by_filename(self, art_filename):
i = 0
for i, art in enumerate(self.app.art_loaded_for_edit):
for idx, art in enumerate(self.app.art_loaded_for_edit):
if art_filename == art.filename:
i = idx
break
else:
i = 0
new_active_art = self.app.art_loaded_for_edit.pop(i)
self.app.art_loaded_for_edit.insert(0, new_active_art)
new_active_renderable = self.app.edit_renderables.pop(i)

View file

@ -626,7 +626,7 @@ class AddLayerDialog(UIDialog):
if not valid_name:
return False, self.name_exists_error
try:
z = float(self.field_texts[1])
float(self.field_texts[1])
except Exception:
return False, self.invalid_z_error
return True, None
@ -684,7 +684,7 @@ class SetLayerZDialog(UIDialog):
def is_input_valid(self):
try:
z = float(self.field_texts[0])
float(self.field_texts[0])
except Exception:
return False, self.invalid_z_error
return True, None
@ -745,7 +745,7 @@ class PaletteFromFileDialog(UIDialog):
src_filename = self.field_texts[0]
palette_filename = self.field_texts[1]
colors = int(self.field_texts[2])
new_pal = PaletteFromFile(self.ui.app, src_filename, palette_filename, colors)
PaletteFromFile(self.ui.app, src_filename, palette_filename, colors)
self.dismiss()

View file

@ -176,7 +176,7 @@ class ChooserDialog(UIDialog):
# os.access(new_dir, os.R_OK) seems to always return True,
# so try/catch listdir instead
try:
l = os.listdir(new_dir)
os.listdir(new_dir)
except PermissionError:
line = "No permission to access {}!".format(os.path.abspath(new_dir))
self.ui.message_line.post_line(line, error=True)

View file

@ -143,7 +143,7 @@ class ImportCommand(ConsoleCommand):
)
if not os.path.exists(filename):
console.ui.app.log("Couldn't find file {}".format(filename))
importer = importer_class(console.ui.app, filename)
importer_class(console.ui.app, filename)
class ExportCommand(ConsoleCommand):
@ -162,7 +162,7 @@ class ExportCommand(ConsoleCommand):
console.ui.app.log(
"Couldn't find exporter class {}".format(exporter_classname)
)
exporter = exporter_class(console.ui.app, filename)
exporter_class(console.ui.app, filename)
class PaletteFromImageCommand(ConsoleCommand):

View file

@ -431,7 +431,7 @@ class ToolPopup(UIElement):
# charset renderable location will be set in update()
charset = self.ui.active_art.charset
palette = self.ui.active_art.palette
cqw, cqh = (
_cqw, cqh = (
self.charset_swatch.art.quad_width,
self.charset_swatch.art.quad_height,
)

View file

@ -294,7 +294,6 @@ class TextTool(UITool):
self.input_active = False
self.ui.tool_settings_changed = True
if self.cursor:
x, y = int(self.cursor.x) + 1, int(-self.cursor.y) + 1
self.cursor.finish_paint()
# self.ui.message_line.post_line('Finished text entry at %s, %s' % (x, y))
self.ui.message_line.post_line("Finished text entry.")

View file

@ -216,9 +216,9 @@ def world_to_screen(app, world_x, world_y, world_z):
# viewport tuple order should be same as glGetFloatv(GL_VIEWPORT)
viewport = (0, 0, app.window_width, app.window_height)
try:
x, y, z = GLU.gluProject(world_x, world_y, world_z, vm, pjm, viewport)
x, y, _z = GLU.gluProject(world_x, world_y, world_z, vm, pjm, viewport)
except Exception:
x, y, z = 0, 0, 0
x, y = 0, 0
app.log("GLU.gluProject failed!")
# does Z mean anything here?
return x, y