Gondwana Game Engine Development (master) - 2.6.1
Gondwana is a cross-platform 2.5D game and rendering engine written in C#/.NET 8. It provides fine-grained control over rendering, timing, and scene composition, with built-in support for parallax, z-ordering, pixel overhang, collision detection, and particle effects. Gondwana targets desktop and web platforms using SkiaSharp for graphics and pluggable audio backends for desktop and browser targets.
Loading...
Searching...
No Matches
BrowserLocalStorageEngineConfigurationStore.cs
2using Microsoft.JSInterop;
3using Newtonsoft.Json;
4
6
16{
20 public const string DefaultStorageKey = "gondwana.configuration";
21
22 private readonly IJSInProcessRuntime _jsRuntime;
23 private readonly string _storageKey;
24 private bool _disposed;
25
33 IJSRuntime jsRuntime,
34 string storageKey = DefaultStorageKey,
35 bool autoSave = false)
36 {
37 ArgumentNullException.ThrowIfNull(jsRuntime);
38 ArgumentException.ThrowIfNullOrWhiteSpace(storageKey);
39
40 _jsRuntime = jsRuntime as IJSInProcessRuntime
41 ?? throw new PlatformNotSupportedException(
42 "BrowserLocalStorageEngineConfigurationStore requires an in-process Blazor WebAssembly JS runtime.");
43 _storageKey = storageKey;
44 AutoSave = autoSave;
45
46 var json = _jsRuntime.Invoke<string?>("localStorage.getItem", _storageKey);
47 Configuration = string.IsNullOrWhiteSpace(json)
49 : JsonConvert.DeserializeObject<EngineConfiguration>(json) ?? new EngineConfiguration();
50 }
51
54
56 public bool AutoSave { get; set; }
57
59 public void Save()
60 {
61 ObjectDisposedException.ThrowIf(_disposed, this);
62
63 var json = JsonConvert.SerializeObject(Configuration, Formatting.Indented);
64 _jsRuntime.InvokeVoid("localStorage.setItem", _storageKey, json);
65 }
66
68 public void Dispose()
69 {
70 if (_disposed)
71 return;
72
73 if (AutoSave)
74 Save();
75
76 _disposed = true;
77 GC.SuppressFinalize(this);
78 }
79}
BrowserLocalStorageEngineConfigurationStore(IJSRuntime jsRuntime, string storageKey=DefaultStorageKey, bool autoSave=false)
Creates a local-storage-backed configuration store and loads its current value.
EngineConfiguration Configuration
Gets the configuration represented by this store.
bool AutoSave
Gets or sets whether the store saves automatically when disposed.
Settings used by the engine when cycling.
Provides a persistence boundary for EngineConfiguration.