Skip to content

Commit

Permalink
fix achievement parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenari committed Jun 15, 2024
1 parent 4041ac5 commit 878de85
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 35 deletions.
4 changes: 4 additions & 0 deletions NetStone.Test/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ public async Task CheckCharacterFull()

var achieve = await chara.GetAchievement();
Assert.NotNull(achieve);
Assert.GreaterOrEqual(1015, achieve.TotalAchievements);
Assert.GreaterOrEqual(8435, achieve.AchievementPoints);
Assert.GreaterOrEqual(21, achieve.NumPages);
Assert.AreEqual(1,achieve.CurrentPage);
foreach (var achievement in achieve.Achievements)
{
Assert.NotNull(achievement.Id);
Expand Down
2 changes: 1 addition & 1 deletion NetStone/Definitions/DefinitionsContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public abstract class DefinitionsContainer : IDisposable
/// <summary>
/// Definitions for a character's achievements
/// </summary>
public PagedDefinition Achievement { get; set; }
public CharacterAchievementDefinition Achievement { get; set; }

/// <summary>
/// Definitions for a character's mounts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,33 @@
namespace NetStone.Definitions.Model.Character;

/// <summary>
/// Models the definition of one achievement entry for a character
/// Models the definition of the achievement list
/// </summary>
public class CharacterAchievementEntryDefinition : PagedEntryDefinition
public class CharacterAchievementDefinition : PagedDefinition
{
/// <summary>
/// Root node of entry
/// Total number of achievements earned by this character
/// </summary>
[JsonProperty("ROOT")]
public new DefinitionsPack Root { get; set; }
[JsonProperty("TOTAL_ACHIEVEMENTS")]
public DefinitionsPack TotalAchievements { get; set; }

/// <summary>
/// Total achievement points earned by this character
/// </summary>
[JsonProperty("ACHIEVEMENT_POINTS")]
public DefinitionsPack AchievementPoints { get; set; }

/// <summary>
/// Full text displayed for this achievement
/// </summary>
[JsonProperty("ACTIVITY_DESCRIPTION")]
public DefinitionsPack ActivityDescription { get; set; }
}
/// <summary>
/// Models the definition of one achievement entry for a character
/// </summary>
public class CharacterAchievementEntryDefinition : PagedEntryDefinition
{
/// <summary>
/// Achievement name
/// </summary>
Expand All @@ -30,28 +47,4 @@ public class CharacterAchievementEntryDefinition : PagedEntryDefinition
/// </summary>
[JsonProperty("TIME")]
public DefinitionsPack Time { get; set; }

/// <summary>
/// Info about pages
/// </summary>
[JsonProperty("PAGE_INFO")]
public DefinitionsPack PageInfo { get; set; }

/// <summary>
/// Total number of achievements earned by this character
/// </summary>
[JsonProperty("TOTAL_ACHIEVEMENTS")]
public DefinitionsPack TotalAchievements { get; set; }

/// <summary>
/// Total achievement points earned by this character
/// </summary>
[JsonProperty("ACHIEVEMENT_POINTS")]
public DefinitionsPack AchievementPoints { get; set; }

/// <summary>
/// Full text displayed for this achievement
/// </summary>
[JsonProperty("ACTIVITY_DESCRIPTION")]
public DefinitionsPack ActivityDescription { get; set; }
}
2 changes: 1 addition & 1 deletion NetStone/Definitions/XivApiDefinitionsContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public override async Task Reload()
this.ClassJob = await GetDefinition<CharacterClassJobDefinition>("profile/classjob.json");
this.Gear = await GetDefinition<CharacterGearDefinition>("profile/gearset.json");
this.Attributes = await GetDefinition<CharacterAttributesDefinition>("profile/attributes.json");
this.Achievement = await GetDefinition<PagedDefinition>("profile/achievements.json");
this.Achievement = await GetDefinition<CharacterAchievementDefinition>("profile/achievements.json");
this.Mount = await GetDefinition<CharacterMountDefinition>("profile/mount.json");
this.Minion = await GetDefinition<CharacterMinionDefinition>("profile/minion.json");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class CharacterAchievementPage : LodestoneParseable, IPaginatedResult<Cha
{
private readonly LodestoneClient client;

private readonly PagedDefinition pageDefinition;
private readonly CharacterAchievementDefinition pageDefinition;
private readonly CharacterAchievementEntryDefinition entryDefinition;

private readonly string charId;
Expand All @@ -26,7 +26,7 @@ public class CharacterAchievementPage : LodestoneParseable, IPaginatedResult<Cha
/// <param name="rootNode">Root node of the achievement page</param>
/// <param name="definition">Parse definition pack</param>
/// <param name="charId">Id of the character</param>
public CharacterAchievementPage(LodestoneClient client, HtmlNode rootNode, PagedDefinition definition,
public CharacterAchievementPage(LodestoneClient client, HtmlNode rootNode, CharacterAchievementDefinition definition,
string charId) : base(rootNode)
{
this.client = client;
Expand All @@ -43,15 +43,15 @@ public int TotalAchievements
{
get
{
var res = ParseRegex(this.entryDefinition.TotalAchievements);
var res = ParseRegex(this.pageDefinition.TotalAchievements);
return int.Parse(res["TotalAchievements"].Value);
}
}

/// <summary>
/// Number of achievement points for this character
/// </summary>
public int AchievementPoints => int.Parse(Parse(this.entryDefinition.AchievementPoints));
public int AchievementPoints => int.Parse(Parse(this.pageDefinition.AchievementPoints));

/// <summary>
/// Indicates if this hold any results
Expand Down

0 comments on commit 878de85

Please sign in to comment.