BlueGit

timfa questward

Files

questward / shared / graphics / settings.js

settings.js

settings.js 2.2 KiB Download Raw
1/** Client graphics preferences (persisted in localStorage). */
2
3export const ViewDistance = Object.freeze({
4 long: "long",
5 short: "short"
6});
7
8export const LightingMode = Object.freeze({
9 soft: "soft",
10 simple: "simple"
11});
12
13export const BloomMode = Object.freeze({
14 on: "on",
15 off: "off"
16});
17
18/** Soft edge blend between blendable ground tiles (grass, dirt, …). */
19export const SoftTerrainMode = Object.freeze({
20 on: "on",
21 off: "off"
22});
23
24/** Auto walk/run by path distance (client-only; ignored while following). */
25export const AutorunMode = Object.freeze({
26 on: "on",
27 off: "off"
28});
29
30export const DEFAULT_GRAPHICS_SETTINGS = Object.freeze({
31 viewDistance: ViewDistance.long,
32 lighting: LightingMode.soft,
33 bloom: BloomMode.on,
34 softTerrain: SoftTerrainMode.on,
35 autorun: AutorunMode.off
36});
37
38const STORAGE_KEY = "questward-graphics-settings";
39
40export function normalizeGraphicsSettings (value)
41{
42 const raw = value && typeof value === "object" ? value : {};
43 const viewDistance = raw.viewDistance === ViewDistance.short
44 ? ViewDistance.short
45 : ViewDistance.long;
46 const lighting = raw.lighting === LightingMode.simple
47 ? LightingMode.simple
48 : LightingMode.soft;
49 const bloom = raw.bloom === BloomMode.off
50 ? BloomMode.off
51 : BloomMode.on;
52 const softTerrain = raw.softTerrain === SoftTerrainMode.off
53 ? SoftTerrainMode.off
54 : SoftTerrainMode.on;
55 const autorun = raw.autorun === AutorunMode.on
56 ? AutorunMode.on
57 : AutorunMode.off;
58 return { viewDistance, lighting, bloom, softTerrain, autorun };
59}
60
61export function loadGraphicsSettings ()
62{
63 try
64 {
65 const text = localStorage.getItem(STORAGE_KEY);
66 if (!text)
67 { return { ...DEFAULT_GRAPHICS_SETTINGS }; }
68 return normalizeGraphicsSettings(JSON.parse(text));
69 }
70 catch
71 {
72 return { ...DEFAULT_GRAPHICS_SETTINGS };
73 }
74}
75
76export function saveGraphicsSettings (settings)
77{
78 const next = normalizeGraphicsSettings(settings);
79 try
80 { localStorage.setItem(STORAGE_KEY, JSON.stringify(next)); }
81 catch
82 { /* ignore quota / private mode */ }
83 return next;
84}
85
86/** Map-ring Chebyshev radius for chunk subscriptions (entities always use VISIBLE_CHUNK_RADIUS). */
87export function staticChunkRadiusForViewDistance (viewDistance, longRadius, shortRadius)
88{
89 return viewDistance === ViewDistance.short ? shortRadius : longRadius;
90}