mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-09-21 17:04:00 +00:00
Move the scenario onto exp_roles and remove the legacy role system
Every call site of expcore.roles now uses exp_roles, and the legacy module, its config, and the glue which refreshed guis on role events are deleted. Where a file only renamed the require and the permission strings the change is mechanical; the rest: - Jail is now "give the Jail role" and unjail "take it away". The role has a higher priority than every other so holding it suppresses them, which is what stashing and restoring the roles was for. - The command role authority derives exp_scenario.command.<name> from the command name, and the role parsers use player_outranks rather than comparing indexes with their own root check. - The admin and spectator triggers, and the gui refresh on role changes, live in exp_scenario/control/roles.lua; the system commands trigger stays with the command authority. - The player list warn button is keyed on create_warning, the permission the command behind it already required, and report on create_report. Both were keyed on names no role held, so only root ever saw them. - The warps and tasks configs say exp_roles where they said expcore.roles. - The role tables the readme and player list read are replaced by get_player_names and get_roles. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
eb715cc176
commit
7034f17b5d
@@ -7,25 +7,23 @@
|
||||
-- import the module from the control modules
|
||||
local Jail = require("modules.exp_legacy.modules.control.jail") --- @dep modules.control.jail
|
||||
|
||||
-- This will move 'MrBiter' to the jail role and remove all other roles from them
|
||||
-- This will give 'MrBiter' the jail role, which suppresses all of their other roles
|
||||
-- the player name and reason are only so they can be included in the event for user feedback
|
||||
Jail.jail_player('MrBiter', 'Cooldude2606', 'Likes biters too much')
|
||||
|
||||
-- This will give 'MrBiter' all his roles back and remove him from jail
|
||||
-- This will remove the jail role from 'MrBiter', restoring their other roles
|
||||
-- again as above the player name is only used in the event for user feedback
|
||||
Jail.unjail_player('MrBiter', 'Cooldude2606')
|
||||
]]
|
||||
|
||||
local Roles = require("modules.exp_legacy.expcore.roles")
|
||||
local Roles = require("modules/exp_roles")
|
||||
|
||||
local valid_player = function(p) return type(p) == "userdata" and p or game.get_player(p) end
|
||||
local assign_roles = Roles.assign_player
|
||||
local unassign_roles = Roles.unassign_player
|
||||
local has_role = Roles.player_has_role
|
||||
local get_roles = Roles.get_player_roles
|
||||
|
||||
--- The role which is given to jailed players, it has a higher priority than every other role
|
||||
local jail_role = "Jail"
|
||||
|
||||
local Jail = {
|
||||
old_roles = {},
|
||||
events = {
|
||||
--- When a player is assigned to jail
|
||||
-- @event on_player_jailed
|
||||
@@ -64,10 +62,10 @@ end
|
||||
-- @tparam LuaPlayer player the player to check if they are in jail
|
||||
-- @treturn boolean whether the player is currently in jail
|
||||
function Jail.is_jailed(player)
|
||||
return has_role(valid_player(player), "Jail")
|
||||
return Roles.player_has_role(valid_player(player), jail_role)
|
||||
end
|
||||
|
||||
--- Moves a player to jail and removes all other roles
|
||||
--- Moves a player to jail, which suppresses all of their other roles
|
||||
-- @tparam LuaPlayer player the player who will be jailed
|
||||
-- @tparam string by_player_name the name of the player who is doing the jailing
|
||||
-- @tparam[opt='Non given.'] string reason the reason that the player is being jailed
|
||||
@@ -79,8 +77,7 @@ function Jail.jail_player(player, by_player_name, reason)
|
||||
|
||||
reason = reason or "Non given."
|
||||
|
||||
if has_role(player, "Jail") then return end
|
||||
local roles = get_roles(player)
|
||||
if Roles.player_has_role(player, jail_role) then return end
|
||||
|
||||
player.walking_state = { walking = false, direction = player.walking_state.direction }
|
||||
player.riding_state = { acceleration = defines.riding.acceleration.nothing, direction = player.riding_state.direction }
|
||||
@@ -89,16 +86,14 @@ function Jail.jail_player(player, by_player_name, reason)
|
||||
player.picking_state = false
|
||||
player.repair_state = { repairing = false, position = player.repair_state.position }
|
||||
|
||||
unassign_roles(player, roles, by_player_name, nil, true)
|
||||
assign_roles(player, "Jail", by_player_name, nil, true)
|
||||
assign_roles(player, roles, by_player_name, nil, true)
|
||||
Roles.assign_player(player, jail_role, by_player_name, true)
|
||||
|
||||
event_emit(Jail.events.on_player_jailed, player, by_player_name, reason)
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
--- Moves a player out of jail and restores all roles previously removed
|
||||
--- Moves a player out of jail, which restores all of their other roles
|
||||
-- @tparam LuaPlayer player the player that will be unjailed
|
||||
-- @tparam string by_player_name the name of the player that is doing the unjail
|
||||
-- @treturn boolean whether the player was unjailed successfully
|
||||
@@ -107,9 +102,9 @@ function Jail.unjail_player(player, by_player_name)
|
||||
if not player then return end
|
||||
if not by_player_name then return end
|
||||
|
||||
if not has_role(player, "Jail") then return end
|
||||
if not Roles.player_has_role(player, jail_role) then return end
|
||||
|
||||
unassign_roles(player, "Jail", by_player_name, nil, true)
|
||||
Roles.unassign_player(player, jail_role, by_player_name, true)
|
||||
|
||||
event_emit(Jail.events.on_player_unjailed, player, by_player_name)
|
||||
|
||||
|
||||
@@ -33,11 +33,7 @@ for _, config_key in ipairs{ "always_protected_names", "always_protected_types",
|
||||
end
|
||||
end
|
||||
|
||||
-- Require roles if a permission is assigned in the config
|
||||
local Roles --- @type table<string, any>
|
||||
if config.ignore_permission then
|
||||
Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
|
||||
end
|
||||
local Roles = require("modules/exp_roles")
|
||||
|
||||
----- Storage Variables -----
|
||||
--- Variables stored in the global table
|
||||
@@ -159,7 +155,7 @@ Event.add(defines.events.on_pre_player_mined_item, function(event)
|
||||
-- Check if the player should be ignored
|
||||
if config.ignore_admins and player.admin then return end
|
||||
if entity.last_user == nil or entity.last_user.index == player.index then return end
|
||||
if config.ignore_permission and Roles.player_allowed(player, config.ignore_permission) then return end
|
||||
if config.ignore_permission and Roles.player_has_permission(player, config.ignore_permission) then return end
|
||||
|
||||
-- Check if the entity is protected
|
||||
if EntityProtection.is_entity_protected(entity)
|
||||
|
||||
@@ -8,7 +8,7 @@ local Commands = require("modules/exp_commands")
|
||||
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
|
||||
local CustomMessages = PlayerData.Settings:combine("JoinMessage")
|
||||
CustomMessages:set_metadata{
|
||||
permission = "command/join-message",
|
||||
permission = "exp_scenario.command.set_join_message",
|
||||
}
|
||||
|
||||
--- When a players data loads show their message
|
||||
|
||||
@@ -10,7 +10,7 @@ local config = require("modules.exp_legacy.config.preset_player_quickbar") --- @
|
||||
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
|
||||
local PlayerFilters = PlayerData.Settings:combine("QuickbarFilters")
|
||||
PlayerFilters:set_metadata{
|
||||
permission = "command/save-quickbar",
|
||||
permission = "exp_scenario.command.save_quickbar",
|
||||
stringify = function(value)
|
||||
if not value then return "No filters set" end
|
||||
local count = 0
|
||||
|
||||
@@ -4,17 +4,17 @@
|
||||
]]
|
||||
|
||||
local Commands = require("modules/exp_commands")
|
||||
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
|
||||
local Roles = require("modules/exp_roles")
|
||||
|
||||
--- Stores the tag for a player
|
||||
local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data
|
||||
local PlayerTags = PlayerData.Settings:combine("Tag")
|
||||
local PlayerTagColors = PlayerData.Settings:combine("TagColor")
|
||||
PlayerTags:set_metadata{
|
||||
permission = "command/tag",
|
||||
permission = "exp_scenario.command.tag",
|
||||
}
|
||||
PlayerTagColors:set_metadata{
|
||||
permission = "command/tag-color",
|
||||
permission = "exp_scenario.command.tag_color",
|
||||
}
|
||||
|
||||
local set_tag = function(player, tag, color)
|
||||
@@ -72,7 +72,7 @@ Commands.new("tag-clear", "Clears your tag. Or another player if you are admin."
|
||||
if other_player == player then
|
||||
-- No player given so removes your tag
|
||||
PlayerTags:remove(other_player)
|
||||
elseif Roles.player_allowed(player, "command/clear-tag/always") then
|
||||
elseif Roles.player_has_permission(player, "exp_scenario.command.tag_clear.always") then
|
||||
-- Player given and user is admin so clears that player's tag
|
||||
PlayerTags:remove(other_player)
|
||||
else
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
local Gui = require("modules/exp_gui")
|
||||
local Roles = require("modules.exp_legacy.expcore.roles")
|
||||
local Event = require("modules/exp_legacy/utils/event")
|
||||
|
||||
--- @diagnostic disable: access-invisible
|
||||
Event.add(Roles.events.on_role_assigned, Gui._ensure_consistency)
|
||||
Event.add(Roles.events.on_role_unassigned, Gui._ensure_consistency)
|
||||
@@ -5,7 +5,7 @@
|
||||
]]
|
||||
|
||||
local Gui = require("modules/exp_gui")
|
||||
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
|
||||
local Roles = require("modules/exp_roles")
|
||||
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
||||
local format_number = require("util").format_number --- @dep util
|
||||
local config = require("modules.exp_legacy.config.vlayer") --- @dep config.vlayer
|
||||
@@ -457,7 +457,7 @@ local vlayer_control_set = Gui.define("vlayer_control_set")
|
||||
vlayer_gui_control_see(disp)
|
||||
local b = vlayer_gui_control_build(disp)
|
||||
local r = vlayer_gui_control_remove(disp)
|
||||
local v = Roles.player_allowed(player, "gui/vlayer-edit")
|
||||
local v = Roles.player_has_permission(player, "exp_scenario.gui.vlayer_edit")
|
||||
b.visible = v
|
||||
r.visible = v
|
||||
|
||||
@@ -484,22 +484,21 @@ Gui.toolbar.create_button{
|
||||
sprite = "entity/solar-panel",
|
||||
tooltip = { "vlayer.main-tooltip" },
|
||||
visible = function(player, element)
|
||||
return Roles.player_allowed(player, "gui/vlayer")
|
||||
return Roles.player_has_permission(player, "exp_scenario.gui.vlayer")
|
||||
end
|
||||
}
|
||||
|
||||
--- Update the visibly of the buttons based on a players roles
|
||||
local function role_update_event(event)
|
||||
local player = game.players[event.player_index]
|
||||
local visible = Roles.player_allowed(player, "gui/vlayer-edit")
|
||||
local visible = Roles.player_has_permission(player, "exp_scenario.gui.vlayer_edit")
|
||||
local container = Gui.get_left_element(vlayer_container, player)
|
||||
local disp = container.frame["vlayer_st_2"].disp.table
|
||||
disp[vlayer_gui_control_build.name].visible = visible
|
||||
disp[vlayer_gui_control_remove.name].visible = visible
|
||||
end
|
||||
|
||||
Event.add(Roles.events.on_role_assigned, role_update_event)
|
||||
Event.add(Roles.events.on_role_unassigned, role_update_event)
|
||||
Event.add(Roles.events.on_player_roles_changed, role_update_event)
|
||||
|
||||
Event.on_nth_tick(config.update_tick_gui, function(_)
|
||||
local stats = vlayer.get_statistics()
|
||||
|
||||
@@ -9,7 +9,7 @@ local Gui = require("modules/exp_gui")
|
||||
local Datastore = require("modules.exp_legacy.expcore.datastore") --- @dep expcore.datastore
|
||||
local Storage = require("modules/exp_util/storage")
|
||||
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
||||
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
|
||||
local Roles = require("modules/exp_roles")
|
||||
local Colors = require("modules/exp_util/include/color")
|
||||
local config = require("modules.exp_legacy.config.gui.warps") --- @dep config.gui.warps
|
||||
local Warps = require("modules.exp_legacy.modules.control.warps") --- @dep modules.control.warps
|
||||
@@ -68,8 +68,8 @@ local function check_player_permissions(player, action, warp)
|
||||
return true
|
||||
elseif action_config == "admin" then
|
||||
return player.admin
|
||||
elseif action_config == "expcore.roles" then
|
||||
return Roles.player_allowed(player, config["expcore_roles_" .. action])
|
||||
elseif action_config == "exp_roles" then
|
||||
return Roles.player_has_permission(player, config["exp_roles_" .. action])
|
||||
end
|
||||
|
||||
-- Return false as all other conditions have not been met
|
||||
@@ -708,7 +708,7 @@ Gui.toolbar.create_button{
|
||||
sprite = config.default_icon.type .. "/" .. config.default_icon.name,
|
||||
tooltip = { "warp-list.main-tooltip" },
|
||||
visible = function(player, element)
|
||||
return Roles.player_allowed(player, "gui/warp-list")
|
||||
return Roles.player_has_permission(player, "exp_scenario.gui.warp_list")
|
||||
end
|
||||
}:on_click(function(def, player, element)
|
||||
-- Set gui keep open state for player that clicked the button: true if visible, false if invisible
|
||||
@@ -885,8 +885,7 @@ local function role_update_event(event)
|
||||
add_new_warp_element.visible = allow_add_warp
|
||||
end
|
||||
|
||||
Event.add(Roles.events.on_role_assigned, role_update_event)
|
||||
Event.add(Roles.events.on_role_unassigned, role_update_event)
|
||||
Event.add(Roles.events.on_player_roles_changed, role_update_event)
|
||||
|
||||
--- When a chart tag is removed or edited make sure it is not one that belongs to a warp
|
||||
local function maintain_tag(event)
|
||||
|
||||
Reference in New Issue
Block a user