Class DecksCreator

java.lang.Object
it.polimi.ingsw.gc14.Model.DecksCreator

public class DecksCreator extends Object
Utility class responsible for loading and creating decks of cards and slots for the game. Cards are loaded from JSON resource files and instantiated according to their type and parameters.
  • Constructor Details

    • DecksCreator

      public DecksCreator()
  • Method Details

    • loadTribeDeckByEra

      public static List<TribeCard> loadTribeDeckByEra(int era) throws IllegalArgumentException
      Loads the tribe card deck for the specified era from the corresponding JSON resource file.
      Parameters:
      era - the era number (1, 2, or 3).
      Returns:
      a list of TribeCard objects for the specified era.
      Throws:
      IllegalArgumentException - if era is not 1, 2, or 3.
    • loadTribeDeck

      public static List<TribeCard> loadTribeDeck(String resourcePath)
      Loads a tribe card deck from the specified JSON resource file path.
      Parameters:
      resourcePath - the path to the JSON resource file.
      Returns:
      a list of TribeCard objects defined in the resource file.
      Throws:
      RuntimeException - if the resource file is not found or an error occurs while reading it.
    • loadBuildingDeckByEra

      public static List<BuildingCard> loadBuildingDeckByEra(int era) throws IllegalArgumentException
      Loads the building card deck for the specified era, filtering cards from the global building deck.
      Parameters:
      era - the era number (1, 2, or 3).
      Returns:
      a list of BuildingCard objects belonging to the specified era.
      Throws:
      IllegalArgumentException - if era is not 1, 2, or 3.
    • loadBuildingDeck

      public static List<BuildingCard> loadBuildingDeck(String resourcePath)
      Loads the full building card deck from the specified JSON resource file path.
      Parameters:
      resourcePath - the path to the JSON resource file.
      Returns:
      a list of BuildingCard objects defined in the resource file.
      Throws:
      RuntimeException - if the resource file is not found or an error occurs while reading it.
    • loadSlotDeck

      public static List<Slot> loadSlotDeck()
      Creates and returns the list of slots used as the game board. Slots are labeled with the letters A through G.
      Returns:
      a list of Slot objects representing the game board.
    • createCard

      private static TribeCard createCard(DecksCreator.TribeCardDefinition def)
      Instantiates a TribeCard from the given definition. Depending on whether the card is an event or a character, the appropriate subclass is created using the type and parameters specified in the definition.
      Parameters:
      def - the DecksCreator.TribeCardDefinition containing the card's type, era, and parameters.
      Returns:
      the instantiated TribeCard.
      Throws:
      IllegalArgumentException - if the card type is unknown or the parameters are invalid.
    • createCard

      private static BuildingCard createCard(DecksCreator.BuildingCardDefinition def)
      Instantiates a BuildingCard from the given definition. The appropriate subclass is selected based on the effect ID specified in the definition. If no specific subclass matches the effect ID, a base BuildingCard is created.
      Parameters:
      def - the DecksCreator.BuildingCardDefinition containing the card's effect ID, era, price, prestige value, and parameters.
      Returns:
      the instantiated BuildingCard.