mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-08-13 00:45:11 +09:00
Merge branch 'explosivegaming:main' into aperx
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -18,7 +18,7 @@ local valid, invalid = Commands.status.success, Commands.status.invalid_input
|
||||
local Roles = require("modules.exp_legacy.expcore.roles")
|
||||
local highest_role = Roles.get_player_highest_role
|
||||
|
||||
local types = {} --- @class Commands.types
|
||||
local types = {} --- @class (partial) Commands.types
|
||||
|
||||
--- A role defined by exp roles
|
||||
types.role = add("role", Commands.types.key_of(Roles.config.roles))
|
||||
|
||||
@@ -15,11 +15,11 @@ local abs = math.abs
|
||||
local commands = {}
|
||||
|
||||
--- @param player LuaPlayer
|
||||
--- @param area BoundingBox
|
||||
--- @param area BoundingBox.struct
|
||||
--- @return boolean
|
||||
local function location_break(player, area)
|
||||
local surface = player.surface -- Allow remote view
|
||||
local is_charted = player.force.is_chunk_charted
|
||||
local is_charted = (player.force --[[@as LuaForce]]).is_chunk_charted
|
||||
if is_charted(surface, { x = floor(area.left_top.x / 32), y = floor(area.left_top.y / 32) }) then
|
||||
return true
|
||||
elseif is_charted(surface, { x = floor(area.left_top.x / 32), y = floor(area.right_bottom.y / 32) }) then
|
||||
@@ -43,7 +43,7 @@ commands.artillery = Commands.new("artillery", { "exp-commands_artillery.descrip
|
||||
end
|
||||
SelectArea:start(player)
|
||||
return Commands.status.success{ "exp-commands_artillery.enter" }
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- when an area is selected to add protection to the area
|
||||
SelectArea:on_selection(function(event)
|
||||
@@ -63,13 +63,14 @@ SelectArea:on_selection(function(event)
|
||||
}
|
||||
|
||||
local count = 0
|
||||
local hits = {} --- @type MapPosition[]
|
||||
local hits = {} --- @type MapPosition.struct[]
|
||||
for _, entity in ipairs(entities) do
|
||||
local skip = false
|
||||
|
||||
local entity_position = entity.position
|
||||
for _, pos in ipairs(hits) do
|
||||
local x = abs(entity.position.x - pos.x)
|
||||
local y = abs(entity.position.y - pos.y)
|
||||
local x = abs(entity_position.x - pos.x)
|
||||
local y = abs(entity_position.y - pos.y)
|
||||
if x * x + y * y < 36 then
|
||||
skip = true
|
||||
break
|
||||
|
||||
@@ -41,7 +41,7 @@ local function get_server_id(server)
|
||||
elseif status == "Offline" then
|
||||
return false, { "exp-commands_connect.offline", server_details.name }
|
||||
end
|
||||
return true, server_id
|
||||
return true, server_id --[[@as string]]
|
||||
elseif server_count_before > 0 then
|
||||
return false, { "exp-commands_connect.wrong-version", concat(server_names_before, ", ") }
|
||||
else
|
||||
|
||||
@@ -25,7 +25,7 @@ Commands.new("kill", { "exp-commands_kill.description" })
|
||||
if script.active_mods["space-age"] then
|
||||
other_player.surface.create_entity{ name = "lightning", position = { other_player.position.x, other_player.position.y - 16 }, target = other_player.character }
|
||||
end
|
||||
other_player.character.die()
|
||||
assert(other_player.character).die()
|
||||
else
|
||||
return Commands.status.unauthorised{ "exp-commands_kill.lower-role" }
|
||||
end
|
||||
|
||||
@@ -22,7 +22,7 @@ commands.lawnmower = Commands.new("lawnmower", { "exp-commands_lawnmower.descrip
|
||||
|
||||
SelectArea:start(player)
|
||||
return Commands.status.success{ "exp-commands_lawnmower.enter" }
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- When an area is selected to be handled
|
||||
SelectArea:on_selection(function(event)
|
||||
|
||||
@@ -37,7 +37,7 @@ end
|
||||
|
||||
--- Get the key used in protected_areas
|
||||
--- TODO expose this from EntityProtection
|
||||
--- @param area BoundingBox
|
||||
--- @param area BoundingBox.struct
|
||||
--- @return string
|
||||
local function get_area_key(area)
|
||||
return format_string("%i,%i", floor(area.left_top.x), floor(area.left_top.y))
|
||||
@@ -49,13 +49,15 @@ end
|
||||
local function show_protected_entity(player, entity)
|
||||
local key = get_entity_key(entity)
|
||||
if renders[player.index][key] then return end
|
||||
local rb = entity.selection_box.right_bottom
|
||||
local selection_box = entity.selection_box
|
||||
local rb = selection_box.right_bottom
|
||||
local position = entity.position
|
||||
renders[player.index][key] = rendering.draw_sprite{
|
||||
sprite = "utility/notification",
|
||||
target = entity,
|
||||
target_offset = {
|
||||
(rb.x - entity.position.x) * 0.75,
|
||||
(rb.y - entity.position.y) * 0.75,
|
||||
(rb.x - position.x) * 0.75,
|
||||
(rb.y - position.y) * 0.75,
|
||||
},
|
||||
x_scale = 2,
|
||||
y_scale = 2,
|
||||
@@ -67,7 +69,7 @@ end
|
||||
--- Show a protected area to a player
|
||||
--- @param player LuaPlayer
|
||||
--- @param surface LuaSurface
|
||||
--- @param area BoundingBox
|
||||
--- @param area BoundingBox.struct
|
||||
local function show_protected_area(player, surface, area)
|
||||
local key = get_area_key(area)
|
||||
if renders[player.index][key] then return end
|
||||
|
||||
@@ -7,7 +7,7 @@ local Storage = require("modules/exp_util/storage")
|
||||
|
||||
--- Storage variables
|
||||
local active_players = {} --- @type table<number, boolean> Stores all players in in protected mode
|
||||
local map_tags = {} --- @type table<number, boolean> Stores all protected map tags
|
||||
local map_tags = {} --- @type table<string, boolean> Stores all protected map tags
|
||||
|
||||
Storage.register({
|
||||
active_players = active_players,
|
||||
|
||||
@@ -6,6 +6,12 @@ local Commands = require("modules/exp_commands")
|
||||
local format_player_name = Commands.format_player_name_locale
|
||||
local format_text = Commands.format_rich_text_color
|
||||
|
||||
--- A colour with every channel set, Color.struct leaves them optional
|
||||
--- @class ExpCommands_Rainbow.Color
|
||||
--- @field r number
|
||||
--- @field g number
|
||||
--- @field b number
|
||||
|
||||
--- Wraps one component into the next
|
||||
--- @param c1 number
|
||||
--- @param c2 number
|
||||
@@ -21,8 +27,8 @@ local function step_component(c1, c2)
|
||||
end
|
||||
|
||||
--- Wraps all components of a colour ensuring it remains valid
|
||||
--- @param color Color
|
||||
--- @return Color
|
||||
--- @param color ExpCommands_Rainbow.Color
|
||||
--- @return ExpCommands_Rainbow.Color
|
||||
local function step_color(color)
|
||||
color.r, color.g = step_component(color.r, color.g)
|
||||
color.g, color.b = step_component(color.g, color.b)
|
||||
@@ -32,9 +38,9 @@ local function step_color(color)
|
||||
end
|
||||
|
||||
--- Get the next colour in the rainbow by the given step
|
||||
--- @param color Color
|
||||
--- @param color ExpCommands_Rainbow.Color
|
||||
--- @param step number
|
||||
--- @return Color
|
||||
--- @return ExpCommands_Rainbow.Color
|
||||
local function next_color(color, step)
|
||||
step = step or 0.1
|
||||
local new_color = { r = 0, g = 0, b = 0 }
|
||||
|
||||
@@ -29,7 +29,7 @@ Commands.new("ratio", { "exp-commands_ratio.description" })
|
||||
|
||||
local amount_of_machines = 1
|
||||
if items_per_second then
|
||||
amount_of_machines = math.ceil(products[1].amount * crafts_per_second)
|
||||
amount_of_machines = math.ceil(assert(assert(products[1]).amount) * crafts_per_second)
|
||||
end
|
||||
|
||||
for _, ingredient in ipairs(ingredients) do
|
||||
@@ -43,7 +43,7 @@ Commands.new("ratio", { "exp-commands_ratio.description" })
|
||||
for i, product in ipairs(products) do
|
||||
Commands.print{
|
||||
product.type == "item" and "exp-commands_ratio.item-out" or "exp-commands_ratio.fluid-out",
|
||||
math.round(product.amount * crafts_per_second, 3),
|
||||
math.round(assert(product.amount) * crafts_per_second, 3),
|
||||
product.name
|
||||
}
|
||||
end
|
||||
|
||||
@@ -11,7 +11,10 @@ local player_has_flag = Roles.player_has_flag
|
||||
|
||||
local Reports = require("modules.exp_legacy.modules.control.reports") --- @dep modules.control.reports
|
||||
|
||||
--- @type Commands.InputParser
|
||||
--- @param input string
|
||||
--- @param player LuaPlayer
|
||||
--- @return Commands.Status
|
||||
--- @return LuaPlayer | LocalisedString
|
||||
local function reportable_player(input, player)
|
||||
local success, status, result = parse_input(input, player, Commands.types.player)
|
||||
if not success then return status, result end
|
||||
@@ -40,11 +43,11 @@ Commands.new("create-report", { "exp-commands_reports.description-create" })
|
||||
if Reports.report_player(other_player, player.name, reason) then
|
||||
local user_message = { "exp-commands_reports.response", other_player_name, reason }
|
||||
local admin_message = { "exp-commands_reports.response-admin", other_player_name, player_name, reason }
|
||||
for _, player in ipairs(game.connected_players) do
|
||||
if player.admin then
|
||||
player.print(admin_message)
|
||||
for _, connected_player in ipairs(game.connected_players) do
|
||||
if connected_player.admin then
|
||||
connected_player.print(admin_message)
|
||||
else
|
||||
player.print(user_message)
|
||||
connected_player.print(user_message)
|
||||
end
|
||||
end
|
||||
else
|
||||
|
||||
@@ -42,7 +42,7 @@ Commands.new("get-roles", { "exp-commands_roles.description-get" })
|
||||
--- @cast other_player LuaPlayer?
|
||||
local roles = get_roles_ordered()
|
||||
local roles_formatted = { "" } --- @type LocalisedString
|
||||
local response = { "exp-commands_roles.list-roles", roles_formatted }
|
||||
local response = { "exp-commands_roles.list-roles", roles_formatted } --[[@as LocalisedString]]
|
||||
if other_player then
|
||||
roles = get_player_roles(other_player)
|
||||
response[1] = "exp-commands_roles.list-player"
|
||||
@@ -55,8 +55,7 @@ Commands.new("get-roles", { "exp-commands_roles.description-get" })
|
||||
end
|
||||
|
||||
local last = #roles_formatted
|
||||
--- @diagnostic disable-next-line nil-check
|
||||
roles_formatted[last] = roles_formatted[last][2]
|
||||
roles_formatted[last] = assert(roles_formatted[last])[2]
|
||||
|
||||
return Commands.status.success(response)
|
||||
end)
|
||||
|
||||
@@ -10,7 +10,10 @@ local format_player_name = Commands.format_player_name_locale
|
||||
local format_number = require("util").format_number
|
||||
|
||||
--- A player who is of a lower role than the executing player
|
||||
--- @type Commands.InputParser
|
||||
--- @param input string
|
||||
--- @param player LuaPlayer
|
||||
--- @return Commands.Status
|
||||
--- @return LuaItemPrototype | LocalisedString
|
||||
local function parse_item(input, player)
|
||||
-- First Case - internal name is given
|
||||
-- Second Case - rich text is given
|
||||
@@ -88,7 +91,7 @@ local function sort_results(results, func)
|
||||
end
|
||||
end
|
||||
|
||||
return sorted
|
||||
return sorted --[[@as SearchResult[] ]]
|
||||
end
|
||||
|
||||
local display_players_time_format = ExpUtil.format_time_factory_locale{ format = "short", hours = true, minutes = true }
|
||||
@@ -146,7 +149,8 @@ Commands.new("search-online", { "exp-commands_search.description-online" })
|
||||
end)
|
||||
|
||||
--- Return the amount of an item a player has
|
||||
--- @type SortFunction
|
||||
--- @param data SearchResult
|
||||
--- @return number
|
||||
local function sort_by_count(data)
|
||||
return data.count
|
||||
end
|
||||
|
||||
@@ -69,7 +69,7 @@ commands.clear_blueprints = Commands.new("clear-blueprints", { "exp-commands_sur
|
||||
|
||||
SelectArea:start(player)
|
||||
return Commands.status.success{ "exp-commands_surface.enter" }
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- When an area is selected
|
||||
SelectArea:on_selection(function(event)
|
||||
|
||||
@@ -34,7 +34,7 @@ commands.teleport = Commands.new("teleport", { "exp-commands_teleport.descriptio
|
||||
elseif not teleport_player(other_player, target_player.physical_surface, target_player.physical_position) then
|
||||
return Commands.status.error{ "exp-commands_teleport.unavailable" }
|
||||
end
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Teleports a player to you.
|
||||
--- @class ExpCommands_Teleport.commands.bring: ExpCommand
|
||||
@@ -49,7 +49,7 @@ commands.bring = Commands.new("bring", { "exp-commands_teleport.description-brin
|
||||
elseif not teleport_player(other_player, player.physical_surface, player.physical_position) then
|
||||
return Commands.status.error{ "exp-commands_teleport.unavailable" }
|
||||
end
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Teleports you to a player.
|
||||
--- @class ExpCommands_Teleport.commands.goto: ExpCommand
|
||||
@@ -64,7 +64,7 @@ commands["goto"] = Commands.new("goto", { "exp-commands_teleport.description-got
|
||||
elseif not teleport_player(player, other_player.physical_surface, other_player.physical_position) then
|
||||
return Commands.status.error{ "exp-commands_teleport.unavailable" }
|
||||
end
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Teleport to spawn
|
||||
--- @class ExpCommands_Teleport.commands.spawn: ExpCommand
|
||||
@@ -92,7 +92,7 @@ commands.spawn = Commands.new("spawn", { "exp-commands_teleport.description-spaw
|
||||
else
|
||||
return Commands.status.unauthorised()
|
||||
end
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
return {
|
||||
commands = commands,
|
||||
|
||||
@@ -10,7 +10,7 @@ local format_number = require("util").format_number
|
||||
local commands = {}
|
||||
|
||||
--- Set all trains to automatic
|
||||
--- @class ExpCommand_Artillery.commands.artillery: ExpCommand
|
||||
--- @class ExpCommand_Trains.commands.set_trains_to_automatic: ExpCommand
|
||||
--- @overload fun(player: LuaPlayer, surface: LuaSurface?, force: LuaForce?)
|
||||
commands.set_trains_to_automatic = Commands.new("set-trains-to-automatic", { "exp-commands_trains.description" })
|
||||
:optional("surface", { "exp-commands_trains.arg-surface" }, Commands.types.surface)
|
||||
@@ -32,7 +32,7 @@ commands.set_trains_to_automatic = Commands.new("set-trains-to-automatic", { "ex
|
||||
end
|
||||
|
||||
game.print{ "exp-commands_trains.response", format_player_name(player), format_number(#trains, false) }
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
return {
|
||||
commands = commands,
|
||||
|
||||
@@ -35,7 +35,7 @@ Commands.new("get-warnings", { "exp-commands_warnings.description-get" })
|
||||
local warnings = Warnings.get_warnings(player)
|
||||
local script_warnings = Warnings.get_script_warnings(player)
|
||||
local other_player_name = format_player_name(other_player)
|
||||
Commands.print{ "exp-commands_warnings.player-title", other_player_name, #warnings, #script_warnings, config.temp_warning_limit }
|
||||
Commands.print{ "exp-commands_warnings.player-title", other_player_name, #warnings, #script_warnings, config.script_warning_limit }
|
||||
for _, warning in pairs(warnings) do
|
||||
local by_player_name_formatted = format_player_name(warning.by_player_name)
|
||||
Commands.print{ "exp-commands_warnings.list-element-player", by_player_name_formatted, warning.reason }
|
||||
@@ -47,12 +47,12 @@ Commands.new("get-warnings", { "exp-commands_warnings.description-get" })
|
||||
for player_name, player_warnings in pairs(warnings) do
|
||||
local player_name_formatted = format_player_name(player_name)
|
||||
local script_warning_count = script_warnings[player_name] and #script_warnings[player_name] or 0
|
||||
Commands.print{ "exp-commands_warnings.list-element", player_name_formatted, #player_warnings, script_warning_count, config.temp_warning_limit }
|
||||
Commands.print{ "exp-commands_warnings.list-element", player_name_formatted, #player_warnings, script_warning_count, config.script_warning_limit }
|
||||
end
|
||||
for player_name, player_warnings in pairs(script_warnings) do
|
||||
if not warnings[player_name] then
|
||||
local player_name_formatted = format_player_name(player_name)
|
||||
Commands.print{ "exp-commands_warnings.list-element", player_name_formatted, 0, #player_warnings, config.temp_warning_limit }
|
||||
Commands.print{ "exp-commands_warnings.list-element", player_name_formatted, 0, #player_warnings, config.script_warning_limit }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -36,7 +36,7 @@ commands.waterfill = Commands.new("waterfill", { "exp-commands_waterfill.descrip
|
||||
SelectArea:start(player)
|
||||
return Commands.status.success{ "exp-commands_waterfill.enter" }
|
||||
end
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- When an area is selected to be converted to water
|
||||
SelectArea:on_selection(function(event)
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
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{
|
||||
|
||||
@@ -31,7 +31,7 @@ local function create_map_tag(corpse_data)
|
||||
message = message .. " at " .. time
|
||||
end
|
||||
|
||||
corpse_data.tag = player.force.add_chart_tag(corpse_data.corpse.surface, {
|
||||
corpse_data.tag = (player.force --[[@as LuaForce]]).add_chart_tag(corpse_data.corpse.surface, {
|
||||
position = corpse_data.corpse.position,
|
||||
icon = config.map_icon,
|
||||
text = message,
|
||||
|
||||
@@ -42,7 +42,7 @@ local function format_position(pos)
|
||||
end
|
||||
|
||||
--- Convert an area to a string
|
||||
--- @param area BoundingBox
|
||||
--- @param area BoundingBox.struct
|
||||
--- @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)
|
||||
@@ -137,7 +137,8 @@ local function on_player_ammo_inventory_changed(event)
|
||||
if not player or not player.character then return end
|
||||
|
||||
local character_ammo = assert(player.get_inventory(defines.inventory.character_ammo))
|
||||
local item = character_ammo[player.character.selected_gun_index]
|
||||
local gun_index = player.character.selected_gun_index --[[@as uint]]
|
||||
local item = character_ammo[gun_index]
|
||||
if not item or not item.valid or not item.valid_for_read then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -16,10 +16,9 @@ end
|
||||
|
||||
--- Replace a tile with the next tile in the degrade chain
|
||||
--- @param surface LuaSurface
|
||||
--- @param position MapPosition
|
||||
--- @param position MapPosition.struct
|
||||
local function degrade_tile(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 = surface.get_tile(position.x, position.y)
|
||||
local tile_name = tile.name
|
||||
local degrade_tile_name = config.degrade_order[tile_name]
|
||||
if not degrade_tile_name then return end
|
||||
@@ -33,8 +32,9 @@ local function degrade_entity(entity)
|
||||
|
||||
local tiles = {}
|
||||
local surface = entity.surface
|
||||
local left_top = entity.bounding_box.left_top
|
||||
local right_bottom = entity.bounding_box.right_bottom
|
||||
local bounding_box = entity.bounding_box
|
||||
local left_top = bounding_box.left_top
|
||||
local right_bottom = bounding_box.right_bottom
|
||||
for x = left_top.x, right_bottom.x do
|
||||
for y = left_top.y, right_bottom.y do
|
||||
local tile = surface.get_tile(x, y)
|
||||
@@ -58,11 +58,10 @@ end
|
||||
|
||||
--- Gets the average tile strengths around position
|
||||
--- @param surface LuaSurface
|
||||
--- @param position MapPosition
|
||||
--- @param position MapPosition.struct
|
||||
--- @return number?
|
||||
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 = surface.get_tile(position.x, position.y)
|
||||
local tile_name = tile.name
|
||||
local strength = config.strengths[tile_name]
|
||||
if not strength then return end
|
||||
|
||||
@@ -31,15 +31,15 @@ local function append_playtime(player_name)
|
||||
end
|
||||
|
||||
--- Get the player name from an event
|
||||
--- @param event { player_index: number, by_player_name: string? }
|
||||
--- @return string, string
|
||||
--- @param event { player_index: uint, by_player_name: string? }
|
||||
--- @return string, string?
|
||||
local function get_player_name(event)
|
||||
local player = game.players[event.player_index]
|
||||
return player.name, event.by_player_name
|
||||
end
|
||||
|
||||
--- Convert a colour value into hex
|
||||
--- @param color Color.0
|
||||
--- @param color Color.struct
|
||||
--- @return string
|
||||
local function to_hex(color)
|
||||
local hex_digits = "0123456789ABCDEF"
|
||||
@@ -53,7 +53,7 @@ local function to_hex(color)
|
||||
end
|
||||
|
||||
--- Emit the requires json to file for the given event arguments
|
||||
--- @param opts { title: string?, color: (Color.0 | string)?, description: string?, tick: number?, fields: { name: string, value: string, inline: boolean? }[] }
|
||||
--- @param opts { title: string?, color: (Color.struct | string)?, description: string?, tick: number?, fields: { name: string, value: string, inline: boolean? }[] }
|
||||
local function emit_event(opts)
|
||||
local admins_online = 0
|
||||
local players_online = 0
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -22,7 +22,7 @@ local min = math.min
|
||||
--- @field trees LuaEntity[]
|
||||
--- @field tree_count number
|
||||
--- @field permission "fast" | "allow" | "disallow"
|
||||
--- @field task Async.AsyncReturn
|
||||
--- @field task Async.AsyncReturn<any>
|
||||
|
||||
local cache --- @type TreeDeconCache?
|
||||
|
||||
@@ -77,14 +77,15 @@ local function get_player_cache(player_index)
|
||||
|
||||
-- Create a new cache if the previous on is in use
|
||||
if not cache or cache.task and not cache.task.completed then
|
||||
cache = {} --[[@as any]]
|
||||
--- @diagnostic disable-next-line: missing-fields
|
||||
cache = {} --[[@as TreeDeconCache]]
|
||||
end
|
||||
|
||||
local player = assert(game.get_player(player_index))
|
||||
cache.tick = game.tick
|
||||
cache.player_index = player_index
|
||||
cache.player = player
|
||||
cache.force = player.force --[[ @as LuaForce ]]
|
||||
cache.force = player.force --[[@as LuaForce]]
|
||||
cache.tree_count = 0
|
||||
cache.trees = {}
|
||||
cache.permission = get_permission(player)
|
||||
|
||||
@@ -6,7 +6,7 @@ local Async = require("modules/exp_util/async")
|
||||
local Storage = require("modules/exp_util/storage")
|
||||
local config = require("modules.exp_legacy.config.compilatron")
|
||||
|
||||
--- @type table<string, Async.AsyncReturn>
|
||||
--- @type table<string, Async.AsyncReturn<any>>
|
||||
local persistent_locations = {}
|
||||
Storage.register(persistent_locations, function(tbl)
|
||||
persistent_locations = tbl
|
||||
@@ -55,7 +55,7 @@ local speech_bubble_task =
|
||||
--- @param entity LuaEntity the entity which will have messages spawn from it
|
||||
--- @param messages LocalisedString[] the messages which should be shown
|
||||
--- @param starting_index number? the message index to start at, default 1
|
||||
--- @return Async.AsyncReturn
|
||||
--- @return Async.AsyncReturn<any>
|
||||
local function register_entity(entity, messages, starting_index)
|
||||
return speech_bubble_task{
|
||||
entity = entity,
|
||||
|
||||
@@ -68,12 +68,13 @@ local function try_deconstruct_output_chest(entity)
|
||||
end
|
||||
|
||||
-- Get all adjacent mining drills and inserters
|
||||
local target_position = target.position
|
||||
local entities = target.surface.find_entities_filtered{
|
||||
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 },
|
||||
},
|
||||
}
|
||||
|
||||
@@ -250,16 +251,17 @@ 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 },
|
||||
},
|
||||
}
|
||||
|
||||
-- Check which could have reached this resource
|
||||
for _, drill in pairs(drills) do
|
||||
local radius = drill.prototype.mining_drill_radius
|
||||
local dx = math.abs(drill.position.x - position.x)
|
||||
local dy = math.abs(drill.position.y - position.y)
|
||||
local drill_position = drill.position
|
||||
local dx = math.abs(drill_position.x - position.x)
|
||||
local dy = math.abs(drill_position.y - position.y)
|
||||
if dx <= radius and dy <= radius then
|
||||
try_deconstruct_miner(drill)
|
||||
end
|
||||
|
||||
@@ -7,11 +7,11 @@ local config = require("modules.exp_legacy.config.spawn_area")
|
||||
--- Apply an offset to a LuaPosition
|
||||
--- @param position MapPosition
|
||||
--- @param offset MapPosition
|
||||
--- @return MapPosition.0
|
||||
--- @return MapPosition.struct
|
||||
local function apply_offset(position, offset)
|
||||
return {
|
||||
x = (position.x or position[1]) + (offset.x or offset[1]),
|
||||
y = (position.y or position[2]) + (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 = (offset.x or offset[1])
|
||||
local y = (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
|
||||
@@ -149,11 +149,13 @@ local function create_entities(surface, offset)
|
||||
local pos = apply_offset({ entity_details[2], entity_details[3] }, offset)
|
||||
local entity = surface.create_entity{ name = entity_details[1], position = pos, force = "neutral" }
|
||||
|
||||
if entity and config.entities.protected then
|
||||
protect_entity(entity)
|
||||
end
|
||||
if entity then
|
||||
if config.entities.protected then
|
||||
protect_entity(entity)
|
||||
end
|
||||
|
||||
entity.operable = config.entities.operable
|
||||
entity.operable = config.entities.operable
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -164,8 +166,7 @@ local function clear_spawn_area(surface, offset)
|
||||
local get_tile = surface.get_tile
|
||||
|
||||
-- Make sure a non water tile is used for filling
|
||||
--- @diagnostic disable-next-line Incorrect Api Type: https://forums.factorio.com/viewtopic.php?f=233&t=109145&p=593761&hilit=get_tile#p593761
|
||||
local starting_tile = get_tile(offset)
|
||||
local starting_tile = get_tile(offset.x, offset.y)
|
||||
local fill_tile = starting_tile.collides_with("player") and "landfill" or starting_tile.name
|
||||
local fill_radius = config.spawn_area.landfill_radius
|
||||
local fill_radius_sqr = fill_radius ^ 2
|
||||
@@ -185,8 +186,7 @@ local function clear_spawn_area(surface, offset)
|
||||
if dst < tile_radius_sqr then
|
||||
-- If it is inside the decon radius always set the tile
|
||||
tiles_to_make[#tiles_to_make + 1] = { 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 < fill_radius_sqr and get_tile(pos).collides_with("player") then
|
||||
elseif dst < fill_radius_sqr and get_tile(pos.x, pos.y).collides_with("player") then
|
||||
-- If it is inside the fill radius only set the tile if it is water
|
||||
tiles_to_make[#tiles_to_make + 1] = { name = fill_tile, position = pos }
|
||||
end
|
||||
@@ -278,7 +278,8 @@ local function on_player_created(event)
|
||||
if config.resource_patches.enabled then create_resource_patches(surface, offset) end
|
||||
if config.turrets.enabled then update_turrets() end
|
||||
|
||||
player.force.set_spawn_position(offset, surface)
|
||||
local force = player.force --[[@as LuaForce]]
|
||||
force.set_spawn_position(offset, surface)
|
||||
player.teleport(offset, surface)
|
||||
end
|
||||
|
||||
|
||||
@@ -66,8 +66,9 @@ local function rename_station(event)
|
||||
|
||||
-- Check which recourse is closest
|
||||
for _, resource in ipairs(resources) do
|
||||
local dx = px - resource.bounding_box.left_top.x
|
||||
local dy = py - resource.bounding_box.left_top.y
|
||||
local resource_box = resource.bounding_box
|
||||
local dx = px - resource_box.left_top.x
|
||||
local dy = py - resource_box.left_top.y
|
||||
local distance = (dx * dx) + (dy * dy)
|
||||
if distance < closest_distance then
|
||||
closest_distance = distance
|
||||
@@ -78,7 +79,8 @@ local function rename_station(event)
|
||||
-- Set the item name and icon
|
||||
if closest_recourse then
|
||||
item_name = closest_recourse.name:gsub("^%l", string.upper):gsub("-", " ") -- remove dashes and making first letter capital
|
||||
local product = closest_recourse.prototype.mineable_properties.products[1]
|
||||
local products = assert(closest_recourse.prototype.mineable_properties.products)
|
||||
local product = assert(products[1])
|
||||
icon = string.format("[img=%s.%s]", product.type, product.name)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -49,7 +49,7 @@ Elements.toggle_section_button = Gui.define("autofill/toggle_section_button")
|
||||
element.sprite = "utility/expand"
|
||||
element.tooltip = { "exp-gui_autofill.tooltip-toggle-section-expand" }
|
||||
end
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Toggle if an entity will be autofilled when played
|
||||
--- @class ExpGui_Autofill.elements.toggle_entity_button: ExpElement
|
||||
@@ -88,7 +88,7 @@ Elements.toggle_entity_button = Gui.define("autofill/toggle_entity_button")
|
||||
style.padding = 0
|
||||
style.height = 22
|
||||
style.width = 22
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Toggle if an item will be inserted into an entity
|
||||
--- @class ExpGui_Autofill.elements.toggle_item_button: ExpElement
|
||||
@@ -127,7 +127,7 @@ Elements.toggle_item_button = Gui.define("autofill/toggle_item_button")
|
||||
style.padding = -2
|
||||
style.height = 32
|
||||
style.width = 32
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- The amount of an item to insert
|
||||
--- @class ExpGui_Autofill.elements.amount_textfield: ExpElement
|
||||
@@ -165,7 +165,7 @@ Elements.amount_textfield = Gui.define("autofill/amount_textfield")
|
||||
element.text = tostring(clamped)
|
||||
player.print{ "exp-gui_autofill.invalid", clamped, rich_img("item", item_settings.name), rich_img("entity", item_settings.entity) }
|
||||
end
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- A disabled version of the autofill settings used as a filler
|
||||
Elements.disabled_autofill_setting = Gui.define("autofill/empty_autofill_setting")
|
||||
@@ -221,9 +221,9 @@ Elements.section = Gui.define("autofill/section")
|
||||
end)
|
||||
:on_click(function(def, player, element, event)
|
||||
--- @cast def ExpGui_Autofill.elements.section
|
||||
event.element = def.data[element] --[[ @as LuaGuiElement ]]
|
||||
event.element = def.data[element] --[[@as LuaGuiElement]]
|
||||
Elements.toggle_section_button:raise_event(event)
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Add an item category to a section, at most three can exist
|
||||
--- @param section LuaGuiElement
|
||||
@@ -238,7 +238,7 @@ function Elements.section.add_category(section, category_name)
|
||||
category.style.vertical_spacing = 1
|
||||
|
||||
local ctn = 0
|
||||
local entity_settings = Elements.section.data[section] --[[ @as ExpGui_Autofill.entity_settings ]]
|
||||
local entity_settings = Elements.section.data[section] --[[@as ExpGui_Autofill.entity_settings]]
|
||||
for _, item_data in pairs(entity_settings.items) do
|
||||
if item_data.category == category_name then
|
||||
Elements.toggle_item_button(category, item_data)
|
||||
@@ -265,7 +265,7 @@ end
|
||||
|
||||
--- Container added to the left gui flow
|
||||
--- @class ExpGui_Autofill.elements.container: ExpElement
|
||||
--- @field data table<string, ExpGui_Autofill.entity_settings>
|
||||
--- @field data table<LuaPlayer, table<string, ExpGui_Autofill.entity_settings>>
|
||||
Elements.container = Gui.define("autofill/container")
|
||||
:draw(function(def, parent)
|
||||
--- @cast def ExpGui_Autofill.elements.container
|
||||
@@ -312,7 +312,7 @@ Elements.container = Gui.define("autofill/container")
|
||||
end
|
||||
|
||||
return container.parent
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Get the autofill settings for a player
|
||||
--- @param player LuaPlayer
|
||||
|
||||
@@ -27,7 +27,7 @@ function Public.show(container)
|
||||
local left_panel_style = left_panel.style
|
||||
left_panel_style.width = 300
|
||||
|
||||
--- @diagnostic disable-next-line invisible
|
||||
--- @diagnostic disable-next-line: access-invisible
|
||||
for element_name in pairs(ExpElement._elements) do
|
||||
local header = left_panel.add{ type = "flow" }.add{ type = "label", name = header_name, caption = element_name }
|
||||
Gui.set_data(header, element_name)
|
||||
@@ -92,18 +92,18 @@ Gui.on_click(
|
||||
input_text_box.text = concat{ "ExpElement._elements[\"", element_name, "\"]" }
|
||||
input_text_box.style.font_color = Color.black
|
||||
|
||||
--- @diagnostic disable-next-line invisible
|
||||
--- @diagnostic disable-next-line: access-invisible
|
||||
local define = ExpElement._elements[element_name]
|
||||
local content = dump({
|
||||
--- @diagnostic disable-next-line invisible
|
||||
--- @diagnostic disable-next-line: access-invisible
|
||||
debug = define._debug,
|
||||
--- @diagnostic disable-next-line invisible
|
||||
--- @diagnostic disable-next-line: access-invisible
|
||||
has_handlers = define._has_handlers,
|
||||
--- @diagnostic disable-next-line invisible
|
||||
--- @diagnostic disable-next-line: access-invisible
|
||||
track_elements = define._track_elements,
|
||||
--- @diagnostic disable-next-line invisible
|
||||
--- @diagnostic disable-next-line: access-invisible
|
||||
elements = ExpIter._scopes[element_name],
|
||||
--- @diagnostic disable-next-line invisible
|
||||
--- @diagnostic disable-next-line: access-invisible
|
||||
data = ExpData._scopes[element_name]._raw,
|
||||
}) or "nil"
|
||||
right_panel.text = content
|
||||
|
||||
@@ -4,7 +4,7 @@ local ExpUtil = require("modules/exp_util")
|
||||
local concat = table.concat
|
||||
local inspect = table.inspect
|
||||
local pcall = pcall
|
||||
local loadstring = loadstring --- @diagnostic disable-line
|
||||
local loadstring = load
|
||||
local rawset = rawset
|
||||
|
||||
local Public = {}
|
||||
|
||||
@@ -24,7 +24,7 @@ function Public.show(container)
|
||||
local left_panel_style = left_panel.style
|
||||
left_panel_style.width = 300
|
||||
|
||||
--- @diagnostic disable-next-line invisible
|
||||
--- @diagnostic disable-next-line: access-invisible
|
||||
for token_id in pairs(Storage._registered) do
|
||||
local header = left_panel.add{ type = "flow" }.add{ type = "label", name = header_name, caption = token_id }
|
||||
Gui.set_data(header, token_id)
|
||||
|
||||
@@ -22,11 +22,10 @@ Elements.online_player_dropdown = Gui.define("player_dropdown")
|
||||
end)
|
||||
:style{
|
||||
height = 24,
|
||||
} --[[ @as any ]]
|
||||
} --[[@as any]]
|
||||
|
||||
--- To help with caching and avoid context changes the player list from the previous update is remembered
|
||||
--- @type (string?)[]
|
||||
do local _player_names = {}
|
||||
do local _player_names = {} --- @type (string?)[]
|
||||
--- Updates the player name list after a join or leave
|
||||
--- @return (string?)[]
|
||||
function Elements.online_player_dropdown._update_player_names()
|
||||
|
||||
@@ -78,7 +78,7 @@ Elements.create_selection_planner = Gui.define("module_inserter/create_selection
|
||||
:on_click(function(def, player, element)
|
||||
--- @cast def ExpGui_ModuleInserter.elements.create_selection_planner
|
||||
SelectArea:start(player, def.data[element])
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Used to select the machine to apply modules to
|
||||
--- @class ExpGui_ModuleInserter.elements.machine_selector: ExpElement
|
||||
@@ -98,7 +98,7 @@ Elements.machine_selector = Gui.define("module_inserter/machine_selector")
|
||||
:on_elem_changed(function(def, player, element, event)
|
||||
--- @cast def ExpGui_ModuleInserter.elements.machine_selector
|
||||
local element_data = def.data[element]
|
||||
local machine_name = element.elem_value --[[ @as string? ]]
|
||||
local machine_name = element.elem_value --[[@as string?]]
|
||||
if not machine_name then
|
||||
if element_data.on_last_row then
|
||||
Elements.module_table.reset_row(element_data.module_table, element)
|
||||
@@ -112,7 +112,7 @@ Elements.machine_selector = Gui.define("module_inserter/machine_selector")
|
||||
Elements.module_table.add_row(element_data.module_table)
|
||||
end
|
||||
end
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Used to select the modules to be applied
|
||||
Elements.module_selector = Gui.define("module_inserter/module_selector")
|
||||
@@ -140,7 +140,7 @@ Elements.module_table = Gui.define("module_inserter/module_table")
|
||||
local slots_per_row = config.module_slots_per_row + 1
|
||||
return Gui.elements.scroll_table(parent, 280, slots_per_row)
|
||||
end)
|
||||
:element_data{} --[[ @as any ]]
|
||||
:element_data{} --[[@as any]]
|
||||
|
||||
--- Get all the rows in a module table
|
||||
--- @param module_table LuaGuiElement
|
||||
@@ -177,7 +177,7 @@ end
|
||||
--- @param machine_selector LuaGuiElement
|
||||
function Elements.module_table.remove_row(module_table, machine_selector)
|
||||
local rows = Elements.module_table.data[module_table]
|
||||
local row = rows[machine_selector.index]
|
||||
local row = assert(rows[machine_selector.index])
|
||||
rows[machine_selector.index] = nil
|
||||
Gui.destroy_if_valid(machine_selector)
|
||||
for _, separator in pairs(row.row_separators) do
|
||||
@@ -193,7 +193,7 @@ end
|
||||
--- @param machine_selector LuaGuiElement
|
||||
function Elements.module_table.reset_row(module_table, machine_selector)
|
||||
local rows = Elements.module_table.data[module_table]
|
||||
local row = rows[machine_selector.index]
|
||||
local row = assert(rows[machine_selector.index])
|
||||
|
||||
for _, separator in pairs(row.row_separators) do
|
||||
separator.visible = false
|
||||
@@ -211,9 +211,9 @@ end
|
||||
--- @param machine_name string
|
||||
function Elements.module_table.refresh_row(module_table, machine_selector, machine_name)
|
||||
local rows = Elements.module_table.data[module_table]
|
||||
local row = rows[machine_selector.index]
|
||||
local row = assert(rows[machine_selector.index])
|
||||
|
||||
local active_module_count = prototypes.entity[machine_name].module_inventory_size
|
||||
local active_module_count = assert(prototypes.entity[machine_name].module_inventory_size)
|
||||
local visible_row_count = math.ceil(active_module_count / config.module_slots_per_row)
|
||||
local visible_module_count = visible_row_count * config.module_slots_per_row
|
||||
local module_elem_value = { name = config.machines[machine_name].module }
|
||||
@@ -277,8 +277,8 @@ local function apply_planners_in_area(player, area, machine_name, planner_with_p
|
||||
-- Bounding box table to be reused in the loop below
|
||||
--- @type BoundingBox
|
||||
local param_area = {
|
||||
left_top = {},
|
||||
right_bottom = {}
|
||||
left_top = { x = 0, y = 0 },
|
||||
right_bottom = { x = 0, y = 0 },
|
||||
}
|
||||
|
||||
-- Update area param table to be reused in the loop below
|
||||
@@ -334,7 +334,7 @@ SelectArea:on_selection(function(event, module_table)
|
||||
}
|
||||
|
||||
for _, row in pairs(Elements.module_table.get_rows(module_table)) do
|
||||
local machine_name = row.machine_selector.elem_value --[[ @as string? ]]
|
||||
local machine_name = row.machine_selector.elem_value --[[@as string?]]
|
||||
if not machine_name then
|
||||
goto continue
|
||||
end
|
||||
@@ -348,8 +348,8 @@ SelectArea:on_selection(function(event, module_table)
|
||||
|
||||
-- Get all the modules selected
|
||||
for i = 1, entity_prototype.module_inventory_size do
|
||||
local module_selector = module_selectors[i]
|
||||
local module = module_selector.elem_value --[[ @as { name: string, quality: string }? ]]
|
||||
local module_selector = assert(module_selectors[i])
|
||||
local module = module_selector.elem_value --[[@as { name: string, quality: string }?]]
|
||||
if module then
|
||||
-- Module selected, add it the module arrays
|
||||
local no_prod_name = module.name:gsub("productivity", "efficiency")
|
||||
|
||||
@@ -22,13 +22,16 @@ local Elements = {}
|
||||
--- @field _cost_scale number
|
||||
|
||||
--- For perf calculate the division of scale against cost ahead of time
|
||||
for _, bonus_data in pairs(config.player_bonus) do
|
||||
--- @type table<string, ExpGui_PlayerBonus.bonus_data>
|
||||
local player_bonus = config.player_bonus
|
||||
|
||||
for _, bonus_data in pairs(player_bonus) do
|
||||
bonus_data._cost_scale = bonus_data.cost / bonus_data.scale
|
||||
end
|
||||
|
||||
--- Progress bar which displays how much of a bonus has been used
|
||||
--- @class ExpGui_PlayerBonus.elements.bonus_used: ExpElement
|
||||
--- @field data number
|
||||
--- @field data table<LuaGuiElement, number>
|
||||
--- @overload fun(parent: LuaGuiElement): LuaGuiElement
|
||||
Elements.bonus_used = Gui.define("player_bonus/bonus_used")
|
||||
:track_all_elements()
|
||||
@@ -44,11 +47,10 @@ Elements.bonus_used = Gui.define("player_bonus/bonus_used")
|
||||
font = "heading-2",
|
||||
color = { 1, 0, 0 },
|
||||
}
|
||||
:element_data(0) --[[ @as any ]]
|
||||
:element_data(0) --[[@as any]]
|
||||
|
||||
--- Value is cached to save perf
|
||||
--- @type table<number, number>
|
||||
do local _points_limit = {}
|
||||
do local _points_limit = {} --- @type table<number, number>
|
||||
--- Clear the cache for points limit
|
||||
--- @param player LuaPlayer
|
||||
function Elements.bonus_used._clear_points_limit_cache(player)
|
||||
@@ -145,7 +147,7 @@ Elements.reset_button = Gui.define("player_bonus/reset_button")
|
||||
Elements.bonus_table.reset_sliders(element_data.bonus_table)
|
||||
local bonus_cost = Elements.bonus_table.calculate_cost(element_data.bonus_table)
|
||||
Elements.bonus_used.refresh(element_data.bonus_used, bonus_cost)
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Link an apply button to this reset button so that it will be disabled after being pressed
|
||||
--- @param reset_button LuaGuiElement
|
||||
@@ -186,7 +188,7 @@ Elements.apply_button = Gui.define("player_bonus/apply_button")
|
||||
Elements.bonus_table.save_sliders(element_data.bonus_table)
|
||||
Elements.container.apply_player_bonus(player)
|
||||
end
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Link an apply button to this reset button so that it will be disabled after being pressed
|
||||
--- @param apply_button LuaGuiElement
|
||||
@@ -207,7 +209,7 @@ Elements.bonus_table_label = Gui.define("player_bonus/table_label")
|
||||
}
|
||||
:style{
|
||||
width = Gui.from_argument(3, 70),
|
||||
} --[[ @as any ]]
|
||||
} --[[@as any]]
|
||||
|
||||
--- @class ExpGui_PlayerBonus.elements.bonus_slider.elements
|
||||
--- @field bonus_used LuaGuiElement
|
||||
@@ -265,7 +267,7 @@ Elements.bonus_slider = Gui.define("player_bonus/bonus_slider")
|
||||
element_data.label.caption = Elements.bonus_slider.calculate_slider_caption(bonus_data, value)
|
||||
element_data.apply_button.enabled = Elements.bonus_used.update(element_data.bonus_used, value_change * bonus_data._cost_scale)
|
||||
element_data.reset_button.enabled = true
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Get the caption of the slider label
|
||||
--- @param bonus_data ExpGui_PlayerBonus.bonus_data
|
||||
@@ -311,7 +313,7 @@ Elements.bonus_table = Gui.define("player_bonus/bonus_table")
|
||||
:draw(function(_, parent)
|
||||
return Gui.elements.scroll_table(parent, 300, 3)
|
||||
end)
|
||||
:element_data{} --[[ @as any ]]
|
||||
:element_data{} --[[@as any]]
|
||||
|
||||
--- Adds a row to the milestone table
|
||||
--- @param bonus_table LuaGuiElement
|
||||
@@ -378,7 +380,7 @@ Elements.container = Gui.define("player_bonus/container")
|
||||
Elements.bonus_used.refresh(elements.bonus_used, bonus_cost)
|
||||
|
||||
return Gui.elements.container.get_root_element(container)
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Set the bonus value for a player
|
||||
--- @param player LuaPlayer
|
||||
@@ -442,7 +444,7 @@ end
|
||||
function Elements.container.calculate_cost(player)
|
||||
local cost = 0
|
||||
local player_data = Elements.container.data[player]
|
||||
for _, bonus_data in pairs(config.player_bonus) do
|
||||
for _, bonus_data in pairs(player_bonus) do
|
||||
cost = cost + (player_data[bonus_data.name] or 0) * bonus_data._cost_scale
|
||||
end
|
||||
return cost
|
||||
|
||||
@@ -48,14 +48,14 @@ Elements.open_action_bar = Gui.define("player_list/open_action_bar")
|
||||
--- @cast def ExpGui_PlayerList.elements.open_action_bar
|
||||
Elements.container.toggle_selected_player(player, def.data[element])
|
||||
Elements.player_table.refresh_player(player)
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Set whether an open action bar button shows as highlighted
|
||||
--- @param open_button LuaGuiElement
|
||||
--- @param highlighted boolean
|
||||
function Elements.open_action_bar.set_highlight(open_button, highlighted)
|
||||
open_button.style = highlighted and "tool_button" or "frame_button"
|
||||
local style = open_button.style
|
||||
local style = open_button.style --[[@as LuaStyle]]
|
||||
style.padding = -2
|
||||
style.width = 8
|
||||
style.height = 14
|
||||
@@ -80,7 +80,7 @@ Elements.close_action_bar = Gui.define("player_list/close_action_bar")
|
||||
:on_click(function(_, player)
|
||||
Elements.container.set_selected_player(player, nil)
|
||||
Elements.player_table.refresh_player(player)
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Button used to confirm a reason
|
||||
--- @class ExpGui_PlayerList.elements.reason_confirm: ExpElement
|
||||
@@ -102,14 +102,14 @@ Elements.reason_confirm = Gui.define("player_list/reason_confirm")
|
||||
local action_name = Elements.container.get_selected_action(player)
|
||||
local button_data = action_name and config.buttons[action_name]
|
||||
if button_data and button_data.reason_callback then
|
||||
local reason = element.parent.entry.text
|
||||
local reason = assert(element.parent).entry.text --[[@as string?]]
|
||||
if reason == nil or not reason:find("%S") then reason = "no reason given" end
|
||||
button_data.reason_callback(player, reason)
|
||||
end
|
||||
element.parent.entry.text = ""
|
||||
assert(element.parent).entry.text = ""
|
||||
Elements.container.set_selected_player(player, nil)
|
||||
Elements.player_table.refresh_player(player)
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Clickable player name label, left click opens the map and right click toggles the action bar
|
||||
--- @class ExpGui_PlayerList.elements.player_name_label: ExpElement
|
||||
@@ -142,7 +142,7 @@ Elements.player_name_label = Gui.define("player_list/player_name_label")
|
||||
Elements.container.toggle_selected_player(player, selected_player)
|
||||
Elements.player_table.refresh_player(player)
|
||||
end
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- @class ExpGui_PlayerList.elements.player_table.row
|
||||
--- @field open_button LuaGuiElement
|
||||
@@ -165,7 +165,7 @@ Elements.player_table = Gui.define("player_list/player_table")
|
||||
end)
|
||||
:style{
|
||||
padding = { 1, 0, 1, 2 },
|
||||
} --[[ @as any ]]
|
||||
} --[[@as any]]
|
||||
|
||||
--- Store the action and reason bars associated with a player table
|
||||
--- @param player_table LuaGuiElement
|
||||
@@ -342,7 +342,7 @@ Elements.action_bar = Gui.define("player_list/action_bar")
|
||||
:style{
|
||||
height = 35,
|
||||
padding = { 1, 3 },
|
||||
} --[[ @as any ]]
|
||||
} --[[@as any]]
|
||||
|
||||
--- Update the action bar buttons to match the selection for a player, hidden when nothing is selected
|
||||
--- @param action_bar LuaGuiElement
|
||||
@@ -390,7 +390,7 @@ Elements.reason_bar = Gui.define("player_list/reason_bar")
|
||||
:style{
|
||||
height = 35,
|
||||
padding = { -1, 3 },
|
||||
} --[[ @as any ]]
|
||||
} --[[@as any]]
|
||||
|
||||
--- Update the reason bar visibility to match the selection, shown only while an action awaits a reason
|
||||
--- @param reason_bar LuaGuiElement
|
||||
@@ -420,7 +420,7 @@ Elements.container = Gui.define("player_list/container")
|
||||
Elements.player_table.rebuild(player_table, row_data)
|
||||
|
||||
return Gui.elements.container.get_root_element(container)
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Get or create the selection state for a player
|
||||
--- @param player LuaPlayer
|
||||
|
||||
@@ -93,7 +93,7 @@ Elements.table_label = Gui.define("player_stats/table_label")
|
||||
}
|
||||
:style{
|
||||
width = Gui.from_argument("width"),
|
||||
} --[[ @as any ]]
|
||||
} --[[@as any]]
|
||||
|
||||
--- Data table that shows all data for a player
|
||||
--- @class ExpGui_PlayerStats.elements.player_stats_table: ExpElement
|
||||
@@ -139,7 +139,7 @@ Elements.player_stats_table = Gui.define("player_stats/data_table")
|
||||
|
||||
def.data[data_table] = labels
|
||||
return data_table
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Refresh a data table with the most recent stats for a player
|
||||
--- @param data_table LuaGuiElement
|
||||
@@ -185,7 +185,7 @@ Elements.player_dropdown = Gui.define("player_stats/player_dropdown")
|
||||
local data_table = def.data[element]
|
||||
local target_player = ElementsExtra.online_player_dropdown.get_selected(element)
|
||||
Elements.player_stats_table.refresh(data_table, target_player)
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Refresh all stats tables associated with a player dropdown
|
||||
function Elements.player_dropdown.refresh_online()
|
||||
|
||||
@@ -9,6 +9,7 @@ local Roles = require("modules/exp_legacy/expcore/roles")
|
||||
local Elements = {}
|
||||
|
||||
--- The flow precision values in the same order as production_precision_dropdown.items
|
||||
--- @type defines.flow_precision_index[]
|
||||
local precision_indexes = {
|
||||
defines.flow_precision_index.five_seconds,
|
||||
defines.flow_precision_index.one_minute,
|
||||
@@ -94,7 +95,7 @@ Elements.item_selector = Gui.define("production_stats/item_selector")
|
||||
element_data.on_last_row = false
|
||||
Elements.production_table.add_row(element_data.production_table)
|
||||
end
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Label used for every element in the production table
|
||||
Elements.table_label = Gui.define("production_stats/table_label")
|
||||
@@ -129,7 +130,7 @@ Elements.production_table = Gui.define("production_stats/production_table")
|
||||
:track_all_elements()
|
||||
:draw(function(def, parent)
|
||||
local scroll_table = Gui.elements.scroll_table(parent, 304, 4)
|
||||
local display_alignments = scroll_table.style.column_alignments
|
||||
local display_alignments = assert(scroll_table.style.column_alignments)
|
||||
for i = 2, 4 do
|
||||
display_alignments[i] = "right"
|
||||
end
|
||||
@@ -144,7 +145,7 @@ Elements.production_table = Gui.define("production_stats/production_table")
|
||||
Elements.table_label(scroll_table, { "exp-gui_production-stats.caption-net" }, { "exp-gui_production-stats.tooltip-per-second" }, "heading_2_label")
|
||||
|
||||
return scroll_table
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Calculate the row data for a production table
|
||||
--- @param force LuaForce
|
||||
@@ -183,7 +184,7 @@ end
|
||||
--- @param item_selector LuaGuiElement
|
||||
function Elements.production_table.remove_row(production_table, item_selector)
|
||||
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
|
||||
Gui.destroy_if_valid(item_selector)
|
||||
for _, element in pairs(row) do
|
||||
@@ -196,7 +197,7 @@ end
|
||||
--- @param item_selector LuaGuiElement
|
||||
function Elements.production_table.reset_row(production_table, item_selector)
|
||||
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.consumption.caption = "0.00"
|
||||
row.net.caption = "0.00"
|
||||
@@ -209,7 +210,7 @@ end
|
||||
--- @param row_data ExpGui_ProductionStats.elements.production_table.row_data
|
||||
function Elements.production_table.refresh_row(production_table, item_selector, row_data)
|
||||
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.consumption.caption = row_data.consumption
|
||||
row.net.caption = row_data.net
|
||||
@@ -223,9 +224,9 @@ function Elements.production_table.refresh_online()
|
||||
local precision_index = precision_indexes[element_data.precision_dropdown.selected_index]
|
||||
for _, row in pairs(element_data.rows) do
|
||||
local item_selector = row.item_selector
|
||||
local item_name = item_selector.elem_value --[[ @as string? ]]
|
||||
local item_name = item_selector.elem_value --[[@as string?]]
|
||||
if item_name then
|
||||
local row_data = Elements.production_table.calculate_row_data(player.force --[[ @as LuaForce ]], player.surface, item_name, precision_index)
|
||||
local row_data = Elements.production_table.calculate_row_data(player.force --[[@as LuaForce]], player.surface, item_name, precision_index)
|
||||
Elements.production_table.refresh_row(production_table, item_selector, row_data)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -43,13 +43,13 @@ local function new_quick_action(command, on_click)
|
||||
:style{
|
||||
width = 160,
|
||||
}
|
||||
:on_click(on_click or function(def, player, element, event)
|
||||
:on_click(on_click or function(_def, player, _element, _event)
|
||||
command(player)
|
||||
end)
|
||||
|
||||
Elements[command_name] = element
|
||||
Actions[command_name] = {
|
||||
command = command --[[ @as ExpCommand ]],
|
||||
command = command --[[@as ExpCommand]],
|
||||
element = element,
|
||||
}
|
||||
end
|
||||
|
||||
@@ -47,7 +47,7 @@ Elements.title_table = Gui.define("readme/title_table")
|
||||
cell_padding = 0,
|
||||
vertical_align = "center",
|
||||
horizontally_stretchable = true,
|
||||
} --[[ @as any ]]
|
||||
} --[[@as any]]
|
||||
|
||||
--- Scroll pane used for title tables
|
||||
--- @class ExpGui_Readme.elements.title_table_scroll: ExpElement
|
||||
@@ -64,7 +64,7 @@ Elements.title_table_scroll = Gui.define("readme/title_table_scroll")
|
||||
padding = { 1, 3 },
|
||||
maximal_height = scroll_height,
|
||||
horizontally_stretchable = true,
|
||||
} --[[ @as any ]]
|
||||
} --[[@as any]]
|
||||
|
||||
--- Sub content frame
|
||||
--- @class ExpGui_Readme.elements.sub_content: ExpElement
|
||||
@@ -80,7 +80,7 @@ Elements.sub_content = Gui.define("readme/sub_content")
|
||||
horizontal_align = "center",
|
||||
padding = { 2, 2 },
|
||||
top_margin = 2,
|
||||
} --[[ @as any ]]
|
||||
} --[[@as any]]
|
||||
|
||||
--- @class ExpGui_Readme.elements.join_server.elements
|
||||
--- @field server_id string
|
||||
@@ -119,7 +119,7 @@ Elements.join_server = Gui.define("readme/join_server")
|
||||
--- @cast def ExpGui_Readme.elements.join_server
|
||||
local server_id = def.data[button].server_id
|
||||
External.request_connection(player, server_id, true)
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Refresh join server button
|
||||
--- @param button LuaGuiElement
|
||||
@@ -244,7 +244,7 @@ define_tab(
|
||||
)
|
||||
|
||||
return container
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
)
|
||||
|
||||
--- Rules tab
|
||||
@@ -261,14 +261,15 @@ define_tab(
|
||||
|
||||
local rules = Gui.elements.scroll_table(container, scroll_height, 1)
|
||||
rules.style = "bordered_table"
|
||||
rules.style.cell_padding = 4
|
||||
local rules_style = rules.style --[[@as LuaStyle]]
|
||||
rules_style.cell_padding = 4
|
||||
|
||||
for i = 1, 15 do
|
||||
Gui.elements.centered_label(rules, frame_width - 30, { "exp-gui_readme.rules-" .. i })
|
||||
end
|
||||
|
||||
return container
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
)
|
||||
|
||||
--- Commands tab
|
||||
@@ -287,7 +288,8 @@ define_tab(
|
||||
|
||||
local commands = Gui.elements.scroll_table(container, scroll_height, 2)
|
||||
commands.style = "bordered_table"
|
||||
commands.style.cell_padding = 0
|
||||
local commands_style = commands.style --[[@as LuaStyle]]
|
||||
commands_style.cell_padding = 0
|
||||
|
||||
for name, command in pairs(Commands.list_for_player(player)) do
|
||||
Gui.elements.centered_label(commands, 120, name)
|
||||
@@ -295,7 +297,7 @@ define_tab(
|
||||
end
|
||||
|
||||
return container
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
)
|
||||
|
||||
--- Servers tab
|
||||
@@ -338,7 +340,7 @@ define_tab(
|
||||
end
|
||||
|
||||
return container
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
)
|
||||
|
||||
--- Backers tab
|
||||
@@ -359,32 +361,32 @@ define_tab(
|
||||
roles = { "Senior Administrator", "Administrator" },
|
||||
title = { "exp-gui_readme.backers-management" },
|
||||
width = 230,
|
||||
players = {},
|
||||
players = {}, --- @type string[]
|
||||
},
|
||||
{
|
||||
roles = { "Board Member", "Senior Backer" },
|
||||
title = { "exp-gui_readme.backers-board" },
|
||||
width = 145,
|
||||
players = {},
|
||||
players = {}, --- @type string[]
|
||||
},
|
||||
{
|
||||
roles = { "Sponsor", "Supporter" },
|
||||
title = { "exp-gui_readme.backers-backers" },
|
||||
width = 196,
|
||||
players = {},
|
||||
players = {}, --- @type string[]
|
||||
},
|
||||
{
|
||||
roles = { "Moderator", "Trainee" },
|
||||
title = { "exp-gui_readme.backers-staff" },
|
||||
width = 235,
|
||||
players = {},
|
||||
players = {}, --- @type string[]
|
||||
},
|
||||
{
|
||||
roles = {},
|
||||
time = 3 * 3600 * 60,
|
||||
title = { "exp-gui_readme.backers-active" },
|
||||
width = 235,
|
||||
players = {},
|
||||
players = {}, --- @type string[]
|
||||
},
|
||||
}
|
||||
|
||||
@@ -433,7 +435,7 @@ define_tab(
|
||||
end
|
||||
|
||||
return container
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
)
|
||||
|
||||
--- @class (exact) ExpGui_Readme.elements.readme_data.param table
|
||||
@@ -599,7 +601,7 @@ define_tab(
|
||||
end
|
||||
|
||||
return container
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
)
|
||||
|
||||
--- @class ExpGui_Readme.elements.container.elements
|
||||
@@ -608,6 +610,7 @@ define_tab(
|
||||
--- Main readme container
|
||||
--- @class ExpGui_Readme.elements.container: ExpElement
|
||||
--- @field data table<LuaGuiElement, ExpGui_Readme.elements.container.elements>
|
||||
--- @overload fun(parent: LuaGuiElement): LuaGuiElement
|
||||
Elements.container = Gui.define("readme/container")
|
||||
:track_all_elements()
|
||||
:draw(function(def, parent)
|
||||
|
||||
@@ -72,7 +72,7 @@ Elements.clock_label = Gui.define("research_milestones/clock_label")
|
||||
type = "label",
|
||||
caption = research_time_format_nil,
|
||||
style = "heading_2_label",
|
||||
} --[[ @as any ]]
|
||||
} --[[@as any]]
|
||||
|
||||
--- Update the clock label for all online players
|
||||
function Elements.clock_label.refresh_online()
|
||||
@@ -95,7 +95,7 @@ Elements.milestone_table_label = Gui.define("research_milestones/table_label")
|
||||
minimal_width = Gui.from_argument(2, 70),
|
||||
horizontal_align = Gui.from_argument(3, "right"),
|
||||
font_color = font_color.neutral,
|
||||
} --[[ @as any ]]
|
||||
} --[[@as any]]
|
||||
|
||||
--- @class ExpGui_ResearchMilestones.elements.milestone_table.row_elements
|
||||
--- @field name LuaGuiElement
|
||||
@@ -124,10 +124,11 @@ Elements.milestone_table = Gui.define("research_milestones/milestone_table")
|
||||
Elements.milestone_table_label(milestone_table, { "exp-gui_research-milestones.caption-difference" })
|
||||
return milestone_table
|
||||
end)
|
||||
:element_data{} --[[ @as any ]]
|
||||
:element_data{} --[[@as any]]
|
||||
|
||||
do local _row_data = {}
|
||||
--- @type ExpGui_ResearchMilestones.elements.milestone_table.row_data
|
||||
--- @diagnostic disable-next-line: missing-fields
|
||||
local empty_row_data = { color = font_color.positive }
|
||||
|
||||
--- Get the row data for a force and research
|
||||
@@ -203,7 +204,7 @@ end
|
||||
--- @param row_index number
|
||||
--- @param row_data ExpGui_ResearchMilestones.elements.milestone_table.row_data
|
||||
function Elements.milestone_table.refresh_row(milestone_table, row_index, row_data)
|
||||
local row = Elements.milestone_table.data[milestone_table][row_index]
|
||||
local row = assert(Elements.milestone_table.data[milestone_table][row_index])
|
||||
row.name.caption = row_data.name
|
||||
row.target.caption = row_data.target
|
||||
row.achieved.caption = row_data.achieved
|
||||
@@ -224,7 +225,7 @@ end
|
||||
--- Refresh all the labels on the table
|
||||
--- @param milestone_table LuaGuiElement
|
||||
function Elements.milestone_table.refresh(milestone_table)
|
||||
local force = Gui.get_player(milestone_table).force --[[ @as LuaForce ]]
|
||||
local force = Gui.get_player(milestone_table).force --[[@as LuaForce]]
|
||||
local start_index = Elements.container.calculate_starting_research_index(force)
|
||||
for row_index = 1, display_size do
|
||||
local row_data = Elements.milestone_table.calculate_row_data(force, start_index + row_index - 1)
|
||||
@@ -234,7 +235,7 @@ end
|
||||
|
||||
--- Refresh all tables for a player
|
||||
function Elements.milestone_table.refresh_player(player)
|
||||
local force = player.force --[[ @as LuaForce ]]
|
||||
local force = player.force --[[@as LuaForce]]
|
||||
local start_index = Elements.container.calculate_starting_research_index(force)
|
||||
for _, milestone_table in Elements.milestone_table:online_elements(player) do
|
||||
for row_index = 1, display_size do
|
||||
@@ -269,10 +270,9 @@ Elements.container = Gui.define("research_milestones/container")
|
||||
local milestone_table = Elements.milestone_table(container)
|
||||
Elements.clock_label(header)
|
||||
|
||||
local force = Gui.get_player(parent).force
|
||||
local force = Gui.get_player(parent).force --[[@as LuaForce]]
|
||||
def.data[force] = def.data[force] or {} -- used by start index and row data
|
||||
|
||||
local force = Gui.get_player(parent).force --[[ @as LuaForce ]]
|
||||
local start_index = Elements.container.calculate_starting_research_index(force)
|
||||
for research_index = start_index, start_index + display_size - 1 do
|
||||
local row_data = Elements.milestone_table.calculate_row_data(force, research_index)
|
||||
@@ -296,7 +296,7 @@ end
|
||||
--- @param research_index number
|
||||
--- @return number
|
||||
function Elements.container.get_achieved_time(force, research_index)
|
||||
return Elements.container.data[force][research_index]
|
||||
return assert(Elements.container.data[force][research_index])
|
||||
end
|
||||
|
||||
--- Calculate the starting research index for a force
|
||||
|
||||
@@ -90,7 +90,7 @@ Elements.toggle_section_button = Gui.define("rocket_info/toggle_section_button")
|
||||
element.sprite = "utility/expand"
|
||||
element.tooltip = { "exp-gui_rocket-info.tooltip-toggle-section-expand" }
|
||||
end
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- A clickable coordinate label which opens the silo location on the map when pressed
|
||||
--- @class ExpGui_RocketInfo.elements.position_label: ExpElement
|
||||
@@ -114,7 +114,7 @@ Elements.position_label = Gui.define("rocket_info/position_label")
|
||||
local entity = def.data[element]
|
||||
if not entity or not entity.valid then return end
|
||||
player.set_controller{ type = defines.controllers.remote, position = entity.position, surface = entity.surface }
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Data table showing the launch statistics for a force
|
||||
--- @class ExpGui_RocketInfo.elements.stats_table: ExpElement
|
||||
@@ -125,7 +125,7 @@ Elements.stats_table = Gui.define("rocket_info/stats_table")
|
||||
:element_data{}
|
||||
:draw(function(def, parent)
|
||||
return Gui.elements.scroll_table(parent, 215, 2)
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- @class ExpGui_RocketInfo.elements.stats_table.row_data
|
||||
--- @field key string Unique key used to look up the value label
|
||||
@@ -218,7 +218,7 @@ end
|
||||
--- Refresh the stats table for a player, adding any rows that do not yet exist
|
||||
--- @param player LuaPlayer
|
||||
function Elements.stats_table.refresh_player(player)
|
||||
local force = player.force --[[ @as LuaForce ]]
|
||||
local force = player.force --[[@as LuaForce]]
|
||||
local row_data = Elements.stats_table.calculate_row_data(force)
|
||||
for _, stats_table in Elements.stats_table:online_elements(player) do
|
||||
Elements.stats_table.refresh(stats_table, row_data)
|
||||
@@ -243,7 +243,7 @@ Elements.milestones_table = Gui.define("rocket_info/milestones_table")
|
||||
:element_data{}
|
||||
:draw(function(def, parent)
|
||||
return Gui.elements.scroll_table(parent, 215, 2)
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- @class ExpGui_RocketInfo.elements.milestones_table.row_data
|
||||
--- @field milestone number The milestone this row represents
|
||||
@@ -315,7 +315,7 @@ end
|
||||
--- Refresh the milestones table for a player, adding rows as new milestones become visible
|
||||
--- @param player LuaPlayer
|
||||
function Elements.milestones_table.refresh_player(player)
|
||||
local force = player.force --[[ @as LuaForce ]]
|
||||
local force = player.force --[[@as LuaForce]]
|
||||
local row_data = Elements.stats_table.calculate_row_data(force)
|
||||
for _, stats_table in Elements.stats_table:online_elements(player) do
|
||||
Elements.stats_table.refresh(stats_table, row_data)
|
||||
@@ -359,7 +359,7 @@ Elements.progress_table = Gui.define("rocket_info/progress_table")
|
||||
|
||||
def.data[progress_table] = { rows = {}, no_silos = no_silos }
|
||||
return progress_table
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- @class ExpGui_RocketInfo.elements.progress_table.row_data
|
||||
--- @field entity LuaEntity
|
||||
@@ -404,9 +404,9 @@ end
|
||||
--- @return ExpGui_RocketInfo.elements.progress_table.row_data[]
|
||||
function Elements.progress_table.calculate_row_data_all(silo_data)
|
||||
local row_data = {}
|
||||
for unit_number, silo_data in pairs(silo_data) do
|
||||
if silo_data.entity.valid then
|
||||
row_data[unit_number] = Elements.progress_table.calculate_row_data(silo_data)
|
||||
for unit_number, silo in pairs(silo_data) do
|
||||
if silo.entity.valid then
|
||||
row_data[unit_number] = Elements.progress_table.calculate_row_data(silo)
|
||||
else
|
||||
-- Prune silos that are no longer valid
|
||||
silo_data[unit_number] = nil
|
||||
@@ -433,7 +433,8 @@ function Elements.progress_table.add_row(progress_table, row_data)
|
||||
progress.style.padding = { 0, 2 }
|
||||
progress.style.font_color = row_data.color
|
||||
|
||||
rows[row_data.entity.unit_number] = { x = x, y = y, progress = progress }
|
||||
local unit_number = row_data.entity.unit_number --[[@as uint]]
|
||||
rows[unit_number] = { x = x, y = y, progress = progress }
|
||||
end
|
||||
|
||||
--- Remove a silo row from the progress table
|
||||
@@ -455,7 +456,8 @@ end
|
||||
--- @param row_data ExpGui_RocketInfo.elements.progress_table.row_data
|
||||
function Elements.progress_table.refresh_row(progress_table, row_data)
|
||||
local element_data = Elements.progress_table.data[progress_table]
|
||||
local row = element_data.rows[row_data.entity.unit_number]
|
||||
local unit_number = row_data.entity.unit_number --[[@as uint]]
|
||||
local row = element_data.rows[unit_number]
|
||||
row.x.caption = row_data.x
|
||||
row.y.caption = row_data.y
|
||||
row.progress.caption = row_data.caption
|
||||
@@ -496,7 +498,7 @@ end
|
||||
--- Refresh the progress table for a player, reconciling rows with the current set of silos
|
||||
--- @param player LuaPlayer
|
||||
function Elements.progress_table.refresh_player(player)
|
||||
local force = player.force --[[ @as LuaForce ]]
|
||||
local force = player.force --[[@as LuaForce]]
|
||||
local silos = Elements.container.get_silos(force)
|
||||
local row_data = Elements.progress_table.calculate_row_data_all(silos)
|
||||
for _, progress_table in Elements.progress_table:online_elements(player) do
|
||||
@@ -539,7 +541,7 @@ Elements.container = Gui.define("rocket_info/container")
|
||||
container.style.padding = 0
|
||||
|
||||
local player = Gui.get_player(parent)
|
||||
local force = player.force --[[ @as LuaForce ]]
|
||||
local force = player.force --[[@as LuaForce]]
|
||||
local force_data = def._get_force_data(force)
|
||||
|
||||
if config.stats.show_stats then
|
||||
@@ -618,9 +620,10 @@ end
|
||||
--- Add a silo to the list of current silos for a force
|
||||
--- @param entity LuaEntity
|
||||
function Elements.container.add_silo(entity)
|
||||
local force = entity.force --[[ @as LuaForce ]]
|
||||
local force = entity.force --[[@as LuaForce]]
|
||||
local silos = Elements.container._get_force_data(force).silos
|
||||
silos[entity.unit_number] = {
|
||||
local unit_number = entity.unit_number --[[@as uint]]
|
||||
silos[unit_number] = {
|
||||
entity = entity,
|
||||
launched = 0,
|
||||
awaiting_reset = false,
|
||||
@@ -630,9 +633,11 @@ end
|
||||
--- Increment the launch count for a silo
|
||||
--- @param entity LuaEntity
|
||||
function Elements.container.increment_silo(entity)
|
||||
local force = entity.force --[[ @as LuaForce ]]
|
||||
local force = entity.force --[[@as LuaForce]]
|
||||
local silos = Elements.container._get_force_data(force).silos
|
||||
local silo_data = silos[entity.unit_number]
|
||||
local unit_number = entity.unit_number
|
||||
--- @cast unit_number uint
|
||||
local silo_data = silos[unit_number]
|
||||
if not silo_data then return end
|
||||
silo_data.launched = silo_data.launched + 1
|
||||
silo_data.awaiting_reset = true
|
||||
@@ -653,8 +658,8 @@ Gui.toolbar.create_button{
|
||||
--- Record the launch and update the stats when a cargo pod finishes ascending
|
||||
--- @param event EventData.on_cargo_pod_finished_ascending
|
||||
local function on_cargo_pod_finished_ascending(event)
|
||||
local force = event.cargo_pod.force --[[ @as LuaForce ]]
|
||||
local rockets_launched = force.rockets_launched
|
||||
local force = event.cargo_pod.force --[[@as LuaForce]]
|
||||
local rockets_launched = force.rockets_launched --[[@as number]]
|
||||
|
||||
-- Update the launch stats for the force
|
||||
local stats = Elements.container.get_stats(force)
|
||||
@@ -686,7 +691,7 @@ end
|
||||
--- @param event EventData.on_rocket_launch_ordered
|
||||
local function on_rocket_launch_ordered(event)
|
||||
Elements.container.increment_silo(event.rocket_silo)
|
||||
Elements.progress_table.refresh_force(event.rocket_silo.force --[[ @as LuaForce ]])
|
||||
Elements.progress_table.refresh_force(event.rocket_silo.force --[[@as LuaForce]])
|
||||
end
|
||||
|
||||
--- Refresh the gui when a player joins the game as it may be outdated
|
||||
@@ -704,7 +709,7 @@ local function on_built(event)
|
||||
local entity = event.entity
|
||||
if not entity.valid or entity.name ~= "rocket-silo" then return end
|
||||
Elements.container.add_silo(entity)
|
||||
Elements.progress_table.refresh_force(entity.force --[[ @as LuaForce ]])
|
||||
Elements.progress_table.refresh_force(entity.force --[[@as LuaForce]])
|
||||
end
|
||||
|
||||
--- Refresh the progress for all forces that own at least one silo
|
||||
|
||||
@@ -79,7 +79,7 @@ Elements.production_label = Gui.define("science_production/production_label")
|
||||
|
||||
def.data[label] = suffix
|
||||
return label
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- @class Elements.production_label.display_data
|
||||
--- @field caption LocalisedString
|
||||
@@ -109,7 +109,7 @@ function Elements.production_label.calculate_display_data(tooltip, value, cutoff
|
||||
end
|
||||
|
||||
local suffix, caption = format_number(value)
|
||||
display_data = display_data or {}
|
||||
display_data = display_data or {} --[[@as Elements.production_label.display_data]]
|
||||
display_data.caption = caption
|
||||
display_data.suffix = suffix
|
||||
display_data.tooltip = tooltip
|
||||
@@ -144,12 +144,12 @@ Elements.no_production_label = Gui.define("science_production/no_production_labe
|
||||
padding = { 2, 4 },
|
||||
single_line = false,
|
||||
width = 200,
|
||||
} --[[ @as any ]]
|
||||
} --[[@as any]]
|
||||
|
||||
--- Refresh a no production label
|
||||
--- @param no_production_label LuaGuiElement
|
||||
function Elements.no_production_label.refresh(no_production_label)
|
||||
local force = Gui.get_player(no_production_label).force --[[ @as LuaForce ]]
|
||||
local force = Gui.get_player(no_production_label).force --[[@as LuaForce]]
|
||||
no_production_label.visible = not Elements.container.has_production(force)
|
||||
end
|
||||
|
||||
@@ -157,7 +157,7 @@ end
|
||||
function Elements.no_production_label.refresh_online()
|
||||
local force_data = {}
|
||||
for player, no_production_label in Elements.no_production_label:online_elements() do
|
||||
local force = player.force --[[ @as LuaForce ]]
|
||||
local force = player.force --[[@as LuaForce]]
|
||||
local visible = force_data[force.name]
|
||||
if visible == nil then
|
||||
visible = not Elements.container.has_production(force)
|
||||
@@ -193,10 +193,11 @@ Elements.science_table = Gui.define("science_production/science_table")
|
||||
local science_table = Gui.elements.scroll_table(parent, 190, 4)
|
||||
local no_production_label = Elements.no_production_label(science_table)
|
||||
Elements.no_production_label.refresh(no_production_label)
|
||||
science_table.style.column_alignments[3] = "right"
|
||||
local science_table_style = science_table.style --[[@as LuaStyle]]
|
||||
science_table_style.column_alignments[3] = "right"
|
||||
return science_table
|
||||
end)
|
||||
:element_data{} --[[ @as any ]]
|
||||
:element_data{} --[[@as any]]
|
||||
|
||||
--- Calculate the data needed to add or refresh a row
|
||||
--- @param force LuaForce
|
||||
@@ -220,7 +221,7 @@ function Elements.science_table.calculate_row_data(force, science_pack, row_data
|
||||
end
|
||||
|
||||
-- Return the pack data
|
||||
row_data = row_data or {}
|
||||
row_data = row_data or {} --[[@as ExpGui_ScienceProduction.elements.science_table.row_data]]
|
||||
row_data.visible = production.total.made > 0
|
||||
row_data.science_pack = science_pack
|
||||
row_data.icon_style = icon_style
|
||||
@@ -280,7 +281,8 @@ function Elements.science_table.add_row(science_table, row_data)
|
||||
column_count = 2,
|
||||
}
|
||||
delta_table.style.padding = 0
|
||||
delta_table.style.column_alignments[1] = "right"
|
||||
local delta_table_style = delta_table.style --[[@as LuaStyle]]
|
||||
delta_table_style.column_alignments[1] = "right"
|
||||
|
||||
-- Draw the net production label
|
||||
local net = Elements.production_label(science_table, row_data.net)
|
||||
@@ -312,7 +314,8 @@ function Elements.science_table.refresh_row(science_table, row_data)
|
||||
-- Update the icon
|
||||
local icon = row.icon
|
||||
icon.style = row_data.icon_style
|
||||
icon.style.height = 55
|
||||
local icon_style = icon.style --[[@as LuaStyle]]
|
||||
icon_style.height = 55
|
||||
|
||||
-- Update the element visibility
|
||||
row.net_suffix.visible = true
|
||||
@@ -326,8 +329,7 @@ function Elements.science_table.refresh_row(science_table, row_data)
|
||||
Elements.production_label.refresh(row.used, row_data.used)
|
||||
end
|
||||
|
||||
--- @type table<string, { [string]: ExpGui_ScienceProduction.elements.science_table.row_data }>
|
||||
do local _row_data = {}
|
||||
do local _row_data = {} --- @type table<string, table<number, ExpGui_ScienceProduction.elements.science_table.row_data>>
|
||||
--- Refresh the production tables for all online players
|
||||
function Elements.science_table.refresh_online()
|
||||
-- Refresh the row data for online forces
|
||||
@@ -361,7 +363,7 @@ Elements.eta_label = Gui.define("science_production/eta_label")
|
||||
caption = clock_time_format_nil,
|
||||
tooltip = long_time_format_nil,
|
||||
style = "frame_title",
|
||||
} --[[ @as any ]]
|
||||
} --[[@as any]]
|
||||
|
||||
--- @class Elements.eta_label.display_data
|
||||
--- @field caption LocalisedString
|
||||
@@ -410,14 +412,13 @@ end
|
||||
--- Refresh an eta label
|
||||
--- @param eta_label LuaGuiElement
|
||||
function Elements.eta_label.refresh(eta_label)
|
||||
local force = Gui.get_player(eta_label).force --[[ @as LuaForce ]]
|
||||
local force = Gui.get_player(eta_label).force --[[@as LuaForce]]
|
||||
local display_data = Elements.eta_label.calculate_display_data(force)
|
||||
eta_label.caption = display_data.caption
|
||||
eta_label.tooltip = display_data.tooltip
|
||||
end
|
||||
|
||||
--- @type Elements.eta_label.display_data
|
||||
do local _display_data = {}
|
||||
do local _display_data = {} --- @type table<string, Elements.eta_label.display_data>
|
||||
--- Refresh the eta label for all online players
|
||||
function Elements.eta_label.refresh_online()
|
||||
-- Refresh the row data for online forces
|
||||
@@ -430,8 +431,10 @@ do local _display_data = {}
|
||||
-- Update the eta labels
|
||||
for player, eta_label in Elements.eta_label:online_elements() do
|
||||
local display_data = _display_data[player.force.name]
|
||||
eta_label.caption = display_data.caption
|
||||
eta_label.tooltip = display_data.tooltip
|
||||
if display_data then
|
||||
eta_label.caption = display_data.caption
|
||||
eta_label.tooltip = display_data.tooltip
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -443,7 +446,7 @@ Elements.container = Gui.define("science_production/container")
|
||||
local container = Gui.elements.container(parent)
|
||||
Gui.elements.header(container, { caption = { "exp-gui_science-production.caption-main" } })
|
||||
|
||||
local force = Gui.get_player(parent).force --[[ @as LuaForce ]]
|
||||
local force = Gui.get_player(parent).force --[[@as LuaForce]]
|
||||
local science_table = Elements.science_table(container)
|
||||
for _, science_pack in ipairs(config) do
|
||||
--- @cast science_pack any
|
||||
@@ -462,7 +465,7 @@ Elements.container = Gui.define("science_production/container")
|
||||
end
|
||||
|
||||
return Gui.elements.container.get_root_element(container)
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Cached mostly because they are long names
|
||||
local _fp_one_minute = defines.flow_precision_index.one_minute
|
||||
@@ -477,8 +480,7 @@ local _fp_one_hour = defines.flow_precision_index.one_hour
|
||||
--- @field ten_minutes ExpGui_ScienceProduction._item_data
|
||||
--- @field one_hour ExpGui_ScienceProduction._item_data
|
||||
|
||||
--- @type table<string, { [string]: ExpGui_ScienceProduction.item_production_data }>
|
||||
do local _production_data = {}
|
||||
do local _production_data = {} --- @type table<string, { [string]: ExpGui_ScienceProduction.item_production_data }>
|
||||
|
||||
--- Get the production stats for a force
|
||||
--- @param flow_stats any
|
||||
|
||||
@@ -25,7 +25,7 @@ Elements.player_dropdown = Gui.define("surveillance/player_dropdown")
|
||||
local camera = def.data[element]
|
||||
local target_player = assert(ElementsExtra.online_player_dropdown.get_selected(element))
|
||||
Elements.camera.set_target_player(camera, target_player)
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Button which sets the target of a camera to the current location
|
||||
--- @class ExpGui_Surveillance.elements.set_location_button: ExpElement
|
||||
@@ -48,7 +48,7 @@ Elements.set_location_button = Gui.define("surveillance/set_location_button")
|
||||
--- @cast def ExpGui_Surveillance.elements.set_location_button
|
||||
local camera = def.data[element]
|
||||
Elements.camera.set_target_position(camera, player.physical_surface_index, player.physical_position)
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- @class ExpGui_Surveillance.elements.type_dropdown.data
|
||||
--- @field player_dropdown LuaGuiElement
|
||||
@@ -87,7 +87,7 @@ Elements.type_dropdown = Gui.define("surveillance/type_dropdown")
|
||||
local target_player = ElementsExtra.online_player_dropdown.get_selected(element_data.player_dropdown)
|
||||
Elements.camera.set_target_player(element_data.camera, target_player)
|
||||
end
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Refresh all online type dropdowns by cycling the associated player dropdown
|
||||
function Elements.type_dropdown.refresh_online()
|
||||
@@ -131,7 +131,7 @@ Elements.zoom_out_button = Gui.define("surveillance/zoom_out_button")
|
||||
if camera.zoom > 0.2 then
|
||||
camera.zoom = camera.zoom - 0.05
|
||||
end
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Buttons which increases zoom by 5%
|
||||
--- @class ExpGui_Surveillance.elements.zoom_in_button: ExpElement
|
||||
@@ -156,7 +156,7 @@ Elements.zoom_in_button = Gui.define("surveillance/zoom_in_button")
|
||||
if camera.zoom < 2.0 then
|
||||
camera.zoom = camera.zoom + 0.05
|
||||
end
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Camera which tracks a target with a physical_position and surface_index
|
||||
--- @class ExpGui_Surveillance.elements.camera: ExpElement
|
||||
@@ -176,7 +176,7 @@ Elements.camera = Gui.define("surveillance/camera")
|
||||
}
|
||||
:element_data(
|
||||
Gui.from_argument(1)
|
||||
) --[[ @as any ]]
|
||||
) --[[@as any]]
|
||||
|
||||
--- Set the target player for the camera
|
||||
--- @param camera LuaGuiElement
|
||||
|
||||
@@ -105,7 +105,7 @@ Elements.new_task_button = Gui.define("task_list/new_task_button")
|
||||
body = "",
|
||||
new = true,
|
||||
})
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Refresh the visibility based on player permissions
|
||||
--- @param new_task_button LuaGuiElement
|
||||
@@ -154,7 +154,7 @@ Elements.view_task_button = Gui.define("task_list/view_task_button")
|
||||
--- @cast def ExpGui_TaskList.element.view_task_button
|
||||
local elements = def.data[view_task_button]
|
||||
Elements.container.open_view_task(elements.container, elements.task)
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Refresh the title and tooltip of the view task button
|
||||
--- @param view_task_button LuaGuiElement
|
||||
@@ -187,19 +187,19 @@ Elements.no_tasks_header = Gui.define("task_list/no_tasks_header")
|
||||
:style{
|
||||
padding = { 2, 0 },
|
||||
bottom_margin = 0,
|
||||
} --[[ @as any ]]
|
||||
} --[[@as any]]
|
||||
|
||||
--- Refresh the visibility of the no tasks label
|
||||
--- @param no_tasks_header LuaGuiElement
|
||||
function Elements.no_tasks_header.refresh(no_tasks_header)
|
||||
local force = Gui.get_player(no_tasks_header).force --[[ @as LuaForce ]]
|
||||
local force = Gui.get_player(no_tasks_header).force --[[@as LuaForce]]
|
||||
no_tasks_header.visible = not Elements.container.has_tasks(force)
|
||||
end
|
||||
|
||||
--- Refresh the visibility of the no tasks label
|
||||
--- @param player LuaPlayer
|
||||
function Elements.no_tasks_header.refresh_player(player)
|
||||
local visible = not Elements.container.has_tasks(player.force --[[ @as LuaForce ]])
|
||||
local visible = not Elements.container.has_tasks(player.force --[[@as LuaForce]])
|
||||
for _, no_tasks_header in Elements.no_tasks_header:tracked_elements(player) do
|
||||
no_tasks_header.visible = visible
|
||||
end
|
||||
@@ -246,13 +246,13 @@ Elements.task_list = Gui.define("task_list/task_list")
|
||||
|
||||
return task_list
|
||||
end)
|
||||
:element_data{} --[[ @as any ]]
|
||||
:element_data{} --[[@as any]]
|
||||
|
||||
--- Adds a task to the task list
|
||||
--- @param task_list LuaGuiElement
|
||||
--- @param task ExpGui_TaskList.Task
|
||||
function Elements.task_list.add_task(task_list, task)
|
||||
local container = assert(task_list.parent.parent.parent)
|
||||
local container = assert(assert(assert(task_list.parent).parent).parent)
|
||||
local view_task_buttons = Elements.task_list.data[task_list]
|
||||
view_task_buttons[task.id] = Elements.view_task_button(task_list, task, container)
|
||||
end
|
||||
@@ -330,7 +330,7 @@ Elements.task_footer = Gui.define("task_list/task_footer")
|
||||
height = 0,
|
||||
padding = 5,
|
||||
use_header_filler = false,
|
||||
} --[[ @as any ]]
|
||||
} --[[@as any]]
|
||||
|
||||
--- @class ExpGui_TaskList.elements.close_task_button.elements
|
||||
--- @field container LuaGuiElement
|
||||
@@ -354,7 +354,7 @@ Elements.close_task_button = Gui.define("task_list/close_task_button")
|
||||
--- @cast def ExpGui_TaskList.element.close_task_button
|
||||
local elements = def.data[close_task_button]
|
||||
Elements.container.close_footers(elements.container)
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- @class ExpGui_TaskList.elements.task_button.elements
|
||||
--- @field task ExpGui_TaskList.Task?
|
||||
@@ -379,7 +379,7 @@ Elements.edit_task_button = Gui.define("task_list/edit_task_button")
|
||||
--- @cast def ExpGui_TaskList.element.edit_task_button
|
||||
local elements = def.data[edit_task_button]
|
||||
Elements.container.open_edit_task(elements.container, assert(elements.task))
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Refresh the edit button
|
||||
--- @param edit_task_button LuaGuiElement
|
||||
@@ -415,9 +415,9 @@ Elements.delete_task_button = Gui.define("task_list/delete_task_button")
|
||||
:on_click(function(def, player, delete_task_button)
|
||||
--- @cast def ExpGui_TaskList.element.delete_task_button
|
||||
local elements = def.data[delete_task_button]
|
||||
Elements.container.remove_task(player.force --[[ @as LuaForce ]], elements.task)
|
||||
Elements.container.remove_task(player.force --[[@as LuaForce]], elements.task)
|
||||
Elements.container.close_footers(elements.container)
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Refresh the delete button
|
||||
--- @param delete_task_button LuaGuiElement
|
||||
@@ -477,7 +477,7 @@ Elements.view_task_footer = Gui.define("task_list/view_task_footer")
|
||||
}
|
||||
|
||||
return view_task_footer
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Refresh the view task with new task details
|
||||
--- @param view_task_footer LuaGuiElement
|
||||
@@ -532,9 +532,9 @@ Elements.task_message_textfield = Gui.define("task_list/task_message_textfield")
|
||||
}
|
||||
:on_text_changed(function(def, player, task_message_textfield)
|
||||
--- @cast def ExpGui_TaskList.elements.task_message_textfield
|
||||
local confirm_task_button = def.data[task_message_textfield].confirm_task_button
|
||||
local confirm_task_button = assert(def.data[task_message_textfield].confirm_task_button)
|
||||
confirm_task_button.enabled = string.len(task_message_textfield.text) > 5
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Set the confirm task button to update on text changed
|
||||
--- @param task_message_textfield LuaGuiElement
|
||||
@@ -549,7 +549,7 @@ end
|
||||
function Elements.task_message_textfield.refresh(task_message_textfield, task)
|
||||
local elements = Elements.task_message_textfield.data[task_message_textfield]
|
||||
local message = task.new and "" or task.title .. "\n" .. task.body
|
||||
elements.confirm_task_button.enabled = string.len(message) > 5
|
||||
assert(elements.confirm_task_button).enabled = string.len(message) > 5
|
||||
task_message_textfield.text = message
|
||||
task_message_textfield.focus()
|
||||
end
|
||||
@@ -590,13 +590,13 @@ Elements.confirm_task_button = Gui.define("task_list/confirm_task_button")
|
||||
|
||||
Elements.container.close_footers(elements.container)
|
||||
|
||||
local force = player.force --[[ @as LuaForce ]]
|
||||
local force = player.force --[[@as LuaForce]]
|
||||
if task.new then
|
||||
Elements.container.add_task(force, task)
|
||||
else
|
||||
Elements.container.refresh_force_online(force, task)
|
||||
end
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Refresh the confirm task button
|
||||
--- @param confirm_task_button LuaGuiElement
|
||||
@@ -612,7 +612,7 @@ function Elements.confirm_task_button.parse(message)
|
||||
-- Trim the spaces of the string
|
||||
local trimmed = string.gsub(message, "^%s*(.-)%s*$", "%1")
|
||||
local title, body = string.match(trimmed, "(.-)\n(.*)")
|
||||
local parsed = { title = title, body = body }
|
||||
local parsed = { title = title, body = body } --[[@as { title: string, body: string }]]
|
||||
if not title then
|
||||
-- If it doesn't match the pattern return the str as a title
|
||||
parsed.title = trimmed
|
||||
@@ -649,7 +649,7 @@ Elements.discard_task_button = Gui.define("task_list/discard_task_button")
|
||||
else
|
||||
Elements.container.open_view_task(elements.container, task)
|
||||
end
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Refresh the discard task button
|
||||
--- @param discard_task_button LuaGuiElement
|
||||
@@ -696,7 +696,7 @@ Elements.edit_task_footer = Gui.define("task_list/edit_task_footer")
|
||||
}
|
||||
|
||||
return edit_task_footer
|
||||
end) --[[ @as any ]]
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Refresh the view task with new task details
|
||||
--- @param edit_task_footer LuaGuiElement
|
||||
@@ -755,9 +755,14 @@ end
|
||||
--- @field view_task_footer LuaGuiElement
|
||||
--- @field edit_task_footer LuaGuiElement
|
||||
|
||||
--- @class ExpGui_TaskList.elements.container.data
|
||||
--- @field global_data { next_task_id: number }
|
||||
--- @field [LuaGuiElement] ExpGui_TaskList.elements.container.elements
|
||||
--- @field [LuaForce] ExpGui_TaskList.Task[]
|
||||
|
||||
--- Container added to the left gui flow
|
||||
--- @class ExpGui_TaskList.elements.container: ExpElement
|
||||
--- @field data table<LuaForce, ExpGui_TaskList.Task[]> | table<LuaGuiElement, ExpGui_TaskList.elements.container.elements> | table<"global_data", { next_task_id: number }>
|
||||
--- @field data ExpGui_TaskList.elements.container.data
|
||||
Elements.container = Gui.define("task_list/container")
|
||||
:track_all_elements()
|
||||
:draw(function(def, parent)
|
||||
@@ -781,7 +786,7 @@ Elements.container = Gui.define("task_list/container")
|
||||
|
||||
-- Add tasks to the list if there are any
|
||||
local player = Gui.get_player(parent)
|
||||
local force = player.force --[[ @as LuaForce ]]
|
||||
local force = player.force --[[@as LuaForce]]
|
||||
local tasks = def.data[force]
|
||||
if tasks then
|
||||
for _, task in ipairs(tasks) do
|
||||
@@ -796,11 +801,11 @@ Elements.container = Gui.define("task_list/container")
|
||||
elements.edit_task_footer.visible = false
|
||||
|
||||
-- Set the data and return
|
||||
def.data[root] = elements --[[ @as any ]]
|
||||
def.data[root] = elements --[[@as any]]
|
||||
return root
|
||||
end)
|
||||
:global_data{ next_task_id = 1 }
|
||||
:force_data{} --[[ @as any ]]
|
||||
:force_data{} --[[@as any]]
|
||||
|
||||
--- Check if a force has tasks
|
||||
--- @param force LuaForce
|
||||
@@ -885,7 +890,7 @@ end
|
||||
--- Refresh all tasks for a player
|
||||
--- @param player LuaPlayer
|
||||
function Elements.container.refresh_player(player)
|
||||
local tasks = Elements.container.data[ player.force --[[ @as LuaForce ]] ]
|
||||
local tasks = Elements.container.data[ player.force --[[@as LuaForce]] ]
|
||||
for _, container in Elements.container:tracked_elements(player) do
|
||||
local elements = Elements.container.data[container]
|
||||
Elements.task_list.refresh_tasks(elements.task_list, tasks)
|
||||
@@ -908,7 +913,7 @@ end
|
||||
|
||||
--- Add the element to the left flow with a toolbar button
|
||||
Gui.add_left_element(Elements.container, function(player)
|
||||
return Elements.container.has_tasks(player.force --[[ @as LuaForce ]])
|
||||
return Elements.container.has_tasks(player.force --[[@as LuaForce]])
|
||||
end)
|
||||
|
||||
Gui.toolbar.create_button{
|
||||
|
||||
Reference in New Issue
Block a user