3using Newtonsoft.Json.Linq;
11internal sealed class FrameJsonConverter : JsonConverter<Frame>
19 public override void WriteJson(
22 JsonSerializer serializer)
30 writer.WriteStartObject();
32 writer.WritePropertyName(
"tilesheet");
35 writer.WritePropertyName(
"regionName");
38 writer.WritePropertyName(
"xTile");
39 writer.WriteValue(value.
XTile);
41 writer.WritePropertyName(
"yTile");
42 writer.WriteValue(value.
YTile);
44 writer.WriteEndObject();
56 public override Frame ReadJson(
60 bool hasExistingValue,
61 JsonSerializer serializer)
63 if (reader.TokenType == JsonToken.Null)
66 var obj = JObject.Load(reader);
68 var tilesheetName = obj.Value<
string>(
"tilesheet");
69 var regionName = obj.Value<
string>(
"regionName") ?? TilesheetRegion.DefaultRegionName;
71 var xTile = obj.Value<
int?>(
"xTile") ?? 0;
72 var yTile = obj.Value<
int?>(
"yTile") ?? 0;
74 if (
string.IsNullOrWhiteSpace(tilesheetName))
75 throw new JsonSerializationException(
"Frame is missing required tilesheet name.");
77 var tilesheet = TilesheetRegistry.Instance.GetOrNull(tilesheetName);
79 if (tilesheet is
null)
81 throw new JsonSerializationException(
82 $
"Could not resolve Tilesheet '{tilesheetName}' while deserializing Frame.");
string Name
Gets the name.
readonly int YTile
The vertical tile coordinate (row index) within the tilesheet.
readonly Tilesheet Tilesheet
The tilesheet that contains the source bitmap for this frame.
readonly string RegionName
The tilesheet region that contains the source bitmap for this frame.
readonly int XTile
The horizontal tile coordinate (column index) within the tilesheet.