mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-08-13 00:45:11 +09:00
Assert optional api results across the scenario modules
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -70,7 +70,7 @@ SelectArea:on_selection(function(event)
|
|||||||
if #chests > 0 then
|
if #chests > 0 then
|
||||||
for _, chest in pairs(chests) do
|
for _, chest in pairs(chests) do
|
||||||
tile_count = tile_count + 1
|
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 } }
|
tiles_to_make[tile_count] = { name = tile_to_apply, position = { chest.position.x, chest.position.y } }
|
||||||
chest.destroy()
|
chest.destroy()
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ local floor = math.floor
|
|||||||
--- Give a player their starting items
|
--- Give a player their starting items
|
||||||
--- @param player LuaPlayer
|
--- @param player LuaPlayer
|
||||||
local function give_starting_items(player)
|
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 get_input_count = get_prod_stats.get_input_count
|
||||||
local insert_param = { name = "", count = 0 }
|
local insert_param = { name = "", count = 0 }
|
||||||
local insert = player.insert
|
local insert = player.insert
|
||||||
|
|||||||
@@ -26,11 +26,12 @@ local function on_entity_damaged(event)
|
|||||||
|
|
||||||
-- Outputs the message as floating text
|
-- Outputs the message as floating text
|
||||||
if message then
|
if message then
|
||||||
|
local entity_position = entity.position --[[@as MapPosition.struct]]
|
||||||
local entity_radius = max(1, entity.get_radius())
|
local entity_radius = max(1, entity.get_radius())
|
||||||
local offset = (random() - 0.5) * entity_radius * config.damage_location_variance
|
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 }
|
local color = { r = 1 - health_percentage, g = health_percentage, b = 0 }
|
||||||
|
|
||||||
FlyingText.create{
|
FlyingText.create{
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ local function format_position(pos)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- Convert an area to a string
|
--- Convert an area to a string
|
||||||
--- @param area BoundingBox
|
--- @param area ExpUtil_AABB.Box
|
||||||
--- @return string
|
--- @return string
|
||||||
local function format_area(area)
|
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)
|
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
|
--- @param event EventData.on_cargo_pod_finished_ascending
|
||||||
local function on_cargo_pod_finished_ascending(event)
|
local function on_cargo_pod_finished_ascending(event)
|
||||||
if event.launched_by_rocket then
|
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
|
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")
|
add_log_line("[ROCKET]", force.rockets_launched, "rockets launched")
|
||||||
elseif config.rocket_launch_display[force.rockets_launched] then
|
elseif config.rocket_launch_display[force.rockets_launched] then
|
||||||
@@ -38,7 +38,7 @@ local function on_pre_player_died(event)
|
|||||||
local cause = event.cause
|
local cause = event.cause
|
||||||
if cause then
|
if cause then
|
||||||
if cause.type == "character" 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
|
else
|
||||||
add_log_line("[DEATH]", player.name, "died because of", cause.name)
|
add_log_line("[DEATH]", player.name, "died because of", cause.name)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ local selection_tool = { name = "selection-tool" }
|
|||||||
--- @param player LuaPlayer
|
--- @param player LuaPlayer
|
||||||
--- @return boolean?
|
--- @return boolean?
|
||||||
local function has_selection_tool_in_hand(player)
|
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
|
end
|
||||||
|
|
||||||
--- Give a selection tool to a player if they don't have one
|
--- Give a selection tool to a player if they don't have one
|
||||||
@@ -62,7 +62,7 @@ end
|
|||||||
local function give_selection_tool(player)
|
local function give_selection_tool(player)
|
||||||
if has_selection_tool_in_hand(player) then return end
|
if has_selection_tool_in_hand(player) then return end
|
||||||
player.clear_cursor()
|
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
|
-- This does not work for selection planners, will make a feature request for it
|
||||||
--player.cursor_stack_temporary = true
|
--player.cursor_stack_temporary = true
|
||||||
@@ -84,7 +84,7 @@ end
|
|||||||
local function remove_selection_tool(player, old_character)
|
local function remove_selection_tool(player, old_character)
|
||||||
-- Remove the selection tool
|
-- Remove the selection tool
|
||||||
if has_selection_tool_in_hand(player) then
|
if has_selection_tool_in_hand(player) then
|
||||||
player.cursor_stack.clear()
|
assert(player.cursor_stack).clear()
|
||||||
else
|
else
|
||||||
player.remove_item(selection_tool)
|
player.remove_item(selection_tool)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user