Files
pihkaal-me/app/stores/app.ts
Pihkaal c8dab1ae9e feat(home): play the white -> background fade only once
NOTE: it's not correctly done, i'm using app state for that, i might move to intro but it's fine for now
2026-01-12 16:36:30 +01:00

65 lines
1.3 KiB
TypeScript

import { z } from "zod/mini";
import type * as THREE from "three";
const STORAGE_ID = "app_settings";
const settingsSchema = z.object({
color: z.object({
col: z.number(),
row: z.number(),
}),
});
type Settings = z.infer<typeof settingsSchema>;
const defaultSettings = (): Settings => ({
color: { col: 0, row: 0 },
});
export const useAppStore = defineStore("app", {
state: () => {
let settings: Settings;
const stored = localStorage.getItem(STORAGE_ID);
try {
settings = settingsSchema.parse(JSON.parse(stored ?? ""));
} catch {
settings = defaultSettings();
}
return {
booted: false,
// shitty but who cares
homeIntroPlayed: false,
settings,
screen: "home" as AppScreen,
camera: null as THREE.Camera | null,
};
},
actions: {
setColor(col: number, row: number) {
this.settings.color = { col, row };
},
navigateTo(screen: AppScreen) {
this.screen = screen;
},
setCamera(camera: THREE.Camera) {
this.camera = camera;
},
save() {
localStorage.setItem(STORAGE_ID, JSON.stringify(this.settings));
},
},
getters: {
color: (state) => ({
col: state.settings.color.col,
row: state.settings.color.row,
hex: APP_COLORS[state.settings.color.row]![state.settings.color.col]!,
}),
},
});