Gondwana Game Engine Development (master) - 2.7.0
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
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
14 internal string? DefinitionIdentity { get; }
15
16 private readonly JToken _baseline;
17
18 private DefinitionProvenance(
19 string? filePath,
20 string? assetsFilePath,
21 string? entryName,
22 object definition,
23 string? definitionIdentity)
24 {
25 FilePath = string.IsNullOrWhiteSpace(filePath) ? null : Path.GetFullPath(filePath);
26 AssetsFilePath = string.IsNullOrWhiteSpace(assetsFilePath) ? null : Path.GetFullPath(assetsFilePath);
27 AssetEntryName = entryName;
28 DefinitionIdentity = definitionIdentity;
29 _baseline = JToken.FromObject(definition);
30 }
31
39 internal static DefinitionProvenance? Capture(
40 string? filePath,
41 string? assetsFilePath,
42 string? entryName,
43 Func<object> capture,
44 string? definitionIdentity = null)
45 {
46 if (string.IsNullOrWhiteSpace(filePath) &&
47 (string.IsNullOrWhiteSpace(assetsFilePath) || string.IsNullOrWhiteSpace(entryName)))
48 return null;
49
50 return new(
51 filePath,
52 assetsFilePath,
53 entryName,
54 capture(),
55 definitionIdentity);
56 }
57
58 internal bool Matches(object definition) => JToken.DeepEquals(_baseline, JToken.FromObject(definition));
59}
60
61// Captures the actual input location separately from user-editable authoring provenance.
62// Editing a loaded definition before materializing it invalidates source preservation.
63internal sealed class DefinitionLoadStamp
64{
65 private readonly JToken _definition;
66 private readonly string? _filePath;
67 private readonly string? _assetsFilePath;
68 private readonly string? _entryName;
69 private readonly string? _definitionIdentity;
70
72 internal string? AssetsFilePath => _assetsFilePath;
73
75 internal string? ReferenceBaseDirectory => _filePath is not null ? Path.GetDirectoryName(_filePath) :
76 _assetsFilePath is not null ? Path.GetDirectoryName(_assetsFilePath) : null;
77
84 internal DefinitionLoadStamp(
85 object definition,
86 string? filePath = null,
87 string? assetsFilePath = null,
88 string? entryName = null,
89 string? definitionIdentity = null)
90 {
91 _definition = JToken.FromObject(definition);
92 _filePath = string.IsNullOrWhiteSpace(filePath) ? null : Path.GetFullPath(filePath);
93 _assetsFilePath = string.IsNullOrWhiteSpace(assetsFilePath) ? null : Path.GetFullPath(assetsFilePath);
94 _entryName = entryName;
95 _definitionIdentity = definitionIdentity;
96 }
97
98 internal DefinitionProvenance? Materialized(object definition, Func<object> capture) =>
99 JToken.DeepEquals(_definition, JToken.FromObject(definition))
100 ? DefinitionProvenance.Capture(
101 _filePath,
102 _assetsFilePath,
103 _entryName,
104 capture,
105 _definitionIdentity)
106 : null;
107}