Skip to content

Commit

Permalink
Add support for Relics
Browse files Browse the repository at this point in the history
  • Loading branch information
sliekens committed Sep 4, 2023
1 parent 95f5bb4 commit cf91e58
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 2 deletions.
Binary file modified GW2SDK.Tests/Data/achievements.json.gz
Binary file not shown.
Binary file modified GW2SDK.Tests/Data/items.json.gz
Binary file not shown.
Binary file modified GW2SDK.Tests/Data/listings.json.gz
Binary file not shown.
Binary file modified GW2SDK.Tests/Data/prices.json.gz
Binary file not shown.
Binary file modified GW2SDK.Tests/Data/recipes.json.gz
Binary file not shown.
Binary file modified GW2SDK.Tests/Data/skins.json.gz
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace GuildWars2.Tests.Features.Items;

public class ItemReaderTest : IClassFixture<ItemFixture>
public class ItemJsonTest : IClassFixture<ItemFixture>
{
public ItemReaderTest(ItemFixture fixture)
public ItemJsonTest(ItemFixture fixture)
{
this.fixture = fixture;
}
Expand Down
2 changes: 2 additions & 0 deletions GW2SDK/Features/Items/Models/ItemJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public static Item GetItem(this JsonElement json, MissingMemberBehavior missingM
return json.GetMinipet(missingMemberBehavior);
case "PowerCore":
return json.GetPowerCore(missingMemberBehavior);
case "Relic" or "Mwcc":
return json.GetRelic(missingMemberBehavior);
case "Tool":
return json.GetTool(missingMemberBehavior);
case "Trinket":
Expand Down
8 changes: 8 additions & 0 deletions GW2SDK/Features/Items/Models/Relics/Relic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using JetBrains.Annotations;

namespace GuildWars2.Items;

[PublicAPI]
public sealed record Relic : Item
{
}
104 changes: 104 additions & 0 deletions GW2SDK/Features/Items/Models/Relics/RelicJson.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using System;
using System.Text.Json;
using GuildWars2.Json;
using JetBrains.Annotations;

namespace GuildWars2.Items;

[PublicAPI]
public static class RelicJson
{
public static Relic GetRelic(
this JsonElement json,
MissingMemberBehavior missingMemberBehavior
)
{
RequiredMember<string> name = new("name");
OptionalMember<string> description = new("description");
RequiredMember<int> level = new("level");
RequiredMember<Rarity> rarity = new("rarity");
RequiredMember<Coin> vendorValue = new("vendor_value");
RequiredMember<GameType> gameTypes = new("game_types");
RequiredMember<ItemFlag> flags = new("flags");
RequiredMember<ItemRestriction> restrictions = new("restrictions");
RequiredMember<int> id = new("id");
RequiredMember<string> chatLink = new("chat_link");
OptionalMember<string> icon = new("icon");
foreach (var member in json.EnumerateObject())
{
if (member.NameEquals("type"))
{
if (!member.Value.ValueEquals("Relic")
&& !member.Value.ValueEquals("Mwcc")) // Temporary value
{
throw new InvalidOperationException(
Strings.InvalidDiscriminator(member.Value.GetString())
);
}
}
else if (member.NameEquals(name.Name))
{
name.Value = member.Value;
}
else if (member.NameEquals(description.Name))
{
description.Value = member.Value;
}
else if (member.NameEquals(level.Name))
{
level.Value = member.Value;
}
else if (member.NameEquals(rarity.Name))
{
rarity.Value = member.Value;
}
else if (member.NameEquals(vendorValue.Name))
{
vendorValue.Value = member.Value;
}
else if (member.NameEquals(gameTypes.Name))
{
gameTypes.Value = member.Value;
}
else if (member.NameEquals(flags.Name))
{
flags.Value = member.Value;
}
else if (member.NameEquals(restrictions.Name))
{
restrictions.Value = member.Value;
}
else if (member.NameEquals(id.Name))
{
id.Value = member.Value;
}
else if (member.NameEquals(chatLink.Name))
{
chatLink.Value = member.Value;
}
else if (member.NameEquals(icon.Name))
{
icon.Value = member.Value;
}
else if (missingMemberBehavior == MissingMemberBehavior.Error)
{
throw new InvalidOperationException(Strings.UnexpectedMember(member.Name));
}
}

return new Relic
{
Id = id.GetValue(),
Name = name.GetValue(),
Description = description.GetValueOrEmpty(),
Level = level.GetValue(),
Rarity = rarity.GetValue(missingMemberBehavior),
VendorValue = vendorValue.GetValue(),
GameTypes = gameTypes.GetValues(missingMemberBehavior),
Flags = flags.GetValues(missingMemberBehavior),
Restrictions = restrictions.GetValues(missingMemberBehavior),
ChatLink = chatLink.GetValue(),
Icon = icon.GetValueOrNull()
};
}
}

0 comments on commit cf91e58

Please sign in to comment.