Class DecksCreator
java.lang.Object
it.polimi.ingsw.gc14.Model.DecksCreator
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classInternal data class representing the raw definition of a building card as loaded from a JSON file.private static classInternal data class representing the raw definition of a tribe card as loaded from a JSON file. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static BuildingCardInstantiates aBuildingCardfrom the given definition.private static TribeCardInstantiates aTribeCardfrom the given definition.static List<BuildingCard> loadBuildingDeck(String resourcePath) Loads the full building card deck from the specified JSON resource file path.static List<BuildingCard> loadBuildingDeckByEra(int era) Loads the building card deck for the specified era, filtering cards from the global building deck.Creates and returns the list of slots used as the game board.loadTribeDeck(String resourcePath) Loads a tribe card deck from the specified JSON resource file path.loadTribeDeckByEra(int era) Loads the tribe card deck for the specified era from the corresponding JSON resource file.
-
Constructor Details
-
DecksCreator
public DecksCreator()
-
-
Method Details
-
loadTribeDeckByEra
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
TribeCardobjects for the specified era. - Throws:
IllegalArgumentException- iferais not 1, 2, or 3.
-
loadTribeDeck
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
TribeCardobjects defined in the resource file. - Throws:
RuntimeException- if the resource file is not found or an error occurs while reading it.
-
loadBuildingDeckByEra
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
BuildingCardobjects belonging to the specified era. - Throws:
IllegalArgumentException- iferais not 1, 2, or 3.
-
loadBuildingDeck
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
BuildingCardobjects defined in the resource file. - Throws:
RuntimeException- if the resource file is not found or an error occurs while reading it.
-
loadSlotDeck
-
createCard
Instantiates aTribeCardfrom 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- theDecksCreator.TribeCardDefinitioncontaining 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
Instantiates aBuildingCardfrom 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 baseBuildingCardis created.- Parameters:
def- theDecksCreator.BuildingCardDefinitioncontaining the card's effect ID, era, price, prestige value, and parameters.- Returns:
- the instantiated
BuildingCard.
-