From b75e283fc028aa42a2cb8d73ce8eba0c02adbff3 Mon Sep 17 00:00:00 2001 From: bbassie <17990055+bbassie@users.noreply.github.com> Date: Fri, 7 Aug 2026 11:08:44 +0000 Subject: [PATCH] Narrow the remaining position, box and colour reads Color.struct leaves every channel optional, so the rainbow command declares its own fully populated colour. Co-Authored-By: Claude Opus 5 (1M context) --- .../module/commands/protected_entities.lua | 12 +++++++----- exp_scenario/module/commands/rainbow.lua | 14 ++++++++++---- exp_scenario/module/control/degrading_tiles.lua | 7 ++++--- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/exp_scenario/module/commands/protected_entities.lua b/exp_scenario/module/commands/protected_entities.lua index 34426b24..b84d14d7 100644 --- a/exp_scenario/module/commands/protected_entities.lua +++ b/exp_scenario/module/commands/protected_entities.lua @@ -37,7 +37,7 @@ end --- Get the key used in protected_areas --- TODO expose this from EntityProtection ---- @param area BoundingBox +--- @param area ExpUtil_AABB.Box --- @return string local function get_area_key(area) return format_string("%i,%i", floor(area.left_top.x), floor(area.left_top.y)) @@ -49,13 +49,15 @@ end local function show_protected_entity(player, entity) local key = get_entity_key(entity) if renders[player.index][key] then return end - local rb = entity.selection_box.right_bottom + local selection_box = entity.selection_box --[[@as ExpUtil_AABB.Box]] + local rb = selection_box.right_bottom + local position = entity.position --[[@as MapPosition.struct]] renders[player.index][key] = rendering.draw_sprite{ sprite = "utility/notification", target = entity, target_offset = { - (rb.x - entity.position.x) * 0.75, - (rb.y - entity.position.y) * 0.75, + (rb.x - position.x) * 0.75, + (rb.y - position.y) * 0.75, }, x_scale = 2, y_scale = 2, @@ -67,7 +69,7 @@ end --- Show a protected area to a player --- @param player LuaPlayer --- @param surface LuaSurface ---- @param area BoundingBox +--- @param area ExpUtil_AABB.Box local function show_protected_area(player, surface, area) local key = get_area_key(area) if renders[player.index][key] then return end diff --git a/exp_scenario/module/commands/rainbow.lua b/exp_scenario/module/commands/rainbow.lua index 1084f84c..c5fd1a36 100644 --- a/exp_scenario/module/commands/rainbow.lua +++ b/exp_scenario/module/commands/rainbow.lua @@ -6,6 +6,12 @@ local Commands = require("modules/exp_commands") local format_player_name = Commands.format_player_name_locale local format_text = Commands.format_rich_text_color +--- A colour with every channel set, Color.struct leaves them optional +--- @class ExpCommands_Rainbow.Color +--- @field r number +--- @field g number +--- @field b number + --- Wraps one component into the next --- @param c1 number --- @param c2 number @@ -21,8 +27,8 @@ local function step_component(c1, c2) end --- Wraps all components of a colour ensuring it remains valid ---- @param color Color ---- @return Color +--- @param color ExpCommands_Rainbow.Color +--- @return ExpCommands_Rainbow.Color local function step_color(color) color.r, color.g = step_component(color.r, color.g) color.g, color.b = step_component(color.g, color.b) @@ -32,9 +38,9 @@ local function step_color(color) end --- Get the next colour in the rainbow by the given step ---- @param color Color +--- @param color ExpCommands_Rainbow.Color --- @param step number ---- @return Color +--- @return ExpCommands_Rainbow.Color local function next_color(color, step) step = step or 0.1 local new_color = { r = 0, g = 0, b = 0 } diff --git a/exp_scenario/module/control/degrading_tiles.lua b/exp_scenario/module/control/degrading_tiles.lua index b83090a1..9eec9c26 100644 --- a/exp_scenario/module/control/degrading_tiles.lua +++ b/exp_scenario/module/control/degrading_tiles.lua @@ -32,8 +32,9 @@ local function degrade_entity(entity) local tiles = {} local surface = entity.surface - local left_top = entity.bounding_box.left_top - local right_bottom = entity.bounding_box.right_bottom + local bounding_box = entity.bounding_box --[[@as ExpUtil_AABB.Box]] + local left_top = bounding_box.left_top + local right_bottom = bounding_box.right_bottom for x = left_top.x, right_bottom.x do for y = left_top.y, right_bottom.y do local tile = surface.get_tile(x, y) @@ -84,7 +85,7 @@ local function on_player_changed_position(event) if player.controller_type ~= defines.controllers.character then return end local surface = player.physical_surface - local position = player.physical_position + local position = player.physical_position --[[@as MapPosition.struct]] local strength = get_tile_strength(surface, position) if not strength then return end