|
@ -1,7 +1,7 @@ |
|
|
using Microsoft.Xna.Framework; |
|
|
using Microsoft.Xna.Framework; |
|
|
using Microsoft.Xna.Framework.Content; |
|
|
using Microsoft.Xna.Framework.Content; |
|
|
using Newtonsoft.Json.Linq; |
|
|
|
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
|
|
|
using System.Text.Json; |
|
|
|
|
|
|
|
|
namespace SemiColinGames { |
|
|
namespace SemiColinGames { |
|
|
public static class Sprites { |
|
|
public static class Sprites { |
|
@ -61,29 +61,32 @@ namespace SemiColinGames { |
|
|
Texture = texture; |
|
|
Texture = texture; |
|
|
animations = new Dictionary<string, SpriteAnimation>(); |
|
|
animations = new Dictionary<string, SpriteAnimation>(); |
|
|
|
|
|
|
|
|
JObject json = JObject.Parse(metadataJson); |
|
|
|
|
|
|
|
|
JsonElement jsonRoot = JsonDocument.Parse(metadataJson).RootElement; |
|
|
|
|
|
|
|
|
frames = new List<Frame>(); |
|
|
frames = new List<Frame>(); |
|
|
foreach (JToken child in json.SelectToken("frames").Children()) { |
|
|
|
|
|
|
|
|
foreach (JsonElement child in jsonRoot.GetProperty("frames").EnumerateArray()) { |
|
|
|
|
|
JsonElement frame = child.GetProperty("frame"); |
|
|
Rectangle source = new Rectangle( |
|
|
Rectangle source = new Rectangle( |
|
|
child.SelectToken("frame.x").Value<int>(), |
|
|
|
|
|
child.SelectToken("frame.y").Value<int>(), |
|
|
|
|
|
child.SelectToken("frame.w").Value<int>(), |
|
|
|
|
|
child.SelectToken("frame.h").Value<int>()); |
|
|
|
|
|
double duration = child.SelectToken("duration").Value<double>() / 1000; |
|
|
|
|
|
|
|
|
frame.GetProperty("x").GetInt32(), |
|
|
|
|
|
frame.GetProperty("y").GetInt32(), |
|
|
|
|
|
frame.GetProperty("w").GetInt32(), |
|
|
|
|
|
frame.GetProperty("h").GetInt32()); |
|
|
|
|
|
|
|
|
|
|
|
double duration = child.GetProperty("duration").GetDouble() / 1000; |
|
|
frames.Add(new Frame(source, duration)); |
|
|
frames.Add(new Frame(source, duration)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// We assume that all frames are the same size (which right now is assured by the
|
|
|
// We assume that all frames are the same size (which right now is assured by the
|
|
|
// Aseprite-based spritesheet export process).
|
|
|
// Aseprite-based spritesheet export process).
|
|
|
Width = frames[0].Source.Width; |
|
|
Width = frames[0].Source.Width; |
|
|
Height = frames[0].Source.Height; |
|
|
Height = frames[0].Source.Height; |
|
|
|
|
|
|
|
|
JToken frameTags = json.SelectToken("meta.frameTags"); |
|
|
|
|
|
foreach (JToken child in frameTags.Children()) { |
|
|
|
|
|
string name = child.SelectToken("name").Value<string>(); |
|
|
|
|
|
int start = child.SelectToken("from").Value<int>(); |
|
|
|
|
|
int end = child.SelectToken("to").Value<int>(); |
|
|
|
|
|
string directionString = child.SelectToken("direction").Value<string>(); |
|
|
|
|
|
|
|
|
JsonElement frameTags = jsonRoot.GetProperty("meta").GetProperty("frameTags"); |
|
|
|
|
|
foreach (JsonElement child in frameTags.EnumerateArray()) { |
|
|
|
|
|
string name = child.GetProperty("name").GetString(); |
|
|
|
|
|
int start = child.GetProperty("from").GetInt32(); |
|
|
|
|
|
int end = child.GetProperty("to").GetInt32(); |
|
|
|
|
|
string directionString = child.GetProperty("direction").GetString(); |
|
|
AnimationDirection direction = directionString == "pingpong" ? |
|
|
AnimationDirection direction = directionString == "pingpong" ? |
|
|
AnimationDirection.PingPong : AnimationDirection.Forward; |
|
|
AnimationDirection.PingPong : AnimationDirection.Forward; |
|
|
double duration = 0; |
|
|
double duration = 0; |
|
|