-
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.
Add json converter for jade bot skins
- Loading branch information
Showing
3 changed files
with
53 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
43 changes: 43 additions & 0 deletions
43
GW2SDK/Features/Hero/Equipment/JadeBots/JadeBotSkinJsonConverter.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,43 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using GuildWars2.Json; | ||
|
||
namespace GuildWars2.Hero.Equipment.JadeBots; | ||
|
||
internal sealed class JadeBotSkinJsonConverter : JsonConverter<JadeBotSkin> | ||
{ | ||
public override JadeBotSkin? Read( | ||
ref Utf8JsonReader reader, | ||
Type typeToConvert, | ||
JsonSerializerOptions options | ||
) | ||
{ | ||
using var document = JsonDocument.ParseValue(ref reader); | ||
return Read(document.RootElement); | ||
} | ||
|
||
public static JadeBotSkin? Read(JsonElement json) | ||
{ | ||
return new JadeBotSkin | ||
{ | ||
Id = json.GetProperty("id").GetInt32(), | ||
Name = json.GetProperty("name").GetStringRequired(), | ||
Description = json.GetProperty("description").GetStringRequired(), | ||
UnlockItemId = json.GetProperty("unlock_item_id").GetInt32() | ||
}; | ||
} | ||
|
||
public override void Write( | ||
Utf8JsonWriter writer, | ||
JadeBotSkin value, | ||
JsonSerializerOptions options | ||
) | ||
{ | ||
writer.WriteStartObject(); | ||
writer.WriteNumber("id", value.Id); | ||
writer.WriteString("name", value.Name); | ||
writer.WriteString("description", value.Description); | ||
writer.WriteNumber("unlock_item_id", value.UnlockItemId); | ||
writer.WriteEndObject(); | ||
} | ||
} |