Skip to content

Commit

Permalink
Fix History
Browse files Browse the repository at this point in the history
  • Loading branch information
Pseudonian committed Sep 26, 2024
1 parent e31a340 commit 33fec7c
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 38 deletions.
30 changes: 27 additions & 3 deletions src/Corruptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ import { Globals as G } from './Variables'
//export const corruptions = ['viscosity', 'drought', 'deflation', 'extinction', 'illiteracy', 'recession', 'dilation', 'hyperchallenge'] as const
//export type Corruptions = typeof corruptions[number]

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

export type Corruptions = {
viscosity: number,
drought: number,
Expand Down Expand Up @@ -554,12 +567,23 @@ export const corruptionLoadLoadout = (loadoutNum: number) => {
}

export const applyCorruptions = (corruptions: string) => {
let corr:Corruptions
if (!corruptions) {
return false
}

const corr = JSON.parse(corruptions) as Corruptions
console.log(corruptions)

if (corruptions.includes('/') && corruptions.split('/').length === 8) {
corr = convertInputToCorruption(corruptions.split('/').map(Number))
}
else {
corr = JSON.parse(corruptions) as Corruptions
}

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

const corruptionLoadoutGetExport = async () => {
const str = JSON.stringify(player.corruptions.used.getLoadout())
const str = JSON.stringify(player.corruptions.prototype.getLoadout())
if ('clipboard' in navigator) {
await navigator.clipboard.writeText(str)
.catch((e: Error) => Alert(i18next.t('corruptions.loadoutExport.saveErrorNavigator', { message: e.message })))
Expand Down
97 changes: 63 additions & 34 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 } from './Corruptions'
import { applyCorruptions, convertInputToCorruption, Corruptions } from './Corruptions'
import { Synergism } from './Events'
import { format, formatTimeShort, player } from './Synergism'
import { IconSets } from './Themes'
Expand Down Expand Up @@ -53,7 +53,7 @@ export type ResetHistoryEntryReincarnate = ResetHistoryEntryBase & {

export type ResetHistoryEntryAscend = ResetHistoryEntryBase & {
c10Completions: number
usedCorruptions: number[]
usedCorruptions: Corruptions | number[]
corruptionScore: number
wowCubes: number
wowTesseracts: number
Expand Down Expand Up @@ -321,28 +321,46 @@ const resetHistoryTableMapping: Record<Category, string> = {
singularity: 'historySingularityTable'
}

// Images associated with the various corruptions.
const resetHistoryCorruptionImages = [
'CorruptViscosity.png',
'CorruptDilation.png',
'CorruptHyperchallenge.png',
'CorruptIlliteracy.png',
'CorruptDeflation.png',
'CorruptExtinction.png',
'CorruptDrought.png',
'CorruptRecession.png'
]
type corruptionInfo = {
image: string,
title: string
}

const resetHistoryCorruptionTitles = [
'Viscosity [Accelerators and Multipliers]',
'Spacial Dilation [Time]',
'Hyperchallenged [Challenge Requirements]',
'Scientific Illiteracy [Obtainium]',
'Market Deflation [Diamonds]',
'Extinction [Ants]',
'Drought [Offering EXP]',
'Financial Recession [Coins]'
]
// Images associated with the various corruptions.
const resetHistoryCorruptionInfo: Record<keyof Corruptions, corruptionInfo> = {
viscosity: {
image: 'CorruptViscosity.png',
title: 'Viscosity [Accelerators and Multipliers]'
},
dilation: {
image: 'CorruptDilation.png',
title: 'Spacial Dilation [Time]',
},
hyperchallenge: {
image: 'CorruptHyperchallenge.png',
title: 'Hyperchallenge [Challenge Requirements'
},
illiteracy: {
image: 'CorruptIlliteracy.png',
title: 'Illiteracy [Obtainium]'
},
deflation: {
image: 'CorruptDeflation.png',
title: 'Market Deflation [Diamonds]'
},
extinction: {
image: 'CorruptExtinction.png',
title: 'Extinction [Ants]'
},
drought: {
image: 'CorruptDrought.png',
title: 'Drought [Offering EXP]',
},
recession: {
image: 'CorruptRecession.png',
title: 'Financial Recession [Coins]'
}
}

// A formatting aid that removes the mantissa from a formatted string. Converts "2.5e1000" to "e1000".
const extractStringExponent = (str: string) => {
Expand Down Expand Up @@ -442,7 +460,7 @@ const resetHistoryRenderRow = (
)

const corruptions = resetHistoryFormatCorruptions(data)

console.log(corruptions)
extra.push(corruptions[0])
extra.push(corruptions[1])
extra.push(corruptions[2])
Expand Down Expand Up @@ -525,21 +543,32 @@ const resetHistoryFormatCorruptions = (data: ResetHistoryEntryAscend): [string,
let corruptions = ''
let loadout = ''
let corrs = 0
for (let i = 0; i < resetHistoryCorruptionImages.length; ++i) {
const corruptionIdx = i + 2
if (corruptionIdx in data.usedCorruptions && data.usedCorruptions[corruptionIdx] !== 0) {
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 {
corrToLoad = data.usedCorruptions
}

for (const corruption in corrToLoad) {
const corrKey = corruption as keyof Corruptions
if (corrToLoad[corrKey] !== 0) {
corruptions += `<img alt="${corrs > 0 ? '/' : ''}" src="Pictures/${IconSets[player.iconSet][0]}/${
resetHistoryCorruptionImages[i]
}" title="${resetHistoryCorruptionTitles[i]}">${data.usedCorruptions[corruptionIdx]}`
} else {
corruptions += `<span>${corrs > 0 ? '/0' : '0'}</span>`
resetHistoryCorruptionInfo[corrKey].image
}" title="${resetHistoryCorruptionInfo[corrKey].title}">${corrToLoad[corrKey]}`
}
corrs++
}

const corr_str = JSON.stringify(corrToLoad)

if (corruptions) {
loadout += `<button class="corrLoad ascendHistoryLoadCorruptions" data-corr="${
data.usedCorruptions.join('/')
}">Load</button>`
loadout += `<button class="corrLoad ascendHistoryLoadCorruptions" data-corr='${
corr_str
}'>Load</button>`
}
if (data.currentChallenge !== undefined) {
score += ` / C${data.currentChallenge}`
Expand Down
4 changes: 3 additions & 1 deletion src/Reset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ const resetAddHistoryEntry = (input: resetNames, from = 'unknown') => {
seconds: player.ascensionCounter,
date: Date.now(),
c10Completions: player.challengecompletions[10],
usedCorruptions: Object.values(player.corruptions.used.getLoadout()),
usedCorruptions: player.corruptions.used.getLoadout(),
corruptionScore: corruptionMetaData[3],
wowCubes: corruptionMetaData[4],
wowTesseracts: corruptionMetaData[5],
Expand All @@ -309,6 +309,8 @@ 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

0 comments on commit 33fec7c

Please sign in to comment.