-
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
3 changed files
with
92 additions
and
2 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
53 changes: 53 additions & 0 deletions
53
GW2SDK/Features/Hero/Equipment/Gliders/GliderSkinJsonConverter.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,53 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using GuildWars2.Json; | ||
|
||
namespace GuildWars2.Hero.Equipment.Gliders; | ||
|
||
internal sealed class GliderSkinJsonConverter : JsonConverter<GliderSkin> | ||
{ | ||
public override GliderSkin? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
using var document = JsonDocument.ParseValue(ref reader); | ||
return Read(document.RootElement); | ||
} | ||
|
||
public static GliderSkin? Read(JsonElement json) | ||
{ | ||
return new GliderSkin | ||
{ | ||
Id = json.GetProperty("id").GetInt32(), | ||
UnlockItemIds = json.GetProperty("unlock_item_ids").GetList(item => item.GetInt32()), | ||
Order = json.GetProperty("order").GetInt32(), | ||
IconHref = json.GetProperty("icon").GetStringRequired(), | ||
Name = json.GetProperty("name").GetStringRequired(), | ||
Description = json.GetProperty("description").GetStringRequired(), | ||
DefaultDyeColorIds = json.GetProperty("default_dye_color_ids").GetList(item => item.GetInt32()) | ||
}; | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, GliderSkin value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteStartObject(); | ||
writer.WriteNumber("id", value.Id); | ||
writer.WriteStartArray("unlock_item_ids"); | ||
foreach (var element in value.UnlockItemIds) | ||
{ | ||
writer.WriteNumberValue(element); | ||
} | ||
|
||
writer.WriteEndArray(); | ||
writer.WriteNumber("order", value.Order); | ||
writer.WriteString("icon", value.IconHref); | ||
writer.WriteString("name", value.Name); | ||
writer.WriteString("description", value.Description); | ||
writer.WriteStartArray("default_dye_color_ids"); | ||
foreach (var element in value.DefaultDyeColorIds) | ||
{ | ||
writer.WriteNumberValue(element); | ||
} | ||
|
||
writer.WriteEndArray(); | ||
writer.WriteEndObject(); | ||
} | ||
} |