Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 71af5f8

Browse files
PseudonianKhafraDev
authored andcommittedNov 6, 2024·
Change prototype name, fix loading live saves
1 parent f7596b8 commit 71af5f8

9 files changed

+75
-31
lines changed
 

‎src/Corruptions.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -354,18 +354,18 @@ export const corruptionDisplay = (corr: keyof Corruptions | 'exit') => {
354354
} satisfies Record<string, string>
355355

356356
if (corr !== 'exit') {
357-
console.log(player.corruptions.prototype.scoreMult(corr))
357+
console.log(player.corruptions.next.scoreMult(corr))
358358
text = {
359359
name: i18next.t(`corruptions.names.${corr}`),
360360
description: i18next.t(`corruptions.descriptions.${corr}`),
361361
current: i18next.t(`corruptions.currentLevel.${corr}`, {level: player.corruptions.used.getLevel(corr), effect: player.corruptions.used.corruptionEffects(corr)}),
362-
planned: i18next.t(`corruptions.prototypeLevel.${corr}`, {level: player.corruptions.prototype.getLevel(corr), effect: player.corruptions.prototype.corruptionEffects(corr)}),
363-
multiplier: i18next.t('corruptions.scoreMultiplier', {curr: player.corruptions.used.scoreMult(corr), next: player.corruptions.prototype.scoreMult(corr)}),
362+
planned: i18next.t(`corruptions.prototypeLevel.${corr}`, {level: player.corruptions.next.getLevel(corr), effect: player.corruptions.next.corruptionEffects(corr)}),
363+
multiplier: i18next.t('corruptions.scoreMultiplier', {curr: player.corruptions.used.scoreMult(corr), next: player.corruptions.next.scoreMult(corr)}),
364364
spiritContribution: i18next.t('corruptions.spiritEffect', {curr: 1, next: 1}),
365365
image: `Pictures/${IconSets[player.iconSet][0]}${corrIcons[corr]}`
366366
}
367367
DOMCacheGetOrSet(`corrCurrent${corr}`).textContent = format(player.corruptions.used.getLevel(corr))
368-
DOMCacheGetOrSet(`corrNext${corr}`).textContent = format(player.corruptions.prototype.getLevel(corr))
368+
DOMCacheGetOrSet(`corrNext${corr}`).textContent = format(player.corruptions.next.getLevel(corr))
369369
}
370370

371371
DOMCacheGetOrSet('corruptionName').textContent = text.name
@@ -385,7 +385,7 @@ export const corruptionStatsUpdate = () => {
385385
const a = DOMCacheGetOrSet(`corrCurrent${corrKey}`)
386386
const b = DOMCacheGetOrSet(`corrNext${corrKey}`)
387387
a.textContent = format(player.corruptions.used.getLevel(corrKey))
388-
b.textContent = format(player.corruptions.prototype.getLevel(corrKey))
388+
b.textContent = format(player.corruptions.next.getLevel(corrKey))
389389
}
390390

