Skip to content

Commit a4cd758

Browse files
committed
change how upgrade conditions work and fix resetting save not working from 0.6 save transfer
1 parent 929ec1a commit a4cd758

File tree

5 files changed

+72
-55
lines changed

5 files changed

+72
-55
lines changed

src/ts/clickercookie.ts

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
161161
this.church.setVisibility(false);
162162

163163
// upgrades
164+
const keyboardBoughtFunc = () => {
165+
this.cookiesPerClick *= 2;
166+
this.UPGRADES_DATA["keyboard1"].building
167+
}
168+
164169
this.UPGRADES_DATA = {
165170
// keyboard
166171
"keyboard1": {
@@ -170,8 +175,8 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
170175
img: "img/upgrades/reinforced-keys.png",
171176
desc: defaultUpgradeDescriptions.keyboard,
172177
building: this.keyboard,
173-
buildingsRequired: 1,
174-
multiplyCookiesPerClick: true
178+
condition() { return (this.building.bought >= 1) ? true : false },
179+
bought: keyboardBoughtFunc
175180
},
176181
"keyboard2": {
177182
name: "Obsidian Keys",
@@ -180,8 +185,8 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
180185
img: "img/upgrades/obsidian-keys.png",
181186
desc: defaultUpgradeDescriptions.keyboard,
182187
building: this.keyboard,
183-
buildingsRequired: 5,
184-
multiplyCookiesPerClick: true
188+
condition() { return (this.building.bought >= 5) ? true : false },
189+
bought: keyboardBoughtFunc
185190
},
186191
"keyboard3": {
187192
name: "Osmium Keys",
@@ -190,8 +195,8 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
190195
img: "img/upgrades/osmium-keys.png",
191196
desc: defaultUpgradeDescriptions.keyboard,
192197
building: this.keyboard,
193-
buildingsRequired: 10,
194-
multiplyCookiesPerClick: true
198+
condition() { return (this.building.bought >= 10) ? true : false },
199+
bought: keyboardBoughtFunc
195200
},
196201
"keyboard4": {
197202
name: "10 finger typing",
@@ -200,8 +205,8 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
200205
img: "img/upgrades/10-finger-typing.png",
201206
desc: defaultUpgradeDescriptions.keyboard,
202207
building: this.keyboard,
203-
buildingsRequired: 25,
204-
multiplyCookiesPerClick: true
208+
condition() { return (this.building.bought >= 25) ? true : false },
209+
bought: keyboardBoughtFunc
205210
},
206211
"keyboard5": {
207212
name: "Macros",
@@ -210,8 +215,8 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
210215
img: "img/upgrades/macros.png",
211216
desc: defaultUpgradeDescriptions.keyboard,
212217
building: this.keyboard,
213-
buildingsRequired: 50,
214-
multiplyCookiesPerClick: true
218+
condition() { return (this.building.bought >= 50) ? true : false },
219+
bought: keyboardBoughtFunc
215220
},
216221
// grandpa
217222
"grandpa1": {
@@ -221,7 +226,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
221226
img: "img/upgrades/hardwood-walking-stick.png",
222227
desc: defaultUpgradeDescriptions.grandpa,
223228
building: this.grandpa,
224-
buildingsRequired: 1
229+
condition() { return this.building.bought >= 1 ? true : false }
225230
},
226231
"grandpa2": {
227232
name: "Rocking Chair",
@@ -230,7 +235,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
230235
img: "img/upgrades/rocking-chair.png",
231236
desc: defaultUpgradeDescriptions.grandpa,
232237
building: this.grandpa,
233-
buildingsRequired: 5
238+
condition() { return this.building.bought >= 5 ? true : false }
234239
},
235240
"grandpa3": {
236241
name: "Reading Glasses",
@@ -239,7 +244,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
239244
img: "img/upgrades/reading-glasses.png",
240245
desc: defaultUpgradeDescriptions.grandpa,
241246
building: this.grandpa,
242-
buildingsRequired: 10
247+
condition() { return this.building.bought >= 10 ? true : false }
243248
},
244249
"grandpa4": {
245250
name: "Dementia Pills",
@@ -248,7 +253,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
248253
img: "img/upgrades/dementia-pills.png",
249254
desc: defaultUpgradeDescriptions.grandpa,
250255
building: this.grandpa,
251-
buildingsRequired: 25
256+
condition() { return this.building.bought >= 25 ? true : false }
252257
},
253258
"grandpa5": {
254259
name: "shotgun",
@@ -257,7 +262,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
257262
img: "img/upgrades/shotgun.png",
258263
desc: defaultUpgradeDescriptions.grandpa,
259264
building: this.grandpa,
260-
buildingsRequired: 50
265+
condition() { return this.building.bought >= 50 ? true : false }
261266
},
262267
// ranch
263268
"ranch1": {
@@ -267,7 +272,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
267272
img: "img/upgrades/pig-slop.png",
268273
desc: defaultUpgradeDescriptions.ranch,
269274
building: this.ranch,
270-
buildingsRequired: 1
275+
condition() { return this.building.bought >= 1 ? true : false}
271276
},
272277
"ranch2": {
273278
name: "Needle bale",
@@ -276,7 +281,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
276281
img: "img/upgrades/needle-bale.png",
277282
desc: defaultUpgradeDescriptions.ranch,
278283
building: this.ranch,
279-
buildingsRequired: 5
284+
condition() { return this.building.bought >= 5 ? true : false}
280285
},
281286
"ranch3": {
282287
name: "Tractors",
@@ -285,7 +290,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
285290
img: "img/upgrades/tractors.png",
286291
desc: defaultUpgradeDescriptions.ranch,
287292
building: this.ranch,
288-
buildingsRequired: 10
293+
condition() { return this.building.bought >= 10 ? true : false}
289294
},
290295
"ranch4": {
291296
name: "Big baconator",
@@ -294,7 +299,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
294299
img: "img/upgrades/big-baconator.png",
295300
desc: defaultUpgradeDescriptions.ranch,
296301
building: this.ranch,
297-
buildingsRequired: 25
302+
condition() { return this.building.bought >= 25 ? true : false}
298303
},
299304
"ranch5": {
300305
name: "Ranch dressing",
@@ -303,7 +308,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
303308
img: "img/upgrades/ranch-dressing.png",
304309
desc: defaultUpgradeDescriptions.ranch,
305310
building: this.ranch,
306-
buildingsRequired: 50
311+
condition() { return this.building.bought >= 50 ? true : false}
307312
},
308313
// television
309314
"television1": {
@@ -313,7 +318,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
313318
img: "img/upgrades/streaming-service.png",
314319
desc: defaultUpgradeDescriptions.television,
315320
building: this.television,
316-
buildingsRequired: 1
321+
condition() { return this.building.bought >= 1 ? true : false}
317322
},
318323
"television2": {
319324
name: "98-inch screen",
@@ -322,7 +327,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
322327
img: "img/upgrades/98-inch-screen.png",
323328
desc: defaultUpgradeDescriptions.television,
324329
building: this.television,
325-
buildingsRequired: 5
330+
condition() { return this.building.bought >= 5 ? true : false}
326331
},
327332
"television3": {
328333
name: "Surround sound",
@@ -331,7 +336,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
331336
img: "img/upgrades/surround-sound.png",
332337
desc: defaultUpgradeDescriptions.television,
333338
building: this.television,
334-
buildingsRequired: 10
339+
condition() { return this.building.bought >= 10 ? true : false}
335340
},
336341
"television4": {
337342
name: "OLED Display",
@@ -340,7 +345,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
340345
img: "img/upgrades/oled-display.png",
341346
desc: defaultUpgradeDescriptions.television,
342347
building: this.television,
343-
buildingsRequired: 25
348+
condition() { return this.building.bought >= 25 ? true : false}
344349
},
345350
"television5": {
346351
name: "8K resolution",
@@ -349,7 +354,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
349354
img: "img/upgrades/8k-resolution.png",
350355
desc: defaultUpgradeDescriptions.television,
351356
building: this.television,
352-
buildingsRequired: 50
357+
condition() { return this.building.bought >= 50 ? true : false}
353358
},
354359
// worker
355360
"worker1": {
@@ -359,7 +364,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
359364
img: "img/upgrades/medkits.png",
360365
desc: defaultUpgradeDescriptions.worker,
361366
building: this.worker,
362-
buildingsRequired: 1
367+
condition() { return this.building.bought >= 1 ? true : false}
363368
},
364369
"worker2": {
365370
name: "Hard hats",
@@ -368,7 +373,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
368373
img: "img/upgrades/hard-hats.png",
369374
desc: defaultUpgradeDescriptions.worker,
370375
building: this.worker,
371-
buildingsRequired: 5
376+
condition() { return this.building.bought >= 5 ? true : false}
372377
},
373378
"worker3": {
374379
name: "Fast fingers*",
@@ -377,7 +382,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
377382
img: "img/upgrades/fast-fingers.png",
378383
desc: defaultUpgradeDescriptions.worker,
379384
building: this.worker,
380-
buildingsRequired: 10
385+
condition() { return this.building.bought >= 10 ? true : false}
381386
},
382387
"worker4": {
383388
name: "Weight training",
@@ -386,7 +391,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
386391
img: "img/upgrades/weight-training.png",
387392
desc: defaultUpgradeDescriptions.worker,
388393
building: this.worker,
389-
buildingsRequired: 25
394+
condition() { return this.building.bought >= 25 ? true : false}
390395
},
391396
"worker5": {
392397
name: "Robot workers",
@@ -395,7 +400,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
395400
img: "img/upgrades/robot-workers.png",
396401
desc: defaultUpgradeDescriptions.worker,
397402
building: this.worker,
398-
buildingsRequired: 50
403+
condition() { return this.building.bought >= 50 ? true : false}
399404
},
400405
// wallet
401406
"wallet1": {
@@ -405,7 +410,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
405410
img: "img/upgrades/200-dollar-bills.png",
406411
desc: defaultUpgradeDescriptions.wallet,
407412
building: this.wallet,
408-
buildingsRequired: 1
413+
condition() { return this.building.bought >= 1 ? true : false}
409414
},
410415
"wallet2": {
411416
name: "Credit cards",
@@ -414,7 +419,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
414419
img: "img/upgrades/credit-cards.png",
415420
desc: defaultUpgradeDescriptions.wallet,
416421
building: this.wallet,
417-
buildingsRequired: 5
422+
condition() { return this.building.bought >= 5 ? true : false}
418423
},
419424
"wallet3": {
420425
name: "Tax refund",
@@ -423,7 +428,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
423428
img: "img/upgrades/tax-refund.png",
424429
desc: defaultUpgradeDescriptions.wallet,
425430
building: this.wallet,
426-
buildingsRequired: 10
431+
condition() { return this.building.bought >= 10 ? true : false}
427432
},
428433
"wallet4": {
429434
name: "safe",
@@ -432,7 +437,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
432437
img: "img/upgrades/safe.png",
433438
desc: defaultUpgradeDescriptions.wallet,
434439
building: this.wallet,
435-
buildingsRequired: 25
440+
condition() { return this.building.bought >= 25 ? true : false}
436441
},
437442
"wallet5": {
438443
name: "Wizard\'s wallet",
@@ -441,7 +446,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
441446
img: "img/upgrades/wizards-wallet.png",
442447
desc: defaultUpgradeDescriptions.wallet,
443448
building: this.wallet,
444-
buildingsRequired: 50
449+
condition() { return this.building.bought >= 50 ? true : false}
445450
},
446451
// church
447452
"church1": {
@@ -451,7 +456,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
451456
img: "img/upgrades/the-pope.png",
452457
desc: defaultUpgradeDescriptions.church,
453458
building: this.church,
454-
buildingsRequired: 1
459+
condition() { return this.building.bought >= 1 ? true : false}
455460
},
456461
"church2": {
457462
name: "Cookie study",
@@ -460,7 +465,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
460465
img: "img/upgrades/cookie-study.png",
461466
desc: defaultUpgradeDescriptions.church,
462467
building: this.church,
463-
buildingsRequired: 5
468+
condition() { return this.building.bought >= 5 ? true : false}
464469
},
465470
"church3": {
466471
name: "Cookie ritual",
@@ -469,7 +474,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
469474
img: "img/upgrades/cookie-ritual.png",
470475
desc: defaultUpgradeDescriptions.church,
471476
building: this.church,
472-
buildingsRequired: 10
477+
condition() { return this.building.bought >= 10 ? true : false}
473478
},
474479
"church4": {
475480
name: "Cookie gods",
@@ -478,7 +483,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
478483
img: "img/upgrades/cookie-gods.png",
479484
desc: defaultUpgradeDescriptions.church,
480485
building: this.church,
481-
buildingsRequired: 25
486+
condition() { return this.building.bought >= 25 ? true : false}
482487
},
483488
"church5": {
484489
name: "Cible",
@@ -487,7 +492,7 @@ export default class ClickerCookie extends Mod<ClickerCookieSaveData> {
487492
img: "img/upgrades/cible.png",
488493
desc: defaultUpgradeDescriptions.church,
489494
building: this.church,
490-
buildingsRequired: 50
495+
condition() { return this.building.bought >= 50 ? true : false}
491496
}
492497
};
493498

src/ts/exmod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class NewMod extends Mod<ModSave> {
3838
price: 69,
3939
desc: "multiplies stuff and stuff",
4040
building: this.banana,
41-
buildingsRequired: 3,
41+
condition() { return (this.building.bought >= 3) ? true : false },
4242
img: "https://cdn.modrinth.com/data/AANobbMI/295862f4724dc3f78df3447ad6072b2dcd3ef0c9_96.webp" // lol
4343
}
4444
};

