mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-08-13 00:45:11 +09:00
Type the legacy role registry
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -48,7 +48,7 @@ local function format_as_pages(commands, page_size)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local aliases = #command.aliases > 0 and { "exp-commands_help.aliases", table.concat(command.aliases, ", ") } or ""
|
local aliases = #command.aliases > 0 and { "exp-commands_help.aliases", table.concat(command.aliases, ", ") } or ""
|
||||||
pages[current_page][page_length] = { "exp-commands_help.format", command.name, description, aliases }
|
assert(pages[current_page])[page_length] = { "exp-commands_help.format", command.name, description, aliases }
|
||||||
end
|
end
|
||||||
|
|
||||||
return pages, total
|
return pages, total
|
||||||
@@ -71,7 +71,7 @@ Commands.new("commands", { "exp-commands_help.description" })
|
|||||||
page = as_number
|
page = as_number
|
||||||
end
|
end
|
||||||
|
|
||||||
keyword = keyword:lower()
|
keyword = assert(keyword):lower()
|
||||||
local pages, found
|
local pages, found
|
||||||
if cache and cache.keyword == keyword then
|
if cache and cache.keyword == keyword then
|
||||||
-- Cached value found, no search is needed
|
-- Cached value found, no search is needed
|
||||||
|
|||||||
@@ -117,6 +117,7 @@ local Groups = require("modules.exp_legacy.expcore.permission_groups")
|
|||||||
local Colours = ExpUtil.color
|
local Colours = ExpUtil.color
|
||||||
local write_json = ExpUtil.write_json
|
local write_json = ExpUtil.write_json
|
||||||
|
|
||||||
|
|
||||||
--- @class Roles.Role
|
--- @class Roles.Role
|
||||||
--- @field name string
|
--- @field name string
|
||||||
--- @field short_hand string
|
--- @field short_hand string
|
||||||
@@ -131,12 +132,13 @@ local write_json = ExpUtil.write_json
|
|||||||
--- @field parent string?
|
--- @field parent string?
|
||||||
--- @field block_auto_assign boolean?
|
--- @field block_auto_assign boolean?
|
||||||
--- @field auto_assign_condition function?
|
--- @field auto_assign_condition function?
|
||||||
|
--- @field set_allow_all fun(self: Roles.Role, state: boolean?): Roles.Role Defined on Roles._prototype
|
||||||
|
|
||||||
local Roles = {
|
local Roles = {
|
||||||
_prototype = {},
|
_prototype = {},
|
||||||
config = {
|
config = {
|
||||||
order = {}, -- Contains the order of the roles, lower index is better
|
order = {}, --- @type string[] Contains the order of the roles, lower index is better
|
||||||
roles = {}, -- Contains the raw info for the roles, indexed by role name
|
roles = {}, --- @type table<string, Roles.Role> Contains the raw info for the roles, indexed by role name
|
||||||
flags = {}, -- Contains functions that run when a flag is added/removed from a player
|
flags = {}, -- Contains functions that run when a flag is added/removed from a player
|
||||||
internal = {}, -- Contains all internally accessed roles, such as root, default
|
internal = {}, -- Contains all internally accessed roles, such as root, default
|
||||||
players = {}, -- Contains the roles that players have
|
players = {}, -- Contains the roles that players have
|
||||||
@@ -214,7 +216,7 @@ game.player.print(Roles.debug())
|
|||||||
function Roles.debug()
|
function Roles.debug()
|
||||||
local output = ""
|
local output = ""
|
||||||
for index, role_name in ipairs(Roles.config.order) do
|
for index, role_name in ipairs(Roles.config.order) do
|
||||||
local role = Roles.config.roles[role_name]
|
local role = assert(Roles.config.roles[role_name])
|
||||||
local color = (role.custom_color or Colours.white) --[[@as Color.struct]]
|
local color = (role.custom_color or Colours.white) --[[@as Color.struct]]
|
||||||
local color_str = string.format("[color=%d, %d, %d]", color.r, color.g, color.b)
|
local color_str = string.format("[color=%d, %d, %d]", color.r, color.g, color.b)
|
||||||
output = output .. string.format("\n%s %s) %s[/color]", color_str, index, serpent.line(role))
|
output = output .. string.format("\n%s %s) %s[/color]", color_str, index, serpent.line(role))
|
||||||
@@ -302,6 +304,7 @@ local role = Roles.get_role_by_name(2)
|
|||||||
]]
|
]]
|
||||||
function Roles.get_role_by_order(index)
|
function Roles.get_role_by_order(index)
|
||||||
local name = Roles.config.order[index]
|
local name = Roles.config.order[index]
|
||||||
|
if not name then return end
|
||||||
return Roles.config.roles[name]
|
return Roles.config.roles[name]
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -412,7 +415,7 @@ function Roles.assign_player(player, roles, by_player_name, skip_checks, silent)
|
|||||||
|
|
||||||
-- If the player has a role that needs to defer the role changes, save the roles that need to be assigned later into a table
|
-- If the player has a role that needs to defer the role changes, save the roles that need to be assigned later into a table
|
||||||
if valid_player and Roles.player_has_flag(valid_player, "defer_role_changes") then
|
if valid_player and Roles.player_has_flag(valid_player, "defer_role_changes") then
|
||||||
local assign_later = Roles.config.deferred_roles[valid_player.name] or {}
|
local assign_later = Roles.config.deferred_roles[assert(valid_player).name] or {}
|
||||||
for _, role in ipairs(role_objects) do
|
for _, role in ipairs(role_objects) do
|
||||||
local role_change = assign_later[role.name]
|
local role_change = assign_later[role.name]
|
||||||
if role_change then
|
if role_change then
|
||||||
@@ -428,7 +431,7 @@ function Roles.assign_player(player, roles, by_player_name, skip_checks, silent)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Roles.config.deferred_roles[valid_player.name] = assign_later
|
Roles.config.deferred_roles[assert(valid_player).name] = assign_later
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -475,7 +478,7 @@ function Roles.unassign_player(player, roles, by_player_name, skip_checks, silen
|
|||||||
-- If the player has a role that needs to defer the role changes, save the roles that need to be unassigned later into a table
|
-- If the player has a role that needs to defer the role changes, save the roles that need to be unassigned later into a table
|
||||||
local defer_changes = Roles.player_has_flag(player, "defer_role_changes")
|
local defer_changes = Roles.player_has_flag(player, "defer_role_changes")
|
||||||
if defer_changes then
|
if defer_changes then
|
||||||
local assign_later = Roles.config.deferred_roles[valid_player.name] or {}
|
local assign_later = Roles.config.deferred_roles[assert(valid_player).name] or {}
|
||||||
for _, role in ipairs(role_objects) do
|
for _, role in ipairs(role_objects) do
|
||||||
local role_change = assign_later[role.name]
|
local role_change = assign_later[role.name]
|
||||||
if role_change then
|
if role_change then
|
||||||
@@ -491,7 +494,7 @@ function Roles.unassign_player(player, roles, by_player_name, skip_checks, silen
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Roles.config.deferred_roles[valid_player.name] = assign_later
|
Roles.config.deferred_roles[assert(valid_player).name] = assign_later
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Remove the player from roles
|
-- Remove the player from roles
|
||||||
@@ -671,7 +674,7 @@ function Roles.define_role_order(order)
|
|||||||
|
|
||||||
-- Re-links roles to they parents as this is called at the end of the config
|
-- Re-links roles to they parents as this is called at the end of the config
|
||||||
for index, role_name in pairs(Roles.config.order) do
|
for index, role_name in pairs(Roles.config.order) do
|
||||||
local role = Roles.config.roles[role_name]
|
local role = assert(Roles.config.roles[role_name])
|
||||||
if not role then
|
if not role then
|
||||||
error("Role with name " .. role_name .. " has not beed defined, either define it or remove it from the order list.", 2)
|
error("Role with name " .. role_name .. " has not beed defined, either define it or remove it from the order list.", 2)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -551,7 +551,8 @@ function ExpUtil.move_items_to_surface(options)
|
|||||||
options.item = item
|
options.item = item
|
||||||
entity = ExpUtil.get_storage_for_stack(options)
|
entity = ExpUtil.get_storage_for_stack(options)
|
||||||
entity.insert(options.item)
|
entity.insert(options.item)
|
||||||
assert(options.item).clear()
|
local item_stack = options.item --[[@as LuaItemStack]]
|
||||||
|
item_stack.clear()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return entity
|
return entity
|
||||||
|
|||||||
Reference in New Issue
Block a user