Make the @as casts actually apply

emmylua only parses the inline cast as `--[[@as T]]`, the spaced form
`--[[ @as T ]]` is treated as a plain comment, so all 149 of them were
doing nothing.

LuaGuiElement.style is a union because a style name can be assigned to
it, so reading it back needs the cast.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
bbassie
2026-08-07 15:31:18 +00:00
co-authored by Claude Opus 5
parent fd2f5a9589
commit 164672602d
32 changed files with 151 additions and 148 deletions
+1 -1
View File
@@ -159,7 +159,7 @@ Commands.server = setmetatable({
Commands.error("Command does not support rcon usage, requires LuaPlayer." .. key)
error("Command does not support rcon usage, requires LuaPlayer." .. key)
end,
}) --[[ @as LuaPlayer ]]
}) --[[@as LuaPlayer]]
--- Status Returns.
-- Return values used by command callbacks
+1 -1
View File
@@ -154,7 +154,7 @@ end
--- @param scope string
--- @return GuiData
function GuiData.get(scope)
return GuiData._scopes[scope] --[[ @as GuiData ]]
return GuiData._scopes[scope] --[[@as GuiData]]
end
--- Used to clean up data from destroyed elements
+12 -12
View File
@@ -28,7 +28,7 @@ Elements.aligned_flow = Gui.define("aligned_flow")
vertically_stretchable = vertical_align ~= "center",
horizontally_stretchable = horizontal_align ~= "center",
}
end) --[[ @as any ]]
end) --[[@as any]]
--- A solid horizontal white bar element
--- @class Gui.elements.bar: ExpElement
@@ -48,7 +48,7 @@ Elements.bar = Gui.define("bar")
else
style.horizontally_stretchable = true
end
end) --[[ @as any ]]
end) --[[@as any]]
--- A label which is centered
--- @class Gui.elements.centered_label: ExpElement
@@ -63,7 +63,7 @@ Elements.centered_label = Gui.define("centered_label")
horizontal_align = "center",
single_line = false,
width = Gui.from_argument(1),
} --[[ @as any ]]
} --[[@as any]]
--- A label which has two white bars on either side of it
--- @class Gui.elements.title_label: ExpElement
@@ -91,7 +91,7 @@ Elements.title_label = Gui.define("title_label")
Elements.bar(flow)
return label
end) --[[ @as any ]]
end) --[[@as any]]
--- A fixed size vertical scroll pane
--- @class Gui.elements.scroll_pane: ExpElement
@@ -109,7 +109,7 @@ Elements.scroll_pane = Gui.define("scroll_pane")
padding = { 1, 3 },
maximal_height = Gui.from_argument(1),
horizontally_stretchable = true,
} --[[ @as any ]]
} --[[@as any]]
--- A fixed size vertical scroll pane containing a table
--- @class Gui.elements.scroll_table: ExpElement
@@ -132,7 +132,7 @@ Elements.scroll_table = Gui.define("scroll_table")
cell_padding = 1,
vertical_align = "center",
horizontally_stretchable = true,
} --[[ @as any ]]
} --[[@as any]]
--- A container frame
--- @class Gui.elements.container: ExpElement
@@ -159,7 +159,7 @@ Elements.container = Gui.define("container")
vertically_stretchable = false,
horizontally_stretchable = false,
minimal_width = Gui.from_argument(1),
} --[[ @as any ]]
} --[[@as any]]
--- Get the root element of a container
--- @param container LuaGuiElement
@@ -183,7 +183,7 @@ Elements.subframe_base = Gui.define("container_subframe")
padding = { 3, 6, 0, 6 },
use_header_filler = false,
horizontally_stretchable = true,
} --[[ @as any ]]
} --[[@as any]]
--- @class Gui.elements.header.opts
--- @field name string?
@@ -212,7 +212,7 @@ Elements.header = Gui.define("container_header")
subframe.add{ type = "empty-widget" }.style.horizontally_stretchable = true
return subframe
end) --[[ @as any ]]
end) --[[@as any]]
--- @class Gui.elements.footer.opts
--- @field name string?
@@ -241,7 +241,7 @@ Elements.footer = Gui.define("container_footer")
subframe.add{ type = "empty-widget" }.style.horizontally_stretchable = true
return subframe
end) --[[ @as any ]]
end) --[[@as any]]
--- A button used to destroy its target when clicked, intended for screen frames
--- @class Gui.elements.screen_frame_close: ExpElement
@@ -259,7 +259,7 @@ Elements.screen_frame_close = Gui.define("screen_frame_close")
:on_click(function(def, player, element, event)
--- @cast def Gui.elements.screen_frame_close
Gui.destroy_if_valid(def.data[element])
end) --[[ @as any ]]
end) --[[@as any]]
--- A draggable frame with close button and button flow
--- @class Gui.elements.screen_frame: ExpElement
@@ -313,7 +313,7 @@ Elements.screen_frame = Gui.define("screen_frame")
direction = "vertical",
style = "inside_shallow_frame_packed",
}
end) --[[ @as any ]]
end) --[[@as any]]
--- Get the button flow for a screen frame
--- @param screen_frame LuaGuiElement
+2 -2
View File
@@ -158,7 +158,7 @@ function ExpElement.new(name)
},
}
ExpElement._elements[element_name] = instance --[[ @as ExpElement ]]
ExpElement._elements[element_name] = instance --[[@as ExpElement]]
return setmetatable(instance, ExpElement._metatable)
end
@@ -460,7 +460,7 @@ function ExpElement._prototype:raise_event(event)
for _, handler in ipairs(handlers) do
-- All gui elements will contain player and element, other events might have these as nil
-- Therefore only the signature of on_event has these values as optional
handler(self, player --[[ @as LuaPlayer ]], event.element, event --[[ @as EventData ]])
handler(self, player --[[@as LuaPlayer]], event.element, event --[[@as EventData]])
end
end
+6 -6
View File
@@ -85,7 +85,7 @@ function Toolbar.set_button_toggled_state(define, player, state, _from_left)
button.style = state and toolbar_button_active_style or toolbar_button_default_style
-- Make the extra required adjustments
local style = button.style
local style = button.style --[[@as LuaStyle]]
style.minimal_width = original_width
style.maximal_height = original_height
if button.type == "sprite-button" then
@@ -393,7 +393,7 @@ end
--- @param player LuaPlayer
--- @param order Gui.ToolbarOrder
function Toolbar.set_order(player, order)
local list = elements.toolbar_settings.data[player] --[[ @as LuaGuiElement ]]
local list = elements.toolbar_settings.data[player] --[[@as LuaGuiElement]]
local left_flow = Gui.get_left_flow(player)
local top_flow = Gui.get_top_flow(player)
@@ -466,7 +466,7 @@ end
function Toolbar.get_state(player)
-- Get the order of toolbar buttons
local order = {}
local list = elements.toolbar_settings.data[player] --[[ @as LuaGuiElement ]]
local list = elements.toolbar_settings.data[player] --[[@as LuaGuiElement]]
for index, item in pairs(list.children) do
order[index] = { name = item.name, favourite = elements.toolbar_list_item.data[item].set_favourite.state }
end
@@ -487,7 +487,7 @@ end
--- @param player LuaPlayer
function Toolbar._create_elements(player)
-- Add any missing items to the gui
local toolbar_list = elements.toolbar_settings.data[player] --[[ @as LuaGuiElement ]]
local toolbar_list = elements.toolbar_settings.data[player] --[[@as LuaGuiElement]]
local previous_last_index = #toolbar_list.children_names
for define in pairs(Gui.top_elements) do
if define ~= elements.close_toolbar and toolbar_list[define.name] == nil then
@@ -513,7 +513,7 @@ end
--- @param player LuaPlayer
function Toolbar._ensure_consistency(player)
-- Update the toolbar buttons
local list = elements.toolbar_settings.data[player] --[[ @as LuaGuiElement ]]
local list = elements.toolbar_settings.data[player] --[[@as LuaGuiElement]]
for _, button in ipairs(toolbar_buttons) do
-- Update the visible state based on if the player is allowed the button
local element = Gui.get_top_element(button, player)
@@ -658,7 +658,7 @@ elements.set_favourite = Gui.define("set_favourite")
width = 180,
}
:on_checked_state_changed(function(def, player, element)
local define = ExpElement.get(element.tags.element_name --[[ @as string ]])
local define = ExpElement.get(element.tags.element_name --[[@as string]])
local top_element = Gui.get_top_element(define, player)
local had_visible = Toolbar.has_visible_buttons(player)
top_element.visible = element.state
@@ -31,7 +31,7 @@ end
-- gets the action player and a coloured name for the action to be used on
local function get_action_player(player)
local selected_player = get_selected_player(player) --[[ @as LuaPlayer ]]
local selected_player = get_selected_player(player) --[[@as LuaPlayer]]
local selected_player_color = format_player_name(selected_player)
return selected_player, selected_player_color
end
@@ -142,7 +142,7 @@ group:set_action('toggle_map_editor', false)
]]
function PermissionsGroups._prototype:set_action(action, state)
local input_action = defines.input_action[action] --[[ @as defines.input_action? ]]
local input_action = defines.input_action[action] --[[@as defines.input_action?]]
if input_action == nil then input_action = action end
assert(type(input_action) == "number", tostring(action) .. " is not a valid input action")
self.actions[input_action] = state
+1 -1
View File
@@ -18,7 +18,7 @@ ToolbarState:on_load(function(player_name, value)
local decompressed = helpers.json_to_table(assert(helpers.decode_string(value), "Failed String Decode"))
local player = assert(game.get_player(player_name))
Gui.toolbar.set_state(player, decompressed --[[ @as Gui.ToolbarState ]])
Gui.toolbar.set_state(player, decompressed --[[@as Gui.ToolbarState]])
return nil -- We don't save the state, use Gui.toolbar.get_state
end)
+2 -2
View File
@@ -273,7 +273,7 @@ local warp_textfield = Gui.define("warp_textfield")
:on_confirmed(function(def, player, element)
local warp_id = element.parent.caption
local warp_name = element.text
local warp_icon = element.parent.parent["icon-" .. warp_id][warp_icon_editing.name].elem_value --[[ @as SignalID ]]
local warp_icon = element.parent.parent["icon-" .. warp_id][warp_icon_editing.name].elem_value --[[@as SignalID]]
if warp_icon.type == nil then warp_icon.type = "item" end
Warps.set_editing(warp_id, player.name)
Warps.update_warp(warp_id, warp_name, warp_icon, player.name)
@@ -293,7 +293,7 @@ local confirm_edit_button = Gui.define("confirm_edit_button")
:on_click(function(def, player, element)
local warp_id = element.parent.caption
local warp_name = element.parent.parent["name-" .. warp_id][warp_textfield.name].text
local warp_icon = element.parent.parent["icon-" .. warp_id][warp_icon_editing.name].elem_value --[[ @as SignalID ]]
local warp_icon = element.parent.parent["icon-" .. warp_id][warp_icon_editing.name].elem_value --[[@as SignalID]]
if warp_icon.type == nil then warp_icon.type = "item" end
Warps.set_editing(warp_id, player.name)
Warps.update_warp(warp_id, warp_name, warp_icon, player.name)
+2 -2
View File
@@ -284,7 +284,7 @@ local server_role = setmetatable({
--- @param player LuaPlayer | string | nil
--- @return ExpRoles.Role[]
function ExpRoles.get_player_roles(player)
local player_name = type(player) == "table" and player.name or player --[[ @as string? ]]
local player_name = type(player) == "table" and player.name or player --[[@as string?]]
-- The server is not a player and is allowed to do anything
if player_name == nil then return { server_role } end
@@ -678,7 +678,7 @@ end
--- @param silent boolean?
--- @param sync boolean
local function change_player_roles(player, roles, change_type, by_player_name, silent, sync)
local player_name = type(player) == "table" and player.name or player --[[ @as string? ]]
local player_name = type(player) == "table" and player.name or player --[[@as string?]]
if not player_name then return end
local role_objects = resolve_roles(roles)
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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)
+4 -4
View File
@@ -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,
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -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)
@@ -84,7 +84,7 @@ local function get_player_cache(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)
+8 -8
View File
@@ -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)
@@ -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
+1 -1
View File
@@ -22,7 +22,7 @@ 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
do local _player_names = {} --- @type (string?)[]
+6 -6
View File
@@ -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
@@ -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
@@ -349,7 +349,7 @@ 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 = 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")
+7 -7
View File
@@ -47,7 +47,7 @@ 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
do local _points_limit = {} --- @type table<number, number>
@@ -147,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
@@ -188,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
@@ -209,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
@@ -267,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
@@ -313,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
@@ -380,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
+9 -9
View File
@@ -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
@@ -109,7 +109,7 @@ Elements.reason_confirm = Gui.define("player_list/reason_confirm")
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
+3 -3
View File
@@ -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()
+4 -4
View File
@@ -94,7 +94,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")
@@ -144,7 +144,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
@@ -223,9 +223,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
+1 -1
View File
@@ -49,7 +49,7 @@ local function new_quick_action(command, on_click)
Elements[command_name] = element
Actions[command_name] = {
command = command --[[ @as ExpCommand ]],
command = command --[[@as ExpCommand]],
element = element,
}
end
+14 -12
View File
@@ -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
@@ -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
@@ -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,7 +124,7 @@ 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
@@ -224,7 +224,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 +234,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
@@ -272,7 +272,7 @@ Elements.container = Gui.define("research_milestones/container")
local force = Gui.get_player(parent).force
def.data[force] = def.data[force] or {} -- used by start index and row data
local force = Gui.get_player(parent).force --[[ @as LuaForce ]]
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)
+13 -13
View File
@@ -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
@@ -500,7 +500,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
@@ -543,7 +543,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
@@ -622,7 +622,7 @@ 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
local unit_number = entity.unit_number
--- @cast unit_number uint
@@ -636,7 +636,7 @@ 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 unit_number = entity.unit_number
--- @cast unit_number uint
@@ -696,7 +696,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
@@ -714,7 +714,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
+11 -10
View File
@@ -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
@@ -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)
@@ -196,7 +196,7 @@ Elements.science_table = Gui.define("science_production/science_table")
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
@@ -312,7 +312,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
@@ -360,7 +361,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
@@ -409,7 +410,7 @@ 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
@@ -441,7 +442,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
@@ -460,7 +461,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
+6 -6
View File
@@ -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
+22 -22
View File
@@ -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,7 +246,7 @@ 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
@@ -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
@@ -534,7 +534,7 @@ Elements.task_message_textfield = Gui.define("task_list/task_message_textfield")
--- @cast def ExpGui_TaskList.elements.task_message_textfield
local confirm_task_button = 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
@@ -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
@@ -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
@@ -781,7 +781,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 +796,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 +885,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 +908,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{
+1 -1
View File
@@ -42,7 +42,7 @@ Elements.server_ups = Gui.define("server_ups")
if not existing or not existing.valid then
def.data[player] = element -- Only set if previous is invalid
end
end) --[[ @as any ]]
end) --[[@as any]]
--- Refresh the caption for all online players
--- @param ups number The UPS to be displayed