mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-08-13 00:45:11 +09:00
Fix arity and return value mismatches
`assert` returns every argument it is given, so `return assert(x, msg)` was leaking the message as a second return value. `get_tile` is documented as taking x and y. The async function class declared `@operator call` with no parameters, which made every async call look over supplied. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -22,13 +22,8 @@
|
|||||||
"globals": [ "__DebugAdapter", "__Profiler" ],
|
"globals": [ "__DebugAdapter", "__Profiler" ],
|
||||||
"disable": [
|
"disable": [
|
||||||
"assign-type-mismatch",
|
"assign-type-mismatch",
|
||||||
"missing-parameter",
|
|
||||||
"param-type-mismatch",
|
"param-type-mismatch",
|
||||||
"preferred-local-alias",
|
"preferred-local-alias",
|
||||||
"redefined-local",
|
|
||||||
"redundant-parameter",
|
|
||||||
"redundant-return-value",
|
|
||||||
"return-type-mismatch",
|
|
||||||
"unnecessary-assert",
|
"unnecessary-assert",
|
||||||
"unnecessary-if",
|
"unnecessary-if",
|
||||||
"unused"
|
"unused"
|
||||||
|
|||||||
@@ -47,10 +47,10 @@ end
|
|||||||
function Gui.get_player(input)
|
function Gui.get_player(input)
|
||||||
if type(input) == "table" and not input.player_index then
|
if type(input) == "table" and not input.player_index then
|
||||||
--- @cast input { element: LuaGuiElement }
|
--- @cast input { element: LuaGuiElement }
|
||||||
return assert(game.get_player(input.element.player_index))
|
return (assert(game.get_player(input.element.player_index)))
|
||||||
end
|
end
|
||||||
--- @cast input LuaGuiElement | { player_index: uint }
|
--- @cast input LuaGuiElement | { player_index: uint }
|
||||||
return assert(game.get_player(input.player_index))
|
return (assert(game.get_player(input.player_index)))
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Toggle the enable state of an element
|
--- Toggle the enable state of an element
|
||||||
@@ -116,7 +116,7 @@ end
|
|||||||
--- @param player LuaPlayer
|
--- @param player LuaPlayer
|
||||||
--- @return LuaGuiElement
|
--- @return LuaGuiElement
|
||||||
function Gui.get_top_element(define, player)
|
function Gui.get_top_element(define, player)
|
||||||
return assert(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
|
end
|
||||||
|
|
||||||
--- Register a element define to be drawn to the left flow on join
|
--- Register a element define to be drawn to the left flow on join
|
||||||
@@ -124,7 +124,7 @@ end
|
|||||||
--- @param player LuaPlayer
|
--- @param player LuaPlayer
|
||||||
--- @return LuaGuiElement
|
--- @return LuaGuiElement
|
||||||
function Gui.get_left_element(define, player)
|
function Gui.get_left_element(define, player)
|
||||||
return assert(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
|
end
|
||||||
|
|
||||||
--- Register a element define to be drawn to the relative flow on join
|
--- Register a element define to be drawn to the relative flow on join
|
||||||
@@ -132,7 +132,7 @@ end
|
|||||||
--- @param player LuaPlayer
|
--- @param player LuaPlayer
|
||||||
--- @return LuaGuiElement
|
--- @return LuaGuiElement
|
||||||
function Gui.get_relative_element(define, player)
|
function Gui.get_relative_element(define, player)
|
||||||
return assert(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
|
end
|
||||||
|
|
||||||
--- Ensure all the correct elements are visible and exist
|
--- Ensure all the correct elements are visible and exist
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ Elements.bar = Gui.define("bar")
|
|||||||
|
|
||||||
--- A label which is centered
|
--- A label which is centered
|
||||||
--- @class Gui.elements.centered_label: ExpElement
|
--- @class Gui.elements.centered_label: ExpElement
|
||||||
--- @overload fun(parent: LuaGuiElement, width: number, caption: LocalisedString, tooltip: LocalisedString?): LuaGuiElement
|
--- @overload fun(parent: LuaGuiElement, width: number, caption: LocalisedString?, tooltip: LocalisedString?): LuaGuiElement
|
||||||
Elements.centered_label = Gui.define("centered_label")
|
Elements.centered_label = Gui.define("centered_label")
|
||||||
:draw{
|
:draw{
|
||||||
type = "label",
|
type = "label",
|
||||||
@@ -319,7 +319,7 @@ Elements.screen_frame = Gui.define("screen_frame")
|
|||||||
--- @param screen_frame LuaGuiElement
|
--- @param screen_frame LuaGuiElement
|
||||||
--- @return LuaGuiElement
|
--- @return LuaGuiElement
|
||||||
function Elements.screen_frame.get_button_flow(screen_frame)
|
function Elements.screen_frame.get_button_flow(screen_frame)
|
||||||
return assert(Elements.screen_frame.data[screen_frame.parent], "Screen frame has no button flow")
|
return (assert(Elements.screen_frame.data[screen_frame.parent], "Screen frame has no button flow"))
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get the root element of a screen frame
|
--- Get the root element of a screen frame
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ end
|
|||||||
--- @param name string
|
--- @param name string
|
||||||
--- @return ExpElement
|
--- @return ExpElement
|
||||||
function ExpElement.get(name)
|
function ExpElement.get(name)
|
||||||
return assert(ExpElement._elements[name], "ExpElement is not defined: " .. tostring(name))
|
return (assert(ExpElement._elements[name], "ExpElement is not defined: " .. tostring(name)))
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Create a new instance of this element definition
|
--- Create a new instance of this element definition
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ local afk_time_units = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
--- @type table<string, LocalisedString | fun(player: LuaPlayer, is_command: boolean): LocalisedString>
|
||||||
messages = { --- @setting messages will trigger when ever the word is said
|
messages = { --- @setting messages will trigger when ever the word is said
|
||||||
["discord"] = { "info.discord" },
|
["discord"] = { "info.discord" },
|
||||||
["expgaming"] = { "info.website" },
|
["expgaming"] = { "info.website" },
|
||||||
@@ -66,6 +67,7 @@ return {
|
|||||||
command_admin_only = false, --- @setting command_admin_only when true will only allow chat commands for admins
|
command_admin_only = false, --- @setting command_admin_only when true will only allow chat commands for admins
|
||||||
command_permission = "command/chat-commands", --- @setting command_permission the permission used to allow command prefixes
|
command_permission = "command/chat-commands", --- @setting command_permission the permission used to allow command prefixes
|
||||||
command_prefix = "!", --- @setting command_prefix prefix used for commands below and to print to all players (if enabled above)
|
command_prefix = "!", --- @setting command_prefix prefix used for commands below and to print to all players (if enabled above)
|
||||||
|
--- @type table<string, LocalisedString | fun(player: LuaPlayer, is_command: boolean): LocalisedString>
|
||||||
commands = { --- @setting commands will trigger only when command prefix is given
|
commands = { --- @setting commands will trigger only when command prefix is given
|
||||||
["dev"] = { "exp_chat-auto-reply.reply-dev" },
|
["dev"] = { "exp_chat-auto-reply.reply-dev" },
|
||||||
["magic"] = { "exp_chat-auto-reply.reply-magic" },
|
["magic"] = { "exp_chat-auto-reply.reply-magic" },
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ local servers = External.get_servers()
|
|||||||
]]
|
]]
|
||||||
function External.get_servers()
|
function External.get_servers()
|
||||||
assert(ext, "No external data was found, use External.valid() to ensure external data exists.")
|
assert(ext, "No external data was found, use External.valid() to ensure external data exists.")
|
||||||
return assert(ext.servers, "No server list was found, please ensure that the external service is running")
|
return (assert(ext.servers, "No server list was found, please ensure that the external service is running"))
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[-- Gets a table of all the servers filtered by name, key is the server id, value is the server details
|
--[[-- Gets a table of all the servers filtered by name, key is the server id, value is the server details
|
||||||
@@ -85,7 +85,7 @@ function External.get_current_server()
|
|||||||
assert(ext, "No external data was found, use External.valid() to ensure external data exists.")
|
assert(ext, "No external data was found, use External.valid() to ensure external data exists.")
|
||||||
local servers = assert(ext.servers, "No server list was found, please ensure that the external service is running")
|
local servers = assert(ext.servers, "No server list was found, please ensure that the external service is running")
|
||||||
local server_id = assert(ext.current, "No current id was found, please ensure that the external service is running")
|
local server_id = assert(ext.current, "No current id was found, please ensure that the external service is running")
|
||||||
return assert(servers[server_id], "No details found for server with id: " .. tostring(server_id))
|
return (assert(servers[server_id], "No details found for server with id: " .. tostring(server_id)))
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[-- Gets the details of the given server
|
--[[-- Gets the details of the given server
|
||||||
@@ -99,7 +99,7 @@ local server = External.get_server_details('eu-01')
|
|||||||
function External.get_server_details(server_id)
|
function External.get_server_details(server_id)
|
||||||
assert(ext, "No external data was found, use External.valid() to ensure external data exists.")
|
assert(ext, "No external data was found, use External.valid() to ensure external data exists.")
|
||||||
local servers = assert(ext.servers, "No server list was found, please ensure that the external service is running")
|
local servers = assert(ext.servers, "No server list was found, please ensure that the external service is running")
|
||||||
return assert(servers[server_id], "No details found for server with id: " .. tostring(server_id))
|
return (assert(servers[server_id], "No details found for server with id: " .. tostring(server_id)))
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[-- Gets the status of the given server
|
--[[-- Gets the status of the given server
|
||||||
|
|||||||
@@ -376,7 +376,7 @@ function Roles.get_player_highest_role(player)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return assert(highest, "Player has no roles")
|
return (assert(highest, "Player has no roles"))
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Assignment.
|
--- Assignment.
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ end
|
|||||||
--- @param surface LuaSurface
|
--- @param surface LuaSurface
|
||||||
--- @param position MapPosition.struct
|
--- @param position MapPosition.struct
|
||||||
local function degrade_tile(surface, position)
|
local function degrade_tile(surface, position)
|
||||||
local tile = surface.get_tile(position)
|
local tile = surface.get_tile(position.x, position.y)
|
||||||
local tile_name = tile.name
|
local tile_name = tile.name
|
||||||
local degrade_tile_name = config.degrade_order[tile_name]
|
local degrade_tile_name = config.degrade_order[tile_name]
|
||||||
if not degrade_tile_name then return end
|
if not degrade_tile_name then return end
|
||||||
@@ -61,7 +61,7 @@ end
|
|||||||
--- @param position MapPosition.struct
|
--- @param position MapPosition.struct
|
||||||
--- @return number?
|
--- @return number?
|
||||||
local function get_tile_strength(surface, position)
|
local function get_tile_strength(surface, position)
|
||||||
local tile = surface.get_tile(position)
|
local tile = surface.get_tile(position.x, position.y)
|
||||||
local tile_name = tile.name
|
local tile_name = tile.name
|
||||||
local strength = config.strengths[tile_name]
|
local strength = config.strengths[tile_name]
|
||||||
if not strength then return end
|
if not strength then return end
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ local function clear_spawn_area(surface, offset)
|
|||||||
local get_tile = surface.get_tile
|
local get_tile = surface.get_tile
|
||||||
|
|
||||||
-- Make sure a non water tile is used for filling
|
-- Make sure a non water tile is used for filling
|
||||||
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_tile = starting_tile.collides_with("player") and "landfill" or starting_tile.name
|
||||||
local fill_radius = config.spawn_area.landfill_radius
|
local fill_radius = config.spawn_area.landfill_radius
|
||||||
local fill_radius_sqr = fill_radius ^ 2
|
local fill_radius_sqr = fill_radius ^ 2
|
||||||
@@ -186,7 +186,7 @@ local function clear_spawn_area(surface, offset)
|
|||||||
if dst < tile_radius_sqr then
|
if dst < tile_radius_sqr then
|
||||||
-- If it is inside the decon radius always set the tile
|
-- If it is inside the decon radius always set the tile
|
||||||
tiles_to_make[#tiles_to_make + 1] = { name = decon_tile, position = pos }
|
tiles_to_make[#tiles_to_make + 1] = { name = decon_tile, position = pos }
|
||||||
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
|
-- 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 }
|
tiles_to_make[#tiles_to_make + 1] = { name = fill_tile, position = pos }
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ Async.status = {}
|
|||||||
|
|
||||||
--- @class Async.AsyncFunction
|
--- @class Async.AsyncFunction
|
||||||
--- @field id string The id of this async function
|
--- @field id string The id of this async function
|
||||||
--- @operator call: Async.AsyncReturn<any>
|
--- @overload fun(...: any): Async.AsyncReturn<any>
|
||||||
Async._function_prototype = {}
|
Async._function_prototype = {}
|
||||||
|
|
||||||
Async._function_metatable = {
|
Async._function_metatable = {
|
||||||
|
|||||||
Reference in New Issue
Block a user