mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 07:33:12 +09:00
InstanceDetails now carries factorio.mod_pack_id as modPackId, so the instance list and pages can show it without fetching each config. The web UI resolves an unset value to the controller default and tags it "Default". The name links to the mod pack page. Closes #852 Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
128 lines
3.5 KiB
TypeScript
128 lines
3.5 KiB
TypeScript
import { Static, Type } from "@sinclair/typebox";
|
|
import { StringEnum } from "./composites.js";
|
|
import { TargetVersion, TargetVersionSchema } from "./version.js";
|
|
|
|
export const InstanceStatus = StringEnum([
|
|
"unknown",
|
|
"unassigned",
|
|
"stopped",
|
|
"starting",
|
|
"running",
|
|
"stopping",
|
|
"creating_save",
|
|
"exporting_data",
|
|
"deleted",
|
|
]);
|
|
|
|
/**
|
|
* Current status of the instance. One of:
|
|
* - `unknown`: Instance is assigned to a host but this host is currently
|
|
* not connected to the contreller.
|
|
* - `unassigned`: Instance is not assigned to a a host and exists only on
|
|
* the controller.
|
|
* - `stopped`: Instance is stopped.
|
|
* - `starting`: Instance is in the process of starting up.
|
|
* - `running`: Instance is running normally.
|
|
* - `stopping`: Instance is in the process of stopping.
|
|
* - `creating_save`: Instance is in the process of creating a save.
|
|
* - `exporting_data`: Instance is in the process of exporting game data.
|
|
* - `deleted`: Instance has been deleted.
|
|
*/
|
|
export type InstanceStatus = Static<typeof InstanceStatus>;
|
|
|
|
export default class InstanceDetails {
|
|
constructor(
|
|
public name: string,
|
|
public id: number,
|
|
public assignedHost: number | undefined,
|
|
public gamePort: number | undefined,
|
|
public status: InstanceStatus,
|
|
public factorioVersion: TargetVersion | undefined,
|
|
public startedAtMs = 0,
|
|
/** Millisecond Unix timestamp this entry was last updated at */
|
|
public updatedAtMs = 0,
|
|
public excludeFromStartAll = false,
|
|
public isTemplate = false,
|
|
public templateId?: number,
|
|
/** Value of factorio.mod_pack_id, undefined means the controller default is used */
|
|
public modPackId?: number,
|
|
) {}
|
|
|
|
get isDeleted() {
|
|
return this.status === "deleted";
|
|
}
|
|
|
|
static jsonSchema = Type.Object({
|
|
"name": Type.String(),
|
|
"id": Type.Integer(),
|
|
"assignedHost": Type.Optional(Type.Integer()),
|
|
"gamePort": Type.Optional(Type.Integer()),
|
|
"status": StringEnum([
|
|
"unknown", "unassigned", "stopped", "starting", "running", "stopping",
|
|
"creating_save", "exporting_data", "deleted",
|
|
]),
|
|
"factorioVersion": Type.Optional(TargetVersionSchema),
|
|
"startedAtMs": Type.Optional(Type.Number()),
|
|
"updatedAtMs": Type.Optional(Type.Number()),
|
|
"excludeFromStartAll": Type.Optional(Type.Boolean()),
|
|
"isTemplate": Type.Optional(Type.Boolean()),
|
|
"templateId": Type.Optional(Type.Integer()),
|
|
"modPackId": Type.Optional(Type.Integer()),
|
|
});
|
|
|
|
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
|
return new this(
|
|
json.name,
|
|
json.id,
|
|
json.assignedHost,
|
|
json.gamePort,
|
|
json.status,
|
|
json.factorioVersion,
|
|
json.startedAtMs,
|
|
json.updatedAtMs,
|
|
json.excludeFromStartAll,
|
|
json.isTemplate,
|
|
json.templateId,
|
|
json.modPackId,
|
|
);
|
|
}
|
|
|
|
toJSON() {
|
|
const json = {
|
|
name: this.name,
|
|
id: this.id,
|
|
status: this.status,
|
|
} as Static<typeof InstanceDetails.jsonSchema>;
|
|
|
|
if (this.assignedHost !== undefined) {
|
|
json.assignedHost = this.assignedHost;
|
|
}
|
|
if (this.gamePort !== undefined) {
|
|
json.gamePort = this.gamePort;
|
|
}
|
|
if (this.factorioVersion !== undefined) {
|
|
json.factorioVersion = this.factorioVersion;
|
|
}
|
|
if (this.startedAtMs !== 0) {
|
|
json.startedAtMs = this.startedAtMs;
|
|
}
|
|
if (this.updatedAtMs !== 0) {
|
|
json.updatedAtMs = this.updatedAtMs;
|
|
}
|
|
if (this.excludeFromStartAll !== false) {
|
|
json.excludeFromStartAll = this.excludeFromStartAll;
|
|
}
|
|
if (this.isTemplate !== false) {
|
|
json.isTemplate = this.isTemplate;
|
|
}
|
|
if (this.templateId !== undefined) {
|
|
json.templateId = this.templateId;
|
|
}
|
|
if (this.modPackId !== undefined) {
|
|
json.modPackId = this.modPackId;
|
|
}
|
|
|
|
return json;
|
|
}
|
|
}
|