mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-21 07:33:12 +09:00
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>
262 lines
6.6 KiB
TypeScript
262 lines
6.6 KiB
TypeScript
/**
|
|
* The scenario features which can be configured from the web interface.
|
|
*
|
|
* Defaults must match the Features.config call in the lua module,
|
|
* test/features.test.js checks this. Only list settings which the lua side
|
|
* reads at runtime.
|
|
*/
|
|
|
|
export type FeatureValue = boolean | number | string;
|
|
|
|
export type FeatureField = {
|
|
name: string,
|
|
title: string,
|
|
description: string,
|
|
} & (
|
|
| { type: "boolean", default: boolean }
|
|
| { type: "number", default: number, min?: number, unit?: string }
|
|
| { type: "string", default: string }
|
|
);
|
|
|
|
export type Feature = {
|
|
name: string,
|
|
title: string,
|
|
description: string,
|
|
fields: FeatureField[],
|
|
};
|
|
|
|
export const features: Feature[] = [
|
|
{
|
|
name: "afk_kick",
|
|
title: "AFK Kick",
|
|
description: "Kick everyone when nobody online is active",
|
|
fields: [
|
|
{
|
|
name: "admin_as_active",
|
|
title: "Admins count as active",
|
|
description: "Admins are active regardless of how long they have been afk",
|
|
type: "boolean",
|
|
default: true,
|
|
},
|
|
{
|
|
name: "trust_as_active",
|
|
title: "Trusted players count as active",
|
|
description: "Players with enough playtime are active regardless of how long they have been afk",
|
|
type: "boolean",
|
|
default: true,
|
|
},
|
|
{
|
|
name: "afk_minutes",
|
|
title: "AFK after",
|
|
description: "Time without input before a player counts as afk",
|
|
type: "number",
|
|
default: 10,
|
|
min: 1,
|
|
unit: "minutes",
|
|
},
|
|
{
|
|
name: "kick_minutes",
|
|
title: "Kick after",
|
|
description: "Time without any active player before everyone is kicked",
|
|
type: "number",
|
|
default: 30,
|
|
min: 1,
|
|
unit: "minutes",
|
|
},
|
|
{
|
|
name: "trust_minutes",
|
|
title: "Trusted after",
|
|
description: "Playtime needed before a player counts as trusted",
|
|
type: "number",
|
|
default: 600,
|
|
min: 0,
|
|
unit: "minutes",
|
|
},
|
|
{
|
|
name: "update_seconds",
|
|
title: "Check every",
|
|
description: "How often to check for active players",
|
|
type: "number",
|
|
default: 1800,
|
|
min: 1,
|
|
unit: "seconds",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: "autofill",
|
|
title: "Autofill",
|
|
description: "Fill ammo and fuel into entities when they are built, configured by each player from the toolbar",
|
|
fields: [],
|
|
},
|
|
{
|
|
name: "chat_auto_reply",
|
|
title: "Chat Auto Reply",
|
|
description: "Reply to key words in chat and run chat commands",
|
|
fields: [
|
|
{
|
|
name: "command_prefix",
|
|
title: "Command prefix",
|
|
description: "Prefix for chat commands, and for key words to reply to everyone",
|
|
type: "string",
|
|
default: "!",
|
|
},
|
|
{
|
|
name: "command_admin_only",
|
|
title: "Commands for admins only",
|
|
description: "Only admins can use chat commands",
|
|
type: "boolean",
|
|
default: false,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: "death_markers",
|
|
title: "Death Markers",
|
|
description: "What happens when players die",
|
|
fields: [
|
|
{
|
|
name: "collect_corpses",
|
|
title: "Collect corpses",
|
|
description: "Put the items of expired corpses in chests",
|
|
type: "boolean",
|
|
default: true,
|
|
},
|
|
{
|
|
name: "show_map_markers",
|
|
title: "Show map markers",
|
|
description: "Add a map marker where a player died",
|
|
type: "boolean",
|
|
default: true,
|
|
},
|
|
{
|
|
name: "clean_map_markers",
|
|
title: "Remove map markers",
|
|
description: "Remove the map marker once the corpse is gone",
|
|
type: "boolean",
|
|
default: false,
|
|
},
|
|
{
|
|
name: "include_time_of_death",
|
|
title: "Include time of death",
|
|
description: "Add the time of death to the map marker",
|
|
type: "boolean",
|
|
default: true,
|
|
},
|
|
{
|
|
name: "show_light_at_corpse",
|
|
title: "Light at corpse",
|
|
description: "Draw a light in the player's colour at their corpse",
|
|
type: "boolean",
|
|
default: true,
|
|
},
|
|
{
|
|
name: "show_line_to_corpse",
|
|
title: "Line to corpse",
|
|
description: "Draw a line from a respawned player to their corpse",
|
|
type: "boolean",
|
|
default: true,
|
|
},
|
|
{
|
|
name: "check_map_tags_seconds",
|
|
title: "Check map markers every",
|
|
description: "How often to replace map markers which were removed",
|
|
type: "number",
|
|
default: 300,
|
|
min: 1,
|
|
unit: "seconds",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: "lawnmower",
|
|
title: "Lawnmower",
|
|
description: "The /lawnmower command which clears corpses and nuclear ground",
|
|
fields: [
|
|
{
|
|
name: "destroy_decoratives",
|
|
title: "Clear decoratives when building",
|
|
description: "Remove decoratives under entities when they are built",
|
|
type: "boolean",
|
|
default: false,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: "mine_depletion",
|
|
title: "Mine Depletion",
|
|
description: "Deconstruct mining drills when their resources run out",
|
|
fields: [
|
|
{
|
|
name: "chest",
|
|
title: "Remove output chests",
|
|
description: "Also deconstruct the chest a drill outputs into",
|
|
type: "boolean",
|
|
default: true,
|
|
},
|
|
{
|
|
name: "beacon",
|
|
title: "Remove beacons",
|
|
description: "Also deconstruct beacons which no longer affect anything",
|
|
type: "boolean",
|
|
default: true,
|
|
},
|
|
{
|
|
name: "fluid",
|
|
title: "Replace with pipes",
|
|
description: "Place pipe ghosts where a drill carried fluid",
|
|
type: "boolean",
|
|
default: true,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: "station_auto_name",
|
|
title: "Station Auto Name",
|
|
description: "Name train stops when they are built",
|
|
fields: [
|
|
{
|
|
name: "station_name",
|
|
title: "Station name",
|
|
description: "Placeholders: __icon__ __item_name__ __backer_name__ __direction__ __x__ __y__",
|
|
type: "string",
|
|
default: "[L] __icon__",
|
|
},
|
|
],
|
|
},
|
|
];
|
|
|
|
/**
|
|
* Check the values for a feature against its fields.
|
|
*
|
|
* @returns the values which differ from their default
|
|
* @throws Error if the feature is unknown, or a value is unknown or the wrong type
|
|
*/
|
|
export function validateFeatureValues(name: string, values: Record<string, FeatureValue>) {
|
|
const feature = features.find(f => f.name === name);
|
|
if (!feature) {
|
|
throw new Error(`Unknown feature ${name}`);
|
|
}
|
|
|
|
const result: Record<string, FeatureValue> = {};
|
|
for (const [key, value] of Object.entries(values)) {
|
|
const field = feature.fields.find(f => f.name === key);
|
|
if (!field) {
|
|
throw new Error(`Feature ${name} has no setting ${key}`);
|
|
}
|
|
if (typeof value !== field.type) {
|
|
throw new Error(`Setting ${key} of ${name} must be a ${field.type}`);
|
|
}
|
|
if (field.type === "number" && !Number.isFinite(value)) {
|
|
throw new Error(`Setting ${key} of ${name} must be a finite number`);
|
|
}
|
|
if (field.type === "number" && field.min !== undefined && (value as number) < field.min) {
|
|
throw new Error(`Setting ${key} of ${name} must be at least ${field.min}`);
|
|
}
|
|
if (value !== field.default) {
|
|
result[key] = value;
|
|
}
|
|
}
|
|
return result;
|
|
}
|