mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-08-13 00:45:11 +09:00
Type the last of the forward declarations
Locals declared ahead of an assignment inside a callback were inferred as nil at every use site. The role event handlers are given a class so the table is not unified with the other module handler tables. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -66,7 +66,7 @@ function Search.on_player_locale_changed(event)
|
|||||||
local ids = player.request_translations(required_translations)
|
local ids = player.request_translations(required_translations)
|
||||||
assert(ids, "Translation ids was nil")
|
assert(ids, "Translation ids was nil")
|
||||||
for i, command_name in ipairs(command_names) do
|
for i, command_name in ipairs(command_names) do
|
||||||
pending[ids[i]] = { locale, command_name }
|
pending[assert(ids[i])] = { locale, command_name }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
-- @config Warnings
|
-- @config Warnings
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
--- @type (LocalisedString[] | fun(player: LuaPlayer, by_player_name: string, number_of_warnings: number))[]
|
||||||
actions = { --- @setting actions what actions are taking at number of warnings
|
actions = { --- @setting actions what actions are taking at number of warnings
|
||||||
-- if a localized string is used then __1__ will by_player_name and __2__ will be the current warning count (auto inserted)
|
-- if a localized string is used then __1__ will by_player_name and __2__ will be the current warning count (auto inserted)
|
||||||
{ "warnings.received", "" },
|
{ "warnings.received", "" },
|
||||||
|
|||||||
@@ -1115,8 +1115,9 @@ local function role_update(event)
|
|||||||
-- Updates the players permission group
|
-- Updates the players permission group
|
||||||
local highest = Roles.get_player_highest_role(player)
|
local highest = Roles.get_player_highest_role(player)
|
||||||
if highest.permission_group then
|
if highest.permission_group then
|
||||||
if highest.permission_group[1] then
|
local permission_group = highest.permission_group --[[@as [boolean, string] ]]
|
||||||
local group = game.permissions.get_group(highest.permission_group[2])
|
if permission_group[1] then
|
||||||
|
local group = game.permissions.get_group(permission_group[2])
|
||||||
if group then
|
if group then
|
||||||
Groups.add_to_permission_group_async(group, player)
|
Groups.add_to_permission_group_async(group, player)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ function Warnings.add_warning(player, by_player_name, reason)
|
|||||||
|
|
||||||
reason = reason or "None given."
|
reason = reason or "None given."
|
||||||
|
|
||||||
local warning_count
|
local warning_count --- @type number
|
||||||
PlayerWarnings:update(player.name, function(_, warnings)
|
PlayerWarnings:update(player.name, function(_, warnings)
|
||||||
local warning = {
|
local warning = {
|
||||||
by_player_name = by_player_name,
|
by_player_name = by_player_name,
|
||||||
|
|||||||
@@ -9,7 +9,10 @@ had, and event_handler expects `events` to be the handlers to register.
|
|||||||
local clusterio_api = require("modules/clusterio/api")
|
local clusterio_api = require("modules/clusterio/api")
|
||||||
local ExpRoles = require("modules/exp_roles/control")
|
local ExpRoles = require("modules/exp_roles/control")
|
||||||
|
|
||||||
return {
|
--- @class ExpRoles.EventHandlers
|
||||||
|
--- @field on_load fun()
|
||||||
|
--- @field events table<defines.events, fun(event: EventData)>
|
||||||
|
local handlers = {
|
||||||
on_load = ExpRoles.on_load,
|
on_load = ExpRoles.on_load,
|
||||||
events = {
|
events = {
|
||||||
[clusterio_api.events.on_server_startup] = ExpRoles.on_server_startup,
|
[clusterio_api.events.on_server_startup] = ExpRoles.on_server_startup,
|
||||||
@@ -17,3 +20,5 @@ return {
|
|||||||
[defines.events.on_player_joined_game] = ExpRoles.on_player_joined_game,
|
[defines.events.on_player_joined_game] = ExpRoles.on_player_joined_game,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return handlers
|
||||||
|
|||||||
@@ -137,7 +137,9 @@ local function on_player_ammo_inventory_changed(event)
|
|||||||
if not player or not player.character then return end
|
if not player or not player.character then return end
|
||||||
|
|
||||||
local character_ammo = assert(player.get_inventory(defines.inventory.character_ammo))
|
local character_ammo = assert(player.get_inventory(defines.inventory.character_ammo))
|
||||||
local item = character_ammo[player.character.selected_gun_index]
|
local gun_index = player.character.selected_gun_index
|
||||||
|
--- @cast gun_index uint
|
||||||
|
local item = character_ammo[gun_index]
|
||||||
if not item or not item.valid or not item.valid_for_read then
|
if not item or not item.valid or not item.valid_for_read then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ Elements.reason_confirm = Gui.define("player_list/reason_confirm")
|
|||||||
local action_name = Elements.container.get_selected_action(player)
|
local action_name = Elements.container.get_selected_action(player)
|
||||||
local button_data = action_name and config.buttons[action_name]
|
local button_data = action_name and config.buttons[action_name]
|
||||||
if button_data and button_data.reason_callback then
|
if button_data and button_data.reason_callback then
|
||||||
local reason = element.parent.entry.text
|
local reason = assert(assert(element.parent).entry).text --[[@as string?]]
|
||||||
if reason == nil or not reason:find("%S") then reason = "no reason given" end
|
if reason == nil or not reason:find("%S") then reason = "no reason given" end
|
||||||
button_data.reason_callback(player, reason)
|
button_data.reason_callback(player, reason)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user