From b92661e9349fef8266a22ae5293407f3e0d8e3ae Mon Sep 17 00:00:00 2001 From: Rudis Muiznieks Date: Wed, 18 Aug 2021 10:09:19 -0500 Subject: [PATCH] figuring out class dependencies --- public/index.html | 10 ++++++++++ src/main.ts | 20 ++++++++++++++++++++ src/model/GameConfig.ts | 18 ++++++++++++++++++ src/model/IResource.ts | 11 +++++++++++ src/model/Resource.ts | 3 --- src/model/resource/Religion.ts | 20 ++++++++++++++++++++ tsconfig.json | 2 +- 7 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 public/index.html create mode 100644 src/main.ts create mode 100644 src/model/GameConfig.ts create mode 100644 src/model/IResource.ts delete mode 100644 src/model/Resource.ts create mode 100644 src/model/resource/Religion.ts diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..0016c3d --- /dev/null +++ b/public/index.html @@ -0,0 +1,10 @@ + + + + irreligio.us + + + + + + diff --git a/src/main.ts b/src/main.ts new file mode 100644 index 0000000..5e6e61e --- /dev/null +++ b/src/main.ts @@ -0,0 +1,20 @@ +/// + +let globalStartTime = 0; + +function gameLoop (config: GameConfig): void { + // figure out how much actual time has passed + const elapsedTime = globalStartTime > 0 + ? (new Date()).getTime() - globalStartTime : 0; + + // run again in 1sec + globalStartTime = (new Date()).getTime(); + setTimeout(() => gameLoop(config), 1000); +} + +// run with default config at startup +(() => { + const config = new GameConfig(); + if (document.readyState !== 'loading') gameLoop(config); + else document.addEventListener('DOMContentLoaded', () => gameLoop(config)); +})(); diff --git a/src/model/GameConfig.ts b/src/model/GameConfig.ts new file mode 100644 index 0000000..e5d751f --- /dev/null +++ b/src/model/GameConfig.ts @@ -0,0 +1,18 @@ +/// +/// + +class GameConfig { + public worldPopulation: number = 790000000; + + // religion configs + public relChristianityShare: number = 0.325; + public relIslamShare: number = 0.215; + public relHinduismShare: number = 0.16; + public relBuddhismShare: number = 0.06; + public relSikhismShare: number = 0.04; + public relJudaismShare: number = 0.02; + public relOtherShare:number = 0.02; + public relNoneShare: number = 0.16; + + constructor () {} +} diff --git a/src/model/IResource.ts b/src/model/IResource.ts new file mode 100644 index 0000000..fc3e6a4 --- /dev/null +++ b/src/model/IResource.ts @@ -0,0 +1,11 @@ +enum ResourceType { + Religion +} + +interface IResource { + name: string, + description: string, + resourceType: ResourceType, + value: number, + max: number +} diff --git a/src/model/Resource.ts b/src/model/Resource.ts deleted file mode 100644 index ee1474b..0000000 --- a/src/model/Resource.ts +++ /dev/null @@ -1,3 +0,0 @@ -class Resource { - public name: string; -} diff --git a/src/model/resource/Religion.ts b/src/model/resource/Religion.ts new file mode 100644 index 0000000..4f22198 --- /dev/null +++ b/src/model/resource/Religion.ts @@ -0,0 +1,20 @@ +/// +/// + +class Religion implements IResource { + public readonly description: string; + public readonly resourceType: ResourceType = ResourceType.Religion; + + public value: number; + public max: number; + + constructor ( + config: GameConfig, + public readonly name: string, + populationShare: number + ) { + this.description = name; + this.max = config.worldPopulation; + this.value = config.worldPopulation * populationShare; + } +} diff --git a/tsconfig.json b/tsconfig.json index 2507836..d0e2d28 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,6 +7,6 @@ "emitDecoratorMetadata": true, "experimentalDecorators": true, "target": "ES5", - "module": "amd" + "module": "none" } }