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
AnimationDefinitionValidator.cs
2
6public static class AnimationDefinitionValidator
7{
14 public static IReadOnlyList<string> Validate(AnimationDefinition definition)
15 {
16 ArgumentNullException.ThrowIfNull(definition);
17
18 var errors = new List<string>();
19
20 if (string.IsNullOrWhiteSpace(definition.Key))
21 errors.Add("Animation key is empty.");
22
23 if (!double.IsFinite(definition.ThrottleTime) || definition.ThrottleTime < 0)
24 errors.Add("ThrottleTime must be a finite, non-negative number.");
25
26 if (!Enum.IsDefined(definition.CycleType))
27 errors.Add($"Unknown cycle type '{definition.CycleType}'.");
28
29 definition.TilesheetSources ??= [];
30 var sourceNames = new HashSet<string>(StringComparer.Ordinal);
31
32 for (int i = 0; i < definition.TilesheetSources.Count; i++)
33 {
34 var source = definition.TilesheetSources[i];
35 var label = $"Tilesheet source {i}";
36
37 if (source is null)
38 {
39 errors.Add($"{label}: source definition is null.");
40 continue;
41 }
42
43 if (string.IsNullOrWhiteSpace(source.Tilesheet))
44 {
45 errors.Add($"{label}: tilesheet name is empty.");
46 }
47 else if (!sourceNames.Add(source.Tilesheet))
48 {
49 errors.Add(
50 $"{label}: duplicate source for tilesheet '{source.Tilesheet}'.");
51 }
52
53 if (!Enum.IsDefined(source.Kind))
54 {
55 errors.Add($"{label}: unknown source kind '{source.Kind}'.");
56 continue;
57 }
58
59 switch (source.Kind)
60 {
61 case AnimationTilesheetSourceKind.LooseDefinitionFile:
62 if (string.IsNullOrWhiteSpace(source.GtsPath))
63 errors.Add($"{label}: loose GTS source path is empty.");
64 break;
65
66 case AnimationTilesheetSourceKind.PackedDefinitionFile:
67 if (string.IsNullOrWhiteSpace(source.AssetsFilePath))
68 errors.Add($"{label}: assets file path is empty.");
69
70 if (string.IsNullOrWhiteSpace(source.AssetEntryName))
71 errors.Add($"{label}: packed GTS entry name is empty.");
72 break;
73 }
74 }
75
76 definition.Frames ??= [];
77 if (definition.Frames.Count == 0)
78 errors.Add("Animation must contain at least one frame.");
79
80 for (int i = 0; i < definition.Frames.Count; i++)
81 {
82 var frame = definition.Frames[i];
83 var label = $"Frame {i}";
84
85 if (frame is null)
86 {
87 errors.Add($"{label}: frame definition is null.");
88 continue;
89 }
90
91 if (string.IsNullOrWhiteSpace(frame.Tilesheet))
92 errors.Add($"{label}: tilesheet name is empty.");
93
94 if (string.IsNullOrWhiteSpace(frame.RegionName))
95 errors.Add($"{label}: region name is empty.");
96
97 if (frame.XTile < 0 || frame.YTile < 0)
98 errors.Add($"{label}: frame coordinates cannot be negative.");
99
100 if (frame.DurationSeconds is { } duration && (!double.IsFinite(duration) || duration <= 0))
101 errors.Add($"{label}: DurationSeconds must be finite and positive, or null for ThrottleTime.");
102 }
103
104 return errors;
105 }
106}
AnimationTilesheetSourceKind
Identifies how a GANI definition can locate one of its logical GTS dependencies for authoring and too...