Browse Source

revert back to Newtonsoft.Json for now

main
Colin McMillen 3 years ago
parent
commit
5e6f95beee
  1. 5
      DesktopGL/DesktopGL.csproj
  2. 41
      Shared/SneakWorld.cs
  3. 31
      Shared/Sprites.cs
  4. 22
      Sneak.sln
  5. 8
      UWP/UWP.csproj

5
DesktopGL/DesktopGL.csproj

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<PublishReadyToRun>false</PublishReadyToRun>
<TieredCompilation>false</TieredCompilation>
</PropertyGroup>
@ -28,5 +28,8 @@
<PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.0.1641" />
<PackageReference Include="System.Text.Json" Version="5.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Newtonsoft.Json\Src\Newtonsoft.Json\Newtonsoft.Json.csproj" />
</ItemGroup>
<Import Project="..\Shared\Shared.projitems" Label="Shared" />
</Project>

41
Shared/SneakWorld.cs

@ -1,8 +1,8 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Text.Json;
namespace SemiColinGames {
@ -14,7 +14,7 @@ namespace SemiColinGames {
private readonly Tile[] obstacles;
private readonly Tile[] decorations;
// Kept around for resetting the world's entities after player death or level restart.
private readonly JsonElement entitiesLayer;
private readonly JToken entitiesLayer;
private NPC[] npcs;
public Player Player { get; private set; }
@ -31,17 +31,17 @@ namespace SemiColinGames {
Camera = new Camera();
LinesOfSight = new LinesOfSight(graphics);
JsonElement jsonRoot = JsonDocument.Parse(json).RootElement;
Width = jsonRoot.GetProperty("width").GetInt32();
Height = jsonRoot.GetProperty("height").GetInt32();
JObject root = JObject.Parse(json);
Width = root.SelectToken("width").Value<int>();
Height = root.SelectToken("height").Value<int>();
List<Tile> hazardTiles = new List<Tile>();
List<Tile> obstacleTiles = new List<Tile>();
List<Tile> obstacleTiles8 = new List<Tile>();
List<Tile> decorationTiles = new List<Tile>();
List<Tile> backgroundTiles = new List<Tile>();
foreach (JsonElement layer in jsonRoot.GetProperty("layers").EnumerateArray()) {
string layerName = layer.GetProperty("name").GetString();
foreach (JToken layer in root.SelectToken("layers").Children()) {
string layerName = layer.SelectToken("name").Value<string>();
if (layerName == "entities") {
entitiesLayer = layer;
(Player, npcs) = ParseEntities(layer);
@ -99,22 +99,21 @@ namespace SemiColinGames {
GC.SuppressFinalize(this);
}
private List<Tile> ParseLayer(JsonElement layer) {
string layerName = layer.GetProperty("name").GetString();
private List<Tile> ParseLayer(JToken layer) {
string layerName = layer.SelectToken("name").Value<string>();
var tileList = new List<Tile>();
int layerWidth = layer.GetProperty("gridCellsX").GetInt32();
int layerHeight = layer.GetProperty("gridCellsY").GetInt32();
int layerWidth = layer.SelectToken("gridCellsX").Value<int>();
int layerHeight = layer.SelectToken("gridCellsY").Value<int>();
gridWidth = Math.Max(gridWidth, layerWidth);
gridHeight = Math.Max(gridHeight, layerHeight);
int dataIndex = -1;
int tileWidth = layer.GetProperty("gridCellWidth").GetInt32();
int tileHeight = layer.GetProperty("gridCellHeight").GetInt32();
int tileWidth = layer.SelectToken("gridCellWidth").Value<int>();
int tileHeight = layer.SelectToken("gridCellHeight").Value<int>();
int textureWidth = Textures.Grassland.Get.Width / tileWidth;
foreach (JsonElement textureIndexElement in layer.GetProperty("data").EnumerateArray()) {
int textureIndex = textureIndexElement.GetInt32();
foreach (int textureIndex in layer.SelectToken("data").Values<int>()) {
dataIndex++;
if (textureIndex == -1) {
continue;
@ -134,14 +133,14 @@ namespace SemiColinGames {
return tileList;
}
private (Player, NPC[]) ParseEntities(JsonElement layer) {
private (Player, NPC[]) ParseEntities(JToken layer) {
Player player = null;
List<NPC> npcs = new List<NPC>();
foreach (JsonElement entity in layer.GetProperty("entities").EnumerateArray()) {
string name = entity.GetProperty("name").GetString();
int x = entity.GetProperty("x").GetInt32();
int y = entity.GetProperty("y").GetInt32();
int facing = entity.GetProperty("flippedX").GetBoolean() ? -1 : 1;
foreach (JToken entity in layer.SelectToken("entities").Children()) {
string name = entity.SelectToken("name").Value<string>();
int x = entity.SelectToken("x").Value<int>();
int y = entity.SelectToken("y").Value<int>();
int facing = entity.SelectToken("flippedX").Value<bool>() ? -1 : 1;
if (name == "player") {
player = new Player(new Vector2(x, y), facing);
} else if (name == "executioner") {

31
Shared/Sprites.cs

@ -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,32 +61,29 @@ namespace SemiColinGames {
Texture = texture;
animations = new Dictionary<string, SpriteAnimation>();
JsonElement jsonRoot = JsonDocument.Parse(metadataJson).RootElement;
JObject json = JObject.Parse(metadataJson);
frames = new List<Frame>();
foreach (JsonElement child in jsonRoot.GetProperty("frames").EnumerateArray()) {
JsonElement frame = child.GetProperty("frame");
foreach (JToken child in json.SelectToken("frames").Children()) {
Rectangle source = new Rectangle(
frame.GetProperty("x").GetInt32(),
frame.GetProperty("y").GetInt32(),
frame.GetProperty("w").GetInt32(),
frame.GetProperty("h").GetInt32());
double duration = child.GetProperty("duration").GetDouble() / 1000;
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;
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;
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();
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>();
AnimationDirection direction = directionString == "pingpong" ?
AnimationDirection.PingPong : AnimationDirection.Forward;
double duration = 0;

22
Sneak.sln

@ -18,6 +18,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Newtonsoft.Json", "..\Newtonsoft.Json\Src\Newtonsoft.Json\Newtonsoft.Json.csproj", "{A4BB5AB0-821E-42C9-9F77-0EF7F737B9D1}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Shared\Shared.projitems*{21570905-5ffd-49fc-b523-1e7e6f191142}*SharedItemsImports = 4
@ -117,6 +119,26 @@ Global
{C86694A5-DD99-4421-AA2C-1230F11C10F8}.Release|x64.Build.0 = Release|Any CPU
{C86694A5-DD99-4421-AA2C-1230F11C10F8}.Release|x86.ActiveCfg = Release|Any CPU
{C86694A5-DD99-4421-AA2C-1230F11C10F8}.Release|x86.Build.0 = Release|Any CPU
{A4BB5AB0-821E-42C9-9F77-0EF7F737B9D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A4BB5AB0-821E-42C9-9F77-0EF7F737B9D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A4BB5AB0-821E-42C9-9F77-0EF7F737B9D1}.Debug|ARM.ActiveCfg = Debug|Any CPU
{A4BB5AB0-821E-42C9-9F77-0EF7F737B9D1}.Debug|ARM.Build.0 = Debug|Any CPU
{A4BB5AB0-821E-42C9-9F77-0EF7F737B9D1}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{A4BB5AB0-821E-42C9-9F77-0EF7F737B9D1}.Debug|ARM64.Build.0 = Debug|Any CPU
{A4BB5AB0-821E-42C9-9F77-0EF7F737B9D1}.Debug|x64.ActiveCfg = Debug|Any CPU
{A4BB5AB0-821E-42C9-9F77-0EF7F737B9D1}.Debug|x64.Build.0 = Debug|Any CPU
{A4BB5AB0-821E-42C9-9F77-0EF7F737B9D1}.Debug|x86.ActiveCfg = Debug|Any CPU
{A4BB5AB0-821E-42C9-9F77-0EF7F737B9D1}.Debug|x86.Build.0 = Debug|Any CPU
{A4BB5AB0-821E-42C9-9F77-0EF7F737B9D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A4BB5AB0-821E-42C9-9F77-0EF7F737B9D1}.Release|Any CPU.Build.0 = Release|Any CPU
{A4BB5AB0-821E-42C9-9F77-0EF7F737B9D1}.Release|ARM.ActiveCfg = Release|Any CPU
{A4BB5AB0-821E-42C9-9F77-0EF7F737B9D1}.Release|ARM.Build.0 = Release|Any CPU
{A4BB5AB0-821E-42C9-9F77-0EF7F737B9D1}.Release|ARM64.ActiveCfg = Release|Any CPU
{A4BB5AB0-821E-42C9-9F77-0EF7F737B9D1}.Release|ARM64.Build.0 = Release|Any CPU
{A4BB5AB0-821E-42C9-9F77-0EF7F737B9D1}.Release|x64.ActiveCfg = Release|Any CPU
{A4BB5AB0-821E-42C9-9F77-0EF7F737B9D1}.Release|x64.Build.0 = Release|Any CPU
{A4BB5AB0-821E-42C9-9F77-0EF7F737B9D1}.Release|x86.ActiveCfg = Release|Any CPU
{A4BB5AB0-821E-42C9-9F77-0EF7F737B9D1}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

8
UWP/UWP.csproj

@ -156,7 +156,10 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.10</Version>
<Version>6.2.12</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.1</Version>
</PackageReference>
<PackageReference Include="SharpDX">
<Version>4.2.0</Version>
@ -176,9 +179,6 @@
<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' ">

Loading…
Cancel
Save