-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
146 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using SFML.Graphics; | ||
|
||
public class ColorConverter : JsonConverter<Color> | ||
{ | ||
public override Color ReadJson(JsonReader reader, Type objectType, Color existingValue, bool hasExistingValue, JsonSerializer serializer) | ||
{ | ||
var token = JToken.Load(reader); | ||
var array = (JArray)token; | ||
|
||
if (array.Count != 3) | ||
throw new JsonSerializationException("Invalid color format. RGB values must be provided as an array of three integers."); | ||
|
||
var r = array[0].Value<byte>(); | ||
var g = array[1].Value<byte>(); | ||
var b = array[2].Value<byte>(); | ||
|
||
return new Color(r, g, b); | ||
} | ||
|
||
public override void WriteJson(JsonWriter writer, Color value, JsonSerializer serializer) | ||
{ | ||
writer.WriteStartArray(); | ||
writer.WriteValue(value.R); | ||
writer.WriteValue(value.G); | ||
writer.WriteValue(value.B); | ||
writer.WriteEndArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
[ | ||
{ | ||
"id": 0, | ||
"name": "Rat", | ||
"description": "A small, brown, rat. its eyes are red, and its appearance is is ugly. also, it is very fast and wants to kill you.", | ||
"HP": 25, | ||
"speed": 3, | ||
"armor": 1, | ||
"attack": 1, | ||
"symbol": "r", | ||
"color": [ | ||
153, | ||
77, | ||
51 | ||
], | ||
"backgroundColor": [ | ||
0, | ||
0, | ||
0 | ||
], | ||
"type": "animal" | ||
}, | ||
{ | ||
"id": 1, | ||
"name": "Zombie", | ||
"description": "A undead (by some force) human body. unstoppable rage and hunger for human flesh is visible in its yellowish eyes. its skin is pale green and full of cuts and bruises.", | ||
"HP": 50, | ||
"speed": 2, | ||
"armor": 2, | ||
"attack": 2, | ||
"symbol": "Z", | ||
"color": [ | ||
100, | ||
155, | ||
100 | ||
], | ||
"backgroundColor": [ | ||
0, | ||
0, | ||
0 | ||
], | ||
"type": "undead" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters