From b5bbf7333210d0c6d663ab887b5b1897cf25b0c1 Mon Sep 17 00:00:00 2001 From: bbassie <17990055+bbassie@users.noreply.github.com> Date: Fri, 7 Aug 2026 11:14:12 +0000 Subject: [PATCH] Patch MapPosition and BoundingBox to the named form The api documents both as a union with a positional array because both are accepted as input, which makes every read of `.x` or `.left_top` optional. Everything read back from the game uses the named form, so the positional variant is removed and we now always write it that way too. The spawn area config offsets and the mine depletion search areas were the only positional writes left, and apply_offset no longer needs its fallback. Co-Authored-By: Claude Opus 5 (1M context) --- exp_legacy/module/config/spawn_area.lua | 12 ++++++------ exp_scenario/module/control/mine_depletion.lua | 8 ++++---- exp_scenario/module/control/spawn_area.lua | 8 ++++---- type.patch.lua | 8 ++++++++ 4 files changed, 22 insertions(+), 14 deletions(-) create mode 100644 type.patch.lua diff --git a/exp_legacy/module/config/spawn_area.lua b/exp_legacy/module/config/spawn_area.lua index 7f95462a..72ee8c8e 100644 --- a/exp_legacy/module/config/spawn_area.lua +++ b/exp_legacy/module/config/spawn_area.lua @@ -188,7 +188,7 @@ return { amount = 4000, size = { 26, 27 }, -- offset = {-64,-32} - offset = { -64, -64 }, + offset = { x = -64, y = -64 }, }, { enabled = false, @@ -196,7 +196,7 @@ return { amount = 4000, size = { 26, 27 }, -- offset = {-64, 0} - offset = { 64, -64 }, + offset = { x = 64, y = -64 }, }, { enabled = false, @@ -204,7 +204,7 @@ return { amount = 4000, size = { 22, 20 }, -- offset = {-64, 32} - offset = { -64, 64 }, + offset = { x = -64, y = 64 }, }, { enabled = false, @@ -212,7 +212,7 @@ return { amount = 4000, size = { 22, 20 }, -- offset = {-64, -64} - offset = { 64, 64 }, + offset = { x = 64, y = 64 }, }, { enabled = false, @@ -220,7 +220,7 @@ return { amount = 4000, size = { 22, 20 }, -- offset = {-64, -96} - offset = { 0, 64 }, + offset = { x = 0, y = 64 }, }, }, }, @@ -233,7 +233,7 @@ return { num_patches = 4, amount = 4000000, -- offset = {-80, -12}, - offset = { -12, 64 }, + offset = { x = -12, y = 64 }, -- offset_next = {0, 6} offset_next = { 6, 0 }, }, diff --git a/exp_scenario/module/control/mine_depletion.lua b/exp_scenario/module/control/mine_depletion.lua index 996a6019..0f54a676 100644 --- a/exp_scenario/module/control/mine_depletion.lua +++ b/exp_scenario/module/control/mine_depletion.lua @@ -73,8 +73,8 @@ local function try_deconstruct_output_chest(entity) type = { "mining-drill", "inserter" }, to_be_deconstructed = false, area = { - { target_position.x - 1, target_position.y - 1 }, - { target_position.x + 1, target_position.y + 1 } + left_top = { x = target_position.x - 1, y = target_position.y - 1 }, + right_bottom = { x = target_position.x + 1, y = target_position.y + 1 }, }, } @@ -251,8 +251,8 @@ local function on_resource_depleted(event) local drills = resource.surface.find_entities_filtered{ type = "mining-drill", area = { - { position.x - max_mining_radius, position.y - max_mining_radius }, - { position.x + max_mining_radius, position.y + max_mining_radius }, + left_top = { x = position.x - max_mining_radius, y = position.y - max_mining_radius }, + right_bottom = { x = position.x + max_mining_radius, y = position.y + max_mining_radius }, }, } diff --git a/exp_scenario/module/control/spawn_area.lua b/exp_scenario/module/control/spawn_area.lua index 6ac8bdf4..4d96e90c 100644 --- a/exp_scenario/module/control/spawn_area.lua +++ b/exp_scenario/module/control/spawn_area.lua @@ -10,8 +10,8 @@ local config = require("modules.exp_legacy.config.spawn_area") --- @return MapPosition.struct local function apply_offset(position, offset) return { - x = assert(position.x or position[1]) + assert(offset.x or offset[1]), - y = assert(position.y or position[2]) + assert(offset.y or offset[2]) + x = position.x + offset.x, + y = position.y + offset.y, } end @@ -21,8 +21,8 @@ end --- @param x_index number --- @param y_index number local function apply_offset_to_array(positions, offset, x_index, y_index) - local x = assert(offset.x or offset[1]) - local y = assert(offset.y or offset[2]) + local x = offset.x + local y = offset.y for _, position in ipairs(positions) do position[x_index] = position[x_index] + x position[y_index] = position[y_index] + y diff --git a/type.patch.lua b/type.patch.lua new file mode 100644 index 00000000..191d59d8 --- /dev/null +++ b/type.patch.lua @@ -0,0 +1,8 @@ +---@meta + +--- The api documents MapPosition and BoundingBox as a union of the named form +--- and a positional array, because both are accepted as input. Everything read +--- back from the game uses the named form, and we always write it that way too, +--- so the positional variant is removed here. +---@alias MapPosition MapPosition.struct +---@alias BoundingBox BoundingBox.struct