2026-03-04 07:09:31 +00:00
|
|
|
import { defineStore } from 'pinia'
|
|
|
|
|
import { ref, computed } from 'vue'
|
|
|
|
|
import type { UIMode } from '@/types/api'
|
|
|
|
|
|
|
|
|
|
const STORAGE_KEY = 'archipelago-ui-mode'
|
|
|
|
|
|
|
|
|
|
export const useUIModeStore = defineStore('uiMode', () => {
|
|
|
|
|
const mode = ref<UIMode>(loadFromStorage())
|
|
|
|
|
|
|
|
|
|
function loadFromStorage(): UIMode {
|
|
|
|
|
const stored = localStorage.getItem(STORAGE_KEY)
|
|
|
|
|
if (stored === 'gamer' || stored === 'easy' || stored === 'chat') return stored
|
|
|
|
|
return 'gamer'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function syncFromBackend(backendMode: UIMode | undefined) {
|
|
|
|
|
if (backendMode && ['gamer', 'easy', 'chat'].includes(backendMode)) {
|
|
|
|
|
mode.value = backendMode
|
2026-03-21 01:57:05 +00:00
|
|
|
try { localStorage.setItem(STORAGE_KEY, backendMode) } catch { /* localStorage full or unavailable */ }
|
2026-03-04 07:09:31 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setMode(newMode: UIMode) {
|
|
|
|
|
mode.value = newMode
|
2026-03-21 01:57:05 +00:00
|
|
|
try { localStorage.setItem(STORAGE_KEY, newMode) } catch { /* localStorage full or unavailable */ }
|
2026-03-04 07:09:31 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-04 12:06:20 +00:00
|
|
|
function cycleMode(): UIMode {
|
|
|
|
|
const order: UIMode[] = ['easy', 'gamer']
|
|
|
|
|
const idx = order.indexOf(mode.value)
|
|
|
|
|
const next = order[(idx >= 0 ? idx + 1 : 0) % order.length] as UIMode
|
|
|
|
|
setMode(next)
|
|
|
|
|
return next
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-04 07:09:31 +00:00
|
|
|
const isGamer = computed(() => mode.value === 'gamer')
|
|
|
|
|
const isEasy = computed(() => mode.value === 'easy')
|
|
|
|
|
const isChat = computed(() => mode.value === 'chat')
|
|
|
|
|
|
2026-03-04 12:06:20 +00:00
|
|
|
return { mode, setMode, cycleMode, syncFromBackend, isGamer, isEasy, isChat }
|
2026-03-04 07:09:31 +00:00
|
|
|
})
|