Compare commits

..

2 Commits

3 changed files with 23 additions and 18 deletions

View File

@ -27,6 +27,7 @@
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.0.1641" />
<PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.0.1641" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="System.Text.Json" Version="5.0.2" />
</ItemGroup>
<Import Project="..\Shared\Shared.projitems" Label="Shared" />
</Project>

View File

@ -1,7 +1,7 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Text.Json;
namespace SemiColinGames {
public static class Sprites {
@ -61,29 +61,32 @@ namespace SemiColinGames {
Texture = texture;
animations = new Dictionary<string, SpriteAnimation>();
JObject json = JObject.Parse(metadataJson);
JsonElement jsonRoot = JsonDocument.Parse(metadataJson).RootElement;
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(
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));
}
// We assume that all frames are the same size (which right now is assured by the
// Aseprite-based spritesheet export process).
Width = frames[0].Source.Width;
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.PingPong : AnimationDirection.Forward;
double duration = 0;

View File

@ -179,18 +179,19 @@
<PackageReference Include="SharpDX.XAudio2">
<Version>4.2.0</Version>
</PackageReference>
<PackageReference Include="System.Text.Json">
<Version>5.0.2</Version>
</PackageReference>
</ItemGroup>
<Import Project="..\Shared\Shared.projitems" Label="Shared" />
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<ItemGroup>
<PackageReference Include="MonoGame.Framework.WindowsUniversal" Version="3.8.0.*" />
<PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.0.*" />
</ItemGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">