From 314806f64797c2b14ee33c7be31046edc9afbb0b Mon Sep 17 00:00:00 2001 From: Rudis Muiznieks Date: Sun, 22 Aug 2021 13:48:48 -0500 Subject: [PATCH] debug renderer improvements --- public/css/debugger.css | 6 +++++- src/model/GameConfig.ts | 2 +- src/model/GameState.ts | 13 +++++++++++-- src/model/resource/Church.ts | 17 +++++++++++++++-- src/model/resource/Compound.ts | 2 +- src/model/resource/House.ts | 9 +++------ src/model/resource/PlayerOrg.ts | 1 + src/model/resource/Tent.ts | 1 + src/render/DebugRenderer.ts | 31 +++++++++++++++++++++++-------- 9 files changed, 61 insertions(+), 21 deletions(-) diff --git a/public/css/debugger.css b/public/css/debugger.css index 6997729..0ef73ce 100644 --- a/public/css/debugger.css +++ b/public/css/debugger.css @@ -4,6 +4,10 @@ body, html { margin: 0; padding: 0; } +.footer { + border: 2px solid black; + padding: 0.25em 0.5em; +} #irreligious-game { display: flex; align-items: stretch; @@ -40,7 +44,7 @@ body, html { margin: 0 0.5em 0.5em 0; } .resource.locked { - display: none; + opacity: 0.25; } #resource-container-religion .resource { background-color: #ccf; diff --git a/src/model/GameConfig.ts b/src/model/GameConfig.ts index 0dabdbd..2a08724 100644 --- a/src/model/GameConfig.ts +++ b/src/model/GameConfig.ts @@ -77,8 +77,8 @@ class GameConfig { state.addResource('crpto', new CryptoCurrency()); state.addResource('tents', new Tent()); state.addResource('house', new House()); - state.addResource('cmpnd', new Compound()); state.addResource('chrch', new Church()); + state.addResource('cmpnd', new Compound()); // add passive resources state.addResource('creds', new Credibility()); diff --git a/src/model/GameState.ts b/src/model/GameState.ts index 3a3801b..d0e0948 100644 --- a/src/model/GameState.ts +++ b/src/model/GameState.ts @@ -1,6 +1,6 @@ class GameState { - private _versionMaj: number = 0; - private _versionMin: number = 1; + private readonly _versionMaj: number = 0; + private readonly _versionMin: number = 1; public config: GameConfig; @@ -71,6 +71,8 @@ class GameState { } public performClick (resourceKey: string): void { + if (!this._resources[resourceKey].isUnlocked(this)) return; + if (this._resources[resourceKey].clickAction !== null) { this._resources[resourceKey].clickAction(this); for (const callback of this.onResourceClick) { @@ -172,4 +174,11 @@ class GameState { console.log('No save game was found.'); } } + + public reset (): void { + const newState: GameState = this.config.generateState(); + localStorage.clear(); + this._resources = newState._resources; + this.log('Reset all game resources.'); + } } diff --git a/src/model/resource/Church.ts b/src/model/resource/Church.ts index f65964b..9ebcfd9 100644 --- a/src/model/resource/Church.ts +++ b/src/model/resource/Church.ts @@ -4,8 +4,21 @@ class Church extends Infrastructure { constructor () { super('Churches', 'Preaching grounds for 2 pastors.'); - this.cost.money = 10000; + this.cost.money = 150000; this._costMultiplier.money = 1.01; - this._baseMax = 2; + } + + public max (state: GameState): number { + // one church per compound + return state.getResource('cmpnd').value; + } + + public isUnlocked (state: GameState): boolean { + if (this._isUnlocked) return true; + const compounds: IResource = state.getResource('cmpnd'); + if (compounds.value > 0) { + this._isUnlocked = true; + } + return this._isUnlocked; } } diff --git a/src/model/resource/Compound.ts b/src/model/resource/Compound.ts index 0195089..113b133 100644 --- a/src/model/resource/Compound.ts +++ b/src/model/resource/Compound.ts @@ -3,7 +3,7 @@ class Compound extends Infrastructure { constructor () { super('Compounds', - 'Provides space for tents and houses and a place to hide more money.'); + 'Provides space for tents, houses, and churches and a place to hide more money.'); this.cost.money = 15000; this._costMultiplier.money = 1.5; } diff --git a/src/model/resource/House.ts b/src/model/resource/House.ts index 2ab42c9..84995dc 100644 --- a/src/model/resource/House.ts +++ b/src/model/resource/House.ts @@ -4,15 +4,12 @@ class House extends Infrastructure { constructor () { super('Houses', 'Provides room to house 10 followers.'); - this.cost.money = 150000; - this._baseMax = 0; - this._costMultiplier.money = 1.1; + this.cost.money = 75000; + this._costMultiplier.money = 1.01; } public max (state: GameState): number { - let max: number = this._baseMax; - max += state.getResource('cmpnd').value * 2; - return max; + return state.getResource('cmpnd').value * 2; } public isUnlocked (state: GameState): boolean { diff --git a/src/model/resource/PlayerOrg.ts b/src/model/resource/PlayerOrg.ts index 10b9971..50bce33 100644 --- a/src/model/resource/PlayerOrg.ts +++ b/src/model/resource/PlayerOrg.ts @@ -52,6 +52,7 @@ class PlayerOrg implements IResource { return; } + this._lastRecruitmentLog = 0; // always log on click this.addValue(1, state); } diff --git a/src/model/resource/Tent.ts b/src/model/resource/Tent.ts index a59e027..1c970fd 100644 --- a/src/model/resource/Tent.ts +++ b/src/model/resource/Tent.ts @@ -10,6 +10,7 @@ class Tent extends Infrastructure { } public max (state: GameState): number { + // ten extra tents per compound let max: number = this._baseMax; max += state.getResource('cmpnd').value * 10; return max; diff --git a/src/render/DebugRenderer.ts b/src/render/DebugRenderer.ts index f213202..fcdfd04 100644 --- a/src/render/DebugRenderer.ts +++ b/src/render/DebugRenderer.ts @@ -75,14 +75,26 @@ class DebugRenderer implements IRenderer { state.performClick(rkey)); } } + // create tools footer + const footer: HTMLElement = document.createElement('div'); + footer.className = 'footer'; + footer.innerHTML = ` + + `; + resDiv.appendChild(footer); + document.getElementById('dbg-btn-reset') + .addEventListener('click', (): void => { + state.reset(); + this._handleClick = true; + }); } for (const rkey of rkeys) { const resource: IResource = state.getResource(rkey); const container: HTMLElement = document .getElementById(`resource-container-${resource.resourceType}`); + const el: HTMLElement = document + .getElementById(`resource-details-${rkey}`); if (resource.isUnlocked(state)) { - const el: HTMLElement = document - .getElementById(`resource-details-${rkey}`); if (el.className !== 'resource') el.className = 'resource'; const elV: Element = el.getElementsByClassName('resource-value')[0]; @@ -105,19 +117,22 @@ class DebugRenderer implements IRenderer { if (enabled) elB[0].removeAttribute('disabled'); else elB[0].setAttribute('disabled', 'disabled'); } + if (resource.inc !== null && resource.inc(state) > 0) { + const elI: Element = + el.getElementsByClassName('resource-inc')[0]; + elI.innerHTML = + ` +${state.formatNumber(resource.inc(state))}/s`; + } if (this._handleClick) { - if (resource.inc !== null && resource.inc(state) > 0) { - const elI: Element = - el.getElementsByClassName('resource-inc')[0]; - elI.innerHTML = - ` +${state.formatNumber(resource.inc(state))}/s`; - } const elC: HTMLCollectionOf = el.getElementsByClassName('resource-cost'); if (elC.length > 0) { elC[0].innerHTML = this._getCostStr(resource, state); } } + } else { + if (el.className !== 'resource locked') + el.className = 'resource locked'; } } this._handleClick = false;