diff --git a/DesktopGL/DesktopGL.csproj b/DesktopGL/DesktopGL.csproj
index 471b6a0..678f1e2 100644
--- a/DesktopGL/DesktopGL.csproj
+++ b/DesktopGL/DesktopGL.csproj
@@ -1,7 +1,7 @@
WinExe
- netcoreapp3.1
+ net5.0
false
false
@@ -28,5 +28,8 @@
+
+
+
diff --git a/Shared/SneakWorld.cs b/Shared/SneakWorld.cs
index fa6b814..63d948c 100644
--- a/Shared/SneakWorld.cs
+++ b/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();
+ Height = root.SelectToken("height").Value();
List hazardTiles = new List();
List obstacleTiles = new List();
List obstacleTiles8 = new List();
List decorationTiles = new List();
List backgroundTiles = new List();
- 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();
if (layerName == "entities") {
entitiesLayer = layer;
(Player, npcs) = ParseEntities(layer);
@@ -99,22 +99,21 @@ namespace SemiColinGames {
GC.SuppressFinalize(this);
}
- private List ParseLayer(JsonElement layer) {
- string layerName = layer.GetProperty("name").GetString();
+ private List ParseLayer(JToken layer) {
+ string layerName = layer.SelectToken("name").Value();
var tileList = new List();
- int layerWidth = layer.GetProperty("gridCellsX").GetInt32();
- int layerHeight = layer.GetProperty("gridCellsY").GetInt32();
+ int layerWidth = layer.SelectToken("gridCellsX").Value();
+ int layerHeight = layer.SelectToken("gridCellsY").Value();
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 tileHeight = layer.SelectToken("gridCellHeight").Value();
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()) {
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 npcs = new List();
- 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();
+ int x = entity.SelectToken("x").Value();
+ int y = entity.SelectToken("y").Value();
+ int facing = entity.SelectToken("flippedX").Value() ? -1 : 1;
if (name == "player") {
player = new Player(new Vector2(x, y), facing);
} else if (name == "executioner") {
diff --git a/Shared/Sprites.cs b/Shared/Sprites.cs
index f59605c..04b0f29 100644
--- a/Shared/Sprites.cs
+++ b/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();
- JsonElement jsonRoot = JsonDocument.Parse(metadataJson).RootElement;
+ JObject json = JObject.Parse(metadataJson);
frames = new List();
- 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(),
+ child.SelectToken("frame.y").Value(),
+ child.SelectToken("frame.w").Value(),
+ child.SelectToken("frame.h").Value());
+ double duration = child.SelectToken("duration").Value() / 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();
+ int start = child.SelectToken("from").Value();
+ int end = child.SelectToken("to").Value();
+ string directionString = child.SelectToken("direction").Value();
AnimationDirection direction = directionString == "pingpong" ?
AnimationDirection.PingPong : AnimationDirection.Forward;
double duration = 0;
diff --git a/Sneak.sln b/Sneak.sln
index aaa8289..dbff81e 100644
--- a/Sneak.sln
+++ b/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
diff --git a/UWP/UWP.csproj b/UWP/UWP.csproj
index f459e74..17a5286 100644
--- a/UWP/UWP.csproj
+++ b/UWP/UWP.csproj
@@ -156,7 +156,10 @@
- 6.2.10
+ 6.2.12
+
+
+ 13.0.1
4.2.0
@@ -176,9 +179,6 @@
4.2.0
-
- 5.0.2
-