Rename bases to templates and add per property inheritance

Review changes for #1142:
- base becomes template everywhere (is_template, template_id,
  --template, --is-template, --templates, InstanceDetails.isTemplate).
- Object fields inherit per property. inherited_fields lists the
  overridden properties for object fields and the template object is
  merged with them.
- Linking a template also inherits fields that hold the default value.
  The server name stays per instance.
- Ports are never inherited.
- InstanceDetails carries templateId.

Web UI: inherited values are locked until unlocked, overridden values
can be inherited again, templates are listed separately, the create
modal can create templates and instances from templates, and the
instance page has "Create template" which can link the source.

Part of #200

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-11-02 11:54:37 +00:00
1 parent 01cf789f5d
commit b5c372f109
21 files changed
+865 -312

No files matched your search

+33 -16
View File
@@ -488,9 +488,9 @@ export interface InstanceConfigFields {
"instance.assigned_host": number | null;
"instance.auto_start": boolean;
"instance.exclude_from_start_all": boolean;
"instance.is_base": boolean;
"instance.base_id": number | null;
"instance.inherited_fields": Record<string, true>;
"instance.is_template": boolean;
"instance.template_id": number | null;
"instance.inherited_fields": Record<string, true | string[]>;
[key: `${string}.load_plugin`]: boolean;
[key: `${string}.version`]: string;
@@ -542,10 +542,13 @@ export class InstanceConfig extends classes.Config<InstanceConfigFields> {
return config;
}
/** Fields that are never inherited from a base instance */
static uninheritableFields = ["instance.name", "instance.is_base", "instance.base_id"];
/** Fields that are never inherited from a template, ports would clash on a shared host */
static uninheritableFields = [
"instance.name", "instance.is_template", "instance.template_id",
"factorio.game_port", "factorio.rcon_port", "factorio.lua_udp_port",
];
/** True if the field can take its value from a base instance */
/** True if the field can take its value from a template */
static isInheritable(name: string) {
const def = this.fieldDefinitions[name as keyof InstanceConfigFields];
return Boolean(def)
@@ -554,9 +557,21 @@ export class InstanceConfig extends classes.Config<InstanceConfigFields> {
&& !this.uninheritableFields.includes(name);
}
/** True if the field currently takes its value from the base instance */
isInherited(name: string) {
return this.get("instance.base_id") !== null && Boolean(this.get("instance.inherited_fields")[name]);
/**
* True if the field, or the given property of an object field, takes its value from the template
*
* @param name - Name of field to check.
* @param prop - Property of an object field to check.
*/
isInherited(name: string, prop?: string) {
if (this.get("instance.template_id") === null) {
return false;
}
const entry = this.get("instance.inherited_fields")[name];
if (entry instanceof Array) {
return prop === undefined || !entry.includes(prop);
}
return Boolean(entry);
}
static fieldDefinitions: classes.ConfigDefs<InstanceConfigFields> = {
@@ -586,24 +601,26 @@ export class InstanceConfig extends classes.Config<InstanceConfigFields> {
type: "boolean",
initialValue: false,
},
"instance.is_base": {
"instance.is_template": {
description:
"Mark this instance as a base other instances can inherit config from. " +
"Bases cannot be assigned to a host or started.",
"Mark this instance as a template other instances can inherit config from. " +
"Templates cannot be assigned to a host or started.",
access: ["controller", "control"],
type: "boolean",
initialValue: false,
},
"instance.base_id": {
title: "Base Instance",
description: "ID of the base instance to inherit config values from",
"instance.template_id": {
title: "Template",
description: "ID of the template to inherit config values from",
access: ["controller", "control"],
inputComponent: "instance_template",
type: "number",
optional: true,
// Checked by the controller
},
"instance.inherited_fields": {
description: "Fields whose value comes from the base instance",
description:
"Fields whose value comes from the template, for object fields the properties set on this instance",
access: ["controller", "control"],
readonly: ["controller"],
type: "object",
+11 -5
View File
@@ -42,7 +42,8 @@ export default class InstanceDetails {
/** Millisecond Unix timestamp this entry was last updated at */
public updatedAtMs = 0,
public excludeFromStartAll = false,
public isBase = false,
public isTemplate = false,
public templateId?: number,
) {}
get isDeleted() {
@@ -62,7 +63,8 @@ export default class InstanceDetails {
"startedAtMs": Type.Optional(Type.Number()),
"updatedAtMs": Type.Optional(Type.Number()),
"excludeFromStartAll": Type.Optional(Type.Boolean()),
"isBase": Type.Optional(Type.Boolean()),
"isTemplate": Type.Optional(Type.Boolean()),
"templateId": Type.Optional(Type.Integer()),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
@@ -76,7 +78,8 @@ export default class InstanceDetails {
json.startedAtMs,
json.updatedAtMs,
json.excludeFromStartAll,
json.isBase,
json.isTemplate,
json.templateId,
);
}
@@ -105,8 +108,11 @@ export default class InstanceDetails {
if (this.excludeFromStartAll !== false) {
json.excludeFromStartAll = this.excludeFromStartAll;
}
if (this.isBase !== false) {
json.isBase = this.isBase;
if (this.isTemplate !== false) {
json.isTemplate = this.isTemplate;
}
if (this.templateId !== undefined) {
json.templateId = this.templateId;
}
return json;
+3 -1
View File
@@ -186,15 +186,17 @@ export class InstanceConfigInheritFieldRequest {
constructor(
public instanceId: number,
public field: string,
public prop?: string,
) { }
static jsonSchema = Type.Object({
"instanceId": Type.Integer(),
"field": Type.String(),
"prop": Type.Optional(Type.String()),
});
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.instanceId, json.field);
return new this(json.instanceId, json.field, json.prop);
}
}