debug renderer improvements
This commit is contained in:
parent
3ada821430
commit
314806f647
|
@ -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;
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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.');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -52,6 +52,7 @@ class PlayerOrg implements IResource {
|
|||
return;
|
||||
}
|
||||
|
||||
this._lastRecruitmentLog = 0; // always log on click
|
||||
this.addValue(1, state);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 = `
|
||||
<button id='dbg-btn-reset'>Reset Game</button>
|
||||
`;
|
||||
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<Element> =
|
||||
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;
|
||||
|
|
Reference in New Issue