mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-21 23:33:12 +09:00
Add a web page for configuring scenario features
Features can now be enabled, disabled, and configured from the web UI while the game is running, without editing Lua files. The first five features covered are AFK Kick, Chat Auto Reply, Death Markers, Mine Depletion, and Station Auto Name. Lua side: module/features.lua holds each feature's defaults, keeps the overrides from the controller in storage, and patches them onto the config table in place. Features.guard skips a feature's handlers while it is disabled. The five config files move from exp_legacy into exp_scenario/module/config and their control files now read config at runtime instead of deciding at load which handlers to register. AFK Kick times are now in minutes. Controller side: features.ts lists the editable settings and their defaults. Overrides that differ from the default are stored in exp_scenario/features.json and guarded by the existing exp_scenario.config.view/edit permissions. The instance plugin sends them over rcon on start, on every change, and again after the controller restarts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
46bb15e4a6
commit
88358b23b9
30 files changed
+1226
-89
No files matched your search
@@ -0,0 +1,46 @@
|
||||
--[[-- Test environment for module/features.lua
|
||||
Extends the shared stubs with a fresh copy of the features module and a stub
|
||||
of exp_util storage which lets tests act out on_init and on_load.
|
||||
|
||||
Run as a chunk by test/lua/runner.js, receiving the shared folder. The suite
|
||||
returned here becomes `...` in each test file.
|
||||
]]
|
||||
|
||||
local shared_root = ... --- @type string
|
||||
local source = assert(debug.getinfo(1, "S")).source:gsub("\\", "/")
|
||||
local plugin_root = assert(source:match("^@(.*)/test/module/env%.lua$"))
|
||||
|
||||
local Framework = assert(loadfile(shared_root .. "/framework.lua"))() --- @type Framework
|
||||
|
||||
--- @class ExpScenario.TestEnv : Stubs
|
||||
--- @field Features ExpScenario.Features A fresh copy of the features module
|
||||
--- @field storage table The table registered with storage, as on_init would store it
|
||||
--- @field on_load fun(tbl: table) Act out on_load with the given storage table
|
||||
--- @field load_config fun(name: string): table Load module/config/<name>.lua
|
||||
|
||||
return Framework.suite(function(env)
|
||||
--- @cast env ExpScenario.TestEnv
|
||||
local callback --- @type fun(tbl: table)
|
||||
env.extend_requires{
|
||||
["modules/exp_util/storage"] = {
|
||||
register = function(tbl, fn)
|
||||
env.storage = tbl
|
||||
callback = fn
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
||||
env.Features = assert(loadfile(plugin_root .. "/module/features.lua"))()
|
||||
env.extend_requires{ ["modules/exp_scenario/features"] = env.Features }
|
||||
|
||||
function env.on_load(tbl)
|
||||
env.storage = tbl
|
||||
callback(tbl)
|
||||
end
|
||||
|
||||
function env.load_config(name)
|
||||
return assert(loadfile(plugin_root .. "/module/config/" .. name .. ".lua"))()
|
||||
end
|
||||
|
||||
return env
|
||||
end)
|
||||
@@ -0,0 +1,63 @@
|
||||
local Suite = ... --- @type Suite<ExpScenario.TestEnv>
|
||||
|
||||
Suite.test("register() enables features unless the defaults say otherwise", function(env)
|
||||
Suite.eq(env.Features.register("on", { value = 1 }).enabled, true, "enabled by default")
|
||||
Suite.eq(env.Features.register("off", { enabled = false }).enabled, false, "the defaults can disable it")
|
||||
Suite.throws(function() env.Features.register("on", {}) end, "Feature already registered: on", "names are unique")
|
||||
end)
|
||||
|
||||
Suite.test("receive_update() changes the registered table in place", function(env)
|
||||
local config = env.Features.register("test", { flag = true, count = 5, text = "a" })
|
||||
env.Features.receive_update{ { name = "test", enabled = false, values = { flag = false, count = 7 } } }
|
||||
Suite.eq(config, { enabled = false, flag = false, count = 7, text = "a" }, "given values replace the defaults")
|
||||
|
||||
env.Features.receive_update{ { name = "test", enabled = true, values = { text = "b" } } }
|
||||
Suite.eq(config, { enabled = true, flag = true, count = 5, text = "b" }, "values left out go back to their default")
|
||||
Suite.eq(env.storage, { test = { enabled = true, text = "b" } }, "the overrides are kept in storage")
|
||||
end)
|
||||
|
||||
Suite.test("receive_update() ignores values which can not be overridden", function(env)
|
||||
local function check() return true end
|
||||
local config = env.Features.register("test", { flag = true, check = check, icon = nil })
|
||||
env.Features.receive_update{
|
||||
{ name = "unknown", enabled = false, values = {} },
|
||||
{ name = "test", enabled = true, values = { flag = "yes", check = false, icon = "x", extra = 1 } },
|
||||
}
|
||||
Suite.eq(config, { enabled = true, flag = true, check = check }, "wrong types, functions, and unknown keys are skipped")
|
||||
Suite.eq(env.storage.unknown, nil, "unknown features are not stored")
|
||||
end)
|
||||
|
||||
Suite.test("on_load applies the overrides from storage", function(env)
|
||||
local config = env.Features.register("test", { flag = true })
|
||||
env.on_load{ test = { enabled = false, flag = false } }
|
||||
Suite.eq(config, { enabled = false, flag = false }, "the saved overrides apply")
|
||||
|
||||
env.Features.receive_update{ { name = "test", enabled = true, values = {} } }
|
||||
Suite.eq(env.storage, { test = { enabled = true } }, "later updates go to the loaded storage table")
|
||||
end)
|
||||
|
||||
Suite.test("guard() skips handlers while the feature is disabled", function(env)
|
||||
local config = env.Features.register("test", {})
|
||||
local calls = {}
|
||||
local lib = env.Features.guard(config, {
|
||||
events = { on_event = function(event) calls[#calls + 1] = event end },
|
||||
on_nth_tick = { [60] = function(event) calls[#calls + 1] = event end },
|
||||
on_init = function() end,
|
||||
})
|
||||
|
||||
lib.events.on_event("a")
|
||||
lib.on_nth_tick[60]("b")
|
||||
env.Features.receive_update{ { name = "test", enabled = false, values = {} } }
|
||||
lib.events.on_event("c")
|
||||
lib.on_nth_tick[60]("d")
|
||||
Suite.eq(calls, { "a", "b" }, "only called while enabled")
|
||||
end)
|
||||
|
||||
Suite.test("config files register their feature", function(env)
|
||||
local config = env.load_config("death_markers")
|
||||
env.Features.receive_update{ { name = "death_markers", enabled = true, values = { show_map_markers = false } } }
|
||||
Suite.eq(config.show_map_markers, false, "death_markers can be changed")
|
||||
Suite.eq(config.period_check_map_tags, 60 * 60 * 5, "other values keep their default")
|
||||
end)
|
||||
|
||||
return Suite.run()
|
||||
Reference in new issue
Block a user