Skip to content

Commit

Permalink
Cache commonly used Card properties
Browse files Browse the repository at this point in the history
  • Loading branch information
azeier committed Nov 18, 2021
1 parent 7832ada commit 5f7806a
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 45 deletions.
113 changes: 68 additions & 45 deletions HearthDb/Card.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,67 +31,87 @@ internal Card(Entity entity)

public string FlavorText => GetLocFlavorText(DefaultLanguage);

public CardClass Class => (CardClass)Entity.GetTag(CLASS);
private CardClass? _class;
public CardClass Class => _class ??= (CardClass)Entity.GetTag(CLASS);

public Rarity Rarity => (Rarity)Entity.GetTag(RARITY);
private Rarity? _rarity;
public Rarity Rarity => _rarity ??= (Rarity)Entity.GetTag(RARITY);

public CardType Type => (CardType)Entity.GetTag(CARDTYPE);
private CardType? _type;
public CardType Type => _type ?? (CardType)Entity.GetTag(CARDTYPE);

public Race Race => (Race)Entity.GetTag(CARDRACE);
private Race? _race;
public Race Race => _race ?? (Race)Entity.GetTag(CARDRACE);

private CardSet? _set;
public CardSet Set
{
get
{
// HACK to fix missing set value on Hall of Fame cards
if(new[]
if (_set == null)
{
CardIds.Collectible.Mage.IceBlock,
CardIds.Collectible.Neutral.ColdlightOracle,
CardIds.Collectible.Neutral.MoltenGiant,

//2019
CardIds.Collectible.Druid.Naturalize,
CardIds.Collectible.Warlock.Doomguard,
CardIds.Collectible.Paladin.DivineFavor,
CardIds.Collectible.Neutral.BakuTheMooneater,
CardIds.Collectible.Neutral.GennGreymane,
CardIds.Collectible.Druid.GloomStag,
CardIds.Collectible.Mage.BlackCat,
CardIds.Collectible.Priest.GlitterMoth,
CardIds.Collectible.Shaman.MurksparkEel,

//2020
CardIds.Collectible.Priest.AuchenaiSoulpriest,
CardIds.Collectible.Priest.HolyFire,
CardIds.Collectible.Priest.Shadowform,
CardIds.Collectible.Priest.ProphetVelen,
CardIds.Collectible.Priest.DivineSpirit,
CardIds.Collectible.Priest.NorthshireCleric,
CardIds.Collectible.Neutral.AcolyteOfPain,
CardIds.Collectible.Neutral.Spellbreaker,
CardIds.Collectible.Neutral.MindControlTech,
CardIds.Collectible.Neutral.MountainGiant,
CardIds.Collectible.Neutral.LeeroyJenkins,
}.Contains(Id))
return CardSet.HOF;
return (CardSet)Entity.GetTag(CARD_SET);
// HACK to fix missing set value on Hall of Fame cards
if (new[]
{
CardIds.Collectible.Mage.IceBlock,
CardIds.Collectible.Neutral.ColdlightOracle,
CardIds.Collectible.Neutral.MoltenGiant,

//2019
CardIds.Collectible.Druid.Naturalize,
CardIds.Collectible.Warlock.Doomguard,
CardIds.Collectible.Paladin.DivineFavor,
CardIds.Collectible.Neutral.BakuTheMooneater,
CardIds.Collectible.Neutral.GennGreymane,
CardIds.Collectible.Druid.GloomStag,
CardIds.Collectible.Mage.BlackCat,
CardIds.Collectible.Priest.GlitterMoth,
CardIds.Collectible.Shaman.MurksparkEel,

//2020
CardIds.Collectible.Priest.AuchenaiSoulpriest,
CardIds.Collectible.Priest.HolyFire,
CardIds.Collectible.Priest.Shadowform,
CardIds.Collectible.Priest.ProphetVelen,
CardIds.Collectible.Priest.DivineSpirit,
CardIds.Collectible.Priest.NorthshireCleric,
CardIds.Collectible.Neutral.AcolyteOfPain,
CardIds.Collectible.Neutral.Spellbreaker,
CardIds.Collectible.Neutral.MindControlTech,
CardIds.Collectible.Neutral.MountainGiant,
CardIds.Collectible.Neutral.LeeroyJenkins,
}.Contains(Id))
{
_set = CardSet.HOF;
}
else
{
_set = (CardSet)Entity.GetTag(CARD_SET);
}
}
return _set.Value;
}
}

public Faction Faction => (Faction)Entity.GetTag(FACTION);

public int Cost => Entity.GetTag(COST);
private int? _cost;
public int Cost => _cost ??= Entity.GetTag(COST);

public int Attack => Entity.GetTag(ATK);
private int? _attack;
public int Attack => _attack ??= Entity.GetTag(ATK);

public int Health => Entity.GetTag(HEALTH);
private int? _health;
public int Health => _health ??= Entity.GetTag(HEALTH);

public int Durability => Entity.GetTag(DURABILITY);
private int? _durability;
public int Durability => _durability ??= Entity.GetTag(DURABILITY);

public int Armor => Entity.GetTag(ARMOR);
private int? _armor;
public int Armor => _armor ??= Entity.GetTag(ARMOR);

public int SpellSchool => Entity.GetTag(SPELL_SCHOOL);
private int? _spellSchool;
public int SpellSchool => _spellSchool ??= Entity.GetTag(SPELL_SCHOOL);

public string[] Mechanics
{
Expand All @@ -111,7 +131,8 @@ public string[] Mechanics

public Locale DefaultLanguage { get; set; } = Locale.enUS;

public bool Collectible => Convert.ToBoolean(Entity.GetTag(COLLECTIBLE));
private bool? _collectible;
public bool Collectible => _collectible ??= Convert.ToBoolean(Entity.GetTag(COLLECTIBLE));

public string GetLocName(Locale lang) => Entity.GetLocString(CARDNAME, lang);

Expand Down Expand Up @@ -150,8 +171,10 @@ public string GetLocText(Locale lang)

public string GetLocFlavorText(Locale lang) => Entity.GetLocString(FLAVORTEXT, lang);

public bool IsWild => Helper.WildSets.Contains(Set);
private bool? _isWild;
public bool IsWild => _isWild ??= Helper.WildSets.Contains(Set);

public bool IsClassic => Helper.ClassicSets.Contains(Set);
private bool? _isClassic;
public bool IsClassic => _isClassic ??= Helper.ClassicSets.Contains(Set);
}
}
1 change: 1 addition & 0 deletions HearthDb/HearthDb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<Copyright>Copyright © HearthSim 2021</Copyright>
<AssemblyVersion>21.8.0.0</AssemblyVersion>
<FileVersion>21.8.0.0</FileVersion>
<LangVersion>8</LangVersion>
</PropertyGroup>

<!-- Remove everything from the hsdata repo except for CardDefs.xml. -->
Expand Down

0 comments on commit 5f7806a

Please sign in to comment.