Fix player types in received game settings
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@506 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
f37219cfbf
commit
a97b8445a2
3 changed files with 18 additions and 16 deletions
|
@ -3,8 +3,6 @@ package jrummikub.control.network;
|
|||
import java.util.UUID;
|
||||
|
||||
import jrummikub.model.GameSettings;
|
||||
import jrummikub.model.PlayerSettings;
|
||||
import jrummikub.model.PlayerSettings.Type;
|
||||
import jrummikub.util.Event;
|
||||
import jrummikub.util.GameData;
|
||||
import jrummikub.util.IEvent;
|
||||
|
@ -33,7 +31,7 @@ public class GameJoinControl extends AbstractGameBeginControl {
|
|||
final GameData gameData, final IView view) {
|
||||
super(connectionControl, view, gameData, SettingsMode.NETWORK_JOIN);
|
||||
|
||||
fixGameSettings(gameData.getGameSettings());
|
||||
NetworkControl.fixGameSettings(gameData.getGameSettings(), connectionControl.getNickname());
|
||||
updateSettingsPanel();
|
||||
|
||||
connections.add(connectionControl.getGameOfferEvent().add(
|
||||
|
@ -43,7 +41,7 @@ public class GameJoinControl extends AbstractGameBeginControl {
|
|||
if (data.getGameID().equals(gameData.getGameID())) {
|
||||
GameSettings settings = data.getGameSettings();
|
||||
|
||||
fixGameSettings(settings);
|
||||
NetworkControl.fixGameSettings(settings, connectionControl.getNickname());
|
||||
|
||||
gameData.setGameSettings(settings);
|
||||
|
||||
|
@ -81,17 +79,6 @@ public class GameJoinControl extends AbstractGameBeginControl {
|
|||
return gameStartEvent;
|
||||
}
|
||||
|
||||
private void fixGameSettings(GameSettings settings) {
|
||||
for (PlayerSettings player : settings.getPlayerList()) {
|
||||
if (player.getType() == Type.HUMAN) {
|
||||
player.setType(Type.NETWORK);
|
||||
} else if (player.getType() == Type.NETWORK
|
||||
&& player.getName().equals(connectionControl.getNickname())) {
|
||||
player.setType(Type.HUMAN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the join control and sets the settings panel in game join mode
|
||||
*/
|
||||
|
|
|
@ -8,6 +8,8 @@ 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;
|
||||
|
@ -39,6 +41,18 @@ 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
|
||||
*
|
||||
|
|
|
@ -13,7 +13,7 @@ public class NetworkRoundControl extends RoundControl {
|
|||
private boolean currentlyActive;
|
||||
|
||||
public NetworkRoundControl(IRoundState roundState, IView view,
|
||||
IConnectionControl connectionControl, boolean startActive) {
|
||||
final IConnectionControl connectionControl, boolean startActive) {
|
||||
super(roundState, view);
|
||||
|
||||
this.connectionControl = connectionControl;
|
||||
|
@ -23,6 +23,7 @@ public class NetworkRoundControl extends RoundControl {
|
|||
new IListener1<IRoundState>() {
|
||||
@Override
|
||||
public void handle(IRoundState state) {
|
||||
NetworkControl.fixGameSettings(state.getGameSettings(), connectionControl.getNickname());
|
||||
setRoundState(state);
|
||||
|
||||
startTurn();
|
||||
|
|
Reference in a new issue