Refactor config to JSON data class pattern

Refactor the Config and ConfigGroup classes to match the JSON data class
pattern with toJSON, toRemote and fromJSON methods replacing the load,
init, and serialize methods.  Since fromJSON requires extra information
the messages structures passes around the plain JSON representation of
the configs instead of serialising instances of the config classes
automatically.
This commit is contained in:
Hornwitser committed 2024-01-06 19:53:32 +01:00
1 parent 27af142a87
commit 001db4befe
24 files changed
+269 -334

No files matched your search

+4
View File
@@ -149,6 +149,7 @@ ControllerGroup.finalize();
* @extends classes.Config
*/
export class ControllerConfig extends classes.Config {
declare static fromJSON: (json: classes.SerializedConfig, location: classes.ConfigLocation) => ControllerConfig;
get(name: "controller.name"): string;
get(name: "controller.mods_directory"): string;
get(name: "controller.database_directory"): string;
@@ -255,6 +256,7 @@ HostGroup.finalize();
* @extends classes.Config
*/
export class HostConfig extends classes.Config {
declare static fromJSON: (json: classes.SerializedConfig, location: classes.ConfigLocation) => HostConfig;
get(name: "host.name"): string;
get(name: "host.id"): number;
get(name: "host.factorio_directory"): string;
@@ -433,6 +435,8 @@ FactorioGroup.finalize();
* @extends classes.Config
*/
export class InstanceConfig extends classes.Config {
declare static fromJSON: (json: classes.SerializedConfig, location: classes.ConfigLocation) => InstanceConfig;
get(name: "instance.name"): string;
get(name: "instance.id"): number;
get(name: "instance.assigned_host"): number | null;