mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-25 15:43:12 +09:00
Cover guis, commands, and intervals in the features framework
Review feedback from Cooldude on the first version.
Features.register is renamed to Features.config, and guard also takes a
feature name so a feature without settings needs no config call.
Autofill uses this. Small configs now live at the top of the file that
uses them: death markers, mine depletion, station auto name, and
lawnmower. AFK kick and chat auto reply keep separate files because
they contain functions.
Periods no longer need a restart. A lib can list intervals, which map a
config key to a handler that runs every config[key] seconds. They are
checked once a second with a stateless tick check. AFK kick and death
markers use this and expose their periods on the page.
Guis: receive_update raises on_feature_changed, and control/features.lua
refreshes every player's gui when it fires. Autofill's toolbar button
checks Features.is_enabled, and hiding the button also hides its left
element. Quick actions refresh on the event too.
Commands: add_flags{ feature = ... } ties a command to a feature, and a
new authority denies it while the feature is disabled. The custom help
and quick actions already leave out denied commands. Lawnmower uses this
and is now added as a lib, so its destroy_decoratives handlers are
actually registered.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
88358b23b9
commit
69e9f172a3
21 files changed
+304
-116
No files matched your search
@@ -3,7 +3,20 @@ import path from "node:path";
|
||||
import t from "tap";
|
||||
import { features, validateFeatureValues } from "../dist/node/features.js";
|
||||
|
||||
/** Read a literal default from a module/config file, only covers single line booleans, numbers, and strings. */
|
||||
/** Every lua file in the module, by path relative to it. */
|
||||
function luaFiles(dir, prefix = "") {
|
||||
return fs.readdirSync(dir, { withFileTypes: true }).flatMap(entry => {
|
||||
const relative = path.posix.join(prefix, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
return luaFiles(path.join(dir, entry.name), relative);
|
||||
}
|
||||
return entry.name.endsWith(".lua") ? [[relative, fs.readFileSync(path.join(dir, entry.name), "utf8")]] : [];
|
||||
});
|
||||
}
|
||||
|
||||
const moduleFiles = luaFiles(path.join(import.meta.dirname, "..", "module"));
|
||||
|
||||
/** Read a literal default from a Features.config call, only covers single line booleans, numbers, and strings. */
|
||||
function luaDefault(source, key) {
|
||||
const match = new RegExp(`^\\s*${key} = (true|false|-?[\\d.]+|"[^"]*"),`, "m").exec(source);
|
||||
return match ? JSON.parse(match[1]) : undefined;
|
||||
@@ -12,9 +25,11 @@ function luaDefault(source, key) {
|
||||
t.test("features", t2 => {
|
||||
for (const feature of features) {
|
||||
t2.test(feature.name, t3 => {
|
||||
const file = path.join(import.meta.dirname, "..", "module", "config", `${feature.name}.lua`);
|
||||
const source = fs.readFileSync(file, "utf8");
|
||||
t3.match(source, `Features.register("${feature.name}"`, "the config file registers the feature");
|
||||
const declarations = moduleFiles.filter(([, source]) => (
|
||||
source.includes(`Features.config("${feature.name}"`) || source.includes(`Features.guard("${feature.name}"`)
|
||||
));
|
||||
t3.equal(declarations.length, 1, "one lua file declares the feature");
|
||||
const source = declarations[0]?.[1] ?? "";
|
||||
for (const field of feature.fields) {
|
||||
t3.equal(luaDefault(source, field.name), field.default, `${field.name} default matches the lua side`);
|
||||
}
|
||||
@@ -32,8 +47,8 @@ t.test("validateFeatureValues()", t2 => {
|
||||
);
|
||||
t2.throws(() => validateFeatureValues("unknown", {}), { message: "Unknown feature unknown" });
|
||||
t2.throws(
|
||||
() => validateFeatureValues("death_markers", { period_check_map_tags: 60 }),
|
||||
{ message: "Feature death_markers has no setting period_check_map_tags" },
|
||||
() => validateFeatureValues("death_markers", { map_icon: "x" }),
|
||||
{ message: "Feature death_markers has no setting map_icon" },
|
||||
);
|
||||
t2.throws(
|
||||
() => validateFeatureValues("death_markers", { show_map_markers: "no" }),
|
||||
|
||||
Reference in new issue
Block a user