mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-08-13 00:45:11 +09:00
Narrow the gui player lookups
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -49,7 +49,7 @@ function Search.prepare(custom_commands)
|
||||
command_objects[name] = {
|
||||
name = name,
|
||||
description = locale_desc,
|
||||
help_text = locale_desc,
|
||||
help_text = locale_desc,
|
||||
usage = locale_desc,
|
||||
aliases = {},
|
||||
}
|
||||
|
||||
@@ -46,8 +46,10 @@ end
|
||||
--- @return LuaPlayer
|
||||
function Gui.get_player(input)
|
||||
if type(input) == "table" and not input.player_index then
|
||||
--- @cast input { element: LuaGuiElement }
|
||||
return assert(game.get_player(input.element.player_index))
|
||||
end
|
||||
--- @cast input LuaGuiElement | { player_index: uint }
|
||||
return assert(game.get_player(input.player_index))
|
||||
end
|
||||
|
||||
@@ -114,7 +116,7 @@ end
|
||||
--- @param player LuaPlayer
|
||||
--- @return LuaGuiElement
|
||||
function Gui.get_top_element(define, player)
|
||||
return assert(player_elements[player.index].top[define.name], "Element is not on the top flow")
|
||||
return assert(assert(player_elements[player.index]).top[define.name], "Element is not on the top flow")
|
||||
end
|
||||
|
||||
--- Register a element define to be drawn to the left flow on join
|
||||
@@ -122,7 +124,7 @@ end
|
||||
--- @param player LuaPlayer
|
||||
--- @return LuaGuiElement
|
||||
function Gui.get_left_element(define, player)
|
||||
return assert(player_elements[player.index].left[define.name], "Element is not on the left flow")
|
||||
return assert(assert(player_elements[player.index]).left[define.name], "Element is not on the left flow")
|
||||
end
|
||||
|
||||
--- Register a element define to be drawn to the relative flow on join
|
||||
@@ -130,7 +132,7 @@ end
|
||||
--- @param player LuaPlayer
|
||||
--- @return LuaGuiElement
|
||||
function Gui.get_relative_element(define, player)
|
||||
return assert(player_elements[player.index].relative[define.name], "Element is not on the relative flow")
|
||||
return assert(assert(player_elements[player.index]).relative[define.name], "Element is not on the relative flow")
|
||||
end
|
||||
|
||||
--- Ensure all the correct elements are visible and exist
|
||||
|
||||
@@ -61,7 +61,7 @@ local GuiData = {
|
||||
--- @field element_data table<uint, table<uint, any>>
|
||||
--- @field player_data table<uint, any>
|
||||
--- @field force_data table<uint, any>
|
||||
--- @field global_data table
|
||||
--- @field global_data table
|
||||
--- @field [DataKey] any
|
||||
-- This class has no prototype methods
|
||||
-- Same as raw but __index ensures the values exist
|
||||
@@ -99,7 +99,7 @@ function GuiData._metatable.__index(self, key)
|
||||
local data = self._raw.player_data
|
||||
return data and data[key.index]
|
||||
elseif object_name == "LuaForce" then
|
||||
--- @cast key LuaForce
|
||||
--- @cast key LuaForce
|
||||
local data = self._raw.force_data
|
||||
return data and data[key.index]
|
||||
else
|
||||
@@ -172,7 +172,7 @@ local function on_object_destroyed(event)
|
||||
for _, scope in pairs(registered_scopes) do
|
||||
local data = scope._raw.element_data
|
||||
local player_elements = data and data[player_index]
|
||||
if player_elements then
|
||||
if data and player_elements then
|
||||
player_elements[element_index] = nil
|
||||
if not next(player_elements) then
|
||||
data[player_index] = nil
|
||||
|
||||
@@ -44,7 +44,7 @@ function FlyingText.create_above_entity(options)
|
||||
local entity = assert(options.target_entity, "A target entity is required")
|
||||
local bounding_box = entity.bounding_box --[[@as ExpUtil_AABB.Box]]
|
||||
local size_y = bounding_box.left_top.y - bounding_box.right_bottom.y
|
||||
local position = entity.position --[[@as MapPosition.struct]]
|
||||
local position = entity.position --[[@as MapPosition.struct]]
|
||||
local offset = options.offset or { x = 0, y = 0 }
|
||||
|
||||
options.position = {
|
||||
@@ -64,9 +64,9 @@ end
|
||||
function FlyingText.create_above_player(options)
|
||||
local player = assert(options.target_player, "A target player is required")
|
||||
local entity = player.character; if not entity then return end
|
||||
local bounding_box = entity.bounding_box --[[@as ExpUtil_AABB.Box]]
|
||||
local bounding_box = entity.bounding_box --[[@as ExpUtil_AABB.Box]]
|
||||
local size_y = bounding_box.left_top.y - bounding_box.right_bottom.y
|
||||
local position = entity.position --[[@as MapPosition.struct]]
|
||||
local position = entity.position --[[@as MapPosition.struct]]
|
||||
local offset = options.offset or { x = 0, y = 0 }
|
||||
|
||||
options.position = {
|
||||
@@ -86,9 +86,9 @@ end
|
||||
function FlyingText.create_as_player(options)
|
||||
local player = assert(options.target_player, "A target player is required")
|
||||
local entity = player.character; if not entity then return end
|
||||
local bounding_box = entity.bounding_box --[[@as ExpUtil_AABB.Box]]
|
||||
local bounding_box = entity.bounding_box --[[@as ExpUtil_AABB.Box]]
|
||||
local size_y = bounding_box.left_top.y - bounding_box.right_bottom.y
|
||||
local position = entity.position --[[@as MapPosition.struct]]
|
||||
local position = entity.position --[[@as MapPosition.struct]]
|
||||
local offset = options.offset or { x = 0, y = 0 }
|
||||
|
||||
options.color = player.chat_color
|
||||
|
||||
Reference in New Issue
Block a user