mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-17 00:40:42 +09:00
Rework features into a Feature class with per field events
Review points from Cooldude: - Feature.register(name[, config]) is required again and returns a feature object. Each feature has its config, its fields, and its overrides, so one registry holds all the data. Only the overrides are stored. On load each feature points at its own stored table again. - The methods are feature:guard(lib), feature:update_config(enabled, values), and feature:is_enabled(). Feature.get(name) looks up a feature, and commands flag the feature object. - update_config raises on_config_updated once per changed value, with the feature name, path, old value, and new value. The gui refresh only reacts to the "enabled" path. - apply only sets values. on_apply is gone. Lookup sets built from lists use Feature.to_set, which is cached by the list itself. A replaced list gets a new set, so the sets are also correct after a load. Protection exposes getters for its protected names and types. Web: settings use small inputs, the same size as the config pages. Fields are shaped like clusterio config field definitions. A field with an inputComponent renders the component registered with the web interface, so the role setting now uses core's role input, and other plugin inputs can be used later. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4bc1773c82
commit
628e4df514
26 files changed
+468
-430
No files matched your search
@@ -3,22 +3,14 @@ Disable new players from having certain items in their inventory, most commonly
|
||||
]]
|
||||
|
||||
local ExpUtil = require("modules/exp_util")
|
||||
local Features = require("modules/exp_scenario/features")
|
||||
local Feature = require("modules/exp_scenario/features")
|
||||
local Roles = require("modules/exp_roles")
|
||||
|
||||
local config = Features.config("nuke_protection", {
|
||||
local feature = Feature.register("nuke_protection", {
|
||||
ignore_admins = true, --- @setting ignore_admins Admins can hold banned items
|
||||
banned_items = { "atomic-bomb" }, --- @setting banned_items Items which are removed from the inventory of players without the bypass permission
|
||||
})
|
||||
|
||||
--- Set of the banned items, rebuilt when the config changes
|
||||
local banned_items = {} --- @type table<string, true>
|
||||
Features.on_apply(config, function()
|
||||
banned_items = {}
|
||||
for _, item_name in ipairs(config.banned_items) do
|
||||
banned_items[item_name] = true
|
||||
end
|
||||
end)
|
||||
local config = feature.config
|
||||
|
||||
--- The inventories which are checked and the events which trigger the check
|
||||
local inventories = {
|
||||
@@ -36,6 +28,7 @@ local function check_items(player, type)
|
||||
if Roles.player_has_permission(player, "exp_scenario.bypass.nuke_protection") then return end
|
||||
if config.ignore_admins and player.admin then return end
|
||||
|
||||
local banned_items = Feature.to_set(config.banned_items)
|
||||
local items = {} --- @type LuaItemStack[]
|
||||
local inventory = assert(player.get_inventory(type))
|
||||
-- Check what items the player has
|
||||
@@ -68,6 +61,6 @@ for event_id, inventory in pairs(inventories) do
|
||||
end
|
||||
end
|
||||
|
||||
return Features.guard(config, {
|
||||
return feature:guard{
|
||||
events = events,
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user