diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/DecksCreator.java b/src/main/java/it/polimi/ingsw/gc14/Model/DecksCreator.java index 4b7388a..971b545 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/DecksCreator.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/DecksCreator.java @@ -15,10 +15,19 @@ import java.io.*; import java.lang.reflect.Type; import java.util.*; -//TODO javadoc +/** + * 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. + */ public class DecksCreator { - //TODO javadoc + /** + * Loads the tribe card deck for the specified era from the corresponding JSON resource file. + * + * @param era the era number (1, 2, or 3). + * @return a list of {@link TribeCard} objects for the specified era. + * @throws IllegalArgumentException if {@code era} is not 1, 2, or 3. + */ public static List loadTribeDeckByEra(int era) throws IllegalArgumentException { return switch (era) { @@ -29,7 +38,13 @@ public class DecksCreator { }; } - //TODO javadoc + /** + * Loads a tribe card deck from the specified JSON resource file path. + * + * @param resourcePath the path to the JSON resource file. + * @return a list of {@link TribeCard} objects defined in the resource file. + * @throws RuntimeException if the resource file is not found or an error occurs while reading it. + */ public static List loadTribeDeck(String resourcePath) { Gson gson = new Gson(); Type listType = new com.google.gson.reflect.TypeToken>(){}.getType(); @@ -51,14 +66,26 @@ public class DecksCreator { } } - //TODO javadoc - public static List loadBuildingDeckByEra(int era) throws IllegalArgumentException + /** + * Loads the building card deck for the specified era, filtering cards from the global building deck. + * + * @param era the era number (1, 2, or 3). + * @return a list of {@link BuildingCard} objects belonging to the specified era. + * @throws IllegalArgumentException if {@code era} is not 1, 2, or 3. + */ + public static List loadBuildingDeckByEra(int era) throws IllegalArgumentException { if(era<=0 || era>3) throw new IllegalArgumentException(); return loadBuildingDeck("/Cards/buildingCards.json").stream().filter(x->x.getEra()==era).toList(); } - //TODO javadoc + /** + * Loads the full building card deck from the specified JSON resource file path. + * + * @param resourcePath the path to the JSON resource file. + * @return a list of {@link BuildingCard} objects defined in the resource file. + * @throws RuntimeException if the resource file is not found or an error occurs while reading it. + */ public static List loadBuildingDeck(String resourcePath) { Gson gson = new Gson(); Type listType = new com.google.gson.reflect.TypeToken>(){}.getType(); @@ -80,7 +107,12 @@ public class DecksCreator { } } - //TODO javadoc + /** + * Creates and returns the list of slots used as the game board. + * Slots are labeled with the letters A through G. + * + * @return a list of {@link Slot} objects representing the game board. + */ public static List loadSlotDeck() { List slots = new ArrayList<>(); @@ -90,7 +122,15 @@ public class DecksCreator { return slots; } - //TODO javadoc + /** + * Instantiates a {@link 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. + * + * @param def the {@link TribeCardDefinition} containing the card's type, era, and parameters. + * @return the instantiated {@link TribeCard}. + * @throws IllegalArgumentException if the card type is unknown or the parameters are invalid. + */ private static TribeCard createCard(TribeCardDefinition def) { int era = def.era; @@ -138,7 +178,14 @@ public class DecksCreator { }; } - //TODO javadoc + /** + * Instantiates a {@link 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 {@link BuildingCard} is created. + * + * @param def the {@link BuildingCardDefinition} containing the card's effect ID, era, price, prestige value, and parameters. + * @return the instantiated {@link BuildingCard}. + */ private static BuildingCard createCard(BuildingCardDefinition def) { return switch (def.effectId) { case 0 -> new Building0(def.era, def.price, def.prestigeValue); @@ -153,7 +200,11 @@ public class DecksCreator { } - //TODO javadoc + /** + * Internal data class representing the raw definition of a tribe card as loaded from a JSON file. + * Contains the card type, era, whether it is armed, whether it is an event card, + * and a list of additional parameters. + */ private static class TribeCardDefinition { String type; int era; @@ -162,7 +213,10 @@ public class DecksCreator { List params; // Object per gestire boolean e int misti } - //TODO javadoc + /** + * Internal data class representing the raw definition of a building card as loaded from a JSON file. + * Contains the effect ID, era, price, prestige value, and a list of additional parameters. + */ private static class BuildingCardDefinition { int effectId; int era;