diff --git a/src/App.vue b/src/App.vue index 6535b0a..9613f04 100644 --- a/src/App.vue +++ b/src/App.vue @@ -49,5 +49,6 @@ const gameComponent = computed(() => { position: absolute; min-height: 100%; height: 100%; + color: var(--foreground); } diff --git a/src/data/common.tsx b/src/data/common.tsx index 9f1436f..b0becca 100644 --- a/src/data/common.tsx +++ b/src/data/common.tsx @@ -288,7 +288,7 @@ export function createCollapsibleModifierSections( return sections; } - const collapsed = persistent>({}); + const collapsed = persistent>({}, false); const jsxFunc = jsx(() => { const sections = calculateSections(); @@ -389,7 +389,7 @@ export function colorText(textToColor: string, color = "var(--accent2)"): JSX.El export function createCollapsibleMilestones(milestones: Record) { // Milestones are typically defined from easiest to hardest, and we want to show hardest first const orderedMilestones = Object.values(milestones).reverse(); - const collapseMilestones = persistent(true); + const collapseMilestones = persistent(true, false); const lockedMilestones = computed(() => orderedMilestones.filter(m => m.earned.value === false) ); diff --git a/src/features/achievements/achievement.tsx b/src/features/achievements/achievement.tsx index c28003c..87af9e2 100644 --- a/src/features/achievements/achievement.tsx +++ b/src/features/achievements/achievement.tsx @@ -76,7 +76,7 @@ export function createAchievement( optionsFunc?: OptionsFunc, ...decorators: Decorator[] ): Achievement { - const earned = persistent(false); + const earned = persistent(false, false); const decoratedData = decorators.reduce((current, next) => Object.assign(current, next.getPersistentData?.()), {}); return createLazyProxy(() => { const achievement = optionsFunc?.() ?? ({} as ReturnType>); diff --git a/src/features/boards/board.ts b/src/features/boards/board.ts index 7f79110..cc17d2e 100644 --- a/src/features/boards/board.ts +++ b/src/features/boards/board.ts @@ -208,11 +208,14 @@ export type GenericBoard = Replace< export function createBoard( optionsFunc: OptionsFunc ): Board { - const state = persistent({ - nodes: [], - selectedNode: null, - selectedAction: null - }); + const state = persistent( + { + nodes: [], + selectedNode: null, + selectedAction: null + }, + false + ); return createLazyProxy(() => { const board = optionsFunc(); diff --git a/src/features/challenges/challenge.tsx b/src/features/challenges/challenge.tsx index d703014..f735191 100644 --- a/src/features/challenges/challenge.tsx +++ b/src/features/challenges/challenge.tsx @@ -103,7 +103,7 @@ export function createChallenge( ...decorators: Decorator[] ): Challenge { const completions = persistent(0); - const active = persistent(false); + const active = persistent(false, false); const decoratedData = decorators.reduce((current, next) => Object.assign(current, next.getPersistentData?.()), {}); return createLazyProxy(() => { const challenge = optionsFunc(); diff --git a/src/features/grids/grid.ts b/src/features/grids/grid.ts index eda80da..53fd7fb 100644 --- a/src/features/grids/grid.ts +++ b/src/features/grids/grid.ts @@ -238,7 +238,7 @@ export type GenericGrid = Replace< export function createGrid( optionsFunc: OptionsFunc ): Grid { - const cellState = persistent>({}); + const cellState = persistent>({}, false); return createLazyProxy(() => { const grid = optionsFunc(); grid.id = getUniqueID("grid-"); diff --git a/src/features/infoboxes/infobox.ts b/src/features/infoboxes/infobox.ts index 43e3ffa..81d7bf6 100644 --- a/src/features/infoboxes/infobox.ts +++ b/src/features/infoboxes/infobox.ts @@ -58,7 +58,7 @@ export type GenericInfobox = Replace< export function createInfobox( optionsFunc: OptionsFunc ): Infobox { - const collapsed = persistent(false); + const collapsed = persistent(false, false); return createLazyProxy(() => { const infobox = optionsFunc(); infobox.id = getUniqueID("infobox-"); diff --git a/src/features/milestones/milestone.tsx b/src/features/milestones/milestone.tsx index d76925e..9908089 100644 --- a/src/features/milestones/milestone.tsx +++ b/src/features/milestones/milestone.tsx @@ -96,7 +96,7 @@ export function createMilestone( optionsFunc?: OptionsFunc, ...decorators: Decorator[] ): Milestone { - const earned = persistent(false); + const earned = persistent(false, false); const decoratedData = decorators.reduce((current, next) => Object.assign(current, next.getPersistentData?.()), {}); return createLazyProxy(() => { const milestone = optionsFunc?.() ?? ({} as ReturnType>); diff --git a/src/features/tabs/TabButton.vue b/src/features/tabs/TabButton.vue index fcd8942..2b4991f 100644 --- a/src/features/tabs/TabButton.vue +++ b/src/features/tabs/TabButton.vue @@ -50,7 +50,7 @@ export default defineComponent({ const glowColorStyle = computed(() => { const color = unwrapRef(glowColor); - if (color != null) { + if (color == null || color === "") { return {}; } if (unref(floating)) { diff --git a/src/features/tabs/tabFamily.ts b/src/features/tabs/tabFamily.ts index 51d298e..5f5c666 100644 --- a/src/features/tabs/tabFamily.ts +++ b/src/features/tabs/tabFamily.ts @@ -101,7 +101,7 @@ export function createTabFamily( throw "Cannot create tab family with 0 tabs"; } - const selected = persistent(Object.keys(tabs)[0]); + const selected = persistent(Object.keys(tabs)[0], false); return createLazyProxy(() => { const tabFamily = optionsFunc?.() ?? ({} as ReturnType>); diff --git a/src/features/tooltips/tooltip.ts b/src/features/tooltips/tooltip.ts index dcc618f..13cb931 100644 --- a/src/features/tooltips/tooltip.ts +++ b/src/features/tooltips/tooltip.ts @@ -78,7 +78,7 @@ export function addTooltip( options.pinnable = false; } else { // eslint-disable-next-line @typescript-eslint/no-explicit-any - (element as any).pinned = options.pinned = persistent(false); + (element as any).pinned = options.pinned = persistent(false, false); } } diff --git a/src/features/upgrades/upgrade.ts b/src/features/upgrades/upgrade.ts index 14ea1ec..7c90aa5 100644 --- a/src/features/upgrades/upgrade.ts +++ b/src/features/upgrades/upgrade.ts @@ -89,7 +89,7 @@ export function createUpgrade( optionsFunc: OptionsFunc, ...decorators: Decorator[] ): Upgrade { - const bought = persistent(false); + const bought = persistent(false, false); const decoratedData = decorators.reduce((current, next) => Object.assign(current, next.getPersistentData?.()), {}); return createLazyProxy(() => { const upgrade = optionsFunc(); diff --git a/src/game/layers.tsx b/src/game/layers.tsx index c689235..532daba 100644 --- a/src/game/layers.tsx +++ b/src/game/layers.tsx @@ -219,7 +219,7 @@ export function createLayer( addingLayers.push(id); persistentRefs[id] = new Set(); - layer.minimized = persistent(false); + layer.minimized = persistent(false, false); Object.assign(layer, optionsFunc.call(layer as BaseLayer)); if ( addingLayers[addingLayers.length - 1] == null || diff --git a/src/game/persistence.ts b/src/game/persistence.ts index 9ad0634..bf3afa9 100644 --- a/src/game/persistence.ts +++ b/src/game/persistence.ts @@ -40,6 +40,11 @@ export const NonPersistent = Symbol("NonPersistent"); * @see {@link Persistent[SaveDataPath]} */ export const SaveDataPath = Symbol("SaveDataPath"); +/** + * A symbol used in {@link Persistent} objects. + * @see {@link Persistent[CheckNaN]} + */ +export const CheckNaN = Symbol("CheckNaN"); /** * This is a union of things that should be safely stringifiable without needing special processes or knowing what to load them in as. @@ -78,6 +83,10 @@ export type Persistent = Ref & { * The path this persistent appears in within the save data object. Predominantly used to ensure it's only placed in there one time. */ [SaveDataPath]: string[] | undefined; + /** + * Whether or not to NaN-check this ref. Should only be true on values expected to always be DecimalSources. + */ + [CheckNaN]: boolean; }; export type NonPersistent = WritableComputedRef & { [DefaultValue]: T }; @@ -115,8 +124,12 @@ function checkNaNAndWrite(persistent: Persistent, value: T) * Create a persistent ref, which can be saved and loaded. * All (non-deleted) persistent refs must be included somewhere within the layer object returned by that layer's options func. * @param defaultValue The value the persistent ref should start at on fresh saves or when reset. + * @param checkNaN Whether or not to check this ref for being NaN on set. Only use on refs that should always be DecimalSources. */ -export function persistent(defaultValue: T | Ref): Persistent { +export function persistent( + defaultValue: T | Ref, + checkNaN = true +): Persistent { const persistentState: Ref = isRef(defaultValue) ? defaultValue : (ref(defaultValue) as Ref); @@ -130,7 +143,11 @@ export function persistent(defaultValue: T | Ref): Persisten return persistentState.value; }, set(value) { - checkNaNAndWrite(persistent, value); + if (checkNaN) { + checkNaNAndWrite(persistent, value); + } else { + persistent[PersistentState].value = value; + } } }) as NonPersistent; nonPersistent[DefaultValue] = defaultValue; @@ -141,7 +158,11 @@ export function persistent(defaultValue: T | Ref): Persisten return persistentState.value as T; }, set value(value: T) { - checkNaNAndWrite(persistent, value); + if (checkNaN) { + checkNaNAndWrite(persistent, value); + } else { + persistent[PersistentState].value = value; + } }, __v_isRef: true, [PersistentState]: persistentState, diff --git a/vite.config.ts b/vite.config.ts index f3ce360..0853646 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -32,6 +32,9 @@ export default defineConfig({ tsconfigPaths(), VitePWA({ includeAssets: ["Logo.svg", "favicon.ico", "robots.txt", "apple-touch-icon.png"], + workbox: { + globPatterns: ['**/*.{js,css,html,ico,png,svg}'] + }, manifest: { name: projInfo.title, short_name: projInfo.title,