Enable stricter type checks

This commit is contained in:
Cooldude2606
2024-11-21 00:03:19 +00:00
parent 51c9356ecc
commit 99ab54da0a
11 changed files with 67 additions and 37 deletions

View File

@@ -42,7 +42,7 @@ end
local function emit_event(args)
local title = args.title or ""
local color = args.color or "0x0"
local color = args.color or "0x0" --- @type string | Color
local description = args.description or ""
if type(color) == "table" then

View File

@@ -14,6 +14,7 @@ end
-- Will degrade a tile down to the next tile when called
local function degrade(surface, position)
--- @diagnostic disable-next-line Incorrect Api Type: https://forums.factorio.com/viewtopic.php?f=233&t=109145&p=593761&hilit=get_tile#p593761
local tile = surface.get_tile(position)
local tile_name = tile.name
local degrade_tile_name = config.degrade_order[tile_name]
@@ -55,6 +56,7 @@ end
-- Gets the mean of the strengths around a tile to give the strength at that position
local function get_tile_strength(surface, position)
--- @diagnostic disable-next-line Incorrect Api Type: https://forums.factorio.com/viewtopic.php?f=233&t=109145&p=593761&hilit=get_tile#p593761
local tile = surface.get_tile(position)
local tile_name = tile.name
local strength = config.strengths[tile_name]
@@ -62,7 +64,7 @@ local function get_tile_strength(surface, position)
for x = -1, 1 do -- x loop
local px = position.x + x
for y = -1, 1 do -- y loop
local check_tile = surface.get_tile{ x = px, y = position.y + y }
local check_tile = surface.get_tile(px, position.y + y)
local check_tile_name = check_tile.name
local check_strength = config.strengths[check_tile_name] or 0
strength = strength + check_strength

View File

@@ -144,9 +144,11 @@ local function spawn_area(surface, position)
local fr = config.spawn_area.landfill_radius
local fr2 = fr ^ 2
--- @diagnostic disable-next-line Incorrect Api Type: https://forums.factorio.com/viewtopic.php?f=233&t=109145&p=593761&hilit=get_tile#p593761
local fill_tile = surface.get_tile(position).name
-- Make sure a non water tile is used for each tile
--- @diagnostic disable-next-line Incorrect Api Type: https://forums.factorio.com/viewtopic.php?f=233&t=109145&p=593761&hilit=get_tile#p593761
if surface.get_tile(position).collides_with("player") then fill_tile = "landfill" end
if decon_tile == nil then decon_tile = fill_tile end
@@ -160,6 +162,7 @@ local function spawn_area(surface, position)
if dst < tr2 then
-- If it is inside the decon radius always set the tile
table.insert(tiles_to_make, { name = decon_tile, position = pos })
--- @diagnostic disable-next-line Incorrect Api Type: https://forums.factorio.com/viewtopic.php?f=233&t=109145&p=593761&hilit=get_tile#p593761
elseif dst < fr2 and surface.get_tile(pos).collides_with("player") then
-- If it is inside the fill radius only set the tile if it is water
table.insert(tiles_to_make, { name = fill_tile, position = pos })

View File

@@ -1,18 +1,21 @@
local Commands = require("modules/exp_commands")
local config = require("modules.exp_legacy.config.personal_logistic") --- @dep config.personal-logistic
local function pl(type, target, amount)
---@param target LuaEntity | LuaPlayer
---@param amount number
local function pl(target, amount)
local c
local s
if type == "p" then
--- @cast target any Remove cast once implemented
error("Needs updating to use 2.0 logistics")
if target.object_name == "LuaPlayer" then
c = target.clear_personal_logistic_slot
s = target.set_personal_logistic_slot
elseif type == "s" then
else
c = target.clear_vehicle_logistic_slot
s = target.set_vehicle_logistic_slot
else
return
end
for _, v in pairs(config.request) do
@@ -69,15 +72,16 @@ end
Commands.new("personal-logistic", "Set Personal Logistic (-1 to cancel all) (Select spidertron to edit spidertron)")
:argument("amount", "", Commands.types.integer_range(-1, 10))
:add_aliases{ "pl" }
:add_flags{ "disabled" } -- Remove once implemented above
:register(function(player, amount)
--- @cast amount number
if player.force.technologies["logistic-robotics"].researched then
if player.selected ~= nil then
if player.selected.name == "spidertron" then
pl("s", player.selected, amount / 10)
pl(player.selected, amount / 10)
end
else
pl("p", player, amount / 10)
pl(player, amount / 10)
end
else
return Commands.status.error("Personal Logistic not researched")

View File

@@ -75,8 +75,14 @@ local function clear_module(player, area, machine)
local m_current_module_content = m_current_module.get_contents()
if m_current_module_content then
for k, m in pairs(m_current_module_content) do
surface.spill_item_stack(entity.bounding_box.left_top, { name = k, count = m }, true, force, false)
for _, item in pairs(m_current_module_content) do
surface.spill_item_stack{
position = entity.bounding_box.left_top,
stack = item --[[ @as ItemStackDefinition https://forums.factorio.com/viewtopic.php?f=233&t=122323]],
enable_looted = true,
force = force,
allow_belts = false
}
end
end
@@ -90,7 +96,7 @@ local function apply_module(player, area, machine, modules)
for _, entity in pairs(player.surface.find_entities_filtered{ area = area, name = machine, force = player.force }) do
local m_current_recipe
if entity.prototype.crafting_speed then
if entity.prototype.get_crafting_speed() then
m_current_recipe = entity.get_recipe()
end

View File

@@ -193,6 +193,7 @@ local function update_science_pack(pack_table, science_pack_data)
pack_table.parent.non_made.visible = false
-- Update the icon
--- @type LuaGuiElement
local pack_icon = pack_table["icon-" .. science_pack] or science_pack_base(pack_table, science_pack_data)
local icon_style = science_pack_data.icon_style
pack_icon.style = icon_style