391391
}
@@ -417,7 +417,7 @@ export const corruptionButtonsAdd = () => {
417417

418418
span = document.createElement('span')
419419
span.id = `corrNext${key}`
420-
span.textContent = `${player.corruptions.prototype.getLevel(key)}`
420+
span.textContent = `${player.corruptions.next.getLevel(key)}`
421421
p.appendChild(span)
422422
row.appendChild(p)
423423

@@ -452,7 +452,7 @@ export const corruptionButtonsAdd = () => {
452452
export const corruptionLoadoutTableCreate = () => {
453453
const table = getElementById<HTMLTableElement>('corruptionLoadoutTable')
454454

455-
const corrNext = player.corruptions.prototype.getLoadout()
455+
const corrNext = player.corruptions.next.getLoadout()
456456
const corrSaves = player.corruptions.saves.getSaves()
457457

458458
// Delete rows that already exist
@@ -493,7 +493,7 @@ export const corruptionLoadoutTableCreate = () => {
493493
const zeroBtn = document.createElement('button')
494494
zeroBtn.className = 'corrLoad'
495495
zeroBtn.textContent = i18next.t('corruptions.loadoutTable.zero')
496-
zeroBtn.addEventListener('click', () => player.corruptions.prototype.resetCorruptions())
496+
zeroBtn.addEventListener('click', () => player.corruptions.next.resetCorruptions())
497497
zeroCell.appendChild(zeroBtn)
498498
zeroCell.title = i18next.t('corruptions.loadoutTable.zeroTitle')
499499

@@ -531,10 +531,10 @@ export const corruptionLoadoutTableCreate = () => {
531531
}
532532
}
533533

534-
export const corruptionLoadoutTableUpdate = (updatePrototype = false, updateRow = 0) => {
534+
export const corruptionLoadoutTableUpdate = (updateNext = false, updateRow = 0) => {
535535
const row = getElementById<HTMLTableElement>('corruptionLoadoutTable').rows[updateRow + 1].cells
536-
if (updatePrototype) {
537-
const corrNext = player.corruptions.prototype.getLoadout()
536+
if (updateNext) {
537+
const corrNext = player.corruptions.next.getLoadout()
538538
let index = 0
539539
for (const corr in corrNext) {
540540
const corrKey = corr as keyof Corruptions
@@ -554,14 +554,14 @@ export const corruptionLoadoutTableUpdate = (updatePrototype = false, updateRow
554554
}
555555

556556
export const corruptionSaveLoadout = (loadoutNum: number) => {
557-
const buildToSave = player.corruptions.prototype.getLoadout()
557+
const buildToSave = player.corruptions.next.getLoadout()
558558
player.corruptions.saves.getSaves()[loadoutNum].loadout.setCorruptionLevels(buildToSave)
559559
corruptionLoadoutTableUpdate(false, loadoutNum + 1)
560560
}
561561

562562
export const corruptionLoadLoadout = (loadoutNum: number) => {
563563
const buildToLoad = player.corruptions.saves.getSaves()[loadoutNum].loadout.getLoadout()
564-
player.corruptions.prototype.setCorruptionLevels(buildToLoad)
564+
player.corruptions.next.setCorruptionLevels(buildToLoad)
565565
corruptionLoadoutTableUpdate(true)
566566
corruptionStatsUpdate()
567567
}
@@ -582,7 +582,7 @@ export const applyCorruptions = (corruptions: string) => {
582582
}
583583

584584
if (corr) {
585-
player.corruptions.prototype.setCorruptionLevels(corr)
585+
player.corruptions.next.setCorruptionLevels(corr)
586586
corruptionLoadoutTableUpdate(true, 0)
587587
corruptionStatsUpdate()
588588
return true
@@ -635,7 +635,7 @@ export const updateCorruptionLoadoutNames = () => {
635635
}
636636

637637
const corruptionLoadoutGetExport = async () => {
638-
const str = JSON.stringify(player.corruptions.prototype.getLoadout())
638+
const str = JSON.stringify(player.corruptions.next.getLoadout())
639639
if ('clipboard' in navigator) {
640640
await navigator.clipboard.writeText(str)
641641
.catch((e: Error) => Alert(i18next.t('corruptions.loadoutExport.saveErrorNavigator', { message: e.message })))

‎src/History.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Decimal from 'break_infinity.js'
33
import i18next from 'i18next'
44
import { antSacrificePointsToMultiplier } from './Ants'
55
import { DOMCacheGetOrSet } from './Cache/DOM'
6-
import { applyCorruptions, convertInputToCorruption, Corruptions } from './Corruptions'
6+
import { applyCorruptions, convertInputToCorruption, type Corruptions } from './Corruptions'
77
import { Synergism } from './Events'
88
import { format, formatTimeShort, player } from './Synergism'
99
import { IconSets } from './Themes'
@@ -546,7 +546,6 @@ const resetHistoryFormatCorruptions = (data: ResetHistoryEntryAscend): [string,
546546
let corrToLoad: Corruptions
547547
// Support old format (which is bad)
548548
if (Array.isArray(data.usedCorruptions)) {
549-
console.log('old data: '+ data.usedCorruptions)
550549
corrToLoad = convertInputToCorruption(data.usedCorruptions.slice(2, 10))
551550
}
552551
else {

‎src/Reset.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,6 @@ const resetAddHistoryEntry = (input: resetNames, from = 'unknown') => {
309309
kind: 'ascend'
310310
}
311311

312-
console.log('historyEntry: ' + historyEntry.usedCorruptions)
313-
314312
// If we are _leaving_ an ascension challenge, log that too.
315313
if (from !== 'enterChallenge' && player.currentChallenge.ascension !== 0) {
316314
historyEntry.currentChallenge = player.currentChallenge.ascension
@@ -733,7 +731,7 @@ export const reset = (input: resetNames, fast = false, from = 'unknown') => {
733731
}
734732

735733
if (player.currentChallenge.ascension !== 15) {
736-
player.corruptions.used.setCorruptionLevelsWithChallengeRequirement(player.corruptions.prototype.getLoadout())
734+
player.corruptions.used.setCorruptionLevelsWithChallengeRequirement(player.corruptions.next.getLoadout())
737735
}
738736
else {
739737
player.corruptions.used.setCorruptionLevelsWithChallengeRequirement(c15Corruptions)

‎src/Synergism.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ import { pixelData, PixelUpgrade } from './PixelUpgrades'
161161
import { updatePlatonicUpgradeBG } from './Platonic'
162162
import { getQuarkBonus, QuarkHandler } from './Quark'
163163
import { playerJsonSchema } from './saves/PlayerJsonSchema'
164-
import { playerSchema } from './saves/PlayerSchema'
165164
import { getFastForwardTotalMultiplier, singularityData, SingularityUpgrade } from './singularity'
166165
import { SingularityChallenge, singularityChallengeData } from './SingularityChallenges'
167166
import {
@@ -178,6 +177,7 @@ import { changeSubTab, changeTab, Tabs } from './Tabs'
178177
import { settingAnnotation, toggleIconSet, toggleTheme } from './Themes'
179178
import { clearTimeout, clearTimers, setInterval, setTimeout } from './Timers'
180179
import type { PlayerSave } from './types/LegacySynergism'
180+
import { playerUpdateVarSchema } from './saves/PlayerUpdateVarSchema'
181181

182182
export const player: Player = {
183183
firstPlayed: new Date().toISOString(),
@@ -863,7 +863,7 @@ export const player: Player = {
863863
},
864864

865865
corruptions: {
866-
prototype: new CorruptionLoadout({}),
866+
next: new CorruptionLoadout({}),
867867
used: new CorruptionLoadout({}),
868868
saves: new CorruptionSaves({
869869
'Loadout 1': {},
@@ -1739,7 +1739,7 @@ const loadSynergy = async () => {
17391739
})
17401740
}
17411741

1742-
const validatedPlayer = playerSchema.safeParse(data)
1742+
const validatedPlayer = playerUpdateVarSchema.safeParse(data)
17431743

17441744
if (validatedPlayer.success) {
17451745
Object.assign(player, validatedPlayer.data)
@@ -2392,7 +2392,7 @@ const loadSynergy = async () => {
23922392
updateCorruptionLoadoutNames()
23932393

23942394
player.corruptions.used.setCorruptionLevelsWithChallengeRequirement(player.corruptions.used.getLoadout())
2395-
player.corruptions.prototype.setCorruptionLevelsWithChallengeRequirement(player.corruptions.prototype.getLoadout())
2395+
player.corruptions.next.setCorruptionLevelsWithChallengeRequirement(player.corruptions.next.getLoadout())
23962396

23972397
DOMCacheGetOrSet('researchrunebonus').textContent = i18next.t(
23982398
'runes.thanksResearches',
@@ -6213,7 +6213,7 @@ export const synergismHotkeys = (event: KeyboardEvent, key: string): void => {
62136213
if (player.toggles[41]) {
62146214
void Notification(i18next.t('main.allCorruptionsZero'), 5000)
62156215
}
6216-
player.corruptions.prototype.resetCorruptions()
6216+
player.corruptions.next.resetCorruptions()
62176217
}
62186218
event.preventDefault()
62196219
}

‎src/Toggles.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ export const toggleCorruptionLevel = (corr: keyof Corruptions, value: number, re
950950

951951
if (reset && player.currentChallenge.ascension !== 15) {
952952
player.corruptions.used.resetCorruptions()
953-
player.corruptions.prototype.resetCorruptions()
953+
player.corruptions.next.resetCorruptions()
954954

955955
corruptionDisplay(G.corruptionTrigger)
956956
DOMCacheGetOrSet('corruptionCleanseConfirm').style.visibility = 'hidden'
@@ -961,7 +961,7 @@ export const toggleCorruptionLevel = (corr: keyof Corruptions, value: number, re
961961
return
962962
}
963963

964-
player.corruptions.prototype.incrementDecrementLevel(corr, value)
964+
player.corruptions.next.incrementDecrementLevel(corr, value)
965965
corruptionDisplay(corr)
966966
corruptionLoadoutTableUpdate(true, 0)
967967
}

‎src/saves/PlayerJsonSchema.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const playerJsonSchema = playerSchema.extend({
2727
corruptions: z.any().transform((stuff: Player['corruptions']) => {
2828
return {
2929
used: stuff.used.getLoadout(),
30-
prototype: stuff.prototype.getLoadout(),
30+
next: stuff.next.getLoadout(),
3131
saves: Object.fromEntries(
3232
stuff.saves.getSaves().map((save) => {
3333
return [save.name, save.loadout.getLoadout()]
@@ -122,7 +122,7 @@ export const playerJsonSchema = playerSchema.extend({
122122

123123
if (player.prototypeCorruptions !== undefined) {
124124
const corrLoadout = convertArrayToCorruption(player.prototypeCorruptions)
125-
player.corruptions.prototype = corrLoadout
125+
player.corruptions.next = corrLoadout
126126
}
127127

128128
if (player.corruptionShowStats !== undefined) {

‎src/saves/PlayerSchema.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ export const playerSchema = z.object({
522522
used: optionalCorruptionSchema.transform((value) => {
523523
return new CorruptionLoadout(value)
524524
}),
525-
prototype: optionalCorruptionSchema.transform((value) => {
525+
next: optionalCorruptionSchema.transform((value) => {
526526
console.log(Object.values(value))
527527
return new CorruptionLoadout(value)
528528
}),

‎src/saves/PlayerUpdateVarSchema.ts

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { CorruptionLoadout, type Corruptions, CorruptionSaves } from "../Corruptions";
2+
import { playerSchema } from "./PlayerSchema";
3+
4+
const convertArrayToCorruption = (array: number[]): Corruptions => {
5+
return {
6+
viscosity: array[2],
7+
dilation: array[3],
8+
hyperchallenge: array[4],
9+
illiteracy: array[5],
10+
deflation: array[6],
11+
extinction: array[7],
12+
drought: array[8],
13+
recession: array[9],
14+
}
15+
}
16+
17+
export const playerUpdateVarSchema = playerSchema.transform((player) => {
18+
if (player.usedCorruptions !== undefined) {
19+
const corrLoadout = convertArrayToCorruption(player.usedCorruptions)
20+
player.corruptions.used = new CorruptionLoadout(corrLoadout)
21+
}
22+
23+
if (player.prototypeCorruptions !== undefined) {
24+
const corrLoadout = convertArrayToCorruption(player.prototypeCorruptions)
25+
player.corruptions.next = new CorruptionLoadout(corrLoadout)
26+
}
27+
28+
if (player.corruptionShowStats !== undefined) {
29+
player.corruptions.showStats = player.corruptionShowStats
30+
}
31+
32+
if (player.corruptionLoadouts !== undefined && player.corruptionLoadoutNames !== undefined) {
33+
const corruptionSaveStuff: { [key: string]: Corruptions } = player.corruptionLoadoutNames.reduce((map, key, index) => {
34+
map[key] = convertArrayToCorruption(player.corruptionLoadouts![index + 1])
35+
return map
36+
}, {} as Record<string, Corruptions>)
37+
38+
player.corruptions.saves = new CorruptionSaves(corruptionSaveStuff)
39+
}
40+
41+
player.usedCorruptions = undefined
42+
player.prototypeCorruptions = undefined
43+
player.corruptionLoadoutNames = undefined
44+
player.corruptionLoadouts = undefined
45+
46+
return player
47+
})

‎src/types/Synergism.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ export interface Player {
537537
ascStatToggles: Record<number, boolean>
538538

539539
corruptions: {
540-
prototype: CorruptionLoadout
540+
next: CorruptionLoadout
541541
used: CorruptionLoadout
542542
saves: CorruptionSaves
543543
showStats: boolean

0 commit comments

Comments
 (0)
Please sign in to comment.