mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 23:30:41 +09:00
Hide unknown mod pack settings and allow removing them (#1179)
Settings stored in a mod pack that no setting prototype in the export data defines are now listed in a collapsed "Unknown settings" panel under each scope instead of under an "Unknown Fields" heading. Each one has a remove link, and a revert link once removed, matching what `clusterioctl mod-pack edit --remove-setting` already allows. They are never removed automatically. Without export data nothing is called unknown and stored settings are listed as before, without a mod heading. Fixes #773 Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d250394580
commit
5d1e98dafd
3 files changed
+212
-77
No files matched your search
@@ -0,0 +1,63 @@
|
||||
import type * as lib from "@clusterio/lib";
|
||||
|
||||
export type ModSettingScope = "startup" | "runtime-global" | "runtime-per-user";
|
||||
|
||||
export type ModSettingField = {
|
||||
name: string;
|
||||
type: string;
|
||||
mod?: string;
|
||||
order?: string;
|
||||
allowed_values?: unknown;
|
||||
};
|
||||
|
||||
const settingTypes = ["bool-setting", "int-setting", "double-setting", "string-setting", "color-setting"];
|
||||
const strcmp = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" }).compare;
|
||||
|
||||
function typeFromValue(value: lib.ModSetting["value"]) {
|
||||
if (typeof value === "boolean") {
|
||||
return "bool-setting";
|
||||
} else if (typeof value === "number") {
|
||||
return "double-setting";
|
||||
} else if (typeof value === "string") {
|
||||
return "string-setting";
|
||||
} else if (typeof value === "object" && "r" in value) {
|
||||
return "color-setting";
|
||||
}
|
||||
throw Error(`Unhandled setting type ${typeof value}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Split the settings of a scope into ones defined by the exported prototypes and stored ones
|
||||
* no prototype defines. Without export data there is nothing to compare to, so none are unknown.
|
||||
*/
|
||||
export function modSettingFields(
|
||||
prototypes: lib.ExportSettings | undefined,
|
||||
scope: ModSettingScope,
|
||||
stored: Map<string, lib.ModSetting>,
|
||||
) {
|
||||
const fromStored = (name: string): ModSettingField => ({ name, type: typeFromValue(stored.get(name)!.value) });
|
||||
if (!prototypes) {
|
||||
return { known: [...stored.keys()].map(fromStored), unknown: [] };
|
||||
}
|
||||
|
||||
const known: ModSettingField[] = Object.entries(prototypes)
|
||||
.filter(([type]) => settingTypes.includes(type))
|
||||
.flatMap(([_, settings]) => Object.values(settings))
|
||||
.filter(p => p.setting_type === scope)
|
||||
.map(p => ({
|
||||
name: p.name,
|
||||
type: p.type,
|
||||
mod: p.mod as string,
|
||||
order: p.order,
|
||||
allowed_values: p.allowed_values,
|
||||
}))
|
||||
.sort((a, b) => strcmp(a.mod, b.mod) || strcmp(a.order || "", b.order || "") || strcmp(a.name, b.name))
|
||||
;
|
||||
const knownNames = new Set(known.map(field => field.name));
|
||||
const unknown = [...stored.keys()]
|
||||
.filter(name => !knownNames.has(name))
|
||||
.sort(strcmp)
|
||||
.map(fromStored)
|
||||
;
|
||||
return { known, unknown };
|
||||
}
|
||||
Reference in new issue
Block a user