Skip to content

Commit

Permalink
Change prototype name, fix loading live saves
Browse files Browse the repository at this point in the history
  • Loading branch information
Pseudonian committed Sep 27, 2024
1 parent 33fec7c commit 27cc5ce
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 31 deletions.
30 changes: 15 additions & 15 deletions src/Corruptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,18 +354,18 @@ export const corruptionDisplay = (corr: keyof Corruptions | 'exit') => {
} satisfies Record<string, string>

if (corr !== 'exit') {
console.log(player.corruptions.prototype.scoreMult(corr))
console.log(player.corruptions.next.scoreMult(corr))
text = {
name: i18next.t(`corruptions.names.${corr}`),
description: i18next.t(`corruptions.descriptions.${corr}`),
current: i18next.t(`corruptions.currentLevel.${corr}`, {level: player.corruptions.used.getLevel(corr), effect: player.corruptions.used.corruptionEffects(corr)}),
planned: i18next.t(`corruptions.prototypeLevel.${corr}`, {level: player.corruptions.prototype.getLevel(corr), effect: player.corruptions.prototype.corruptionEffects(corr)}),
multiplier: i18next.t('corruptions.scoreMultiplier', {curr: player.corruptions.used.scoreMult(corr), next: player.corruptions.prototype.scoreMult(corr)}),
planned: i18next.t(`corruptions.prototypeLevel.${corr}`, {level: player.corruptions.next.getLevel(corr), effect: player.corruptions.next.corruptionEffects(corr)}),
multiplier: i18next.t('corruptions.scoreMultiplier', {curr: player.corruptions.used.scoreMult(corr), next: player.corruptions.next.scoreMult(corr)}),
spiritContribution: i18next.t('corruptions.spiritEffect', {curr: 1, next: 1}),
image: `Pictures/${IconSets[player.iconSet][0]}${corrIcons[corr]}`
}
DOMCacheGetOrSet(`corrCurrent${corr}`).textContent = format(player.corruptions.used.getLevel(corr))
DOMCacheGetOrSet(`corrNext${corr}`).textContent = format(player.corruptions.prototype.getLevel(corr))
DOMCacheGetOrSet(`corrNext${corr}`).textContent = format(player.corruptions.next.getLevel(corr))
}

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

}
Expand Down Expand Up @@ -417,7 +417,7 @@ export const corruptionButtonsAdd = () => {

span = document.createElement('span')
span.id = `corrNext${key}`
span.textContent = `${player.corruptions.prototype.getLevel(key)}`
span.textContent = `${player.corruptions.next.getLevel(key)}`
p.appendChild(span)
row.appendChild(p)

Expand Down Expand Up @@ -452,7 +452,7 @@ export const corruptionButtonsAdd = () => {
export const corruptionLoadoutTableCreate = () => {
const table = getElementById<HTMLTableElement>('corruptionLoadoutTable')

const corrNext = player.corruptions.prototype.getLoadout()
const corrNext = player.corruptions.next.getLoadout()
const corrSaves = player.corruptions.saves.getSaves()

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

Expand Down Expand Up @@ -531,10 +531,10 @@ export const corruptionLoadoutTableCreate = () => {
}
}

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

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

export const corruptionLoadLoadout = (loadoutNum: number) => {
const buildToLoad = player.corruptions.saves.getSaves()[loadoutNum].loadout.getLoadout()
player.corruptions.prototype.setCorruptionLevels(buildToLoad)
player.corruptions.next.setCorruptionLevels(buildToLoad)
corruptionLoadoutTableUpdate(true)
corruptionStatsUpdate()
}
Expand All @@ -582,7 +582,7 @@ export const applyCorruptions = (corruptions: string) => {
}

if (corr) {
player.corruptions.prototype.setCorruptionLevels(corr)
player.corruptions.next.setCorruptionLevels(corr)
corruptionLoadoutTableUpdate(true, 0)
corruptionStatsUpdate()
return true
Expand Down Expand Up @@ -635,7 +635,7 @@ export const updateCorruptionLoadoutNames = () => {
}

const corruptionLoadoutGetExport = async () => {
const str = JSON.stringify(player.corruptions.prototype.getLoadout())
const str = JSON.stringify(player.corruptions.next.getLoadout())
if ('clipboard' in navigator) {
await navigator.clipboard.writeText(str)
.catch((e: Error) => Alert(i18next.t('corruptions.loadoutExport.saveErrorNavigator', { message: e.message })))
Expand Down
3 changes: 1 addition & 2 deletions src/History.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Decimal from 'break_infinity.js'
import i18next from 'i18next'
import { antSacrificePointsToMultiplier } from './Ants'
import { DOMCacheGetOrSet } from './Cache/DOM'
import { applyCorruptions, convertInputToCorruption, Corruptions } from './Corruptions'
import { applyCorruptions, convertInputToCorruption, type Corruptions } from './Corruptions'
import { Synergism } from './Events'
import { format, formatTimeShort, player } from './Synergism'
import { IconSets } from './Themes'
Expand Down Expand Up @@ -546,7 +546,6 @@ const resetHistoryFormatCorruptions = (data: ResetHistoryEntryAscend): [string,
let corrToLoad: Corruptions
// Support old format (which is bad)
if (Array.isArray(data.usedCorruptions)) {
console.log('old data: '+ data.usedCorruptions)
corrToLoad = convertInputToCorruption(data.usedCorruptions.slice(2, 10))
}
else {
Expand Down
4 changes: 1 addition & 3 deletions src/Reset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,6 @@ const resetAddHistoryEntry = (input: resetNames, from = 'unknown') => {
kind: 'ascend'
}

console.log('historyEntry: ' + historyEntry.usedCorruptions)

// If we are _leaving_ an ascension challenge, log that too.
if (from !== 'enterChallenge' && player.currentChallenge.ascension !== 0) {
historyEntry.currentChallenge = player.currentChallenge.ascension
Expand Down Expand Up @@ -733,7 +731,7 @@ export const reset = (input: resetNames, fast = false, from = 'unknown') => {
}

if (player.currentChallenge.ascension !== 15) {
player.corruptions.used.setCorruptionLevelsWithChallengeRequirement(player.corruptions.prototype.getLoadout())
player.corruptions.used.setCorruptionLevelsWithChallengeRequirement(player.corruptions.next.getLoadout())
}
else {
player.corruptions.used.setCorruptionLevelsWithChallengeRequirement(c15Corruptions)
Expand Down
10 changes: 5 additions & 5 deletions src/Synergism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ import { pixelData, PixelUpgrade } from './PixelUpgrades'
import { updatePlatonicUpgradeBG } from './Platonic'
import { getQuarkBonus, QuarkHandler } from './Quark'
import { playerJsonSchema } from './saves/PlayerJsonSchema'
import { playerSchema } from './saves/PlayerSchema'
import { getFastForwardTotalMultiplier, singularityData, SingularityUpgrade } from './singularity'
import { SingularityChallenge, singularityChallengeData } from './SingularityChallenges'
import {
Expand All @@ -178,6 +177,7 @@ import { changeSubTab, changeTab, Tabs } from './Tabs'
import { settingAnnotation, toggleIconSet, toggleTheme } from './Themes'
import { clearTimeout, clearTimers, setInterval, setTimeout } from './Timers'
import type { PlayerSave } from './types/LegacySynergism'
import { playerUpdateVarSchema } from './saves/PlayerUpdateVarSchema'

export const player: Player = {
firstPlayed: new Date().toISOString(),
Expand Down Expand Up @@ -863,7 +863,7 @@ export const player: Player = {
},

corruptions: {
prototype: new CorruptionLoadout({}),
next: new CorruptionLoadout({}),
used: new CorruptionLoadout({}),
saves: new CorruptionSaves({
'Loadout 1': {},
Expand Down Expand Up @@ -1665,7 +1665,7 @@ const loadSynergy = async () => {
})
}

const validatedPlayer = playerSchema.safeParse(data)
const validatedPlayer = playerUpdateVarSchema.safeParse(data)

if (validatedPlayer.success) {
Object.assign(player, validatedPlayer.data)
Expand Down Expand Up @@ -2306,7 +2306,7 @@ const loadSynergy = async () => {
updateCorruptionLoadoutNames()

player.corruptions.used.setCorruptionLevelsWithChallengeRequirement(player.corruptions.used.getLoadout())
player.corruptions.prototype.setCorruptionLevelsWithChallengeRequirement(player.corruptions.prototype.getLoadout())
player.corruptions.next.setCorruptionLevelsWithChallengeRequirement(player.corruptions.next.getLoadout())

DOMCacheGetOrSet('researchrunebonus').textContent = i18next.t(
'runes.thanksResearches',
Expand Down Expand Up @@ -6127,7 +6127,7 @@ export const synergismHotkeys = (event: KeyboardEvent, key: string): void => {
if (player.toggles[41]) {
void Notification(i18next.t('main.allCorruptionsZero'), 5000)
}
player.corruptions.prototype.resetCorruptions()
player.corruptions.next.resetCorruptions()
}
event.preventDefault()
}
Expand Down
4 changes: 2 additions & 2 deletions src/Toggles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ export const toggleCorruptionLevel = (corr: keyof Corruptions, value: number, re

if (reset && player.currentChallenge.ascension !== 15) {
player.corruptions.used.resetCorruptions()
player.corruptions.prototype.resetCorruptions()
player.corruptions.next.resetCorruptions()

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

player.corruptions.prototype.incrementDecrementLevel(corr, value)
player.corruptions.next.incrementDecrementLevel(corr, value)
corruptionDisplay(corr)
corruptionLoadoutTableUpdate(true, 0)
}
Expand Down
4 changes: 2 additions & 2 deletions src/saves/PlayerJsonSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const playerJsonSchema = playerSchema.extend({
corruptions: z.any().transform((stuff: Player['corruptions']) => {
return {
used: stuff.used.getLoadout(),
prototype: stuff.prototype.getLoadout(),
next: stuff.next.getLoadout(),
saves: Object.fromEntries(
stuff.saves.getSaves().map((save) => {
return [save.name, save.loadout.getLoadout()]
Expand Down Expand Up @@ -122,7 +122,7 @@ export const playerJsonSchema = playerSchema.extend({

if (player.prototypeCorruptions !== undefined) {
const corrLoadout = convertArrayToCorruption(player.prototypeCorruptions)
player.corruptions.prototype = corrLoadout
player.corruptions.next = corrLoadout
}

if (player.corruptionShowStats !== undefined) {
Expand Down
2 changes: 1 addition & 1 deletion src/saves/PlayerSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ export const playerSchema = z.object({
used: optionalCorruptionSchema.transform((value) => {
return new CorruptionLoadout(value)
}),
prototype: optionalCorruptionSchema.transform((value) => {
next: optionalCorruptionSchema.transform((value) => {
console.log(Object.values(value))
return new CorruptionLoadout(value)
}),
Expand Down
47 changes: 47 additions & 0 deletions src/saves/PlayerUpdateVarSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { CorruptionLoadout, type Corruptions, CorruptionSaves } from "../Corruptions";
import { playerSchema } from "./PlayerSchema";

const convertArrayToCorruption = (array: number[]): Corruptions => {
return {
viscosity: array[2],
dilation: array[3],
hyperchallenge: array[4],
illiteracy: array[5],
deflation: array[6],
extinction: array[7],
drought: array[8],
recession: array[9],
}
}

export const playerUpdateVarSchema = playerSchema.transform((player) => {
if (player.usedCorruptions !== undefined) {
const corrLoadout = convertArrayToCorruption(player.usedCorruptions)
player.corruptions.used = new CorruptionLoadout(corrLoadout)
}

if (player.prototypeCorruptions !== undefined) {
const corrLoadout = convertArrayToCorruption(player.prototypeCorruptions)
player.corruptions.next = new CorruptionLoadout(corrLoadout)
}

if (player.corruptionShowStats !== undefined) {
player.corruptions.showStats = player.corruptionShowStats
}

if (player.corruptionLoadouts !== undefined && player.corruptionLoadoutNames !== undefined) {
const corruptionSaveStuff: { [key: string]: Corruptions } = player.corruptionLoadoutNames.reduce((map, key, index) => {
map[key] = convertArrayToCorruption(player.corruptionLoadouts![index + 1])
return map
}, {} as Record<string, Corruptions>)

player.corruptions.saves = new CorruptionSaves(corruptionSaveStuff)
}

player.usedCorruptions = undefined
player.prototypeCorruptions = undefined
player.corruptionLoadoutNames = undefined
player.corruptionLoadouts = undefined

return player
})
2 changes: 1 addition & 1 deletion src/types/Synergism.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ export interface Player {
ascStatToggles: Record<number, boolean>

corruptions: {
prototype: CorruptionLoadout
next: CorruptionLoadout
used: CorruptionLoadout
saves: CorruptionSaves
showStats: boolean
Expand Down

0 comments on commit 27cc5ce

Please sign in to comment.