Skip to content

Commit c8a56e5

Browse files
committed
Make buildings owned be tied to BuildingHandler
1 parent 325278d commit c8a56e5

File tree

4 files changed

+10
-18
lines changed

4 files changed

+10
-18
lines changed

src/ts/clickercookie.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ export default class ClickerCookie extends Mod {
668668
document.getElementById("cookiesStat").innerText = `${Handlers.CURRENTLY_CLICKED.getCurrentlyClicked().namePlural}: ${makeSlightlyImperfectFloatNice(this.cookies)}`;
669669
document.getElementById("allTimeCookies").innerText = `All Time ${Handlers.CURRENTLY_CLICKED.getCurrentlyClicked().namePlural}: ${makeSlightlyImperfectFloatNice(this.totalCookies)}`;
670670
document.getElementById("cookiesPerSecondStat").innerText = `${Handlers.CURRENTLY_CLICKED.getCurrentlyClicked().namePlural} Per Second: ${makeSlightlyImperfectFloatNice(this.cookiesPerSecond)}`;
671-
document.getElementById("buildingsOwnedStat").innerText = `Buildings Owned: ${commaify(Game.getInstance().buildingsOwned)}`; // todo: should this be in Game? How should statistics actually work at all?
671+
document.getElementById("buildingsOwnedStat").innerText = `Buildings Owned: ${commaify(Handlers.BUILDING.buildingsOwned)}`; // todo: should this be in Game? How should statistics actually work at all?
672672
document.getElementById("cookieBeenClickedTimesStat").innerText = `Total ${Handlers.CURRENTLY_CLICKED.getCurrentlyClicked().name} Clicks: ${this.cookieBeenClickedTimes}`;
673673
document.getElementById("cookiesPerClickStat").innerText = `${Handlers.CURRENTLY_CLICKED.getCurrentlyClicked().namePlural} Per Click: ${this.cookiesPerClick}`;
674674
}

src/ts/handlers.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,15 @@ export class CurrentlyClickedHandler extends Handler<CurrentlyClickedObject> {
118118
}
119119

120120
/* Buildings*/
121-
export class BuildingHandler extends Handler<Building> {}
121+
export class BuildingHandler extends Handler<Building> {
122+
public get buildingsOwned(): number {
123+
let bought = 0;
124+
for (const value of this) {
125+
bought += value.bought;
126+
}
127+
return bought;
128+
}
129+
}
122130

123131
/* Upgrades */
124132
export class UpgradeHandler extends Handler<Upgrade> {

src/ts/helper.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ export class Interval {
131131
}
132132

133133
reset(newTimeout: number = this.timeout) {
134-
console.log(this.timeout);
135134
this.timeout = newTimeout;
136135
return this.stop().start();
137136
}

src/ts/main.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,6 @@ export class Game extends SaveProvider {
105105
/** Said to be the physical manifestation of the cookie gods themselves... */
106106
public clickercookie: ClickerCookie;
107107

108-
// buildings owned
109-
private _buildingsOwned: number = 0;
110-
public get buildingsOwned() { return this._buildingsOwned }
111-
public set buildingsOwned(num: number) {
112-
this._buildingsOwned = num;
113-
this.clickercookie.updateStatistics();
114-
}
115-
116108
// self-explainatory-ish things
117109
private _hasCheated: boolean;
118110
public get hasCheated() { return this._hasCheated }
@@ -333,13 +325,6 @@ export class Game extends SaveProvider {
333325
if (!this.theGameCanLoopBecauseTheInitializationIsCompleted) return;
334326

335327
Handlers.UPGRADE.checkUpgradeAvailability();
336-
337-
// stats that need to be updated beforehand
338-
let buildingsOwned = 0;
339-
for (const building of Handlers.BUILDING) {
340-
buildingsOwned += building.bought;
341-
}
342-
this.buildingsOwned = buildingsOwned;
343328

344329
let cps = 0;
345330
for (const building of Handlers.BUILDING) {

0 commit comments

Comments
 (0)