added property changes impl
This commit is contained in:
@@ -6,64 +6,109 @@ import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Character;
|
||||
import it.polimi.ingsw.gc14.Model.GamePackage.Board;
|
||||
import it.polimi.ingsw.gc14.Model.GamePackage.CurrentState;
|
||||
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyChangeSupport;
|
||||
import java.io.Serializable;
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.*;
|
||||
//TODO
|
||||
|
||||
public class MiniModel implements Serializable {
|
||||
|
||||
private final PropertyChangeSupport support = new PropertyChangeSupport(this);
|
||||
|
||||
public Board board;
|
||||
public Map<Slot,Player> slotPlayerMap;
|
||||
public Map<Slot, Player> slotPlayerMap;
|
||||
public OrderLogicCard orderLogicCard;
|
||||
public CurrentState currentState;
|
||||
public Map<String,Player> players;
|
||||
public List<Totems>availableTotems;
|
||||
public CurrentState currentState;
|
||||
public Map<String, Player> players;
|
||||
public List<Totems> availableTotems;
|
||||
|
||||
// --- Costruttori invariati ---
|
||||
|
||||
public MiniModel() {
|
||||
|
||||
}
|
||||
|
||||
public MiniModel(Board board) {
|
||||
this.board = board;
|
||||
}
|
||||
public MiniModel(Board board, Map<Slot,Player> slotPlayerMap, OrderLogicCard orderLogicCard, CurrentState currentState, List<Player> players, List<Totems>availableTotems) {
|
||||
|
||||
public MiniModel(Board board, Map<Slot, Player> slotPlayerMap, OrderLogicCard orderLogicCard,
|
||||
CurrentState currentState, List<Player> players, List<Totems> availableTotems) {
|
||||
this.board = board;
|
||||
this.slotPlayerMap = slotPlayerMap;
|
||||
this.orderLogicCard = orderLogicCard;
|
||||
this.currentState = currentState;
|
||||
this.players=new HashMap<>();
|
||||
this.availableTotems=availableTotems;
|
||||
this.players = new HashMap<>();
|
||||
this.availableTotems = availableTotems;
|
||||
setPlayers(players);
|
||||
}
|
||||
|
||||
// --- Gestione listener ---
|
||||
|
||||
public void addPropertyChangeListener(PropertyChangeListener listener) {
|
||||
support.addPropertyChangeListener(listener);
|
||||
}
|
||||
|
||||
public void removePropertyChangeListener(PropertyChangeListener listener) {
|
||||
support.removePropertyChangeListener(listener);
|
||||
}
|
||||
|
||||
// --- Setter con notifica ---
|
||||
|
||||
public void setBoard(Board board) {
|
||||
Board old = this.board;
|
||||
this.board = board;
|
||||
support.firePropertyChange("board", old, board);
|
||||
}
|
||||
public void setAvailableTotems(List<Totems>availableTotems) {
|
||||
|
||||
public void setAvailableTotems(List<Totems> availableTotems) {
|
||||
List<Totems> old = this.availableTotems;
|
||||
this.availableTotems = availableTotems;
|
||||
support.firePropertyChange("availableTotems", old, availableTotems);
|
||||
}
|
||||
public void setSlotPlayerMap(Map<Slot,Player> slotPlayerMap) {
|
||||
|
||||
public void setSlotPlayerMap(Map<Slot, Player> slotPlayerMap) {
|
||||
Map<Slot, Player> old = this.slotPlayerMap;
|
||||
this.slotPlayerMap = slotPlayerMap;
|
||||
support.firePropertyChange("slotPlayerMap", old, slotPlayerMap);
|
||||
}
|
||||
|
||||
public void setOrderLogicCard(OrderLogicCard orderLogicCard) {
|
||||
OrderLogicCard old = this.orderLogicCard;
|
||||
this.orderLogicCard = orderLogicCard;
|
||||
support.firePropertyChange("orderLogicCard", old, orderLogicCard);
|
||||
}
|
||||
|
||||
public void setCurrentState(CurrentState currentState) {
|
||||
CurrentState old = this.currentState;
|
||||
this.currentState = currentState;
|
||||
support.firePropertyChange("currentState", old, currentState);
|
||||
}
|
||||
|
||||
public void setPlayers(List<Player> players) {
|
||||
Map<String, Player> old = new HashMap<>(this.players != null ? this.players : new HashMap<>());
|
||||
for (Player player : players) {
|
||||
this.players.put(player.getUserName(),player);
|
||||
this.players.put(player.getUserName(), player);
|
||||
}
|
||||
support.firePropertyChange("players", old, this.players);
|
||||
}
|
||||
public void setPlayer(Player player)
|
||||
{
|
||||
players.put(player.getUserName(),player);
|
||||
|
||||
public void setPlayer(Player player) {
|
||||
Map<String, Player> old = new HashMap<>(this.players);
|
||||
players.put(player.getUserName(), player);
|
||||
support.firePropertyChange("players", old, this.players);
|
||||
}
|
||||
public int getPositionByUsername(String username)
|
||||
{
|
||||
int i=0;
|
||||
for (Player player : players.values())
|
||||
{
|
||||
if(player.getUserName().equals(username))
|
||||
{
|
||||
|
||||
// --- Metodi invariati ---
|
||||
|
||||
public int getPositionByUsername(String username) {
|
||||
int i = 0;
|
||||
for (Player player : players.values()) {
|
||||
if (player.getUserName().equals(username)) {
|
||||
return i;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ public abstract class OrderLogicCard implements Serializable {
|
||||
/**
|
||||
* The queue of {@link Player Players} associated with this order logic card.
|
||||
*/
|
||||
protected Queue<Player> players;
|
||||
public Queue<Player> players;
|
||||
|
||||
/**
|
||||
* The list of {@link Player Players} associated with this order logic card.
|
||||
|
||||
Reference in New Issue
Block a user