-
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
5 changed files
with
137 additions
and
3 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
50 changes: 50 additions & 0 deletions
50
GW2SDK/Features/Hero/Equipment/Finishers/FinisherJsonConverter.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,50 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using GuildWars2.Json; | ||
|
||
namespace GuildWars2.Hero.Equipment.Finishers; | ||
|
||
internal sealed class FinisherJsonConverter : JsonConverter<Finisher> | ||
{ | ||
public override Finisher? Read( | ||
ref Utf8JsonReader reader, | ||
Type typeToConvert, | ||
JsonSerializerOptions options | ||
) | ||
{ | ||
using var document = JsonDocument.ParseValue(ref reader); | ||
return Read(document.RootElement); | ||
} | ||
|
||
public static Finisher? Read(JsonElement json) | ||
{ | ||
return new Finisher | ||
{ | ||
Id = json.GetProperty("id").GetInt32(), | ||
LockedText = json.GetProperty("locked_text").GetStringRequired(), | ||
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() | ||
}; | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, Finisher value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteStartObject(); | ||
writer.WriteNumber("id", value.Id); | ||
writer.WriteString("locked_text", value.LockedText); | ||
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.WriteEndObject(); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
GW2SDK/Features/Hero/Equipment/Finishers/UnlockedFinisherJsonConverter.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,50 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using GuildWars2.Json; | ||
|
||
namespace GuildWars2.Hero.Equipment.Finishers; | ||
|
||
internal sealed class UnlockedFinisherJsonConverter : JsonConverter<UnlockedFinisher> | ||
{ | ||
public override UnlockedFinisher? Read( | ||
ref Utf8JsonReader reader, | ||
Type typeToConvert, | ||
JsonSerializerOptions options | ||
) | ||
{ | ||
using var document = JsonDocument.ParseValue(ref reader); | ||
return Read(document.RootElement); | ||
} | ||
|
||
public static UnlockedFinisher? Read(JsonElement json) | ||
{ | ||
return new UnlockedFinisher | ||
{ | ||
Id = json.GetProperty("id").GetInt32(), | ||
Permanent = json.GetProperty("permanent").GetBoolean(), | ||
Quantity = json.GetProperty("quantity").GetNullableInt32() | ||
}; | ||
} | ||
|
||
public override void Write( | ||
Utf8JsonWriter writer, | ||
UnlockedFinisher value, | ||
JsonSerializerOptions options | ||
) | ||
{ | ||
writer.WriteStartObject(); | ||
writer.WriteNumber("id", value.Id); | ||
writer.WriteBoolean("permanent", value.Permanent); | ||
writer.WritePropertyName("quantity"); | ||
if (value.Quantity is not null) | ||
{ | ||
writer.WriteNumberValue(value.Quantity.Value); | ||
} | ||
else | ||
{ | ||
writer.WriteNullValue(); | ||
} | ||
|
||
writer.WriteEndObject(); | ||
} | ||
} |