diff --git a/Makefile b/Makefile
deleted file mode 100644
index 97bbaac..0000000
--- a/Makefile
+++ /dev/null
@@ -1,13 +0,0 @@
-all: lint build
-
-build:
- tsc
-
-lint:
- tslint --project .
-
-clean:
- rm -f public/js/irreligious.js
-
-run:
- firefox public/index.html
diff --git a/cmd b/cmd
new file mode 100755
index 0000000..5e01db2
--- /dev/null
+++ b/cmd
@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+
+cmd=$1
+
+if [ "$cmd" = "build" ]; then
+ tslint --project . && tsc
+elif [ "$cmd" = "run" ]; then
+ firefox public/index.html &
+else
+ echo "Usage: ./cmd build - lint and compile"
+ echo " ./cmd run - run in firefox"
+fi
diff --git a/public/css/debugger.css b/public/css/debugger.css
index b9946d2..873ec31 100644
--- a/public/css/debugger.css
+++ b/public/css/debugger.css
@@ -1,4 +1,5 @@
-#irreligious-game {
+#irreligious-game, .resource-type-container {
+ clear: all;
overflow: auto;
}
div.resource {
diff --git a/src/model/GameConfig.ts b/src/model/GameConfig.ts
index 25791c9..b964afb 100644
--- a/src/model/GameConfig.ts
+++ b/src/model/GameConfig.ts
@@ -1,7 +1,7 @@
///
///
///
-///
+///
class GameConfig {
public worldPopulation: number = 790000000;
@@ -58,7 +58,7 @@ class GameConfig {
// add purchasable resources
state.addResource('money', new Money(0, 1000));
- state.addResource('bonds', new SavingsBonds(0));
+ state.addResource('bonds', new Savings(0));
return state;
}
diff --git a/src/model/resource/IResource.ts b/src/model/resource/IResource.ts
index 13db3bf..1cf4dc9 100644
--- a/src/model/resource/IResource.ts
+++ b/src/model/resource/IResource.ts
@@ -1,7 +1,7 @@
enum ResourceType {
- Religion,
- Consumable,
- Infrastructure
+ Religion = 'religion',
+ Consumable = 'consumable',
+ Infrastructure = 'infrastructure'
}
interface IResource {
diff --git a/src/model/resource/SavingsBonds.ts b/src/model/resource/Savings.ts
similarity index 71%
rename from src/model/resource/SavingsBonds.ts
rename to src/model/resource/Savings.ts
index dc8116b..6bf65a7 100644
--- a/src/model/resource/SavingsBonds.ts
+++ b/src/model/resource/Savings.ts
@@ -1,14 +1,14 @@
///
-class SavingsBonds extends Purchasable {
+class Savings extends Purchasable {
public max?: number = null;
private _isUnlocked = false;
constructor (
public value: number,
) {
- super('Savings Bonds', 'Grows money by a small amount over time.');
- this.cost = { 'money': 25 };
+ super('Savings', "Can't be spent, but grows money over time.");
+ this.cost = { 'money': 10 };
this._costMultiplier = { 'money': 1.1 };
}
@@ -22,6 +22,6 @@ class SavingsBonds extends Purchasable {
}
protected purchaseEffect (state: GameState) {
- state.getResource('money').inc += 0.25;
+ state.getResource('money').inc += 1;
}
}
diff --git a/src/render/DebugRenderer.ts b/src/render/DebugRenderer.ts
index f88e336..ce6fc8d 100644
--- a/src/render/DebugRenderer.ts
+++ b/src/render/DebugRenderer.ts
@@ -6,64 +6,70 @@ class DebugRenderer implements IRenderer {
private _handleClick = true;
public render (state: GameState) {
- const container = document.getElementById('irreligious-game');
- if (container === null) {
- console.log('Cannot find #irreligious-game container.'); // tslint:disable-line
- } else {
- if (!this._initialized) {
- this._initialized = true;
- state.onResourceClick.push(() => this._handleClick = true);
- const style = document.createElement('link');
- style.setAttribute('rel', 'stylesheet');
- style.setAttribute('href', 'css/debugger.css');
- const head = document.getElementsByTagName('head')[0];
- head.appendChild(style);
+ if (!this._initialized) {
+ const container = document.getElementById('irreligious-game');
+ this._initialized = true;
+ state.onResourceClick.push(() => this._handleClick = true);
+ const style = document.createElement('link');
+ style.setAttribute('rel', 'stylesheet');
+ style.setAttribute('href', 'css/debugger.css');
+ const head = document.getElementsByTagName('head')[0];
+ head.appendChild(style);
+ // create containers for each resource type
+ for (const item in ResourceType) {
+ if (isNaN(Number(item))) {
+ const el = document.createElement('div');
+ el.id = `resource-container-${ResourceType[item]}`;
+ el.className = 'resource-type-container';
+ container.appendChild(el);
+ }
}
- const rkeys = state.getResources();
- for (const rkey of rkeys) {
- const resource = state.getResource(rkey);
- if (resource.isUnlocked(state)) {
- let el = document.getElementById(`r_${rkey}`);
- if (el === null) {
- el = document.createElement('div');
- el.className = 'resource';
- el.id = `r_${rkey}`;
- let content = `
- ${resource.name}
-
- `;
- if (resource.clickText !== null) {
- content += `
`;
- }
- if (resource.cost !== null && Object.keys(resource.cost) !== null) {
- content += `
Cost: `;
- }
- el.innerHTML = content;
- container.appendChild(el);
- if (resource.clickAction !== null) {
- const btn = el.getElementsByClassName('btn')[0];
- btn.addEventListener('click', () => state.performClick(rkey));
- }
+ }
+ const rkeys = state.getResources();
+ for (const rkey of rkeys) {
+ const resource = state.getResource(rkey);
+ console.log(`getting container resource-container-${resource.resourceType}`); // tslint:disable-line
+ const container = document.getElementById(`resource-container-${resource.resourceType}`);
+ if (resource.isUnlocked(state)) {
+ let el = document.getElementById(`resource-details-${rkey}`);
+ if (el === null) {
+ el = document.createElement('div');
+ el.className = 'resource';
+ el.id = `resource-details-${rkey}`;
+ let content = `
+ ${resource.name}
+
+ `;
+ if (resource.clickText !== null) {
+ content += `
`;
}
- const elV = el.getElementsByClassName('value')[0];
- const elT = el.getElementsByClassName('max')[0];
- elV.innerHTML = this.formatNumber(resource.value, 1);
- elT.innerHTML = resource.max !== null ? ` / ${this.formatNumber(resource.max, 1)}` : '';
- if (this._handleClick) {
- if (resource.inc > 0) {
- console.log(`${resource.name} inc ${resource.inc} to ${this.formatNumber(resource.inc, 1)}`); // tslint:disable-line
- const elI = el.getElementsByClassName('inc')[0];
- elI.innerHTML = ` +${this.formatNumber(resource.inc, 1)}/s`;
- }
- const elC = el.getElementsByClassName('cost');
- if (elC.length > 0) {
- elC[0].innerHTML = this.getCostStr(resource, state);
- }
+ if (resource.cost !== null && Object.keys(resource.cost) !== null) {
+ content += `
Cost: `;
+ }
+ el.innerHTML = content;
+ container.appendChild(el);
+ if (resource.clickAction !== null) {
+ const btn = el.getElementsByClassName('resource-btn')[0];
+ btn.addEventListener('click', () => state.performClick(rkey));
+ }
+ }
+ const elV = el.getElementsByClassName('resource-value')[0];
+ const elT = el.getElementsByClassName('resource-max')[0];
+ elV.innerHTML = this.formatNumber(resource.value, 1);
+ elT.innerHTML = resource.max !== null ? ` / ${this.formatNumber(resource.max, 1)}` : '';
+ if (this._handleClick) {
+ if (resource.inc > 0) {
+ const elI = el.getElementsByClassName('resource-inc')[0];
+ elI.innerHTML = ` +${this.formatNumber(resource.inc, 1)}/s`;
+ }
+ const elC = el.getElementsByClassName('resource-cost');
+ if (elC.length > 0) {
+ elC[0].innerHTML = this.getCostStr(resource, state);
}
}
}
- this._handleClick = false;
}
+ this._handleClick = false;
}
private getCostStr (resource: IResource, state: GameState) {
@@ -84,7 +90,7 @@ class DebugRenderer implements IRenderer {
private formatNumber (num: number, digits: number): string {
const lookup = [
{ value: 1, symbol: "" },
- { value: 1e3, symbol: "k" },
+ { value: 1e3, symbol: "K" },
{ value: 1e6, symbol: "M" },
{ value: 1e9, symbol: "G" },
{ value: 1e12, symbol: "T" },
@@ -95,6 +101,6 @@ class DebugRenderer implements IRenderer {
const item = lookup.slice().reverse().find((i) => num >= i.value);
return item
? (num / item.value).toFixed(digits).replace(rx, "$1") + item.symbol
- : "0";
+ : num.toFixed(digits).replace(rx, "$1");
}
}