From c2c800a4f5b6319a52f5185799d582e514535720 Mon Sep 17 00:00:00 2001 From: akupiec Date: Sun, 17 Jan 2021 13:02:56 +0100 Subject: [PATCH] typescript in root --- gulp/webpack.config.js | 7 +- gulp/webpack.production.config.js | 5 + package.json | 1 + src/js/core/buffer_maintainer.js | 2 +- src/js/game/automatic_save.js | 2 +- src/js/game/belt_path.js | 2 +- src/js/game/blueprint.js | 2 +- src/js/game/buildings/analyzer.js | 2 +- src/js/game/buildings/balancer.js | 2 +- src/js/game/buildings/belt.js | 2 +- src/js/game/buildings/comparator.js | 2 +- src/js/game/buildings/constant_signal.js | 2 +- src/js/game/buildings/cutter.js | 2 +- src/js/game/buildings/display.js | 2 +- src/js/game/buildings/filter.js | 2 +- src/js/game/buildings/lever.js | 2 +- src/js/game/buildings/logic_gate.js | 2 +- src/js/game/buildings/miner.js | 2 +- src/js/game/buildings/mixer.js | 2 +- src/js/game/buildings/painter.js | 2 +- src/js/game/buildings/reader.js | 2 +- src/js/game/buildings/rotater.js | 2 +- src/js/game/buildings/stacker.js | 2 +- src/js/game/buildings/storage.js | 2 +- src/js/game/buildings/transistor.js | 2 +- src/js/game/buildings/trash.js | 2 +- src/js/game/buildings/underground_belt.js | 2 +- src/js/game/buildings/virtual_processor.js | 2 +- src/js/game/buildings/wire.js | 2 +- src/js/game/buildings/wire_tunnel.js | 2 +- src/js/game/camera.js | 2 +- src/js/game/core.js | 2 +- src/js/game/dynamic_tickrate.js | 2 +- src/js/game/entity.js | 2 +- src/js/game/entity_manager.js | 2 +- src/js/game/game_mode.js | 2 +- src/js/game/game_system.js | 2 +- src/js/game/game_system_manager.js | 2 +- src/js/game/game_system_with_filter.js | 2 +- src/js/game/hub_goals.js | 2 +- src/js/game/hud/base_hud_part.js | 2 +- src/js/game/hud/dynamic_dom_attach.js | 2 +- src/js/game/hud/hud.js | 2 +- src/js/game/hud/parts/base_toolbar.js | 2 +- src/js/game/hud/parts/building_placer.js | 2 +- src/js/game/hud/parts/interactive_tutorial.js | 2 +- src/js/game/hud/parts/statistics_handle.js | 2 +- src/js/game/hud/trailer_maker.js | 2 +- src/js/game/key_action_mapper.js | 2 +- src/js/game/logic.js | 2 +- src/js/game/map.js | 2 +- src/js/game/map_chunk.js | 2 +- src/js/game/map_chunk_view.js | 2 +- src/js/game/meta_building.js | 2 +- src/js/game/production_analytics.js | 2 +- src/js/game/{root.js => root.ts} | 430 +++++++++--------- src/js/game/shape_definition_manager.js | 2 +- src/js/game/sound_proxy.js | 2 +- src/js/game/time/base_game_speed.js | 2 +- src/js/game/time/game_time.js | 2 +- src/js/platform/browser/game_analytics.js | 2 +- src/js/platform/sound.js | 2 +- src/js/savegame/serialization_data_types.js | 2 +- src/js/savegame/serializer_internal.js | 2 +- src/js/tsconfig.json | 69 +-- 65 files changed, 291 insertions(+), 341 deletions(-) rename src/js/game/{root.js => root.ts} (55%) diff --git a/gulp/webpack.config.js b/gulp/webpack.config.js index 6e1d7388..6a4c5910 100644 --- a/gulp/webpack.config.js +++ b/gulp/webpack.config.js @@ -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: { diff --git a/gulp/webpack.production.config.js b/gulp/webpack.production.config.js index c26bca68..770de3ab 100644 --- a/gulp/webpack.production.config.js +++ b/gulp/webpack.production.config.js @@ -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", diff --git a/package.json b/package.json index 715bf26d..341f9469 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/src/js/core/buffer_maintainer.js b/src/js/core/buffer_maintainer.js index 1d506803..4cfd8ab1 100644 --- a/src/js/core/buffer_maintainer.js +++ b/src/js/core/buffer_maintainer.js @@ -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"; diff --git a/src/js/game/automatic_save.js b/src/js/game/automatic_save.js index 9d841966..a2370c76 100644 --- a/src/js/game/automatic_save.js +++ b/src/js/game/automatic_save.js @@ -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 /** diff --git a/src/js/game/belt_path.js b/src/js/game/belt_path.js index dde81549..7b3a59ce 100644 --- a/src/js/game/belt_path.js +++ b/src/js/game/belt_path.js @@ -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"); diff --git a/src/js/game/blueprint.js b/src/js/game/blueprint.js index 63989393..46cfc2c5 100644 --- a/src/js/game/blueprint.js +++ b/src/js/game/blueprint.js @@ -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 { /** diff --git a/src/js/game/buildings/analyzer.js b/src/js/game/buildings/analyzer.js index 8335f730..42376134 100644 --- a/src/js/game/buildings/analyzer.js +++ b/src/js/game/buildings/analyzer.js @@ -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]); diff --git a/src/js/game/buildings/balancer.js b/src/js/game/buildings/balancer.js index 2f14e36c..6e7a88ab 100644 --- a/src/js/game/buildings/balancer.js +++ b/src/js/game/buildings/balancer.js @@ -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"; diff --git a/src/js/game/buildings/belt.js b/src/js/game/buildings/belt.js index 84646b19..2b09a850 100644 --- a/src/js/game/buildings/belt.js +++ b/src/js/game/buildings/belt.js @@ -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]; diff --git a/src/js/game/buildings/comparator.js b/src/js/game/buildings/comparator.js index 6738d514..cbf12320 100644 --- a/src/js/game/buildings/comparator.js +++ b/src/js/game/buildings/comparator.js @@ -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 { diff --git a/src/js/game/buildings/constant_signal.js b/src/js/game/buildings/constant_signal.js index 983594cb..3f3896c5 100644 --- a/src/js/game/buildings/constant_signal.js +++ b/src/js/game/buildings/constant_signal.js @@ -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"; diff --git a/src/js/game/buildings/cutter.js b/src/js/game/buildings/cutter.js index 7dee4449..088976c2 100644 --- a/src/js/game/buildings/cutter.js +++ b/src/js/game/buildings/cutter.js @@ -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} */ diff --git a/src/js/game/buildings/display.js b/src/js/game/buildings/display.js index 422bea81..62657764 100644 --- a/src/js/game/buildings/display.js +++ b/src/js/game/buildings/display.js @@ -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"; diff --git a/src/js/game/buildings/filter.js b/src/js/game/buildings/filter.js index 2d81ce83..e21226ce 100644 --- a/src/js/game/buildings/filter.js +++ b/src/js/game/buildings/filter.js @@ -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 { diff --git a/src/js/game/buildings/lever.js b/src/js/game/buildings/lever.js index 7ddaf65f..01c4bf84 100644 --- a/src/js/game/buildings/lever.js +++ b/src/js/game/buildings/lever.js @@ -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"; diff --git a/src/js/game/buildings/logic_gate.js b/src/js/game/buildings/logic_gate.js index b61d4373..2f9d3784 100644 --- a/src/js/game/buildings/logic_gate.js +++ b/src/js/game/buildings/logic_gate.js @@ -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"; diff --git a/src/js/game/buildings/miner.js b/src/js/game/buildings/miner.js index f0b837a1..cd31492e 100644 --- a/src/js/game/buildings/miner.js +++ b/src/js/game/buildings/miner.js @@ -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"; diff --git a/src/js/game/buildings/mixer.js b/src/js/game/buildings/mixer.js index cbde309e..13d7babc 100644 --- a/src/js/game/buildings/mixer.js +++ b/src/js/game/buildings/mixer.js @@ -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 { diff --git a/src/js/game/buildings/painter.js b/src/js/game/buildings/painter.js index 6e941403..7fbfc2ba 100644 --- a/src/js/game/buildings/painter.js +++ b/src/js/game/buildings/painter.js @@ -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"; diff --git a/src/js/game/buildings/reader.js b/src/js/game/buildings/reader.js index 006d6582..6acac7b2 100644 --- a/src/js/game/buildings/reader.js +++ b/src/js/game/buildings/reader.js @@ -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"; diff --git a/src/js/game/buildings/rotater.js b/src/js/game/buildings/rotater.js index 7df94d16..fcc08f17 100644 --- a/src/js/game/buildings/rotater.js +++ b/src/js/game/buildings/rotater.js @@ -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} */ diff --git a/src/js/game/buildings/stacker.js b/src/js/game/buildings/stacker.js index 40a9c5ae..a522e28e 100644 --- a/src/js/game/buildings/stacker.js +++ b/src/js/game/buildings/stacker.js @@ -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 { diff --git a/src/js/game/buildings/storage.js b/src/js/game/buildings/storage.js index 5574e137..2321da12 100644 --- a/src/js/game/buildings/storage.js +++ b/src/js/game/buildings/storage.js @@ -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; diff --git a/src/js/game/buildings/transistor.js b/src/js/game/buildings/transistor.js index ebcfeac3..47c2428c 100644 --- a/src/js/game/buildings/transistor.js +++ b/src/js/game/buildings/transistor.js @@ -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} */ diff --git a/src/js/game/buildings/trash.js b/src/js/game/buildings/trash.js index 43108b9e..8d22fee1 100644 --- a/src/js/game/buildings/trash.js +++ b/src/js/game/buildings/trash.js @@ -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]); diff --git a/src/js/game/buildings/underground_belt.js b/src/js/game/buildings/underground_belt.js index 2761443d..8c4e2160 100644 --- a/src/js/game/buildings/underground_belt.js +++ b/src/js/game/buildings/underground_belt.js @@ -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"; diff --git a/src/js/game/buildings/virtual_processor.js b/src/js/game/buildings/virtual_processor.js index b4f91762..837cc71e 100644 --- a/src/js/game/buildings/virtual_processor.js +++ b/src/js/game/buildings/virtual_processor.js @@ -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"; diff --git a/src/js/game/buildings/wire.js b/src/js/game/buildings/wire.js index 61b75073..b5cca9f8 100644 --- a/src/js/game/buildings/wire.js +++ b/src/js/game/buildings/wire.js @@ -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 = [ diff --git a/src/js/game/buildings/wire_tunnel.js b/src/js/game/buildings/wire_tunnel.js index 2626dd12..4a456c39 100644 --- a/src/js/game/buildings/wire_tunnel.js +++ b/src/js/game/buildings/wire_tunnel.js @@ -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]); diff --git a/src/js/game/camera.js b/src/js/game/camera.js index 107d1fb4..4733eeef 100644 --- a/src/js/game/camera.js +++ b/src/js/game/camera.js @@ -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"); diff --git a/src/js/game/core.js b/src/js/game/core.js index 2df8989f..f9bd6b9a 100644 --- a/src/js/game/core.js +++ b/src/js/game/core.js @@ -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"; diff --git a/src/js/game/dynamic_tickrate.js b/src/js/game/dynamic_tickrate.js index 3e29aba3..960787f8 100644 --- a/src/js/game/dynamic_tickrate.js +++ b/src/js/game/dynamic_tickrate.js @@ -1,4 +1,4 @@ -import { GameRoot } from "./root"; +import { GameRoot } from "./root.ts"; import { createLogger } from "../core/logging"; import { globalConfig } from "../core/config"; diff --git a/src/js/game/entity.js b/src/js/game/entity.js index d7dd715e..7e9c7051 100644 --- a/src/js/game/entity.js +++ b/src/js/game/entity.js @@ -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"; diff --git a/src/js/game/entity_manager.js b/src/js/game/entity_manager.js index b4101fc8..7d43bddc 100644 --- a/src/js/game/entity_manager.js +++ b/src/js/game/entity_manager.js @@ -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"; diff --git a/src/js/game/game_mode.js b/src/js/game/game_mode.js index 15403eb5..eb2c3e29 100644 --- a/src/js/game/game_mode.js +++ b/src/js/game/game_mode.js @@ -2,7 +2,7 @@ import { enumHubGoalRewards } from "./tutorial_goals"; /* typehints:end */ -import { GameRoot } from "./root"; +import { GameRoot } from "./root.ts"; /** @typedef {{ * shape: string, diff --git a/src/js/game/game_system.js b/src/js/game/game_system.js index defae1bf..3a94d095 100644 --- a/src/js/game/game_system.js +++ b/src/js/game/game_system.js @@ -1,5 +1,5 @@ /* typehints:start */ -import { GameRoot } from "./root"; +import { GameRoot } from "./root.ts"; import { DrawParameters } from "../core/draw_parameters"; /* typehints:end */ diff --git a/src/js/game/game_system_manager.js b/src/js/game/game_system_manager.js index 74ba798f..03d03fe1 100644 --- a/src/js/game/game_system_manager.js +++ b/src/js/game/game_system_manager.js @@ -1,5 +1,5 @@ /* typehints:start */ -import { GameRoot } from "./root"; +import { GameRoot } from "./root.ts"; /* typehints:end */ import { createLogger } from "../core/logging"; diff --git a/src/js/game/game_system_with_filter.js b/src/js/game/game_system_with_filter.js index a6efeffd..225d3808 100644 --- a/src/js/game/game_system_with_filter.js +++ b/src/js/game/game_system_with_filter.js @@ -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"; diff --git a/src/js/game/hub_goals.js b/src/js/game/hub_goals.js index 9a945128..5ef2be4c 100644 --- a/src/js/game/hub_goals.js +++ b/src/js/game/hub_goals.js @@ -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"; diff --git a/src/js/game/hud/base_hud_part.js b/src/js/game/hud/base_hud_part.js index 84b6d619..a774daf8 100644 --- a/src/js/game/hud/base_hud_part.js +++ b/src/js/game/hud/base_hud_part.js @@ -1,5 +1,5 @@ /* typehints:start */ -import { GameRoot } from "../root"; +import { GameRoot } from "../root.ts"; import { DrawParameters } from "../../core/draw_parameters"; /* typehints:end */ diff --git a/src/js/game/hud/dynamic_dom_attach.js b/src/js/game/hud/dynamic_dom_attach.js index 2b150448..0c882f60 100644 --- a/src/js/game/hud/dynamic_dom_attach.js +++ b/src/js/game/hud/dynamic_dom_attach.js @@ -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 diff --git a/src/js/game/hud/hud.js b/src/js/game/hud/hud.js index d64f96a8..7e4711f5 100644 --- a/src/js/game/hud/hud.js +++ b/src/js/game/hud/hud.js @@ -1,5 +1,5 @@ /* typehints:start */ -import { GameRoot } from "../root"; +import { GameRoot } from "../root.ts"; /* typehints:end */ /* dev:start */ diff --git a/src/js/game/hud/parts/base_toolbar.js b/src/js/game/hud/parts/base_toolbar.js index b3f5abfc..a19808fb 100644 --- a/src/js/game/hud/parts/base_toolbar.js +++ b/src/js/game/hud/parts/base_toolbar.js @@ -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"; diff --git a/src/js/game/hud/parts/building_placer.js b/src/js/game/hud/parts/building_placer.js index 7dccb7a4..5b2b2ddb 100644 --- a/src/js/game/hud/parts/building_placer.js +++ b/src/js/game/hud/parts/building_placer.js @@ -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 { diff --git a/src/js/game/hud/parts/interactive_tutorial.js b/src/js/game/hud/parts/interactive_tutorial.js index e48a77fb..e7806940 100644 --- a/src/js/game/hud/parts/interactive_tutorial.js +++ b/src/js/game/hud/parts/interactive_tutorial.js @@ -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"; diff --git a/src/js/game/hud/parts/statistics_handle.js b/src/js/game/hud/parts/statistics_handle.js index a64a5f5b..cd9836b8 100644 --- a/src/js/game/hud/parts/statistics_handle.js +++ b/src/js/game/hud/parts/statistics_handle.js @@ -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} */ diff --git a/src/js/game/hud/trailer_maker.js b/src/js/game/hud/trailer_maker.js index e9193a93..9fd67bd9 100644 --- a/src/js/game/hud/trailer_maker.js +++ b/src/js/game/hud/trailer_maker.js @@ -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"; diff --git a/src/js/game/key_action_mapper.js b/src/js/game/key_action_mapper.js index 9fa4ffe1..baccd182 100644 --- a/src/js/game/key_action_mapper.js +++ b/src/js/game/key_action_mapper.js @@ -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 */ diff --git a/src/js/game/logic.js b/src/js/game/logic.js index 7ec7b8ab..f774c18c 100644 --- a/src/js/game/logic.js +++ b/src/js/game/logic.js @@ -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"); diff --git a/src/js/game/map.js b/src/js/game/map.js index a5ec8f21..482d767f 100644 --- a/src/js/game/map.js +++ b/src/js/game/map.js @@ -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() { diff --git a/src/js/game/map_chunk.js b/src/js/game/map_chunk.js index 54af1125..43be87e2 100644 --- a/src/js/game/map_chunk.js +++ b/src/js/game/map_chunk.js @@ -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"; diff --git a/src/js/game/map_chunk_view.js b/src/js/game/map_chunk_view.js index 848afbab..7c97241b 100644 --- a/src/js/game/map_chunk_view.js +++ b/src/js/game/map_chunk_view.js @@ -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"; diff --git a/src/js/game/meta_building.js b/src/js/game/meta_building.js index 9deee272..9a3df0b3 100644 --- a/src/js/game/meta_building.js +++ b/src/js/game/meta_building.js @@ -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"; diff --git a/src/js/game/production_analytics.js b/src/js/game/production_analytics.js index eda79c83..76943024 100644 --- a/src/js/game/production_analytics.js +++ b/src/js/game/production_analytics.js @@ -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"; diff --git a/src/js/game/root.js b/src/js/game/root.ts similarity index 55% rename from src/js/game/root.js rename to src/js/game/root.ts index 6f1e7c36..f4539189 100644 --- a/src/js/game/root.js +++ b/src/js/game/root.ts @@ -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} */ -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.>} */ - 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.>} */ + 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]; + } + } + } +} diff --git a/src/js/game/shape_definition_manager.js b/src/js/game/shape_definition_manager.js index 5bcfcc4b..905277da 100644 --- a/src/js/game/shape_definition_manager.js +++ b/src/js/game/shape_definition_manager.js @@ -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"); diff --git a/src/js/game/sound_proxy.js b/src/js/game/sound_proxy.js index 162f0bc0..c29e6149 100644 --- a/src/js/game/sound_proxy.js +++ b/src/js/game/sound_proxy.js @@ -1,5 +1,5 @@ /* typehints:start */ -import { GameRoot } from "./root"; +import { GameRoot } from "./root.ts"; /* typehints:end */ import { Vector } from "../core/vector"; diff --git a/src/js/game/time/base_game_speed.js b/src/js/game/time/base_game_speed.js index 8898b6cf..4544f339 100644 --- a/src/js/game/time/base_game_speed.js +++ b/src/js/game/time/base_game_speed.js @@ -1,5 +1,5 @@ /* typehints:start */ -import { GameRoot } from "../root"; +import { GameRoot } from "../root.ts"; /* typehints:end */ import { BasicSerializableObject } from "../../savegame/serialization"; diff --git a/src/js/game/time/game_time.js b/src/js/game/time/game_time.js index 07b224a7..33635fb6 100644 --- a/src/js/game/time/game_time.js +++ b/src/js/game/time/game_time.js @@ -1,5 +1,5 @@ /* typehints:start */ -import { GameRoot } from "../root"; +import { GameRoot } from "../root.ts"; /* typehints:end */ import { types, BasicSerializableObject } from "../../savegame/serialization"; diff --git a/src/js/platform/browser/game_analytics.js b/src/js/platform/browser/game_analytics.js index a3947be6..473b9c53 100644 --- a/src/js/platform/browser/game_analytics.js +++ b/src/js/platform/browser/game_analytics.js @@ -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"; diff --git a/src/js/platform/sound.js b/src/js/platform/sound.js index 9d5a8461..bb3b9e4e 100644 --- a/src/js/platform/sound.js +++ b/src/js/platform/sound.js @@ -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"; diff --git a/src/js/savegame/serialization_data_types.js b/src/js/savegame/serialization_data_types.js index 9d3b689f..d765f6b0 100644 --- a/src/js/savegame/serialization_data_types.js +++ b/src/js/savegame/serialization_data_types.js @@ -1,5 +1,5 @@ /* typehints:start */ -import { GameRoot } from "../game/root"; +import { GameRoot } from "../game/root.ts"; import { BasicSerializableObject } from "./serialization"; /* typehints:end */ diff --git a/src/js/savegame/serializer_internal.js b/src/js/savegame/serializer_internal.js index c75cebad..63c852a1 100644 --- a/src/js/savegame/serializer_internal.js +++ b/src/js/savegame/serializer_internal.js @@ -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"); diff --git a/src/js/tsconfig.json b/src/js/tsconfig.json index 7ecc605a..7b6aa64e 100644 --- a/src/js/tsconfig.json +++ b/src/js/tsconfig.json @@ -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"] }