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
DefinitionProvenance.cs
1using Newtonsoft.Json.Linq;
2
3namespace Gondwana;
4
5// Owned by the materialized object (or collection manager), never by a global name map.
6// Compare the serializer's complete runtime projection, including nested mutable data.
7internal sealed class DefinitionProvenance
8{
9 internal string? FilePath { get; }
10 internal string? AssetsFilePath { get; }
11 internal string? AssetEntryName { get; }
12 private readonly JToken _baseline;
13
14 private DefinitionProvenance(string? filePath, string? assetsFilePath, string? entryName, object definition)
15 {
16 FilePath = string.IsNullOrWhiteSpace(filePath) ? null : Path.GetFullPath(filePath);
17 AssetsFilePath = string.IsNullOrWhiteSpace(assetsFilePath) ? null : Path.GetFullPath(assetsFilePath);
18 AssetEntryName = entryName;
19 _baseline = JToken.FromObject(definition);
20 }
21
22 internal static DefinitionProvenance? Capture(string? filePath, string? assetsFilePath,
23 string? entryName, Func<object> capture)
24 {
25 if (string.IsNullOrWhiteSpace(filePath) &&
26 (string.IsNullOrWhiteSpace(assetsFilePath) || string.IsNullOrWhiteSpace(entryName)))
27 return null;
28 return new(filePath, assetsFilePath, entryName, capture());
29 }
30
31 internal bool Matches(object definition) => JToken.DeepEquals(_baseline, JToken.FromObject(definition));
32}
33
34// Captures the actual input location separately from user-editable authoring provenance.
35// Editing a loaded definition before materializing it invalidates source preservation.
36internal sealed class DefinitionLoadStamp
37{
38 private readonly JToken _definition;
39 private readonly string? _filePath;
40 private readonly string? _assetsFilePath;
41 private readonly string? _entryName;
42
43 internal DefinitionLoadStamp(object definition, string? filePath = null, string? assetsFilePath = null, string? entryName = null)
44 {
45 _definition = JToken.FromObject(definition);
46 _filePath = string.IsNullOrWhiteSpace(filePath) ? null : Path.GetFullPath(filePath);
47 _assetsFilePath = string.IsNullOrWhiteSpace(assetsFilePath) ? null : Path.GetFullPath(assetsFilePath);
48 _entryName = entryName;
49 }
50
51 internal DefinitionProvenance? Materialized(object definition, Func<object> capture) =>
52 JToken.DeepEquals(_definition, JToken.FromObject(definition))
53 ? DefinitionProvenance.Capture(_filePath, _assetsFilePath, _entryName, capture)
54 : null;
55}