2020-10-07 06:36:02 +00:00
|
|
|
/* typehints:start */
|
|
|
|
|
import { enumHubGoalRewards } from "./tutorial_goals";
|
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
|
|
|
|
|
|
|
|
/** @typedef {{
|
|
|
|
|
* shape: string,
|
|
|
|
|
* amount: number
|
|
|
|
|
* }} UpgradeRequirement */
|
|
|
|
|
|
|
|
|
|
/** @typedef {{
|
|
|
|
|
* required: Array<UpgradeRequirement>
|
|
|
|
|
* improvement?: number,
|
|
|
|
|
* excludePrevious?: boolean
|
|
|
|
|
* }} TierRequirement */
|
|
|
|
|
|
|
|
|
|
/** @typedef {Array<TierRequirement>} UpgradeTiers */
|
|
|
|
|
|
|
|
|
|
/** @typedef {{
|
|
|
|
|
* shape: string,
|
|
|
|
|
* required: number,
|
|
|
|
|
* reward: enumHubGoalRewards,
|
|
|
|
|
* throughputOnly?: boolean
|
|
|
|
|
* }} LevelDefinition */
|
|
|
|
|
|
2021-03-14 21:22:14 +00:00
|
|
|
export class GameMode extends BasicSerializableObject {
|
|
|
|
|
/** @returns {string} */
|
|
|
|
|
static getId() {
|
|
|
|
|
abstract;
|
|
|
|
|
return "unknown-mode";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static getSchema() {
|
|
|
|
|
return {
|
|
|
|
|
id: types.string
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static create (root) {
|
|
|
|
|
let id;
|
|
|
|
|
|
|
|
|
|
if (!root.savegame.gameMode || !root.savegame.gameMode.id) {
|
|
|
|
|
id = "Regular";
|
|
|
|
|
} else {
|
|
|
|
|
id = root.savegame.gameMode.id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Mode = gGameModeRegistry.findById(id);
|
|
|
|
|
|
|
|
|
|
return new Mode(root);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @param {GameRoot} root */
|
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-14 21:22:14 +00:00
|
|
|
this.id = this.getId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getId() {
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
return this.constructor.getId();
|
2020-10-07 06:36:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Should return all available upgrades
|
|
|
|
|
* @returns {Object<string, UpgradeTiers>}
|
|
|
|
|
*/
|
|
|
|
|
getUpgrades() {
|
|
|
|
|
abstract;
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the blueprint shape key
|
|
|
|
|
* @returns {string}
|
|
|
|
|
*/
|
|
|
|
|
getBlueprintShapeKey() {
|
|
|
|
|
abstract;
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the goals for all levels including their reward
|
|
|
|
|
* @returns {Array<LevelDefinition>}
|
|
|
|
|
*/
|
|
|
|
|
getLevelDefinitions() {
|
|
|
|
|
abstract;
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Should return whether free play is available or if the game stops
|
|
|
|
|
* after the predefined levels
|
|
|
|
|
* @returns {boolean}
|
|
|
|
|
*/
|
|
|
|
|
getIsFreeplayAvailable() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|