mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-08-13 00:45:11 +09:00
Assert row lookups and the position shorthand
spawn_area accepts both position forms on purpose, so it asserts that one of the two is present rather than narrowing the type. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -16,7 +16,7 @@ end
|
|||||||
|
|
||||||
--- Replace a tile with the next tile in the degrade chain
|
--- Replace a tile with the next tile in the degrade chain
|
||||||
--- @param surface LuaSurface
|
--- @param surface LuaSurface
|
||||||
--- @param position MapPosition
|
--- @param position MapPosition.struct
|
||||||
local function degrade_tile(surface, position)
|
local function degrade_tile(surface, position)
|
||||||
local tile = surface.get_tile(position)
|
local tile = surface.get_tile(position)
|
||||||
local tile_name = tile.name
|
local tile_name = tile.name
|
||||||
@@ -58,7 +58,7 @@ end
|
|||||||
|
|
||||||
--- Gets the average tile strengths around position
|
--- Gets the average tile strengths around position
|
||||||
--- @param surface LuaSurface
|
--- @param surface LuaSurface
|
||||||
--- @param position MapPosition
|
--- @param position MapPosition.struct
|
||||||
--- @return number?
|
--- @return number?
|
||||||
local function get_tile_strength(surface, position)
|
local function get_tile_strength(surface, position)
|
||||||
local tile = surface.get_tile(position)
|
local tile = surface.get_tile(position)
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ local config = require("modules.exp_legacy.config.spawn_area")
|
|||||||
--- @return MapPosition.struct
|
--- @return MapPosition.struct
|
||||||
local function apply_offset(position, offset)
|
local function apply_offset(position, offset)
|
||||||
return {
|
return {
|
||||||
x = (position.x or position[1]) + (offset.x or offset[1]),
|
x = assert(position.x or position[1]) + assert(offset.x or offset[1]),
|
||||||
y = (position.y or position[2]) + (offset.y or offset[2])
|
y = assert(position.y or position[2]) + assert(offset.y or offset[2])
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -21,8 +21,8 @@ end
|
|||||||
--- @param x_index number
|
--- @param x_index number
|
||||||
--- @param y_index number
|
--- @param y_index number
|
||||||
local function apply_offset_to_array(positions, offset, x_index, y_index)
|
local function apply_offset_to_array(positions, offset, x_index, y_index)
|
||||||
local x = (offset.x or offset[1])
|
local x = assert(offset.x or offset[1])
|
||||||
local y = (offset.y or offset[2])
|
local y = assert(offset.y or offset[2])
|
||||||
for _, position in ipairs(positions) do
|
for _, position in ipairs(positions) do
|
||||||
position[x_index] = position[x_index] + x
|
position[x_index] = position[x_index] + x
|
||||||
position[y_index] = position[y_index] + y
|
position[y_index] = position[y_index] + y
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ end
|
|||||||
--- @param item_selector LuaGuiElement
|
--- @param item_selector LuaGuiElement
|
||||||
function Elements.production_table.remove_row(production_table, item_selector)
|
function Elements.production_table.remove_row(production_table, item_selector)
|
||||||
local rows = Elements.production_table.data[production_table].rows
|
local rows = Elements.production_table.data[production_table].rows
|
||||||
local row = rows[item_selector.index]
|
local row = assert(rows[item_selector.index])
|
||||||
rows[item_selector.index] = nil
|
rows[item_selector.index] = nil
|
||||||
Gui.destroy_if_valid(item_selector)
|
Gui.destroy_if_valid(item_selector)
|
||||||
for _, element in pairs(row) do
|
for _, element in pairs(row) do
|
||||||
@@ -197,7 +197,7 @@ end
|
|||||||
--- @param item_selector LuaGuiElement
|
--- @param item_selector LuaGuiElement
|
||||||
function Elements.production_table.reset_row(production_table, item_selector)
|
function Elements.production_table.reset_row(production_table, item_selector)
|
||||||
local rows = Elements.production_table.data[production_table].rows
|
local rows = Elements.production_table.data[production_table].rows
|
||||||
local row = rows[item_selector.index]
|
local row = assert(rows[item_selector.index])
|
||||||
row.production.caption = "0.00"
|
row.production.caption = "0.00"
|
||||||
row.consumption.caption = "0.00"
|
row.consumption.caption = "0.00"
|
||||||
row.net.caption = "0.00"
|
row.net.caption = "0.00"
|
||||||
@@ -210,7 +210,7 @@ end
|
|||||||
--- @param row_data ExpGui_ProductionStats.elements.production_table.row_data
|
--- @param row_data ExpGui_ProductionStats.elements.production_table.row_data
|
||||||
function Elements.production_table.refresh_row(production_table, item_selector, row_data)
|
function Elements.production_table.refresh_row(production_table, item_selector, row_data)
|
||||||
local rows = Elements.production_table.data[production_table].rows
|
local rows = Elements.production_table.data[production_table].rows
|
||||||
local row = rows[item_selector.index]
|
local row = assert(rows[item_selector.index])
|
||||||
row.production.caption = row_data.production
|
row.production.caption = row_data.production
|
||||||
row.consumption.caption = row_data.consumption
|
row.consumption.caption = row_data.consumption
|
||||||
row.net.caption = row_data.net
|
row.net.caption = row_data.net
|
||||||
|
|||||||
Reference in New Issue
Block a user