revert back to Newtonsoft.Json for now
This commit is contained in:
parent
b98bb61bd9
commit
5e6f95beee
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>WinExe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<PublishReadyToRun>false</PublishReadyToRun>
|
<PublishReadyToRun>false</PublishReadyToRun>
|
||||||
<TieredCompilation>false</TieredCompilation>
|
<TieredCompilation>false</TieredCompilation>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@ -28,5 +28,8 @@
|
|||||||
<PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.0.1641" />
|
<PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.0.1641" />
|
||||||
<PackageReference Include="System.Text.Json" Version="5.0.2" />
|
<PackageReference Include="System.Text.Json" Version="5.0.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\Newtonsoft.Json\Src\Newtonsoft.Json\Newtonsoft.Json.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="..\Shared\Shared.projitems" Label="Shared" />
|
<Import Project="..\Shared\Shared.projitems" Label="Shared" />
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text.Json;
|
|
||||||
|
|
||||||
namespace SemiColinGames {
|
namespace SemiColinGames {
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ namespace SemiColinGames {
|
|||||||
private readonly Tile[] obstacles;
|
private readonly Tile[] obstacles;
|
||||||
private readonly Tile[] decorations;
|
private readonly Tile[] decorations;
|
||||||
// Kept around for resetting the world's entities after player death or level restart.
|
// 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;
|
private NPC[] npcs;
|
||||||
|
|
||||||
public Player Player { get; private set; }
|
public Player Player { get; private set; }
|
||||||
@ -31,17 +31,17 @@ namespace SemiColinGames {
|
|||||||
Camera = new Camera();
|
Camera = new Camera();
|
||||||
LinesOfSight = new LinesOfSight(graphics);
|
LinesOfSight = new LinesOfSight(graphics);
|
||||||
|
|
||||||
JsonElement jsonRoot = JsonDocument.Parse(json).RootElement;
|
JObject root = JObject.Parse(json);
|
||||||
Width = jsonRoot.GetProperty("width").GetInt32();
|
Width = root.SelectToken("width").Value<int>();
|
||||||
Height = jsonRoot.GetProperty("height").GetInt32();
|
Height = root.SelectToken("height").Value<int>();
|
||||||
|
|
||||||
List<Tile> hazardTiles = new List<Tile>();
|
List<Tile> hazardTiles = new List<Tile>();
|
||||||
List<Tile> obstacleTiles = new List<Tile>();
|
List<Tile> obstacleTiles = new List<Tile>();
|
||||||
List<Tile> obstacleTiles8 = new List<Tile>();
|
List<Tile> obstacleTiles8 = new List<Tile>();
|
||||||
List<Tile> decorationTiles = new List<Tile>();
|
List<Tile> decorationTiles = new List<Tile>();
|
||||||
List<Tile> backgroundTiles = new List<Tile>();
|
List<Tile> backgroundTiles = new List<Tile>();
|
||||||
foreach (JsonElement layer in jsonRoot.GetProperty("layers").EnumerateArray()) {
|
foreach (JToken layer in root.SelectToken("layers").Children()) {
|
||||||
string layerName = layer.GetProperty("name").GetString();
|
string layerName = layer.SelectToken("name").Value<string>();
|
||||||
if (layerName == "entities") {
|
if (layerName == "entities") {
|
||||||
entitiesLayer = layer;
|
entitiesLayer = layer;
|
||||||
(Player, npcs) = ParseEntities(layer);
|
(Player, npcs) = ParseEntities(layer);
|
||||||
@ -99,22 +99,21 @@ namespace SemiColinGames {
|
|||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Tile> ParseLayer(JsonElement layer) {
|
private List<Tile> ParseLayer(JToken layer) {
|
||||||
string layerName = layer.GetProperty("name").GetString();
|
string layerName = layer.SelectToken("name").Value<string>();
|
||||||
|
|
||||||
var tileList = new List<Tile>();
|
var tileList = new List<Tile>();
|
||||||
|
|
||||||
int layerWidth = layer.GetProperty("gridCellsX").GetInt32();
|
int layerWidth = layer.SelectToken("gridCellsX").Value<int>();
|
||||||
int layerHeight = layer.GetProperty("gridCellsY").GetInt32();
|
int layerHeight = layer.SelectToken("gridCellsY").Value<int>();
|
||||||
gridWidth = Math.Max(gridWidth, layerWidth);
|
gridWidth = Math.Max(gridWidth, layerWidth);
|
||||||
gridHeight = Math.Max(gridHeight, layerHeight);
|
gridHeight = Math.Max(gridHeight, layerHeight);
|
||||||
|
|
||||||
int dataIndex = -1;
|
int dataIndex = -1;
|
||||||
int tileWidth = layer.GetProperty("gridCellWidth").GetInt32();
|
int tileWidth = layer.SelectToken("gridCellWidth").Value<int>();
|
||||||
int tileHeight = layer.GetProperty("gridCellHeight").GetInt32();
|
int tileHeight = layer.SelectToken("gridCellHeight").Value<int>();
|
||||||
int textureWidth = Textures.Grassland.Get.Width / tileWidth;
|
int textureWidth = Textures.Grassland.Get.Width / tileWidth;
|
||||||
foreach (JsonElement textureIndexElement in layer.GetProperty("data").EnumerateArray()) {
|
foreach (int textureIndex in layer.SelectToken("data").Values<int>()) {
|
||||||
int textureIndex = textureIndexElement.GetInt32();
|
|
||||||
dataIndex++;
|
dataIndex++;
|
||||||
if (textureIndex == -1) {
|
if (textureIndex == -1) {
|
||||||
continue;
|
continue;
|
||||||
@ -134,14 +133,14 @@ namespace SemiColinGames {
|
|||||||
return tileList;
|
return tileList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private (Player, NPC[]) ParseEntities(JsonElement layer) {
|
private (Player, NPC[]) ParseEntities(JToken layer) {
|
||||||
Player player = null;
|
Player player = null;
|
||||||
List<NPC> npcs = new List<NPC>();
|
List<NPC> npcs = new List<NPC>();
|
||||||
foreach (JsonElement entity in layer.GetProperty("entities").EnumerateArray()) {
|
foreach (JToken entity in layer.SelectToken("entities").Children()) {
|
||||||
string name = entity.GetProperty("name").GetString();
|
string name = entity.SelectToken("name").Value<string>();
|
||||||
int x = entity.GetProperty("x").GetInt32();
|
int x = entity.SelectToken("x").Value<int>();
|
||||||
int y = entity.GetProperty("y").GetInt32();
|
int y = entity.SelectToken("y").Value<int>();
|
||||||
int facing = entity.GetProperty("flippedX").GetBoolean() ? -1 : 1;
|
int facing = entity.SelectToken("flippedX").Value<bool>() ? -1 : 1;
|
||||||
if (name == "player") {
|
if (name == "player") {
|
||||||
player = new Player(new Vector2(x, y), facing);
|
player = new Player(new Vector2(x, y), facing);
|
||||||
} else if (name == "executioner") {
|
} else if (name == "executioner") {
|
||||||
|
@ -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,32 +61,29 @@ namespace SemiColinGames {
|
|||||||
Texture = texture;
|
Texture = texture;
|
||||||
animations = new Dictionary<string, SpriteAnimation>();
|
animations = new Dictionary<string, SpriteAnimation>();
|
||||||
|
|
||||||
JsonElement jsonRoot = JsonDocument.Parse(metadataJson).RootElement;
|
JObject json = JObject.Parse(metadataJson);
|
||||||
|
|
||||||
frames = new List<Frame>();
|
frames = new List<Frame>();
|
||||||
foreach (JsonElement child in jsonRoot.GetProperty("frames").EnumerateArray()) {
|
foreach (JToken child in json.SelectToken("frames").Children()) {
|
||||||
JsonElement frame = child.GetProperty("frame");
|
|
||||||
Rectangle source = new Rectangle(
|
Rectangle source = new Rectangle(
|
||||||
frame.GetProperty("x").GetInt32(),
|
child.SelectToken("frame.x").Value<int>(),
|
||||||
frame.GetProperty("y").GetInt32(),
|
child.SelectToken("frame.y").Value<int>(),
|
||||||
frame.GetProperty("w").GetInt32(),
|
child.SelectToken("frame.w").Value<int>(),
|
||||||
frame.GetProperty("h").GetInt32());
|
child.SelectToken("frame.h").Value<int>());
|
||||||
|
double duration = child.SelectToken("duration").Value<double>() / 1000;
|
||||||
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;
|
||||||
|
|
||||||
JsonElement frameTags = jsonRoot.GetProperty("meta").GetProperty("frameTags");
|
JToken frameTags = json.SelectToken("meta.frameTags");
|
||||||
foreach (JsonElement child in frameTags.EnumerateArray()) {
|
foreach (JToken child in frameTags.Children()) {
|
||||||
string name = child.GetProperty("name").GetString();
|
string name = child.SelectToken("name").Value<string>();
|
||||||
int start = child.GetProperty("from").GetInt32();
|
int start = child.SelectToken("from").Value<int>();
|
||||||
int end = child.GetProperty("to").GetInt32();
|
int end = child.SelectToken("to").Value<int>();
|
||||||
string directionString = child.GetProperty("direction").GetString();
|
string directionString = child.SelectToken("direction").Value<string>();
|
||||||
AnimationDirection direction = directionString == "pingpong" ?
|
AnimationDirection direction = directionString == "pingpong" ?
|
||||||
AnimationDirection.PingPong : AnimationDirection.Forward;
|
AnimationDirection.PingPong : AnimationDirection.Forward;
|
||||||
double duration = 0;
|
double duration = 0;
|
||||||
|
22
Sneak.sln
22
Sneak.sln
@ -18,6 +18,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
|||||||
.editorconfig = .editorconfig
|
.editorconfig = .editorconfig
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Newtonsoft.Json", "..\Newtonsoft.Json\Src\Newtonsoft.Json\Newtonsoft.Json.csproj", "{A4BB5AB0-821E-42C9-9F77-0EF7F737B9D1}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SharedMSBuildProjectFiles) = preSolution
|
GlobalSection(SharedMSBuildProjectFiles) = preSolution
|
||||||
Shared\Shared.projitems*{21570905-5ffd-49fc-b523-1e7e6f191142}*SharedItemsImports = 4
|
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|x64.Build.0 = Release|Any CPU
|
||||||
{C86694A5-DD99-4421-AA2C-1230F11C10F8}.Release|x86.ActiveCfg = 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
|
{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
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -156,7 +156,10 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
|
<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>
|
||||||
<PackageReference Include="SharpDX">
|
<PackageReference Include="SharpDX">
|
||||||
<Version>4.2.0</Version>
|
<Version>4.2.0</Version>
|
||||||
@ -176,9 +179,6 @@
|
|||||||
<PackageReference Include="SharpDX.XAudio2">
|
<PackageReference Include="SharpDX.XAudio2">
|
||||||
<Version>4.2.0</Version>
|
<Version>4.2.0</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="System.Text.Json">
|
|
||||||
<Version>5.0.2</Version>
|
|
||||||
</PackageReference>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="..\Shared\Shared.projitems" Label="Shared" />
|
<Import Project="..\Shared\Shared.projitems" Label="Shared" />
|
||||||
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' ">
|
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' ">
|
||||||
|
Loading…
Reference in New Issue
Block a user