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
@@ -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