Fix up GameSettings in ConnectionControl
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@550 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
81de4ad99f
commit
df535edb70
5 changed files with 21 additions and 28 deletions
|
@ -12,6 +12,7 @@ import jrummikub.control.RoundControl.InvalidTurnInfo;
|
|||
import jrummikub.model.GameSettings;
|
||||
import jrummikub.model.IRoundState;
|
||||
import jrummikub.model.ITable;
|
||||
import jrummikub.model.PlayerSettings;
|
||||
import jrummikub.util.Event;
|
||||
import jrummikub.util.Event1;
|
||||
import jrummikub.util.Event2;
|
||||
|
@ -74,6 +75,19 @@ public class ConnectionControl implements IConnectionControl {
|
|||
}
|
||||
};
|
||||
|
||||
private void fixGameSettings(GameSettings settings) {
|
||||
for (PlayerSettings player : settings.getPlayerList()) {
|
||||
if (player.getType() == PlayerSettings.Type.HUMAN) {
|
||||
player.setType(PlayerSettings.Type.NETWORK);
|
||||
}
|
||||
|
||||
if (player.getType() == PlayerSettings.Type.NETWORK
|
||||
&& player.getName().equals(getNickname())) {
|
||||
player.setType(PlayerSettings.Type.HUMAN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final LoginData loginData;
|
||||
private volatile Connection connection;
|
||||
private volatile MultiUserChat muc;
|
||||
|
@ -493,6 +507,7 @@ public class ConnectionControl implements IConnectionControl {
|
|||
UUID uuid = UUID.fromString(extension.getValue("uuid"));
|
||||
GameSettings settings = (GameSettings) Base64.decodeToObject(extension
|
||||
.getValue("gameSettings"));
|
||||
fixGameSettings(settings);
|
||||
|
||||
GameData gameData = new GameData(uuid, settings, sender);
|
||||
gameOfferEvent.emit(gameData);
|
||||
|
@ -527,14 +542,17 @@ public class ConnectionControl implements IConnectionControl {
|
|||
} else if (messageType.equals("round_start")) {
|
||||
roundStartEvent.emit();
|
||||
} else if (messageType.equals("round_state_update")) {
|
||||
roundStateUpdateEvent.emit((IRoundState) Base64.decodeToObject(extension
|
||||
.getValue("state")));
|
||||
IRoundState state = (IRoundState) Base64.decodeToObject(extension
|
||||
.getValue("state"));
|
||||
fixGameSettings(state.getGameSettings());
|
||||
roundStateUpdateEvent.emit(state);
|
||||
} else if (messageType.equals("table_update")) {
|
||||
tableUpdateEvent.emit((ITable) Base64.decodeToObject(extension
|
||||
.getValue("table")));
|
||||
} else if (messageType.equals("turn_end")) {
|
||||
TurnEndData data = (TurnEndData) Base64.decodeToObject(extension
|
||||
.getValue("data"));
|
||||
fixGameSettings(data.getRoundState().getGameSettings());
|
||||
turnEndEvent.emit(data.getRoundState(), data.getInvalidTurnInfo());
|
||||
} else if (messageType.equals("next_player")) {
|
||||
nextPlayerEvent.emit();
|
||||
|
|
|
@ -2,7 +2,6 @@ package jrummikub.control.network;
|
|||
|
||||
import java.util.UUID;
|
||||
|
||||
import jrummikub.model.GameSettings;
|
||||
import jrummikub.util.Event;
|
||||
import jrummikub.util.GameData;
|
||||
import jrummikub.util.IEvent;
|
||||
|
@ -31,7 +30,6 @@ public class GameJoinControl extends AbstractGameBeginControl {
|
|||
final GameData gameData, final IView view) {
|
||||
super(connectionControl, view, gameData, SettingsMode.NETWORK_JOIN);
|
||||
|
||||
NetworkControl.fixGameSettings(gameData.getGameSettings(), connectionControl.getNickname());
|
||||
updateSettingsPanel();
|
||||
|
||||
connections.add(connectionControl.getGameOfferEvent().add(
|
||||
|
@ -39,11 +37,7 @@ public class GameJoinControl extends AbstractGameBeginControl {
|
|||
@Override
|
||||
public void handle(GameData data) {
|
||||
if (data.getGameID().equals(gameData.getGameID())) {
|
||||
GameSettings settings = data.getGameSettings();
|
||||
|
||||
NetworkControl.fixGameSettings(settings, connectionControl.getNickname());
|
||||
|
||||
gameData.setGameSettings(settings);
|
||||
gameData.setGameSettings(data.getGameSettings());
|
||||
|
||||
updateSettingsPanel();
|
||||
}
|
||||
|
|
|
@ -8,8 +8,6 @@ import java.util.UUID;
|
|||
|
||||
import jrummikub.control.SaveControl;
|
||||
import jrummikub.model.GameSettings;
|
||||
import jrummikub.model.PlayerSettings;
|
||||
import jrummikub.model.PlayerSettings.Type;
|
||||
import jrummikub.util.Connection;
|
||||
import jrummikub.util.Event;
|
||||
import jrummikub.util.GameData;
|
||||
|
@ -43,18 +41,6 @@ public class NetworkControl {
|
|||
private List<UUID> games = new ArrayList<UUID>();
|
||||
private Map<UUID, GameData> gameMap = new HashMap<UUID, GameData>();
|
||||
|
||||
public static void fixGameSettings(GameSettings settings, String nickname) {
|
||||
for (PlayerSettings player : settings.getPlayerList()) {
|
||||
if (player.getType() == Type.HUMAN) {
|
||||
player.setType(Type.NETWORK);
|
||||
}
|
||||
|
||||
if (player.getType() == Type.NETWORK && player.getName().equals(nickname)) {
|
||||
player.setType(Type.HUMAN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new network control
|
||||
*
|
||||
|
|
|
@ -24,8 +24,6 @@ public class NetworkRoundControl extends RoundControl {
|
|||
new IListener1<IRoundState>() {
|
||||
@Override
|
||||
public void handle(IRoundState state) {
|
||||
NetworkControl.fixGameSettings(state.getGameSettings(),
|
||||
connectionControl.getNickname());
|
||||
setRoundState(state);
|
||||
}
|
||||
}));
|
||||
|
|
|
@ -34,9 +34,6 @@ public class NetworkTurnControl extends AbstractTurnControl {
|
|||
new IListener2<IRoundState, InvalidTurnInfo>() {
|
||||
@Override
|
||||
public void handle(IRoundState state, InvalidTurnInfo invalidTurnInfo) {
|
||||
NetworkControl.fixGameSettings(state.getGameSettings(),
|
||||
connectionControl.getNickname());
|
||||
|
||||
endOfTurn(state, invalidTurnInfo);
|
||||
}
|
||||
}));
|
||||
|
|
Reference in a new issue