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
SceneLayerTileArrayConverter.cs
1using Newtonsoft.Json;
2using Newtonsoft.Json.Linq;
3
4namespace Gondwana.Scenes;
5
6// Json.NET cannot restore reference-preserved multidimensional arrays. Accept
7// both the historical {$id,$values} envelope and a plain rectangular array.
8internal sealed class SceneLayerTileArrayConverter : JsonConverter<SceneLayerTile[,]>
9{
11 public override SceneLayerTile[,] ReadJson(JsonReader reader, Type objectType, SceneLayerTile[,]? existingValue,
12 bool hasExistingValue, JsonSerializer serializer)
13 {
14 var token = JToken.Load(reader);
15 var rows = (JArray)(token is JObject obj ? obj["$values"]! : token);
16 int height = rows.Count == 0 ? 0 : ((JArray)rows[0]).Count;
17 var result = new SceneLayerTile[rows.Count, height];
18 if (token is JObject envelope && envelope.Value<string>("$id") is { } id)
19 serializer.ReferenceResolver!.AddReference(serializer, id, result);
20 for (int x = 0; x < rows.Count; x++)
21 {
22 if (rows[x] is not JArray column || column.Count != height)
23 throw new JsonSerializationException("SceneLayerTileArray must be rectangular.");
24 for (int y = 0; y < height; y++)
25 result[x, y] = column[y].ToObject<SceneLayerTile>(serializer)!;
26 }
27 return result;
28 }
29
31 public override bool CanWrite => false;
33 public override void WriteJson(JsonWriter writer, SceneLayerTile[,]? value, JsonSerializer serializer) =>
34 throw new NotSupportedException();
35}