Commit 01ad1106 authored by Louis Bal Dit Sollier's avatar Louis Bal Dit Sollier
Browse files

Merge branch 'int/v2' into 'feature/main/createGame'

# Conflicts:
#   src/main/java/client/main/controller/FXCreateGame.java
#   src/main/java/client/main/controller/FXHome.java
parents 2d2711b1 7ca04d65
...@@ -9,7 +9,6 @@ import javafx.application.Application; ...@@ -9,7 +9,6 @@ import javafx.application.Application;
import javafx.stage.Stage; import javafx.stage.Stage;
import main.java.client.data.DataCoreClient; import main.java.client.data.DataCoreClient;
import main.java.client.game.GameCore; import main.java.client.game.GameCore;
import main.java.client.game.controller.MainGameController;
import main.java.client.main.controller.MainControllerFX; import main.java.client.main.controller.MainControllerFX;
import main.java.client.main.controller.MainCore; import main.java.client.main.controller.MainCore;
import main.java.client.network.ComCoreClient; import main.java.client.network.ComCoreClient;
...@@ -23,7 +22,7 @@ public class ClientApp extends Application { ...@@ -23,7 +22,7 @@ public class ClientApp extends Application {
private static ComCoreClient comCoreClient; private static ComCoreClient comCoreClient;
private static DataCoreClient dataCoreClient; private static DataCoreClient dataCoreClient;
public static MainCore mainCore; public static MainCore mainCore;
private static GameCore gameCore; public static GameCore gameCore;
public static final String APPLICATION_NAME = "Othello"; public static final String APPLICATION_NAME = "Othello";
public static final int APPLICATION_WIDTH = 889; public static final int APPLICATION_WIDTH = 889;
public static final int APPLICATION_HEIGHT = 500; public static final int APPLICATION_HEIGHT = 500;
...@@ -55,7 +54,7 @@ public class ClientApp extends Application { ...@@ -55,7 +54,7 @@ public class ClientApp extends Application {
dataCoreClient = new DataCoreClient(); dataCoreClient = new DataCoreClient();
// IHM Game Core // IHM Game Core
gameCore = new GameCore(new MainGameController()); gameCore = new GameCore();
// IHM Main Core // IHM Main Core
mainCore = new MainCore(new MainControllerFX()); mainCore = new MainCore(new MainControllerFX());
...@@ -63,9 +62,10 @@ public class ClientApp extends Application { ...@@ -63,9 +62,10 @@ public class ClientApp extends Application {
// Set implementations // Set implementations
dataCoreClient.setDataToCom(comCoreClient.getDataToComClientImpl()); dataCoreClient.setDataToCom(comCoreClient.getDataToComClientImpl());
dataCoreClient.setDataToMain(mainCore.getDataToMainImpl()); dataCoreClient.setDataToMain(mainCore.getDataToMainImpl());
dataCoreClient.setDataToGame(gameCore.getDataToGame());
comCoreClient.setComToDataClient(dataCoreClient.getClientComToDataImpl()); comCoreClient.setComToDataClient(dataCoreClient.getClientComToDataImpl());
mainCore.setMainToData(dataCoreClient.getMainToDataImpl()); mainCore.setMainToData(dataCoreClient.getMainToDataImpl());
// TODO missing: gameCore.setGameToData(dataCoreClient.getDataToGameImpl()); gameCore.setGameToData(dataCoreClient.getGameToDataImpl());
} }
@Override @Override
......
...@@ -27,11 +27,13 @@ public class ComToDataClientImpl implements IComToData { ...@@ -27,11 +27,13 @@ public class ComToDataClientImpl implements IComToData {
@Override @Override
public void addNewUser(UserLight user) { public void addNewUser(UserLight user) {
dataCoreClient.getListConnectedUsers().add(user); dataCoreClient.getListConnectedUsers().add(user);
dataCoreClient.getDataToMain().updateUserList(user);
} }
@Override @Override
public void notifyNewGame(GameLight newGameCreated) { public void notifyNewGame(GameLight newGameCreated) {
dataCoreClient.getListGameLight().add(newGameCreated);
dataCoreClient.getDataToMain().showNewGame(newGameCreated);
} }
@Override @Override
...@@ -41,7 +43,7 @@ public class ComToDataClientImpl implements IComToData { ...@@ -41,7 +43,7 @@ public class ComToDataClientImpl implements IComToData {
@Override @Override
public void receiveChatMessage(Message message) { public void receiveChatMessage(Message message) {
dataCoreClient.getDataToGame().displayMessage(message);
} }
@Override @Override
...@@ -86,6 +88,16 @@ public class ComToDataClientImpl implements IComToData { ...@@ -86,6 +88,16 @@ public class ComToDataClientImpl implements IComToData {
dataCoreClient.getDataToMain().sendLists(players, gamesAvailable); dataCoreClient.getDataToMain().sendLists(players, gamesAvailable);
} }
@Override
public void forwardPlayers(List<UserLight> players) {
dataCoreClient.setListConnectedUsers(players);
}
@Override
public void forwardGames(List<GameLight> games) {
dataCoreClient.setListGameLight(games);
}
@Override @Override
public void receiveServerStateOnConnection(ArrayList<UserLight> usersOnline, ArrayList<GameLight> gamesOnline) { public void receiveServerStateOnConnection(ArrayList<UserLight> usersOnline, ArrayList<GameLight> gamesOnline) {
......
package main.java.client.data; package main.java.client.data;
import main.java.common.dataModel.*; import java.util.List;
import main.java.common.dataModel.Board;
import main.java.common.dataModel.GameLight;
import main.java.common.dataModel.Move;
import main.java.common.dataModel.UserHeavy;
import main.java.common.dataModel.UserLight;
import main.java.common.interfaces.client.IComToData; import main.java.common.interfaces.client.IComToData;
import main.java.common.interfaces.client.IDataToCom; import main.java.common.interfaces.client.IDataToCom;
import main.java.common.interfaces.client.IDataToGame;
import main.java.common.interfaces.client.IDataToMain; import main.java.common.interfaces.client.IDataToMain;
import main.java.common.interfaces.client.IMainToData; import main.java.common.interfaces.client.IMainToData;
import java.util.List;
public class DataCoreClient { public class DataCoreClient {
private UserHeavy localUserHeavy; private UserHeavy localUserHeavy;
private UserLight localUserLight; private UserLight localUserLight;
private List<UserLight> listConnectedUsers; private List<UserLight> listConnectedUsers;
private List<GameLight> listGameLight;
private MainToDataImpl mainToDataImpl;
private ComToDataClientImpl comToDataClientImpl;
private GameToDataImpl gameToDataImpl;
private IDataToCom dataToCom;
private IDataToMain dataToMain;
private IDataToGame dataToGame;
public DataCoreClient() {
mainToDataImpl = new MainToDataImpl(this);
comToDataClientImpl = new ComToDataClientImpl(this);
gameToDataImpl = new GameToDataImpl(this);
}
private List<GameLight> listGameLight; public List<UserLight> getListConnectedUsers() {
return listConnectedUsers;
}
private MainToDataImpl mainToDataImpl; public void setListConnectedUsers(List<UserLight> listConnectedUsers) {
private ComToDataClientImpl comToDataClientImpl; this.listConnectedUsers = listConnectedUsers;
}
private IDataToCom dataToCom; public UserHeavy getLocalUserHeavy() {
private IDataToMain dataToMain; return localUserHeavy;
}
public DataCoreClient() { public void setLocalUserHeavy(UserHeavy localUserHeavy) {
mainToDataImpl = new MainToDataImpl(this); this.localUserHeavy = localUserHeavy;
comToDataClientImpl = new ComToDataClientImpl(this); }
}
public List<UserLight> getListConnectedUsers() { public void setLocalUserLight(UserLight localUserLight) {
return listConnectedUsers; this.localUserLight = localUserLight;
} }
public void setListConnectedUsers(List<UserLight> listConnectedUsers) { public IComToData getClientComToDataImpl() {
this.listConnectedUsers = listConnectedUsers; return comToDataClientImpl;
} }
public UserHeavy getLocalUserHeavy() { public IMainToData getMainToDataImpl() {
return localUserHeavy; return mainToDataImpl;
} }
public void setLocalUserHeavy(UserHeavy localUserHeavy) { public IDataToCom getDataToCom() {
this.localUserHeavy = localUserHeavy; return dataToCom;
} }
public void setLocalUserLight(UserLight localUserLight) { public void setDataToCom(IDataToCom dataToCom) {
this.localUserLight = localUserLight; this.dataToCom = dataToCom;
} }
public IComToData getClientComToDataImpl() { public void setListGameLight(List<GameLight> listGameLight) {
return comToDataClientImpl; this.listGameLight = listGameLight;
} }
public IMainToData getMainToDataImpl() { public List<GameLight> getListGameLight() {
return mainToDataImpl; return listGameLight;
} }
public IDataToCom getDataToCom() { private boolean isMoveValid(Move playerMove, Board boardGame) {
return dataToCom; return false;
} }
public void setDataToCom(IDataToCom dataToCom) { public IDataToMain getDataToMain() {
this.dataToCom = dataToCom; return dataToMain;
} }
public void setListGameLight(List<GameLight> listGameLight) { public void setDataToMain(IDataToMain dataToMain) {
this.listGameLight = listGameLight; this.dataToMain = dataToMain;
} }
private boolean isMoveValid(Move playerMove, Board boardGame) { public IDataToGame getDataToGame() {
return false; return dataToGame;
} }
public IDataToMain getDataToMain() { public void setDataToGame(IDataToGame dataToGame) {
return dataToMain; this.dataToGame = dataToGame;
} }
public void setDataToMain(IDataToMain dataToMain) { public GameToDataImpl getGameToDataImpl() {
this.dataToMain = dataToMain; return gameToDataImpl;
} }
} }
package main.java.client.data;
import java.sql.Timestamp;
import java.util.Date;
import java.util.UUID;
import main.java.common.dataModel.GameLight;
import main.java.common.dataModel.UserZero;
import main.java.common.interfaces.client.IGameToData;
public class GameToDataImpl implements IGameToData {
DataCoreClient dataCoreClient;
public GameToDataImpl(DataCoreClient dataCoreClient) {
this.dataCoreClient = dataCoreClient;
}
@Override
public void playMove(int x, int y, UserZero u) {
}
@Override
public void getPlayer(UUID id) {
}
@Override
public void newGameAvailable(GameLight gl) {
dataCoreClient.getDataToCom().addNewGameAvailable(gl);
}
@Override
public void askGame(UUID gameId, UUID userId) {
}
@Override
public void newMessage(String m, UUID gameId) throws Exception {
dataCoreClient.getDataToCom().sendChatMessage(m, new Timestamp(new Date().getTime()),
dataCoreClient.getLocalUserHeavy().getId(), gameId);
}
}
package main.java.client.data; package main.java.client.data;
import main.java.common.dataModel.GameHeavy;
import main.java.common.dataModel.GameLight;
import main.java.common.dataModel.UserHeavy;
import main.java.common.dataModel.UserLight;
import main.java.common.interfaces.client.IMainToData;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import javafx.scene.Scene;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
...@@ -20,179 +11,209 @@ import java.util.ArrayList; ...@@ -20,179 +11,209 @@ import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.UUID; import java.util.UUID;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import javafx.stage.Stage;
import main.java.common.dataModel.GameHeavy;
import main.java.common.dataModel.GameLight;
import main.java.common.dataModel.GameStatus;
import main.java.common.dataModel.UserHeavy;
import main.java.common.dataModel.UserLight;
import main.java.common.interfaces.client.IMainToData;
public class MainToDataImpl implements IMainToData { public class MainToDataImpl implements IMainToData {
DataCoreClient dataCoreClient; DataCoreClient dataCoreClient;
public MainToDataImpl(DataCoreClient dataCoreClient) { public MainToDataImpl(DataCoreClient dataCoreClient) {
this.dataCoreClient = dataCoreClient; this.dataCoreClient = dataCoreClient;
} }
public static void createUser(UserLight userLight, UserHeavy userHeavy) throws Exception { public static void createUser(UserLight userLight, UserHeavy userHeavy) throws Exception {
String userFilePath = Configuration.SAVE_DIR + File.separator + userLight.getPseudo() + ".json"; String userFilePath = Configuration.SAVE_DIR + File.separator + userLight.getPseudo() + ".json";
File userFile = new File(userFilePath); File userFile = new File(userFilePath);
if (userFile.exists()) if (userFile.exists()) {
throw new Exception("This user already exists on this computer"); throw new Exception("This user already exists on this computer");
}
JsonObject userJson = new JsonObject();
userJson.addProperty("id", userLight.getId().toString()); JsonObject userJson = new JsonObject();
userJson.addProperty("pseudo", userLight.getPseudo()); userJson.addProperty("id", userLight.getId().toString());
userJson.addProperty("lastName", userLight.getLastName()); userJson.addProperty("pseudo", userLight.getPseudo());
userJson.addProperty("firstName", userLight.getFirstName()); userJson.addProperty("lastName", userLight.getLastName());
if (userLight.getDateOfBirth() == null) userJson.addProperty("firstName", userLight.getFirstName());
userJson.addProperty("dateOfBirth", (String) null); if (userLight.getDateOfBirth() == null) {
else userJson.addProperty("dateOfBirth", (String) null);
userJson.addProperty("dateOfBirth", new SimpleDateFormat("dd-MM-yyyy").format(userLight.getDateOfBirth())); } else {
userJson.addProperty("avatarId", userLight.getAvatarId()); userJson.addProperty("dateOfBirth", new SimpleDateFormat("dd-MM-yyyy").format(userLight.getDateOfBirth()));
userJson.addProperty("playedGames", userLight.getPlayedGames()); }
userJson.addProperty("wonGames", userLight.getWonGames()); userJson.addProperty("avatarId", userLight.getAvatarId());
userJson.addProperty("password", userHeavy.getPassword()); userJson.addProperty("playedGames", userLight.getPlayedGames());
userJson.addProperty("serverAddress", userHeavy.getServerAddress()); userJson.addProperty("wonGames", userLight.getWonGames());
userJson.addProperty("serverPort", userHeavy.getServerPort()); userJson.addProperty("password", userHeavy.getPassword());
userJson.addProperty("serverAddress", userHeavy.getServerAddress());
userFile.getParentFile().mkdirs(); userJson.addProperty("serverPort", userHeavy.getServerPort());
FileWriter fw = new FileWriter(userFilePath);
fw.write(userJson.toString()); userFile.getParentFile().mkdirs();
fw.close(); FileWriter fw = new FileWriter(userFilePath);
} fw.write(userJson.toString());
fw.close();
@Override }
public void selectGames(GameLight g) {
@Override
} public void selectGames(GameLight g) {
@Override }
public void acceptanceAcquired(UUID u_id, Boolean validation) {
@Override
} public void acceptanceAcquired(UUID u_id, Boolean validation) {
@Override }
public Scene newGame(UserLight ul, Boolean spectatorsOk, Boolean chatOk, Boolean creatorPlayWhite, int limitMove, Scene sceneFx) {
return null; @Override
} public Stage newGame(UserLight ul, Boolean spectatorsOk, Boolean chatOk, Boolean creatorPlayWhite, int limitMove,
Stage stageFx) {
@Override GameLight gameCreated = new GameLight(UUID.randomUUID(), ul, null, GameStatus.PENDING, spectatorsOk, chatOk,
public void updatedProfile(UserLight profile) { creatorPlayWhite, limitMove);
dataCoreClient.getDataToGame().getGameScreen(gameCreated, stageFx);
} return stageFx;
}
@Override
public void requestToDataToSpecialGame(GameLight game, UserLight user, Scene sceneFx) { @Override
public void updatedProfile(UserLight profile) {
}
}
@Override
public void sendServerParams(String ip, int port) { @Override
public void requestToDataToSpecialGame(GameLight game, UserLight user, Stage stageFx) {
}
}
@Override
public ArrayList<GameLight> displaySavedGames(UUID id) { @Override
return null; public void sendServerParams(String ip, int port) {
}
}
@Override
public GameHeavy getSavedGame(UUID id) { @Override
return null; public ArrayList<GameLight> displaySavedGames(UUID id) {
} return null;
}
@Override
public void sendUserInfo(String pseudo, String lastName, String firstName, Date dateOfBirth, int avatarId, String password) throws Exception { @Override
if (lastName == null || firstName == null || password == null) public GameHeavy getSavedGame(UUID id) {
throw new Exception("One or more required field is empty"); return null;
UUID id = UUID.randomUUID(); }
createUser(new UserLight(id, pseudo, lastName, firstName, dateOfBirth, avatarId, 0, 0), new UserHeavy(id, pseudo, password, null, null, null));
} @Override
public void sendUserInfo(String pseudo, String lastName, String firstName, Date dateOfBirth, int avatarId,
@Override String password) throws Exception {
public void downloadUserProfile(String filePath) { if (lastName == null || firstName == null || password == null) {
throw new Exception("One or more required field is empty");
} }
UUID id = UUID.randomUUID();
@Override createUser(new UserLight(id, pseudo, lastName, firstName, dateOfBirth, avatarId, 0, 0),
public void updateProfile(UserLight profileLight, UserHeavy profileHeavy) throws Exception { new UserHeavy(id, pseudo, password, null, null, null));
String userFilePath = Configuration.SAVE_DIR + File.separator + dataCoreClient.getLocalUserHeavy().getPseudo() + ".json"; }
File userFile = new File(userFilePath);
if (!userFile.exists()) @Override
throw new Exception("File for user " + dataCoreClient.getLocalUserHeavy().getPseudo() + " not found"); public void downloadUserProfile(String filePath) {
String oldFilePath = userFilePath + profileLight.getId().toString();
File oldFile = new File(oldFilePath); }
if (oldFile.exists())
throw new Exception("Error while backuping old data"); @Override
userFile.renameTo(oldFile); public void updateProfile(UserLight profileLight, UserHeavy profileHeavy) throws Exception {
try { String userFilePath = Configuration.SAVE_DIR + File.separator + dataCoreClient.getLocalUserHeavy().getPseudo()
createUser(profileLight, profileHeavy); + ".json";
} catch (Exception e) { File userFile = new File(userFilePath);
System.out.println(e.getMessage()); if (!userFile.exists()) {
oldFile.renameTo(userFile); throw new Exception("File for user " + dataCoreClient.getLocalUserHeavy().getPseudo() + " not found");
} }
oldFile.delete(); String oldFilePath = userFilePath + profileLight.getId().toString();
} File oldFile = new File(oldFilePath);
if (oldFile.exists()) {
@Override throw new Exception("Error while backuping old data");
public void identify(String login, String password, String address) throws Exception { }
//blank playername or password userFile.renameTo(oldFile);
if (login.isEmpty() || password.isEmpty()) { try {
throw new Exception("Data error: due to empty login or password"); createUser(profileLight, profileHeavy);
} // dataCoreClient.getDataToCom().notifyUpdateProfile(profileLight); TO DISCUSS
login(login, password); // WITH COM
dataCoreClient.getDataToCom().connectUserOnline(getUserLightFromFile(login), address); } catch (Exception e) {
} System.out.println(e.getMessage());
oldFile.renameTo(userFile);
public UserLight getUserLightFromFile(String pseudo) throws Exception, IOException, ParseException { }
String path = Configuration.SAVE_DIR + File.separator + pseudo + ".json";