mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-12 07:54:52 +09:00
- The instance sends every value of a feature, defaults included, so update_config is one loop which sets each field and compares. The stored table is the last set of values, and _apply is gone. - values_equal compares table sizes before the contents. - Protected entities are registered with register_on_object_destroyed and forgotten in on_object_destroyed, which covers every way an entity can go. The four removal handlers and the validity checks are gone. Entities destroyed while the feature is disabled are swept when it is enabled again. Saves from before the registrations table get it through the Storage on_init callback. - Spawn area applied the water offset twice and the pattern offset never. The pattern tiles now move with the entities above them. - pruneFeatureValues reads a validation result instead of catching an error, and FeaturesPage hands its pending state and unsaved bar to helpers. - Shorter comments throughout. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
56 lines
2.0 KiB
Lua
56 lines
2.0 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 Feature 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): ExpScenario.Feature Load module/config/<name>.lua
|
|
--- @field logged string[] Messages passed to log
|
|
--- @field events table[] Raised events, name and tick filled in
|
|
|
|
return Framework.suite(function(env)
|
|
--- @cast env ExpScenario.TestEnv
|
|
local callback --- @type fun(tbl: table)
|
|
env.logged = {}
|
|
log = function(message) env.logged[#env.logged + 1] = message end
|
|
table_size = function(tbl)
|
|
local size = 0
|
|
for _ in pairs(tbl) do size = size + 1 end
|
|
return size
|
|
end
|
|
env.extend_requires{
|
|
["modules/exp_util/storage"] = {
|
|
register = function(tbl, fn)
|
|
env.storage = tbl
|
|
callback = fn
|
|
end,
|
|
},
|
|
}
|
|
|
|
env.Feature = assert(loadfile(plugin_root .. "/module/features.lua"))()
|
|
env.extend_requires{ ["modules/exp_scenario/features"] = env.Feature }
|
|
|
|
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)
|