-
Notifications
You must be signed in to change notification settings - Fork 1
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
4 changed files
with
127 additions
and
1 deletion.
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
52 changes: 52 additions & 0 deletions
52
GW2SDK/Features/Hero/Equipment/Dyes/ColorInfoJsonConverter.cs
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,52 @@ | ||
using System.Drawing; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace GuildWars2.Hero.Equipment.Dyes; | ||
|
||
internal sealed class ColorInfoJsonConverter : JsonConverter<ColorInfo> | ||
{ | ||
public override ColorInfo Read( | ||
ref Utf8JsonReader reader, | ||
Type typeToConvert, | ||
JsonSerializerOptions options | ||
) | ||
{ | ||
using var document = JsonDocument.ParseValue(ref reader); | ||
return Read(document.RootElement); | ||
} | ||
|
||
public static ColorInfo Read(JsonElement json) | ||
{ | ||
return new ColorInfo | ||
{ | ||
Brightness = json.GetProperty("brightness").GetInt32(), | ||
Contrast = json.GetProperty("contrast").GetDouble(), | ||
Hue = json.GetProperty("hue").GetInt32(), | ||
Saturation = json.GetProperty("saturation").GetDouble(), | ||
Lightness = json.GetProperty("lightness").GetDouble(), | ||
Rgb = Color.FromArgb(json.GetProperty("rgb").GetInt32()) | ||
}; | ||
} | ||
|
||
public override void Write( | ||
Utf8JsonWriter writer, | ||
ColorInfo value, | ||
JsonSerializerOptions options | ||
) | ||
{ | ||
Write(writer, value); | ||
} | ||
|
||
public static void Write(Utf8JsonWriter writer, ColorInfo value) | ||
{ | ||
writer.WriteStartObject(); | ||
writer.WriteNumber("brightness", value.Brightness); | ||
writer.WriteNumber("contrast", value.Contrast); | ||
writer.WriteNumber("hue", value.Hue); | ||
writer.WriteNumber("saturation", value.Saturation); | ||
writer.WriteNumber("lightness", value.Lightness); | ||
writer.WriteNumber("rgb", value.Rgb.ToArgb()); | ||
writer.WriteEndObject(); | ||
} | ||
} |
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