Class CardCatalogue

java.lang.Object
net.demilich.metastone.game.cards.CardCatalogue

public class CardCatalogue extends Object
A place that stores CardCatalogueRecord records that were generated from the "cards" Java package.
  • Field Details

  • Constructor Details

    • CardCatalogue

      public CardCatalogue()
  • Method Details

    • getBannedDraftCards

      public static Set<String> getBannedDraftCards()
    • getHardRemovalCardIds

      public static Set<String> getHardRemovalCardIds()
    • getOneOneNeutralMinionCardId

      public static String getOneOneNeutralMinionCardId()
    • getNeutralHero

      public static String getNeutralHero()
    • getAll

      @NotNull public static @NotNull CardList getAll()
    • getCards

      @NotNull public static @NotNull Map<String,Card> getCards()
      Returns a mutable reference to the cards loaded into this catalogue.

      Changing the cards here changes all their references in all games. However, getCardById(String) returns clones.

      Returns:
    • getCardById

      @NotNull public static @NotNull Card getCardById(@NotNull @NotNull String id)
      Gets a card from the card database by a specific ID. These IDs correspond to the names of the JSON files in the cards/src/main/resources/cards directory. Staging cards are never retrieved. The catalogue does not respect DeckFormat filters here, and will return any card with a valid ID.

      Some effects, like CastFromGroupSpell, create temporary cards that exist only in the game context. Generally, you should call GameContext.getCardById(String) in order to correctly retrieve those cards.

      Parameters:
      id -
      Returns:
      Throws:
      NullPointerException - if the card cannot be found or if the card's version exceeds the currently configured version. (Versions are only used for Trace objects.)
    • getRecords

      @NotNull public static @NotNull Map<String,CardCatalogueRecord> getRecords()
      Gets all the CardCatalogueRecord objects specified in the cards module.
      Returns:
    • getCardByName

      @Nullable public static @Nullable Card getCardByName(String name)
    • getCardByName

      public static Card getCardByName(String name, String heroClass)
    • query

      public static CardList query(DeckFormat deckFormat)
    • query

      public static CardList query(DeckFormat deckFormat, com.hiddenswitch.spellsource.rpc.Spellsource.CardTypeMessage.CardType cardType)
    • query

      public static CardList query(DeckFormat deckFormat, String heroClass)
    • query

      public static CardList query(DeckFormat deckFormat, com.hiddenswitch.spellsource.rpc.Spellsource.CardTypeMessage.CardType cardType, com.hiddenswitch.spellsource.rpc.Spellsource.RarityMessage.Rarity rarity, String heroClass)
    • query

      @NotNull public static @NotNull CardList query(DeckFormat deckFormat, com.hiddenswitch.spellsource.rpc.Spellsource.CardTypeMessage.CardType cardType, com.hiddenswitch.spellsource.rpc.Spellsource.RarityMessage.Rarity rarity, String heroClass, Attribute tag, boolean clone)
      Queries the card catalogue for cards that match the specified filters.
      Parameters:
      deckFormat -
      cardType -
      rarity -
      heroClass -
      tag -
      clone -
      Returns:
    • loadCardsFromPackage

      public static void loadCardsFromPackage(List<com.hiddenswitch.spellsource.core.CardResources> cardResources)
      Loads all the cards from the specified CardResources instances.
      Parameters:
      cardResources -
    • addOrReplaceCard

      public static String addOrReplaceCard(String json) throws IOException
      Adds or replaces a card for the given JSON.

      If a CardDesc.getName() name field is specified and no id, the

      Parameters:
      json -
      Throws:
      IOException
    • removeCard

      public static void removeCard(String id)
      Removes the specified card by ID from the catalogue.
      Parameters:
      id -
    • loadCards

      public static void loadCards(Collection<com.hiddenswitch.spellsource.core.ResourceInputStream> inputStreams)
      Loads all the cards from the specified ResourceInputStream instances, which can be a mix of files and resources.
      Parameters:
      inputStreams -
    • loadAllCards

      public static void loadAllCards()
      Loads all the cards from all classpath resources that are recursively inside the "cards" directory.
    • loadCardsFromFilesystemDirectories

      public static void loadCardsFromFilesystemDirectories(String... directories)
    • loadAllCards

      public static void loadAllCards(String directory)
      Loads all the cards from the specified directory.

      Prevents loadCardsFromPackage() from also redundantly loading the same cards.

      Does not use ClassGraph so does not need to allocate direct byte buffers.

      Parameters:
      directory -
    • unloadCards

      public static void unloadCards()
    • loadCardsFromPackage

      public static void loadCardsFromPackage()
      Loads all the cards specified in the "cards/src/main/resources" + DEFAULT_CARDS_FOLDER directory in the cards module. This can be called multiple times, but will not "refresh" the catalogue file.
    • firstLoad

      public static boolean firstLoad()
    • getFormatCard

      public static Card getFormatCard(String name)
    • getHeroCard

      public static Card getHeroCard(String heroClass)
    • getClassCards

      public static CardList getClassCards(DeckFormat format)
      Retrieves all the "class_" Spellsource.CardTypeMessage.CardType.CLASS cards that specify a hero card, color, heroClass string, etc. for the specified class in the specified format.
      Parameters:
      format -
      Returns:
    • getBaseClasses

      public static List<String> getBaseClasses(DeckFormat deckFormat)
      Retrieves the HeroClass strings that correspond to the classes in the specified format.
      Parameters:
      deckFormat -
      Returns:
    • query

      public static CardList query(DeckFormat deckFormat, Predicate<Card> filter)
    • stream

      public static Stream<Card> stream()
    • getVersion

      public static int getVersion()
    • setVersion

      public static void setVersion(int version)