-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from OliBomby/dev
Dev update 1.6.8.0
- Loading branch information
Showing
35 changed files
with
694 additions
and
60 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using System.IO; | ||
using Mapping_Tools.Classes.MathUtil; | ||
using Newtonsoft.Json; | ||
|
||
namespace Mapping_Tools.Classes.JsonConverters { | ||
public class Vector2Converter : JsonConverter { | ||
public override bool CanConvert(Type objectType) { | ||
return objectType == typeof(Vector2) || objectType == typeof(Vector2?); | ||
} | ||
|
||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { | ||
var v = (Vector2)value; | ||
|
||
writer.WriteStartObject(); | ||
writer.WritePropertyName("X"); | ||
serializer.Serialize(writer, v.X); | ||
writer.WritePropertyName("Y"); | ||
serializer.Serialize(writer, v.Y); | ||
writer.WriteEndObject(); | ||
} | ||
|
||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { | ||
var x = default(double); | ||
var y = default(double); | ||
var gotX = false; | ||
var gotY = false; | ||
while (reader.Read()) { | ||
if (reader.TokenType != JsonToken.PropertyName) | ||
break; | ||
|
||
var propertyName = (string)reader.Value; | ||
if (!reader.Read()) | ||
continue; | ||
|
||
switch (propertyName) { | ||
case "X": | ||
x = serializer.Deserialize<double>(reader); | ||
gotX = true; | ||
break; | ||
case "Y": | ||
y = serializer.Deserialize<double>(reader); | ||
gotY = true; | ||
break; | ||
} | ||
} | ||
|
||
if (!(gotX && gotY)) { | ||
throw new InvalidDataException("A Vector2 must contain X and Y properties."); | ||
} | ||
|
||
return new Vector2(x, y); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.