Coverage Summary for Class: TotemChoice (it.polimi.ingsw.gc14.Network.NetworkEvents)

Class Class, % Method, % Branch, % Line, %
TotemChoice 0% (0/1) 0% (0/4) 0% (0/2) 0% (0/15)


 package it.polimi.ingsw.gc14.Network.NetworkEvents;
 
 import it.polimi.ingsw.gc14.Controller.GameController;
 import it.polimi.ingsw.gc14.ErrorType;
 import it.polimi.ingsw.gc14.Model.Game;
 import it.polimi.ingsw.gc14.Model.MiniModel;
 import it.polimi.ingsw.gc14.Model.Totems;
 import it.polimi.ingsw.gc14.Network.EventType;
 import it.polimi.ingsw.gc14.Network.NetworkEvent;
 
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
 
 /**
  * Network event used to handle a player's totem choice.
  */
 public class TotemChoice extends NetworkEvent implements Serializable {
 
     /**
      * Name of the totem selected by the player.
      */
     private final String totem;
 
     /**
      * List of totems still available after the choice has been processed.
      */
     private List<Totems> availableTotems;
 
     /**
      * Constructs a totem choice event for the specified player.
      *
      * @param username the username of the player making the choice.
      * @param totem    the name of the selected totem.
      */
     public TotemChoice(String username, String totem) {
         super(username, EventType.TOTEM_CHOICE, false, ErrorType.WRONG_ACTION);
         this.totem = totem;
     }
 
     @Override
     public void enrichWithGameState(Game game, ArrayList<String> disconnectedUsernames) {
         super.enrichWithGameState(game, disconnectedUsernames);
         this.availableTotems = game.getAvailableTotems();
     }
 
     /**
      * Applies the totem choice event to the server-side game controller.
      *
      * @param gameController the game controller on which to apply the event.
      * @return {@code true} if the totem choice is handled successfully,
      *         {@code false} otherwise.
      */
     @Override
     public boolean apply(GameController gameController) {
         return gameController.totemChoice(username, totem);
     }
 
     /**
      * Applies the totem choice update to the client-side mini model.
      *
      * <p>If the event does not represent an error, the player data,
      * turn order, current game state, slot assignments, and available
      * totems are updated.
      *
      * @param miniModel the mini model on which to apply the event.
      */
     @Override
     public void apply(MiniModel miniModel) {
         synchronized (miniModel) {
             if (isError)
                 return;
 
             miniModel.setPlayers(playerList);
             miniModel.setOrderLogicCard(orderLogicCard);
             miniModel.setCurrentState(currentState);
             miniModel.setSlotPlayerMap(slotPlayerMap);
             miniModel.setAvailableTotems(availableTotems);
             miniModel.setLastEvent(this);
         }
     }
 }