Assert optional api results across the scenario modules

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
bbassie
2026-08-07 15:31:43 +00:00
co-authored by Claude Opus 5
parent f9ce3c4145
commit 3c0b5069fc
6 changed files with 11 additions and 10 deletions
+1 -1
View File
@@ -70,7 +70,7 @@ SelectArea:on_selection(function(event)
if #chests > 0 then
for _, chest in pairs(chests) do
tile_count = tile_count + 1
if chest.get_inventory(defines.inventory.chest).is_empty() and tile_count <= item_count_total then
if assert(chest.get_inventory(defines.inventory.chest)).is_empty() and tile_count <= item_count_total then
tiles_to_make[tile_count] = { name = tile_to_apply, position = { chest.position.x, chest.position.y } }
chest.destroy()
else
+1 -1
View File
@@ -8,7 +8,7 @@ local floor = math.floor
--- Give a player their starting items
--- @param player LuaPlayer
local function give_starting_items(player)
local get_prod_stats = player.force.get_item_production_statistics(player.physical_surface)
local get_prod_stats = (player.force --[[@as LuaForce]]).get_item_production_statistics(player.physical_surface)
local get_input_count = get_prod_stats.get_input_count
local insert_param = { name = "", count = 0 }
local insert = player.insert
@@ -26,11 +26,12 @@ local function on_entity_damaged(event)
-- Outputs the message as floating text
if message then
local entity_position = entity.position --[[@as MapPosition.struct]]
local entity_radius = max(1, entity.get_radius())
local offset = (random() - 0.5) * entity_radius * config.damage_location_variance
local position = { x = entity.position.x + offset, y = entity.position.y - entity_radius }
local position = { x = entity_position.x + offset, y = entity_position.y - entity_radius }
local health_percentage = entity.get_health_ratio()
local health_percentage = assert(entity.get_health_ratio())
local color = { r = 1 - health_percentage, g = health_percentage, b = 0 }
FlyingText.create{
@@ -42,7 +42,7 @@ local function format_position(pos)
end
--- Convert an area to a string
--- @param area BoundingBox
--- @param area ExpUtil_AABB.Box
--- @return string
local function format_area(area)
return format_string("%.1f,%.1f,%.1f,%.1f", area.left_top.x, area.left_top.y, area.right_bottom.x, area.right_bottom.y)
@@ -23,7 +23,7 @@ end
--- @param event EventData.on_cargo_pod_finished_ascending
local function on_cargo_pod_finished_ascending(event)
if event.launched_by_rocket then
local force = event.cargo_pod.force
local force = event.cargo_pod.force --[[@as LuaForce]]
if force.rockets_launched >= config.rocket_launch_display_rate and force.rockets_launched % config.rocket_launch_display_rate == 0 then
add_log_line("[ROCKET]", force.rockets_launched, "rockets launched")
elseif config.rocket_launch_display[force.rockets_launched] then
@@ -38,7 +38,7 @@ local function on_pre_player_died(event)
local cause = event.cause
if cause then
if cause.type == "character" then
add_log_line("[DEATH]", player.name, "died because of", cause.player.name)
add_log_line("[DEATH]", player.name, "died because of", assert(cause.player).name)
else
add_log_line("[DEATH]", player.name, "died because of", cause.name)
end
+3 -3
View File
@@ -54,7 +54,7 @@ local selection_tool = { name = "selection-tool" }
--- @param player LuaPlayer
--- @return boolean?
local function has_selection_tool_in_hand(player)
return player.cursor_stack and player.cursor_stack.valid_for_read and player.cursor_stack.name == "selection-tool"
return assert(player.cursor_stack) and assert(player.cursor_stack).valid_for_read and assert(player.cursor_stack).name == "selection-tool"
end
--- Give a selection tool to a player if they don't have one
@@ -62,7 +62,7 @@ end
local function give_selection_tool(player)
if has_selection_tool_in_hand(player) then return end
player.clear_cursor()
player.cursor_stack.set_stack(selection_tool)
assert(player.cursor_stack).set_stack(selection_tool)
-- This does not work for selection planners, will make a feature request for it
--player.cursor_stack_temporary = true
@@ -84,7 +84,7 @@ end
local function remove_selection_tool(player, old_character)
-- Remove the selection tool
if has_selection_tool_in_hand(player) then
player.cursor_stack.clear()
assert(player.cursor_stack).clear()
else
player.remove_item(selection_tool)
end