mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-08-13 00:45:11 +09:00
Type forward declared handlers and assert element parents
The player list action setter runs during control setup, before any of the callbacks that use it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -335,9 +335,10 @@ Below here is the toolbar settings GUI and its associated functions
|
|||||||
--- @param dst LuaGuiElement
|
--- @param dst LuaGuiElement
|
||||||
local function copy_style(src, dst)
|
local function copy_style(src, dst)
|
||||||
dst.style = src.style.name
|
dst.style = src.style.name
|
||||||
dst.style.height = toolbar_button_small
|
local style = dst.style --[[@as LuaStyle]]
|
||||||
dst.style.width = toolbar_button_small
|
style.height = toolbar_button_small
|
||||||
dst.style.padding = -2
|
style.width = toolbar_button_small
|
||||||
|
style.padding = -2
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Reorder the buttons relative to each other, this will update the datastore
|
--- Reorder the buttons relative to each other, this will update the datastore
|
||||||
@@ -365,7 +366,7 @@ local function move_toolbar_button(player, item, offset)
|
|||||||
local other_element = Gui.get_left_element(other_left_element, player)
|
local other_element = Gui.get_left_element(other_left_element, player)
|
||||||
local left_index = element.get_index_in_parent()
|
local left_index = element.get_index_in_parent()
|
||||||
local other_index = other_element.get_index_in_parent()
|
local other_index = other_element.get_index_in_parent()
|
||||||
element.parent.swap_children(left_index, other_index)
|
assert(element.parent).swap_children(left_index, other_index)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- If we are moving in/out of first/last place we need to update the move buttons
|
-- If we are moving in/out of first/last place we need to update the move buttons
|
||||||
@@ -620,7 +621,7 @@ elements.move_item_up = Gui.define("move_item_up")
|
|||||||
size = toolbar_button_small,
|
size = toolbar_button_small,
|
||||||
})
|
})
|
||||||
:on_click(function(def, player, element)
|
:on_click(function(def, player, element)
|
||||||
local item = assert(element.parent.parent)
|
local item = assert(assert(element.parent).parent)
|
||||||
move_toolbar_button(player, item, -1)
|
move_toolbar_button(player, item, -1)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -635,7 +636,7 @@ elements.move_item_down = Gui.define("move_item_down")
|
|||||||
size = toolbar_button_small,
|
size = toolbar_button_small,
|
||||||
})
|
})
|
||||||
:on_click(function(def, player, element)
|
:on_click(function(def, player, element)
|
||||||
local item = assert(element.parent.parent)
|
local item = assert(assert(element.parent).parent)
|
||||||
move_toolbar_button(player, item, 1)
|
move_toolbar_button(player, item, 1)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ local Colors = require("modules/exp_util/include/color")
|
|||||||
local format_player_name = ExpUtil.format_player_name_locale
|
local format_player_name = ExpUtil.format_player_name_locale
|
||||||
|
|
||||||
--- Accessors injected by the gui so the actions can read the selected player and set the selected action
|
--- Accessors injected by the gui so the actions can read the selected player and set the selected action
|
||||||
local get_selected_player, set_selected_action
|
local get_selected_player --- @type fun(player: LuaPlayer): LuaPlayer
|
||||||
|
local set_selected_action --- @type fun(player: LuaPlayer, action: string?)
|
||||||
local function set_accessors(player_getter, action_setter)
|
local function set_accessors(player_getter, action_setter)
|
||||||
get_selected_player, set_selected_action = player_getter, action_setter
|
get_selected_player, set_selected_action = player_getter, action_setter
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ local warp_icon_button = Gui.define("warp_icon_button")
|
|||||||
:style(Styles.sprite32)
|
:style(Styles.sprite32)
|
||||||
:on_click(function(def, player, element)
|
:on_click(function(def, player, element)
|
||||||
if element.type == "choose-elem-button" then return end
|
if element.type == "choose-elem-button" then return end
|
||||||
local warp_id = element.parent.caption
|
local warp_id = assert(element.parent).caption
|
||||||
Warps.teleport_player(warp_id, player)
|
Warps.teleport_player(warp_id, player)
|
||||||
|
|
||||||
-- Reset the warp cooldown if the player does not have unlimited warps
|
-- Reset the warp cooldown if the player does not have unlimited warps
|
||||||
@@ -226,7 +226,7 @@ local warp_label = Gui.define("warp_label")
|
|||||||
horizontally_stretchable = true,
|
horizontally_stretchable = true,
|
||||||
}
|
}
|
||||||
:on_click(function(def, player, element)
|
:on_click(function(def, player, element)
|
||||||
local warp_id = element.parent.caption
|
local warp_id = assert(element.parent).caption
|
||||||
local warp = Warps.get_warp(warp_id)
|
local warp = Warps.get_warp(warp_id)
|
||||||
player.set_controller{ type = defines.controllers.remote, position = warp.position, surface = warp.surface }
|
player.set_controller{ type = defines.controllers.remote, position = warp.position, surface = warp.surface }
|
||||||
end)
|
end)
|
||||||
@@ -271,9 +271,9 @@ local warp_textfield = Gui.define("warp_textfield")
|
|||||||
right_margin = 2,
|
right_margin = 2,
|
||||||
}
|
}
|
||||||
:on_confirmed(function(def, player, element)
|
:on_confirmed(function(def, player, element)
|
||||||
local warp_id = element.parent.caption
|
local warp_id = assert(element.parent).caption
|
||||||
local warp_name = element.text
|
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 = assert(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
|
if warp_icon.type == nil then warp_icon.type = "item" end
|
||||||
Warps.set_editing(warp_id, player.name)
|
Warps.set_editing(warp_id, player.name)
|
||||||
Warps.update_warp(warp_id, warp_name, warp_icon, player.name)
|
Warps.update_warp(warp_id, warp_name, warp_icon, player.name)
|
||||||
@@ -315,7 +315,7 @@ local cancel_edit_button = Gui.define("cancel_edit_button")
|
|||||||
}
|
}
|
||||||
:style(Styles.sprite22)
|
:style(Styles.sprite22)
|
||||||
:on_click(function(def, player, element)
|
:on_click(function(def, player, element)
|
||||||
local warp_id = element.parent.caption
|
local warp_id = assert(element.parent).caption
|
||||||
-- Check if this is the first edit, if so remove the warp.
|
-- Check if this is the first edit, if so remove the warp.
|
||||||
local warp = Warps.get_warp(warp_id)
|
local warp = Warps.get_warp(warp_id)
|
||||||
if warp.updates == 1 then
|
if warp.updates == 1 then
|
||||||
@@ -337,7 +337,7 @@ local remove_warp_button = Gui.define("remove_warp_button")
|
|||||||
}
|
}
|
||||||
:style(Styles.sprite22)
|
:style(Styles.sprite22)
|
||||||
:on_click(function(def, player, element)
|
:on_click(function(def, player, element)
|
||||||
local warp_id = element.parent.caption
|
local warp_id = assert(element.parent).caption
|
||||||
Warps.remove_warp(warp_id)
|
Warps.remove_warp(warp_id)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -353,7 +353,7 @@ local edit_warp_button = Gui.define("edit_warp_button")
|
|||||||
}
|
}
|
||||||
:style(Styles.sprite22)
|
:style(Styles.sprite22)
|
||||||
:on_click(function(def, player, element)
|
:on_click(function(def, player, element)
|
||||||
local warp_id = element.parent.caption
|
local warp_id = assert(element.parent).caption
|
||||||
Warps.set_editing(warp_id, player.name, true)
|
Warps.set_editing(warp_id, player.name, true)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -433,8 +433,8 @@ local function update_warp_elements(element, warp, warp_player_is_on, on_cooldow
|
|||||||
-- Check if button element is valid
|
-- Check if button element is valid
|
||||||
if not element or not element.valid then return end
|
if not element or not element.valid then return end
|
||||||
|
|
||||||
local label_style = element.parent.parent["name-" .. warp.warp_id][warp_label.name].style
|
local label_style = assert(element.parent).parent["name-" .. warp.warp_id][warp_label.name].style
|
||||||
local warp_status_element = element.parent.parent["name-" .. warp.warp_id][warp_status.name]
|
local warp_status_element = assert(element.parent).parent["name-" .. warp.warp_id][warp_status.name]
|
||||||
|
|
||||||
-- If player is not on a warp
|
-- If player is not on a warp
|
||||||
if not warp_player_is_on then
|
if not warp_player_is_on then
|
||||||
|
|||||||
Reference in New Issue
Block a user