-
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
10 changed files
with
116 additions
and
2 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
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 | ||
{ | ||
} |
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,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() | ||
}; | ||
} | ||
} |