/** Client graphics preferences (persisted in localStorage). */ export const ViewDistance = Object.freeze({ long: "long", short: "short" }); export const LightingMode = Object.freeze({ soft: "soft", simple: "simple" }); export const BloomMode = Object.freeze({ on: "on", off: "off" }); /** Soft edge blend between blendable ground tiles (grass, dirt, …). */ export const SoftTerrainMode = Object.freeze({ on: "on", off: "off" }); /** * Wet sand shoreline width (% of the tile facing liquid water). * Stored as percent strings for the settings UI. */ export const WetSandBand = Object.freeze({ off: "0", narrow: "30", medium: "60", wide: "100" }); /** Auto walk/run by path distance (client-only; ignored while following). */ export const AutorunMode = Object.freeze({ on: "on", off: "off" }); export const DEFAULT_GRAPHICS_SETTINGS = Object.freeze({ viewDistance: ViewDistance.long, lighting: LightingMode.soft, bloom: BloomMode.on, softTerrain: SoftTerrainMode.on, wetSand: WetSandBand.medium, autorun: AutorunMode.off }); const WET_SAND_BAND_VALUES = new Set(Object.values(WetSandBand)); const STORAGE_KEY = "questward-graphics-settings"; /** Map a wetSand settings value to a 0–1 tile fraction. */ export function wetSandBandFraction (value) { const raw = String(value ?? WetSandBand.medium); const pct = Number(raw); if (!Number.isFinite(pct) || pct <= 0) { return 0; } return Math.min(1, pct / 100); } export function normalizeGraphicsSettings (value) { const raw = value && typeof value === "object" ? value : {}; const viewDistance = raw.viewDistance === ViewDistance.short ? ViewDistance.short : ViewDistance.long; const lighting = raw.lighting === LightingMode.simple ? LightingMode.simple : LightingMode.soft; const bloom = raw.bloom === BloomMode.off ? BloomMode.off : BloomMode.on; const softTerrain = raw.softTerrain === SoftTerrainMode.off ? SoftTerrainMode.off : SoftTerrainMode.on; const wetSand = WET_SAND_BAND_VALUES.has(String(raw.wetSand)) ? String(raw.wetSand) : WetSandBand.medium; const autorun = raw.autorun === AutorunMode.on ? AutorunMode.on : AutorunMode.off; return { viewDistance, lighting, bloom, softTerrain, wetSand, autorun }; } export function loadGraphicsSettings () { try { const text = localStorage.getItem(STORAGE_KEY); if (!text) { return { ...DEFAULT_GRAPHICS_SETTINGS }; } return normalizeGraphicsSettings(JSON.parse(text)); } catch { return { ...DEFAULT_GRAPHICS_SETTINGS }; } } export function saveGraphicsSettings (settings) { const next = normalizeGraphicsSettings(settings); try { localStorage.setItem(STORAGE_KEY, JSON.stringify(next)); } catch { /* ignore quota / private mode */ } return next; } /** Map-ring Chebyshev radius for chunk subscriptions (entities always use VISIBLE_CHUNK_RADIUS). */ export function staticChunkRadiusForViewDistance (viewDistance, longRadius, shortRadius) { return viewDistance === ViewDistance.short ? shortRadius : longRadius; }