1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00

typescript in root

This commit is contained in:
akupiec 2021-01-17 13:02:56 +01:00
parent abb7ac782d
commit c2c800a4f5
65 changed files with 291 additions and 341 deletions

View File

@ -9,7 +9,7 @@ const CircularDependencyPlugin = require("circular-dependency-plugin");
module.exports = ({ watch = false, standalone = false }) => {
return {
mode: "development",
devtool: "cheap-source-map",
devtool: "source-map",
entry: {
"bundle.js": [path.resolve(__dirname, "../src/js/main.js")],
},
@ -107,6 +107,11 @@ module.exports = ({ watch = false, standalone = false }) => {
type: "json", // Required by Webpack v4
use: "yaml-loader",
},
{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
output: {

View File

@ -172,6 +172,11 @@ module.exports = ({
type: "javascript/auto",
},
{ test: /\.(png|jpe?g|svg)$/, loader: "ignore-loader" },
{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.js$/,
enforce: "pre",

View File

@ -98,6 +98,7 @@
"sass-unused": "^0.3.0",
"strip-json-comments": "^3.0.1",
"trim": "^0.0.1",
"ts-loader": "^8.0.14",
"yarn": "^1.22.4"
}
}

View File

@ -1,4 +1,4 @@
import { GameRoot } from "../game/root";
import { GameRoot } from "../game/root.ts";
import { clearBufferBacklog, freeCanvas, getBufferStats, makeOffscreenBuffer } from "./buffer_utils";
import { createLogger } from "./logging";
import { round1Digit } from "./utils";

View File

@ -1,6 +1,6 @@
import { globalConfig } from "../core/config";
import { createLogger } from "../core/logging";
import { GameRoot } from "./root";
import { GameRoot } from "./root.ts";
// How important it is that a savegame is created
/**

View File

@ -8,7 +8,7 @@ import { BasicSerializableObject, types } from "../savegame/serialization";
import { BaseItem } from "./base_item";
import { Entity } from "./entity";
import { typeItemSingleton } from "./item_resolver";
import { GameRoot } from "./root";
import { GameRoot } from "./root.ts";
const logger = createLogger("belt_path");

View File

@ -3,7 +3,7 @@ import { DrawParameters } from "../core/draw_parameters";
import { findNiceIntegerValue } from "../core/utils";
import { Vector } from "../core/vector";
import { Entity } from "./entity";
import { GameRoot } from "./root";
import { GameRoot } from "./root.ts";
export class Blueprint {
/**

View File

@ -4,7 +4,7 @@ import { enumLogicGateType, LogicGateComponent } from "../components/logic_gate"
import { enumPinSlotType, WiredPinsComponent } from "../components/wired_pins";
import { Entity } from "../entity";
import { MetaBuilding } from "../meta_building";
import { GameRoot } from "../root";
import { GameRoot } from "../root.ts";
import { enumHubGoalRewards } from "../tutorial_goals";
const overlayMatrix = generateMatrixRotations([1, 1, 0, 1, 1, 1, 0, 1, 0]);

View File

@ -4,7 +4,7 @@ import { ItemEjectorComponent } from "../components/item_ejector";
import { enumItemProcessorTypes, ItemProcessorComponent } from "../components/item_processor";
import { Entity } from "../entity";
import { MetaBuilding, defaultBuildingVariant } from "../meta_building";
import { GameRoot } from "../root";
import { GameRoot } from "../root.ts";
import { enumHubGoalRewards } from "../tutorial_goals";
import { T } from "../../translations";
import { formatItemsPerSecond, generateMatrixRotations } from "../../core/utils";

View File

@ -6,7 +6,7 @@ import { T } from "../../translations";
import { BeltComponent } from "../components/belt";
import { Entity } from "../entity";
import { MetaBuilding } from "../meta_building";
import { GameRoot } from "../root";
import { GameRoot } from "../root.ts";
import { THEME } from "../theme";
export const arrayBeltVariantToRotation = [enumDirection.top, enumDirection.left, enumDirection.right];

View File

@ -3,7 +3,7 @@ import { enumLogicGateType, LogicGateComponent } from "../components/logic_gate"
import { enumPinSlotType, WiredPinsComponent } from "../components/wired_pins";
import { Entity } from "../entity";
import { MetaBuilding } from "../meta_building";
import { GameRoot } from "../root";
import { GameRoot } from "../root.ts";
import { enumHubGoalRewards } from "../tutorial_goals";
export class MetaComparatorBuilding extends MetaBuilding {

View File

@ -2,7 +2,7 @@ import { enumDirection, Vector } from "../../core/vector";
import { enumPinSlotType, WiredPinsComponent } from "../components/wired_pins";
import { Entity } from "../entity";
import { MetaBuilding } from "../meta_building";
import { GameRoot } from "../root";
import { GameRoot } from "../root.ts";
import { ConstantSignalComponent } from "../components/constant_signal";
import { generateMatrixRotations } from "../../core/utils";
import { enumHubGoalRewards } from "../tutorial_goals";

View File

@ -6,7 +6,7 @@ import { ItemEjectorComponent } from "../components/item_ejector";
import { enumItemProcessorTypes, ItemProcessorComponent } from "../components/item_processor";
import { Entity } from "../entity";
import { defaultBuildingVariant, MetaBuilding } from "../meta_building";
import { GameRoot } from "../root";
import { GameRoot } from "../root.ts";
import { enumHubGoalRewards } from "../tutorial_goals";
/** @enum {string} */

View File

@ -2,7 +2,7 @@ import { enumDirection, Vector } from "../../core/vector";
import { enumPinSlotType, WiredPinsComponent } from "../components/wired_pins";
import { Entity } from "../entity";
import { MetaBuilding } from "../meta_building";
import { GameRoot } from "../root";
import { GameRoot } from "../root.ts";
import { DisplayComponent } from "../components/display";
import { enumHubGoalRewards } from "../tutorial_goals";

View File

@ -7,7 +7,7 @@ import { ItemEjectorComponent } from "../components/item_ejector";
import { enumPinSlotType, WiredPinsComponent } from "../components/wired_pins";
import { Entity } from "../entity";
import { MetaBuilding } from "../meta_building";
import { GameRoot } from "../root";
import { GameRoot } from "../root.ts";
import { enumHubGoalRewards } from "../tutorial_goals";
export class MetaFilterBuilding extends MetaBuilding {

View File

@ -2,7 +2,7 @@ import { enumDirection, Vector } from "../../core/vector";
import { enumPinSlotType, WiredPinsComponent } from "../components/wired_pins";
import { Entity } from "../entity";
import { MetaBuilding } from "../meta_building";
import { GameRoot } from "../root";
import { GameRoot } from "../root.ts";
import { LeverComponent } from "../components/lever";
import { enumHubGoalRewards } from "../tutorial_goals";

View File

@ -2,7 +2,7 @@ import { enumDirection, Vector } from "../../core/vector";
import { enumPinSlotType, WiredPinsComponent } from "../components/wired_pins";
import { Entity } from "../entity";
import { MetaBuilding, defaultBuildingVariant } from "../meta_building";
import { GameRoot } from "../root";
import { GameRoot } from "../root.ts";
import { enumLogicGateType, LogicGateComponent } from "../components/logic_gate";
import { generateMatrixRotations } from "../../core/utils";
import { enumHubGoalRewards } from "../tutorial_goals";

View File

@ -3,7 +3,7 @@ import { ItemEjectorComponent } from "../components/item_ejector";
import { MinerComponent } from "../components/miner";
import { Entity } from "../entity";
import { MetaBuilding, defaultBuildingVariant } from "../meta_building";
import { GameRoot } from "../root";
import { GameRoot } from "../root.ts";
import { enumHubGoalRewards } from "../tutorial_goals";
import { T } from "../../translations";
import { formatItemsPerSecond, generateMatrixRotations } from "../../core/utils";

View File

@ -6,7 +6,7 @@ import { ItemEjectorComponent } from "../components/item_ejector";
import { enumItemProcessorTypes, ItemProcessorComponent } from "../components/item_processor";
import { Entity } from "../entity";
import { MetaBuilding } from "../meta_building";
import { GameRoot } from "../root";
import { GameRoot } from "../root.ts";
import { enumHubGoalRewards } from "../tutorial_goals";
export class MetaMixerBuilding extends MetaBuilding {

View File

@ -10,7 +10,7 @@ import {
} from "../components/item_processor";
import { Entity } from "../entity";
import { defaultBuildingVariant, MetaBuilding } from "../meta_building";
import { GameRoot } from "../root";
import { GameRoot } from "../root.ts";
import { enumHubGoalRewards } from "../tutorial_goals";
import { WiredPinsComponent, enumPinSlotType } from "../components/wired_pins";

View File

@ -5,7 +5,7 @@ import { enumItemProcessorTypes, ItemProcessorComponent } from "../components/it
import { enumPinSlotType, WiredPinsComponent } from "../components/wired_pins";
import { Entity } from "../entity";
import { MetaBuilding } from "../meta_building";
import { GameRoot } from "../root";
import { GameRoot } from "../root.ts";
import { BeltUnderlaysComponent } from "../components/belt_underlays";
import { BeltReaderComponent } from "../components/belt_reader";
import { enumHubGoalRewards } from "../tutorial_goals";

View File

@ -6,7 +6,7 @@ import { ItemEjectorComponent } from "../components/item_ejector";
import { enumItemProcessorTypes, ItemProcessorComponent } from "../components/item_processor";
import { Entity } from "../entity";
import { defaultBuildingVariant, MetaBuilding } from "../meta_building";
import { GameRoot } from "../root";
import { GameRoot } from "../root.ts";
import { enumHubGoalRewards } from "../tutorial_goals";
/** @enum {string} */

View File

@ -6,7 +6,7 @@ import { ItemEjectorComponent } from "../components/item_ejector";
import { enumItemProcessorTypes, ItemProcessorComponent } from "../components/item_processor";
import { Entity } from "../entity";
import { MetaBuilding } from "../meta_building";
import { GameRoot } from "../root";
import { GameRoot } from "../root.ts";
import { enumHubGoalRewards } from "../tutorial_goals";
export class MetaStackerBuilding extends MetaBuilding {

View File

@ -7,7 +7,7 @@ import { StorageComponent } from "../components/storage";
import { enumPinSlotType, WiredPinsComponent } from "../components/wired_pins";
import { Entity } from "../entity";
import { MetaBuilding } from "../meta_building";
import { GameRoot } from "../root";
import { GameRoot } from "../root.ts";
import { enumHubGoalRewards } from "../tutorial_goals";
const storageSize = 5000;

View File

@ -4,7 +4,7 @@ import { enumLogicGateType, LogicGateComponent } from "../components/logic_gate"
import { enumPinSlotType, WiredPinsComponent } from "../components/wired_pins";
import { Entity } from "../entity";
import { defaultBuildingVariant, MetaBuilding } from "../meta_building";
import { GameRoot } from "../root";
import { GameRoot } from "../root.ts";
import { enumHubGoalRewards } from "../tutorial_goals";
/** @enum {string} */

View File

@ -4,7 +4,7 @@ import { ItemAcceptorComponent } from "../components/item_acceptor";
import { enumItemProcessorTypes, ItemProcessorComponent } from "../components/item_processor";
import { Entity } from "../entity";
import { MetaBuilding } from "../meta_building";
import { GameRoot } from "../root";
import { GameRoot } from "../root.ts";
import { enumHubGoalRewards } from "../tutorial_goals";
const overlayMatrix = generateMatrixRotations([1, 1, 0, 1, 1, 1, 0, 1, 1]);

View File

@ -5,7 +5,7 @@ import { ItemEjectorComponent } from "../components/item_ejector";
import { enumUndergroundBeltMode, UndergroundBeltComponent } from "../components/underground_belt";
import { Entity } from "../entity";
import { MetaBuilding, defaultBuildingVariant } from "../meta_building";
import { GameRoot } from "../root";
import { GameRoot } from "../root.ts";
import { globalConfig } from "../../core/config";
import { enumHubGoalRewards } from "../tutorial_goals";
import { formatItemsPerSecond, generateMatrixRotations } from "../../core/utils";

View File

@ -3,7 +3,7 @@ import { LogicGateComponent, enumLogicGateType } from "../components/logic_gate"
import { WiredPinsComponent, enumPinSlotType } from "../components/wired_pins";
import { Entity } from "../entity";
import { defaultBuildingVariant, MetaBuilding } from "../meta_building";
import { GameRoot } from "../root";
import { GameRoot } from "../root.ts";
import { enumHubGoalRewards } from "../tutorial_goals";
import { MetaCutterBuilding } from "./cutter";
import { MetaPainterBuilding } from "./painter";

View File

@ -5,7 +5,7 @@ import { SOUNDS } from "../../platform/sound";
import { enumWireType, enumWireVariant, WireComponent } from "../components/wire";
import { Entity } from "../entity";
import { defaultBuildingVariant, MetaBuilding } from "../meta_building";
import { GameRoot } from "../root";
import { GameRoot } from "../root.ts";
import { enumHubGoalRewards } from "../tutorial_goals";
export const arrayWireRotationVariantToType = [

View File

@ -3,7 +3,7 @@ import { Vector } from "../../core/vector";
import { WireTunnelComponent } from "../components/wire_tunnel";
import { Entity } from "../entity";
import { MetaBuilding } from "../meta_building";
import { GameRoot } from "../root";
import { GameRoot } from "../root.ts";
import { enumHubGoalRewards } from "../tutorial_goals";
const wireTunnelOverlayMatrix = generateMatrixRotations([0, 1, 0, 1, 1, 1, 0, 1, 0]);

View File

@ -7,7 +7,7 @@ import { clamp } from "../core/utils";
import { mixVector, Vector } from "../core/vector";
import { BasicSerializableObject, types } from "../savegame/serialization";
import { KEYMAPPINGS } from "./key_action_mapper";
import { GameRoot } from "./root";
import { GameRoot } from "./root.ts";
const logger = createLogger("camera");

View File

@ -33,7 +33,7 @@ import { MapView } from "./map_view";
import { defaultBuildingVariant } from "./meta_building";
import { RegularGameMode } from "./modes/regular";
import { ProductionAnalytics } from "./production_analytics";
import { GameRoot } from "./root";
import { GameRoot } from "./root.ts";
import { ShapeDefinitionManager } from "./shape_definition_manager";
import { SoundProxy } from "./sound_proxy";
import { GameTime } from "./time/game_time";

View File

@ -1,4 +1,4 @@
import { GameRoot } from "./root";
import { GameRoot } from "./root.ts";
import { createLogger } from "../core/logging";
import { globalConfig } from "../core/config";

View File

@ -3,7 +3,7 @@ import { DrawParameters } from "../core/draw_parameters";
import { Component } from "./component";
/* typehints:end */
import { GameRoot } from "./root";
import { GameRoot } from "./root.ts";
import { globalConfig } from "../core/config";
import { enumDirectionToVector, enumDirectionToAngle } from "../core/vector";
import { BasicSerializableObject, types } from "../savegame/serialization";

View File

@ -1,6 +1,6 @@
import { arrayDeleteValue, newEmptyMap, fastArrayDeleteValue } from "../core/utils";
import { Component } from "./component";
import { GameRoot } from "./root";
import { GameRoot } from "./root.ts";
import { Entity } from "./entity";
import { BasicSerializableObject, types } from "../savegame/serialization";
import { createLogger } from "../core/logging";

View File

@ -2,7 +2,7 @@
import { enumHubGoalRewards } from "./tutorial_goals";
/* typehints:end */
import { GameRoot } from "./root";
import { GameRoot } from "./root.ts";
/** @typedef {{
* shape: string,

View File

@ -1,5 +1,5 @@
/* typehints:start */
import { GameRoot } from "./root";
import { GameRoot } from "./root.ts";
import { DrawParameters } from "../core/draw_parameters";
/* typehints:end */

View File

@ -1,5 +1,5 @@
/* typehints:start */
import { GameRoot } from "./root";
import { GameRoot } from "./root.ts";
/* typehints:end */
import { createLogger } from "../core/logging";

View File

@ -3,7 +3,7 @@ import { Component } from "./component";
import { Entity } from "./entity";
/* typehints:end */
import { GameRoot } from "./root";
import { GameRoot } from "./root.ts";
import { GameSystem } from "./game_system";
import { arrayDelete, arrayDeleteValue } from "../core/utils";
import { globalConfig } from "../core/config";

View File

@ -5,7 +5,7 @@ import { BasicSerializableObject, types } from "../savegame/serialization";
import { enumColors } from "./colors";
import { enumItemProcessorTypes } from "./components/item_processor";
import { enumAnalyticsDataSource } from "./production_analytics";
import { GameRoot } from "./root";
import { GameRoot } from "./root.ts";
import { enumSubShape, ShapeDefinition } from "./shape_definition";
import { enumHubGoalRewards } from "./tutorial_goals";

View File

@ -1,5 +1,5 @@
/* typehints:start */
import { GameRoot } from "../root";
import { GameRoot } from "../root.ts";
import { DrawParameters } from "../../core/draw_parameters";
/* typehints:end */

View File

@ -1,5 +1,5 @@
import { TrackedState } from "../../core/tracked_state";
import { GameRoot } from "../root";
import { GameRoot } from "../root.ts";
// Automatically attaches and detaches elements from the dom
// Also supports detaching elements after a given time, useful if there is a

View File

@ -1,5 +1,5 @@
/* typehints:start */
import { GameRoot } from "../root";
import { GameRoot } from "../root.ts";
/* typehints:end */
/* dev:start */

View File

@ -3,7 +3,7 @@ import { STOP_PROPAGATION } from "../../../core/signal";
import { makeDiv, safeModulo } from "../../../core/utils";
import { KEYMAPPINGS } from "../../key_action_mapper";
import { MetaBuilding } from "../../meta_building";
import { GameRoot } from "../../root";
import { GameRoot } from "../../root.ts";
import { BaseHUDPart } from "../base_hud_part";
import { DynamicDomAttach } from "../dynamic_dom_attach";

View File

@ -18,7 +18,7 @@ import { THEME } from "../../theme";
import { DynamicDomAttach } from "../dynamic_dom_attach";
import { HUDBuildingPlacerLogic } from "./building_placer_logic";
import { makeOffscreenBuffer } from "../../../core/buffer_utils";
import { layers } from "../../root";
import { layers } from "../../root.ts";
import { getCodeFromBuildingData } from "../../building_codes";
export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {

View File

@ -1,6 +1,6 @@
import { BaseHUDPart } from "../base_hud_part";
import { makeDiv } from "../../../core/utils";
import { GameRoot } from "../../root";
import { GameRoot } from "../../root.ts";
import { MinerComponent } from "../../components/miner";
import { DynamicDomAttach } from "../dynamic_dom_attach";
import { TrackedState } from "../../../core/tracked_state";

View File

@ -3,7 +3,7 @@ import { globalConfig } from "../../../core/config";
import { clamp, formatBigNumber, round2Digits } from "../../../core/utils";
import { T } from "../../../translations";
import { enumAnalyticsDataSource } from "../../production_analytics";
import { GameRoot } from "../../root";
import { GameRoot } from "../../root.ts";
import { ShapeDefinition } from "../../shape_definition";
/** @enum {string} */

View File

@ -1,4 +1,4 @@
import { GameRoot } from "../root";
import { GameRoot } from "../root.ts";
import { globalConfig } from "../../core/config";
import { Vector, mixVector } from "../../core/vector";
import { lerp } from "../../core/utils";

View File

@ -1,5 +1,5 @@
/* typehints:start */
import { GameRoot } from "./root";
import { GameRoot } from "./root.ts";
import { InputReceiver } from "../core/input_receiver";
import { Application } from "../application";
/* typehints:end */

View File

@ -8,7 +8,7 @@ import { enumWireVariant } from "./components/wire";
import { Entity } from "./entity";
import { CHUNK_OVERLAY_RES } from "./map_chunk_view";
import { MetaBuilding } from "./meta_building";
import { GameRoot } from "./root";
import { GameRoot } from "./root.ts";
import { WireNetwork } from "./systems/wire";
const logger = createLogger("ingame/logic");

View File

@ -4,7 +4,7 @@ import { BasicSerializableObject, types } from "../savegame/serialization";
import { BaseItem } from "./base_item";
import { Entity } from "./entity";
import { MapChunkView } from "./map_chunk_view";
import { GameRoot } from "./root";
import { GameRoot } from "./root.ts";
export class BaseMap extends BasicSerializableObject {
static getId() {

View File

@ -7,7 +7,7 @@ import { BaseItem } from "./base_item";
import { enumColors } from "./colors";
import { Entity } from "./entity";
import { COLOR_ITEM_SINGLETONS } from "./items/color_item";
import { GameRoot } from "./root";
import { GameRoot } from "./root.ts";
import { enumSubShape } from "./shape_definition";
import { Rectangle } from "../core/rectangle";

View File

@ -3,7 +3,7 @@ import { DrawParameters } from "../core/draw_parameters";
import { getBuildingDataFromCode } from "./building_codes";
import { Entity } from "./entity";
import { MapChunk } from "./map_chunk";
import { GameRoot } from "./root";
import { GameRoot } from "./root.ts";
import { THEME } from "./theme";
import { drawSpriteClipped } from "../core/draw_utils";

View File

@ -4,7 +4,7 @@ import { Vector } from "../core/vector";
import { SOUNDS } from "../platform/sound";
import { StaticMapEntityComponent } from "./components/static_map_entity";
import { Entity } from "./entity";
import { GameRoot } from "./root";
import { GameRoot } from "./root.ts";
import { getCodeFromBuildingData } from "./building_codes";
export const defaultBuildingVariant = "default";

View File

@ -1,4 +1,4 @@
import { GameRoot } from "./root";
import { GameRoot } from "./root.ts";
import { ShapeDefinition } from "./shape_definition";
import { globalConfig } from "../core/config";
import { BaseItem } from "./base_item";

View File

@ -1,225 +1,205 @@
/* eslint-disable no-unused-vars */
import { Signal } from "../core/signal";
import { RandomNumberGenerator } from "../core/rng";
import { createLogger } from "../core/logging";
// Type hints
/* typehints:start */
import { GameTime } from "./time/game_time";
import { EntityManager } from "./entity_manager";
import { GameSystemManager } from "./game_system_manager";
import { GameHUD } from "./hud/hud";
import { MapView } from "./map_view";
import { Camera } from "./camera";
import { InGameState } from "../states/ingame";
import { AutomaticSave } from "./automatic_save";
import { Application } from "../application";
import { SoundProxy } from "./sound_proxy";
import { Savegame } from "../savegame/savegame";
import { GameLogic } from "./logic";
import { ShapeDefinitionManager } from "./shape_definition_manager";
import { HubGoals } from "./hub_goals";
import { BufferMaintainer } from "../core/buffer_maintainer";
import { ProductionAnalytics } from "./production_analytics";
import { Entity } from "./entity";
import { ShapeDefinition } from "./shape_definition";
import { BaseItem } from "./base_item";
import { DynamicTickrate } from "./dynamic_tickrate";
import { KeyActionMapper } from "./key_action_mapper";
import { Vector } from "../core/vector";
import { GameMode } from "./game_mode";
/* typehints:end */
const logger = createLogger("game/root");
/** @type {Array<Layer>} */
export const layers = ["regular", "wires"];
/**
* The game root is basically the whole game state at a given point,
* combining all important classes. We don't have globals, but this
* class is passed to almost all game classes.
*/
export class GameRoot {
/**
* Constructs a new game root
* @param {Application} app
*/
constructor(app) {
this.app = app;
/** @type {Savegame} */
this.savegame = null;
/** @type {InGameState} */
this.gameState = null;
/** @type {KeyActionMapper} */
this.keyMapper = null;
// Store game dimensions
this.gameWidth = 500;
this.gameHeight = 500;
// Stores whether the current session is a fresh game (true), or was continued (false)
/** @type {boolean} */
this.gameIsFresh = true;
// Stores whether the logic is already initialized
/** @type {boolean} */
this.logicInitialized = false;
// Stores whether the game is already initialized, that is, all systems etc have been created
/** @type {boolean} */
this.gameInitialized = false;
/**
* Whether a bulk operation is running
*/
this.bulkOperationRunning = false;
//////// Other properties ///////
/** @type {Camera} */
this.camera = null;
/** @type {HTMLCanvasElement} */
this.canvas = null;
/** @type {CanvasRenderingContext2D} */
this.context = null;
/** @type {MapView} */
this.map = null;
/** @type {GameLogic} */
this.logic = null;
/** @type {EntityManager} */
this.entityMgr = null;
/** @type {GameHUD} */
this.hud = null;
/** @type {GameSystemManager} */
this.systemMgr = null;
/** @type {GameTime} */
this.time = null;
/** @type {HubGoals} */
this.hubGoals = null;
/** @type {BufferMaintainer} */
this.buffers = null;
/** @type {AutomaticSave} */
this.automaticSave = null;
/** @type {SoundProxy} */
this.soundProxy = null;
/** @type {ShapeDefinitionManager} */
this.shapeDefinitionMgr = null;
/** @type {ProductionAnalytics} */
this.productionAnalytics = null;
/** @type {DynamicTickrate} */
this.dynamicTickrate = null;
/** @type {Layer} */
this.currentLayer = "regular";
/** @type {GameMode} */
this.gameMode = null;
this.signals = {
// Entities
entityManuallyPlaced: /** @type {TypedSignal<[Entity]>} */ (new Signal()),
entityAdded: /** @type {TypedSignal<[Entity]>} */ (new Signal()),
entityChanged: /** @type {TypedSignal<[Entity]>} */ (new Signal()),
entityGotNewComponent: /** @type {TypedSignal<[Entity]>} */ (new Signal()),
entityComponentRemoved: /** @type {TypedSignal<[Entity]>} */ (new Signal()),
entityQueuedForDestroy: /** @type {TypedSignal<[Entity]>} */ (new Signal()),
entityDestroyed: /** @type {TypedSignal<[Entity]>} */ (new Signal()),
// Global
resized: /** @type {TypedSignal<[number, number]>} */ (new Signal()),
readyToRender: /** @type {TypedSignal<[]>} */ (new Signal()),
aboutToDestruct: /** @type {TypedSignal<[]>} */ new Signal(),
// Game Hooks
gameSaved: /** @type {TypedSignal<[]>} */ (new Signal()), // Game got saved
gameRestored: /** @type {TypedSignal<[]>} */ (new Signal()), // Game got restored
gameFrameStarted: /** @type {TypedSignal<[]>} */ (new Signal()), // New frame
storyGoalCompleted: /** @type {TypedSignal<[number, string]>} */ (new Signal()),
upgradePurchased: /** @type {TypedSignal<[string]>} */ (new Signal()),
// Called right after game is initialized
postLoadHook: /** @type {TypedSignal<[]>} */ (new Signal()),
shapeDelivered: /** @type {TypedSignal<[ShapeDefinition]>} */ (new Signal()),
itemProduced: /** @type {TypedSignal<[BaseItem]>} */ (new Signal()),
bulkOperationFinished: /** @type {TypedSignal<[]>} */ (new Signal()),
editModeChanged: /** @type {TypedSignal<[Layer]>} */ (new Signal()),
// Called to check if an entity can be placed, second parameter is an additional offset.
// Use to introduce additional placement checks
prePlacementCheck: /** @type {TypedSignal<[Entity, Vector]>} */ (new Signal()),
// Called before actually placing an entity, use to perform additional logic
// for freeing space before actually placing.
freeEntityAreaBeforeBuild: /** @type {TypedSignal<[Entity]>} */ (new Signal()),
};
// RNG's
/** @type {Object.<string, Object.<string, RandomNumberGenerator>>} */
this.rngs = {};
// Work queue
this.queue = {
requireRedraw: false,
};
}
/**
* Destructs the game root
*/
destruct() {
logger.log("destructing root");
this.signals.aboutToDestruct.dispatch();
this.reset();
}
/**
* Resets the whole root and removes all properties
*/
reset() {
if (this.signals) {
// Destruct all signals
for (let i = 0; i < this.signals.length; ++i) {
this.signals[i].removeAll();
}
}
if (this.hud) {
this.hud.cleanup();
}
if (this.camera) {
this.camera.cleanup();
}
// Finally free all properties
for (let prop in this) {
if (this.hasOwnProperty(prop)) {
delete this[prop];
}
}
}
}
/* eslint-disable no-unused-vars */
import { Signal } from "../core/signal";
import { RandomNumberGenerator } from "../core/rng";
import { createLogger } from "../core/logging";
// Type hints
/* typehints:start */
import { GameTime } from "./time/game_time";
import { EntityManager } from "./entity_manager";
import { GameSystemManager } from "./game_system_manager";
import { GameHUD } from "./hud/hud";
import { MapView } from "./map_view";
import { Camera } from "./camera";
import { InGameState } from "../states/ingame";
import { AutomaticSave } from "./automatic_save";
import { Application } from "../application";
import { SoundProxy } from "./sound_proxy";
import { Savegame } from "../savegame/savegame";
import { GameLogic } from "./logic";
import { ShapeDefinitionManager } from "./shape_definition_manager";
import { HubGoals } from "./hub_goals";
import { BufferMaintainer } from "../core/buffer_maintainer";
import { ProductionAnalytics } from "./production_analytics";
import { Entity } from "./entity";
import { ShapeDefinition } from "./shape_definition";
import { BaseItem } from "./base_item";
import { DynamicTickrate } from "./dynamic_tickrate";
import { KeyActionMapper } from "./key_action_mapper";
import { Vector } from "../core/vector";
import { GameMode } from "./game_mode";
/* typehints:end */
const logger = createLogger("game/root");
export const layers: Layer[] = ["regular", "wires"];
/**
* The game root is basically the whole game state at a given point,
* combining all important classes. We don't have globals, but this
* class is passed to almost all game classes.
*/
export class GameRoot {
app: Application;
savegame: Savegame | null = null;
gameState: InGameState | null = null;
keyMapper: KeyActionMapper | null = null;
// Store game dimensions
gameWidth = 500;
gameHeight = 500;
// Stores whether the current session is a fresh game (true), or was continued (false)
gameIsFresh: boolean = true;
// Stores whether the logic is already initialized
logicInitialized: boolean = false;
// Stores whether the game is already initialized, that is, all systems etc have been created
gameInitialized: boolean = false;
/**
* Whether a bulk operation is running
*/
bulkOperationRunning = false;
//////// Other properties ///////
camera: Camera | null = null;
canvas: HTMLCanvasElement | null = null;
context: CanvasRenderingContext2D | null = null;
map: MapView | null = null;
logic: GameLogic | null = null;
entityMgr: EntityManager | null = null;
hud: GameHUD | null = null;
systemMgr: GameSystemManager | null = null;
time: GameTime | null = null;
hubGoals: HubGoals | null = null;
buffers: BufferMaintainer | null = null;
automaticSave: AutomaticSave | null = null;
soundProxy: SoundProxy | null = null;
shapeDefinitionMgr: ShapeDefinitionManager | null = null;
productionAnalytics: ProductionAnalytics | null = null;
dynamicTickrate: DynamicTickrate | null = null;
currentLayer: Layer = "regular";
gameMode: GameMode | null = null;
signals: any;
rngs: {};
queue: { requireRedraw: boolean };
/**
* Constructs a new game root
*/
constructor(app: Application) {
this.app = app;
this.signals = {
// Entities
entityManuallyPlaced: /** @type {TypedSignal<[Entity]>} */ new Signal(),
entityAdded: /** @type {TypedSignal<[Entity]>} */ new Signal(),
entityChanged: /** @type {TypedSignal<[Entity]>} */ new Signal(),
entityGotNewComponent: /** @type {TypedSignal<[Entity]>} */ new Signal(),
entityComponentRemoved: /** @type {TypedSignal<[Entity]>} */ new Signal(),
entityQueuedForDestroy: /** @type {TypedSignal<[Entity]>} */ new Signal(),
entityDestroyed: /** @type {TypedSignal<[Entity]>} */ new Signal(),
// Global
resized: /** @type {TypedSignal<[number, number]>} */ new Signal(),
readyToRender: /** @type {TypedSignal<[]>} */ new Signal(),
aboutToDestruct: /** @type {TypedSignal<[]>} */ new Signal(),
// Game Hooks
gameSaved: /** @type {TypedSignal<[]>} */ new Signal(), // Game got saved
gameRestored: /** @type {TypedSignal<[]>} */ new Signal(), // Game got restored
gameFrameStarted: /** @type {TypedSignal<[]>} */ new Signal(), // New frame
storyGoalCompleted: /** @type {TypedSignal<[number, string]>} */ new Signal(),
upgradePurchased: /** @type {TypedSignal<[string]>} */ new Signal(),
// Called right after game is initialized
postLoadHook: /** @type {TypedSignal<[]>} */ new Signal(),
shapeDelivered: /** @type {TypedSignal<[ShapeDefinition]>} */ new Signal(),
itemProduced: /** @type {TypedSignal<[BaseItem]>} */ new Signal(),
bulkOperationFinished: /** @type {TypedSignal<[]>} */ new Signal(),
editModeChanged: /** @type {TypedSignal<[Layer]>} */ new Signal(),
// Called to check if an entity can be placed, second parameter is an additional offset.
// Use to introduce additional placement checks
prePlacementCheck: /** @type {TypedSignal<[Entity, Vector]>} */ new Signal(),
// Called before actually placing an entity, use to perform additional logic
// for freeing space before actually placing.
freeEntityAreaBeforeBuild: /** @type {TypedSignal<[Entity]>} */ new Signal(),
};
// RNG's
/** @type {Object.<string, Object.<string, RandomNumberGenerator>>} */
this.rngs = {};
// Work queue
this.queue = {
requireRedraw: false,
};
}
/**
* Destructs the game root
*/
destruct() {
logger.log("destructing root");
this.signals.aboutToDestruct.dispatch();
this.reset();
}
/**
* Resets the whole root and removes all properties
*/
reset() {
if (this.signals) {
// Destruct all signals
for (let i = 0; i < this.signals.length; ++i) {
this.signals[i].removeAll();
}
}
if (this.hud) {
this.hud.cleanup();
}
if (this.camera) {
this.camera.cleanup();
}
// Finally free all properties
for (const prop in this) {
if (this.hasOwnProperty(prop)) {
delete this[prop];
}
}
}
}

View File

@ -2,7 +2,7 @@ import { createLogger } from "../core/logging";
import { BasicSerializableObject } from "../savegame/serialization";
import { enumColors } from "./colors";
import { ShapeItem } from "./items/shape_item";
import { GameRoot } from "./root";
import { GameRoot } from "./root.ts";
import { enumSubShape, ShapeDefinition } from "./shape_definition";
const logger = createLogger("shape_definition_manager");

View File

@ -1,5 +1,5 @@
/* typehints:start */
import { GameRoot } from "./root";
import { GameRoot } from "./root.ts";
/* typehints:end */
import { Vector } from "../core/vector";

View File

@ -1,5 +1,5 @@
/* typehints:start */
import { GameRoot } from "../root";
import { GameRoot } from "../root.ts";
/* typehints:end */
import { BasicSerializableObject } from "../../savegame/serialization";

View File

@ -1,5 +1,5 @@
/* typehints:start */
import { GameRoot } from "../root";
import { GameRoot } from "../root.ts";
/* typehints:end */
import { types, BasicSerializableObject } from "../../savegame/serialization";

View File

@ -3,7 +3,7 @@ import { createLogger } from "../../core/logging";
import { queryParamOptions } from "../../core/query_parameters";
import { BeltComponent } from "../../game/components/belt";
import { StaticMapEntityComponent } from "../../game/components/static_map_entity";
import { GameRoot } from "../../game/root";
import { GameRoot } from "../../game/root.ts";
import { InGameState } from "../../states/ingame";
import { GameAnalyticsInterface } from "../game_analytics";
import { FILE_NOT_FOUND } from "../storage";

View File

@ -1,7 +1,7 @@
/* typehints:start */
import { Application } from "../application";
import { Vector } from "../core/vector";
import { GameRoot } from "../game/root";
import { GameRoot } from "../game/root.ts";
/* typehints:end */
import { newEmptyMap, clamp } from "../core/utils";

View File

@ -1,5 +1,5 @@
/* typehints:start */
import { GameRoot } from "../game/root";
import { GameRoot } from "../game/root.ts";
import { BasicSerializableObject } from "./serialization";
/* typehints:end */

View File

@ -3,7 +3,7 @@ import { createLogger } from "../core/logging";
import { Vector } from "../core/vector";
import { getBuildingDataFromCode } from "../game/building_codes";
import { Entity } from "../game/entity";
import { GameRoot } from "../game/root";
import { GameRoot } from "../game/root.ts";
const logger = createLogger("serializer_internal");

View File

@ -1,59 +1,18 @@
{
"compilerOptions": {
/* Basic Options */
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"lib": ["DOM", "ES2018"] /* Specify library files to be included in the compilation. */,
"allowJs": true /* Allow javascript files to be compiled. */,
"checkJs": true /* Report errors in .js files. */,
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./typedefs_gen", /* Concatenate and emit output to single file. */
// "outDir": "./typedefs_gen", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "incremental": true, /* Enable incremental compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
"noEmit": true /* Do not emit outputs. */,
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
// "strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
"strictFunctionTypes": true /* Enable strict checking of function types. */,
"strictBindCallApply": true /* Enable strict 'bind', 'call', and 'apply' methods on functions. */,
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
"noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */,
"alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */,
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
"noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */,
/* Module Resolution Options */
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
"resolveJsonModule": true
"target": "es6",
"module": "commonjs",
"lib": ["DOM", "ES2018"],
"sourceMap": true,
"strictFunctionTypes": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"esModuleInterop": true,
"resolveJsonModule": true,
"skipLibCheck": true
},
"exclude": ["webworkers"]
"exclude": ["webworkers", "node_modules"]
}