Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev committed Jun 10, 2024
1 parent dcb62e0 commit 01d162c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 22 deletions.
5 changes: 4 additions & 1 deletion src/Synergism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ import { handleLogin } from './Login'
import { octeractData, OcteractUpgrade } from './Octeracts'
import { updatePlatonicUpgradeBG } from './Platonic'
import { QuarkHandler } from './Quark'
import { playerSchema } from './saves/PlayerSchema'
import { getFastForwardTotalMultiplier, singularityData, SingularityUpgrade } from './singularity'
import { SingularityChallenge, singularityChallengeData } from './SingularityChallenges'
import {
Expand All @@ -174,7 +175,6 @@ 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 { playerSchema } from './saves/PlayerSchema'

export const player: Player = {
firstPlayed: new Date().toISOString(),
Expand Down Expand Up @@ -6361,6 +6361,9 @@ export const reloadShit = async (reset = false) => {
const parsed = playerSchema.safeParse(JSON.parse(atob(saveObject)))
console.log(parsed.data, parsed.error)

// @ts-ignore
globalThis.zodPlayer = parsed

await loadSynergy()
}

Expand Down
62 changes: 41 additions & 21 deletions src/saves/PlayerSchema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import Decimal from 'break_infinity.js'
import { z, ZodType } from 'zod'
import { WowCubes, WowHypercubes, WowPlatonicCubes, WowTesseracts } from '../CubeExperimental'
import { AbyssHepteract, AcceleratorBoostHepteract, AcceleratorHepteract, ChallengeHepteract, ChronosHepteract, HyperrealismHepteract, MultiplierHepteract, QuarkHepteract } from '../Hepteracts'
import {
AbyssHepteract,
AcceleratorBoostHepteract,
AcceleratorHepteract,
ChallengeHepteract,
ChronosHepteract,
HyperrealismHepteract,
MultiplierHepteract,
QuarkHepteract
} from '../Hepteracts'
import { QuarkHandler } from '../Quark'

const decimalSchema = z.custom<Decimal>((value) => {
Expand All @@ -13,13 +22,14 @@ const decimalSchema = z.custom<Decimal>((value) => {
}
}).transform((decimalSource) => new Decimal(decimalSource))

const arrayStartingWithNull = (s: ZodType) => z.array(z.union([z.null(), s]))
.refine((arr) => arr.length > 0 && arr[0] === null, {
message: 'First element must be null'
})
.refine((arr) => arr.slice(1).every((element) => typeof element === 'number'), {
message: 'All elements after the first must be numbers'
})
const arrayStartingWithNull = (s: ZodType) =>
z.array(z.union([z.null(), s]))
.refine((arr) => arr.length > 0 && arr[0] === null, {
message: 'First element must be null'
})
.refine((arr) => arr.slice(1).every((element) => typeof element === 'number'), {
message: 'All elements after the first must be numbers'
})

const ascendBuildingSchema = z.object({
cost: z.number(),
Expand All @@ -28,11 +38,18 @@ const ascendBuildingSchema = z.object({
multiplier: z.number()
})

const singularityUpgradeSchema = (key: string) => z.object({
level: z.number(),
toggleBuy: z.number(),
freeLevels: z.number(),
[key]: z.number()
const singularityUpgradeSchema = (key: string) =>
z.object({
level: z.number(),
toggleBuy: z.number(),
freeLevels: z.number(),
[key]: z.number()
})

const toggleSchema = z.record(z.string(), z.boolean()).transform((record) => {
return Object.fromEntries(
Object.entries(record).filter(([key, _value]) => /^\d+$/.test(key))
)
})

export const playerSchema = z.object({
Expand Down Expand Up @@ -215,7 +232,7 @@ export const playerSchema = z.object({
transcendShards: decimalSchema,
reincarnationShards: decimalSchema,

toggles: z.record(z.string().regex(/^\d+$/), z.boolean().default(false)),
toggles: toggleSchema,

challengecompletions: z.number().array(),
highestchallengecompletions: z.union([z.number(), z.null()]).array(),
Expand Down Expand Up @@ -381,7 +398,7 @@ export const playerSchema = z.object({
hepteractCrafts: z.object({
chronos: z.any().transform(() => ChronosHepteract),
hyperrealism: z.any().transform(() => HyperrealismHepteract),
quark: z.any().transform(() =>QuarkHepteract),
quark: z.any().transform(() => QuarkHepteract),
challenge: z.any().transform(() => ChallengeHepteract),
abyss: z.any().transform(() => AbyssHepteract),
accelerator: z.any().transform(() => AcceleratorHepteract),
Expand Down Expand Up @@ -485,11 +502,14 @@ export const playerSchema = z.object({
octeractTimer: z.number(),
insideSingularityChallenge: z.boolean(),

singularityChallenges: z.record(z.string(), z.object({
completions: z.number(),
highestSingularityCompleted: z.number(),
enabled: z.boolean()
})),
singularityChallenges: z.record(
z.string(),
z.object({
completions: z.number(),
highestSingularityCompleted: z.number(),
enabled: z.boolean()
})
),

ambrosia: z.number(),
lifetimeAmbrosia: z.number(),
Expand All @@ -498,7 +518,7 @@ export const playerSchema = z.object({
visitedAmbrosiaSubtab: z.boolean(),
spentBlueberries: z.number(),
// TODO: is this right?
blueberryUpgrades: z.record(z.string(), singularityUpgradeSchema('blueberriesInvested')),
blueberryUpgrades: z.record(z.string(), singularityUpgradeSchema('blueberriesInvested')),

// TODO: what type?
blueberryLoadouts: z.record(z.string().regex(/^\d+$/), z.any()),
Expand Down

0 comments on commit 01d162c

Please sign in to comment.