2020-10-07 06:36:02 +00:00
|
|
|
/* typehints:start */
|
2021-03-14 21:22:14 +00:00
|
|
|
import { GameRoot } from "./root";
|
2020-10-07 06:36:02 +00:00
|
|
|
/* typehints:end */
|
|
|
|
|
|
2021-03-14 21:22:14 +00:00
|
|
|
import { gGameModeRegistry } from "../core/global_registries";
|
|
|
|
|
import { types, BasicSerializableObject } from "../savegame/serialization";
|
2020-10-07 06:36:02 +00:00
|
|
|
|
2021-03-14 21:22:14 +00:00
|
|
|
export class GameMode extends BasicSerializableObject {
|
|
|
|
|
/** @returns {string} */
|
|
|
|
|
static getId() {
|
|
|
|
|
abstract;
|
2021-03-15 19:49:34 +00:00
|
|
|
return "Unknown";
|
2021-03-14 21:22:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static getSchema() {
|
2021-03-15 19:49:34 +00:00
|
|
|
return {};
|
2021-03-14 21:22:14 +00:00
|
|
|
}
|
|
|
|
|
|
2021-03-15 19:49:34 +00:00
|
|
|
/**
|
|
|
|
|
* @param {GameRoot} root
|
|
|
|
|
* @param {string} [id=Regular]
|
|
|
|
|
*/
|
|
|
|
|
static create (root, id = "Regular") {
|
|
|
|
|
// id = "Regular"
|
|
|
|
|
return new (gGameModeRegistry.findById(id))(root);
|
2021-03-14 21:22:14 +00:00
|
|
|
}
|
|
|
|
|
|
2021-03-15 19:49:34 +00:00
|
|
|
/**
|
|
|
|
|
* @param {GameRoot} root
|
|
|
|
|
* @param {string} [id=Regular]
|
|
|
|
|
*/
|
2020-10-07 06:36:02 +00:00
|
|
|
constructor(root) {
|
2021-03-14 21:22:14 +00:00
|
|
|
super();
|
2020-10-07 06:36:02 +00:00
|
|
|
this.root = root;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-15 19:49:34 +00:00
|
|
|
serialize() {
|
|
|
|
|
return {
|
|
|
|
|
$: this.getId(),
|
|
|
|
|
data: super.serialize()
|
|
|
|
|
}
|
2020-10-07 06:36:02 +00:00
|
|
|
}
|
|
|
|
|
|
2021-03-15 19:49:34 +00:00
|
|
|
deserialize({ $, data }) {
|
|
|
|
|
const Mode = gGameModeRegistry.findById($);
|
2020-10-07 06:36:02 +00:00
|
|
|
|
2021-03-15 19:49:34 +00:00
|
|
|
return super.deserialize(data, Mode, gGameModeRegistry.getId(), this.root);
|
2020-10-07 06:36:02 +00:00
|
|
|
}
|
|
|
|
|
|
2021-03-15 19:49:34 +00:00
|
|
|
getId() {
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
return this.constructor.getId();
|
2020-10-07 06:36:02 +00:00
|
|
|
}
|
|
|
|
|
}
|