src/ts/handlers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export class UpgradeHandler extends Handler<Upgrade> {
207207
*/
208208
checkUpgradeAvailability() {
209209
for (const value of this) {
210-
if (value.building.bought >= value.buildingsRequired && value.unlocked === false) {
210+
if (value.condition(Game.getInstance()) && value.unlocked === false) {
211211
value.setVisibility(true);
212212
value.unlocked = true;
213213
}

src/ts/main.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,9 @@ export class Game implements SaveProvider<GameSaveData> {
200200
// 0.6 save
201201
// todo: needs to be thoroughly playtested
202202
// todo: do these need to be nested or was this just 11:00 programming moment and i wasn't thinking
203-
if (typeof JSON.parse(localStorage.getItem(this.savinator5000.currentSaveName)) === "object") {
204-
if (JSON.parse(localStorage.getItem(this.savinator5000.currentSaveName))["core.cookies"]) {
203+
const parsedCurrentSave = JSON.parse(localStorage.getItem(this.savinator5000.currentSaveName));
204+
if (typeof parsedCurrentSave === "object" && parsedCurrentSave !== null) {
205+
if (parsedCurrentSave["core.cookies"]) {
205206
console.log("0.6 save detected, prompting user to transfer save.")
206207
new SimplePopup({
207208
x: 400,

0 commit comments

Comments
 (0)