Files
factorio-expcluster/exp_scenario/test/module/env.lua
T
bbassieandClaude Opus 5.5 88358b23b9 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>
2026-09-28 17:56:14 +00:00

47 lines
1.6 KiB
Lua

--[[-- 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)