figuring out class dependencies

This commit is contained in:
Rudis Muiznieks 2021-08-18 10:09:19 -05:00
parent 8c67935390
commit b92661e934
7 changed files with 80 additions and 4 deletions

10
public/index.html Normal file
View file

@ -0,0 +1,10 @@
<!doctype html>
<html lang='en'>
<head>
<title>irreligio.us</title>
<meta charset='utf-8'>
<script src='js/irreligious.js'></script>
</head>
<body>
</body>
</html>

20
src/main.ts Normal file
View file

@ -0,0 +1,20 @@
/// <reference path="./model/GameConfig.ts" />
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));
})();

18
src/model/GameConfig.ts Normal file
View file

@ -0,0 +1,18 @@
/// <reference path="./IResource.ts" />
/// <reference path="./resource/Religion.ts" />
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 () {}
}

11
src/model/IResource.ts Normal file
View file

@ -0,0 +1,11 @@
enum ResourceType {
Religion
}
interface IResource {
name: string,
description: string,
resourceType: ResourceType,
value: number,
max: number
}

View file

@ -1,3 +0,0 @@
class Resource {
public name: string;
}

View file

@ -0,0 +1,20 @@
/// <reference path="../GameConfig.ts" />
/// <reference path="../IResource.ts" />
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;
}
}

View file

@ -7,6 +7,6 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "ES5",
"module": "amd"
"module": "none"
}
}