Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rewrite saving/loading/importing saves #604

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "dist/bundle.js",
"dependencies": {
"@ungap/custom-elements": "^1.3.0",
"async-lock": "^1.4.1",
"break_infinity.js": "^2.0.0",
"clipboard": "^2.0.11",
"eventemitter3": "^4.0.7",
Expand All @@ -17,6 +18,7 @@
},
"devDependencies": {
"@biomejs/biome": "^1.4.1",
"@types/async-lock": "^1.4.2",
"@types/lodash.clonedeepwith": "^4.5.9",
"@types/lz-string": "^1.3.34",
"deep-object-diff": "^1.1.9",
Expand Down
3 changes: 2 additions & 1 deletion src/Calculate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import { hepteractEffective } from './Hepteracts'
import { disableHotkeys, enableHotkeys } from './Hotkeys'
import { quarkHandler } from './Quark'
import { reset } from './Reset'
import { saveSynergy } from './saves/Save'
import { calculateSingularityDebuff } from './singularity'
import { getFastForwardTotalMultiplier } from './singularity'
import { cacheReinitialize } from './StatCache'
import { format, getTimePinnedToLoadDate, player, resourceGain, saveSynergy, updateAll } from './Synergism'
import { format, getTimePinnedToLoadDate, player, resourceGain, updateAll } from './Synergism'
import { toggleTalismanBuy, updateTalismanInventory } from './Talismans'
import { clearInterval, setInterval } from './Timers'
import type { resetNames } from './types/Synergism'
Expand Down
3 changes: 2 additions & 1 deletion src/EventListeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ import { buyPlatonicUpgrades, createPlatonicDescription } from './Platonic'
import { buyResearch, researchDescriptions } from './Research'
import { resetrepeat, updateAutoCubesOpens, updateAutoReset, updateTesseractAutoBuyAmount } from './Reset'
import { displayRuneInformation, redeemShards } from './Runes'
import { saveSynergy } from './saves/Save'
import { buyShopUpgrades, resetShopUpgrades, shopData, shopDescriptions, shopUpgradeTypes, useConsumable } from './Shop'
import { buyGoldenQuarks, getLastUpgradeInfo, singularityPerks } from './singularity'
import { displayStats } from './Statistics'
import { generateExportSummary } from './Summary'
import { player, resetCheck, saveSynergy } from './Synergism'
import { player, resetCheck } from './Synergism'
import { changeSubTab, Tabs } from './Tabs'
import {
buyAllTalismanResources,
Expand Down
87 changes: 61 additions & 26 deletions src/ImportExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ import { testing, version } from './Config'
import { Synergism } from './Events'
import { addTimers } from './Helper'
import { quarkHandler } from './Quark'
import { saveLock } from './saves/Load'
import { playerJsonSchema } from './saves/PlayerJsonSchema'
import { playerSchema } from './saves/PlayerSchema'
import { saveSynergy } from './saves/Save'
import { shopData } from './Shop'
import { singularityData } from './singularity'
import { synergismStage } from './Statistics'
import { blankSave, format, player, reloadShit, saveCheck, saveSynergy } from './Synergism'
import { blankSave, format, player, reloadShit } from './Synergism'
import { changeSubTab, changeTab, Tabs } from './Tabs'
import type { Player } from './types/Synergism'
import { Alert, Confirm, Prompt } from './UpdateHTML'
import { cleanString, getElementById, productContents, sumContents } from './Utility'
import { assert, cleanString, getElementById, productContents, sumContents } from './Utility'
import { btoa } from './Utility'
import { Globals as G } from './Variables'

Expand Down Expand Up @@ -246,8 +248,9 @@ export const exportSynergism = async (
: 1
if (+player.singularityUpgrades.goldenQuarks3.getEffect().bonus > 0) {
player.goldenQuarks += Math.floor(
player.goldenQuarksTimer
/ (3600 / +player.singularityUpgrades.goldenQuarks3.getEffect().bonus)
player.goldenQuarksTimer / (
3600 / +player.singularityUpgrades.goldenQuarks3.getEffect().bonus
)
) * bonusGQMultiplier
player.goldenQuarksTimer = player.goldenQuarksTimer
% (3600 / +player.singularityUpgrades.goldenQuarks3.getEffect().bonus)
Expand Down Expand Up @@ -338,33 +341,47 @@ export const importData = async (

export const importSynergism = async (input: string | null, reset = false) => {
if (typeof input !== 'string') {
return Alert(i18next.t('importexport.unableImport'))
await Alert(i18next.t('importexport.unableImport'))
return
}

const d = LZString.decompressFromBase64(input)
const f = d ? (JSON.parse(d) as Player) : (JSON.parse(atob(input)) as Player)
let f: unknown

if (
f.exporttest === 'YES!'
|| f.exporttest === true
|| (f.exporttest === false && testing)
|| (f.exporttest === 'NO!' && testing)
) {
const saveString = btoa(JSON.stringify(f))
try {
f = d ? JSON.parse(d) : JSON.parse(atob(input))
} catch (e) {
await Alert(i18next.t('importexport.unableImport'))
return
}

const save = playerSchema.safeParse(f)

if (!save.success) {
console.log(save.error)
await Alert(i18next.t('importexport.unableImport'))
return
}

if (save.data.exporttest === true || (!save.data.exporttest && testing)) {
const { data: hold, success } = playerJsonSchema.safeParse(save.data)
assert(success)
const saveString = btoa(JSON.stringify(hold))

if (saveString === null) {
return Alert(i18next.t('importexport.unableImport'))
}

saveCheck.canSave = false
const item = new Blob([saveString], { type: 'text/plain' })
localStorage.setItem('Synergysave2', saveString)
await localforage.setItem<Blob>('Synergysave2', item)
await saveLock.acquire('load', async (done) => {
const item = new Blob([saveString], { type: 'text/plain' })
localStorage.setItem('Synergysave2', saveString)
await localforage.setItem<Blob>('Synergysave2', item)

localStorage.setItem('saveScumIsCheating', Date.now().toString())
localStorage.setItem('saveScumIsCheating', Date.now().toString())

await reloadShit(reset)
saveCheck.canSave = true
await reloadShit(reset)
done()
})
return
} else {
return Alert(i18next.t('importexport.loadTestInLive'))
Expand Down Expand Up @@ -620,13 +637,31 @@ export const promocodes = async (input: string | null, amount?: number) => {
}

if (player.highestSingularityCount >= 200 && player.highestSingularityCount < 205) {
const freeLevelOct1 = Math.max(player.octeractUpgrades.octeractGain.level / 100, Math.pow(player.octeractUpgrades.octeractGain.level * player.octeractUpgrades.octeractGain.freeLevels / 1000, 0.5))
const freeLevelOct1 = Math.max(
player.octeractUpgrades.octeractGain.level / 100,
Math.pow(
player.octeractUpgrades.octeractGain.level * player.octeractUpgrades.octeractGain.freeLevels / 1000,
0.5
)
)
player.octeractUpgrades.octeractGain.freeLevels += freeLevelOct1
freeLevels.octeractGain = freeLevelOct1
}
else if (player.highestSingularityCount >= 205) {
const freeLevelOct1 = Math.max(player.octeractUpgrades.octeractGain.level / 100, Math.pow(player.octeractUpgrades.octeractGain.level * player.octeractUpgrades.octeractGain.freeLevels / 640, 0.5))
const freeLevelOct2 = Math.max(player.octeractUpgrades.octeractGain2.level / 100, Math.pow(Math.pow(player.octeractUpgrades.octeractGain2.level, 2) * player.octeractUpgrades.octeractGain2.freeLevels / 125000, 0.333))
} else if (player.highestSingularityCount >= 205) {
const freeLevelOct1 = Math.max(
player.octeractUpgrades.octeractGain.level / 100,
Math.pow(
player.octeractUpgrades.octeractGain.level * player.octeractUpgrades.octeractGain.freeLevels / 640,
0.5
)
)
const freeLevelOct2 = Math.max(
player.octeractUpgrades.octeractGain2.level / 100,
Math.pow(
Math.pow(player.octeractUpgrades.octeractGain2.level, 2) * player.octeractUpgrades.octeractGain2.freeLevels
/ 125000,
0.333
)
)

player.octeractUpgrades.octeractGain.freeLevels += freeLevelOct1
player.octeractUpgrades.octeractGain2.freeLevels += freeLevelOct2
Expand Down
3 changes: 1 addition & 2 deletions src/Octeracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ export class OcteractUpgrade extends DynamicUpgrade {

if (this.level >= actualFreeLevels) {
return actualFreeLevels + this.level
}
else {
} else {
return 2 * Math.sqrt(actualFreeLevels * this.level)
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Reset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ import { autoBuyPlatonicUpgrades, updatePlatonicUpgradeBG } from './Platonic'
import { buyResearch, updateResearchBG } from './Research'
import { resetofferings } from './Runes'
import { playerJsonSchema } from './saves/PlayerJsonSchema'
import { saveSynergy } from './saves/Save'
import { resetShopUpgrades, shopData } from './Shop'
import { calculateSingularityDebuff, getFastForwardTotalMultiplier } from './singularity'
import { blankSave, format, player, saveSynergy, updateAll, updateEffectiveLevelMult } from './Synergism'
import { blankSave, format, player, updateAll, updateEffectiveLevelMult } from './Synergism'
import { changeSubTab, changeTab, Tabs } from './Tabs'
import { updateTalismanAppearance, updateTalismanInventory } from './Talismans'
import { calculateTesseractBlessings } from './Tesseracts'
Expand Down
Loading
Loading