Commit f0e885b6 authored by Thomas Lecluse's avatar Thomas Lecluse
Browse files

Merge branch 'feature/fix/v2' into 'int/v2'

Feature/fix/v2

See merge request !30
parents 77555add 40b175b6
...@@ -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
......
package main.java.client.data; package main.java.client.data;
import main.java.common.dataModel.*;
import main.java.common.interfaces.client.*;
import java.util.List; 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.IDataToCom;
import main.java.common.interfaces.client.IDataToGame;
import main.java.common.interfaces.client.IDataToMain;
import main.java.common.interfaces.client.IMainToData;
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 List<GameLight> listGameLight; private MainToDataImpl mainToDataImpl;
private ComToDataClientImpl comToDataClientImpl;
private GameToDataImpl gameToDataImpl;
private MainToDataImpl mainToDataImpl; private IDataToCom dataToCom;
private ComToDataClientImpl comToDataClientImpl; private IDataToMain dataToMain;
private GameToDataImpl gameToDataImpl; private IDataToGame dataToGame;
private IDataToCom dataToCom; public DataCoreClient() {
private IDataToMain dataToMain; mainToDataImpl = new MainToDataImpl(this);
private IDataToGame dataToGame; comToDataClientImpl = new ComToDataClientImpl(this);
gameToDataImpl = new GameToDataImpl(this);
}
public DataCoreClient() { public List<UserLight> getListConnectedUsers() {
mainToDataImpl = new MainToDataImpl(this); return listConnectedUsers;
comToDataClientImpl = new ComToDataClientImpl(this); }
gameToDataImpl = new GameToDataImpl(this);
}
public List<UserLight> getListConnectedUsers() { public void setListConnectedUsers(List<UserLight> listConnectedUsers) {
return listConnectedUsers; this.listConnectedUsers = listConnectedUsers;
} }
public void setListConnectedUsers(List<UserLight> listConnectedUsers) { public UserHeavy getLocalUserHeavy() {
this.listConnectedUsers = listConnectedUsers; return localUserHeavy;
} }
public UserHeavy getLocalUserHeavy() { public void setLocalUserHeavy(UserHeavy localUserHeavy) {
return localUserHeavy; this.localUserHeavy = localUserHeavy;
} }
public void setLocalUserHeavy(UserHeavy localUserHeavy) { public void setLocalUserLight(UserLight localUserLight) {
this.localUserHeavy = localUserHeavy; this.localUserLight = localUserLight;
} }
public void setLocalUserLight(UserLight localUserLight) { public IComToData getClientComToDataImpl() {
this.localUserLight = localUserLight; return comToDataClientImpl;
} }
public IComToData getClientComToDataImpl() { public IMainToData getMainToDataImpl() {
return comToDataClientImpl; return mainToDataImpl;
} }
public IMainToData getMainToDataImpl() { public IDataToCom getDataToCom() {
return mainToDataImpl; return dataToCom;
} }
public IDataToCom getDataToCom() { public void setDataToCom(IDataToCom dataToCom) {
return dataToCom; this.dataToCom = dataToCom;
} }
public void setDataToCom(IDataToCom dataToCom) { public void setListGameLight(List<GameLight> listGameLight) {
this.dataToCom = dataToCom; this.listGameLight = listGameLight;
} }
public void setListGameLight(List<GameLight> listGameLight) { public List<GameLight> getListGameLight() {
this.listGameLight = listGameLight; return listGameLight;
} }
public List<GameLight>getListGameLight(){ private boolean isMoveValid(Move playerMove, Board boardGame) {
return listGameLight; return false;
} }
private boolean isMoveValid(Move playerMove, Board boardGame) { public IDataToMain getDataToMain() {
return false; return dataToMain;
} }
public IDataToMain getDataToMain() { public void setDataToMain(IDataToMain dataToMain) {
return dataToMain; this.dataToMain = dataToMain;
} }
public void setDataToMain(IDataToMain dataToMain) { public IDataToGame getDataToGame() {
this.dataToMain = dataToMain; return dataToGame;
} }
public IDataToGame getDataToGame() { public void setDataToGame(IDataToGame dataToGame) {
return dataToGame; this.dataToGame = dataToGame;
} }
public GameToDataImpl getGameToDataImpl() { public GameToDataImpl getGameToDataImpl() {
return gameToDataImpl; return gameToDataImpl;
} }
} }
package main.java.client.data; package main.java.client.data;
import main.java.common.dataModel.GameLight;
import main.java.common.dataModel.Message;
import main.java.common.dataModel.UserLight;
import main.java.common.dataModel.UserZero;
import main.java.common.interfaces.client.IGameToData;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.Date; import java.util.Date;
import java.util.ListIterator;
import java.util.UUID; 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 { public class GameToDataImpl implements IGameToData {
DataCoreClient dataCoreClient; DataCoreClient dataCoreClient;
public GameToDataImpl(DataCoreClient dataCoreClient) { public GameToDataImpl(DataCoreClient dataCoreClient) {
this.dataCoreClient = dataCoreClient; this.dataCoreClient = dataCoreClient;
} }
@Override @Override
public void playMove(int x, int y, UserZero u) { public void playMove(int x, int y, UserZero u) {
} }
@Override @Override
public void getPlayer(UUID id) { public void getPlayer(UUID id) {
} }
@Override @Override
public void newGameAvailable(GameLight gl) { public void newGameAvailable(GameLight gl) {
dataCoreClient.getDataToCom().addNewGameAvailable(gl); dataCoreClient.getDataToCom().addNewGameAvailable(gl);
} }
@Override @Override
public void askGame(UUID gameId, UUID userId) { public void askGame(UUID gameId, UUID userId) {
} }
@Override @Override
public void newMessage(String m, UUID pid, UUID gameId) throws Exception { public void newMessage(String m, UUID gameId) throws Exception {
dataCoreClient.getDataToCom().sendChatMessage(m, new Timestamp(new Date().getTime()), pid, gameId); 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.*;
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;
...@@ -17,182 +11,209 @@ import java.util.ArrayList; ...@@ -17,182 +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) {
GameLight gameCreated = new GameLight(UUID.randomUUID(), ul, null, GameStatus.PENDING, spectatorsOk, chatOk, creatorPlayWhite, limitMove); @Override
dataCoreClient.getDataToGame().getGameScreen(gameCreated, sceneFx); public Stage newGame(UserLight ul, Boolean spectatorsOk, Boolean chatOk, Boolean creatorPlayWhite, int limitMove,
return sceneFx; Stage stageFx) {
} GameLight gameCreated = new GameLight(UUID.randomUUID(), ul, null, GameStatus.PENDING, spectatorsOk, chatOk,
creatorPlayWhite, limitMove);
@Override dataCoreClient.getDataToGame().getGameScreen(gameCreated, stageFx);
public void updatedProfile(UserLight profile) { return stageFx;
}
}
@Override
@Override public void updatedProfile(UserLight profile) {
public void requestToDataToSpecialGame(GameLight game, UserLight user, Scene sceneFx) {
}
}
@Override
@Override public void requestToDataToSpecialGame(GameLight game, UserLight user, Stage stageFx) {
public void sendServerParams(String ip, int port) {
}
}
@Override
@Override public void sendServerParams(String ip, int port) {
public ArrayList<GameLight> displaySavedGames(UUID id) {
return null; }
}
@Override
@Override public ArrayList<GameLight> displaySavedGames(UUID id) {
public GameHeavy getSavedGame(UUID id) { return null;
return null; }
}
@Override
@Override public GameHeavy getSavedGame(UUID id) {
public void sendUserInfo(String pseudo, String lastName, String firstName, Date dateOfBirth, int avatarId, String password) throws Exception { return null;
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), new UserHeavy(id, pseudo, password, null, null, null)); public void sendUserInfo(String pseudo, String lastName, String firstName, Date dateOfBirth, int avatarId,
} String password) throws Exception {
if (lastName == null || firstName == null || password == null) {
@Override throw new Exception("One or more required field is empty");
public void downloadUserProfile(String filePath) { }
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 updateProfile(UserLight profileLight, UserHeavy profileHeavy) throws Exception {
String userFilePath = Configuration.SAVE_DIR + File.separator + dataCoreClient.getLocalUserHeavy().getPseudo() + ".json"; @Override
File userFile = new File(userFilePath); public void downloadUserProfile(String filePath) {
if (!userFile.exists())
throw new Exception("File for user " + dataCoreClient.getLocalUserHeavy().getPseudo() + " not found"); }
String oldFilePath = userFilePath + profileLight.getId().toString();
File oldFile = new File(oldFilePath); @Override
if (oldFile.exists()) public void updateProfile(UserLight profileLight, UserHeavy profileHeavy) throws Exception {
throw new Exception("Error while backuping old data"); String userFilePath = Configuration.SAVE_DIR + File.separator + dataCoreClient.getLocalUserHeavy().getPseudo()
userFile.renameTo(oldFile); + ".json";
try { File userFile = new File(userFilePath);
createUser(profileLight, profileHeavy); if (!userFile.exists()) {
//dataCoreClient.getDataToCom().notifyUpdateProfile(profileLight); TO DISCUSS WITH COM throw new Exception("File for user " + dataCoreClient.getLocalUserHeavy().getPseudo() + " not found");
} catch (Exception e) { }
System.out.println(e.getMessage()); String oldFilePath = userFilePath + profileLight.getId().toString();
oldFile.renameTo(userFile); File oldFile = new File(oldFilePath);
} if (oldFile.exists()) {
oldFile.delete(); throw new Exception("Error while backuping old data");
} }
userFile.renameTo(oldFile);
@Override try {
public void identify(String login, String password, String address) throws Exception { createUser(profileLight, profileHeavy);
//blank playername or password // dataCoreClient.getDataToCom().notifyUpdateProfile(profileLight); TO DISCUSS
if (login.isEmpty() || password.isEmpty()) { // WITH COM
throw new Exception("Data error: due to empty login or password"); } catch (Exception e) {
} System.out.println(e.getMessage());
login(login, password); oldFile.renameTo(userFile);
dataCoreClient.getDataToCom().connectUserOnline(getUserLightFromFile(login), address); }
} oldFile.delete();
}
public UserLight getUserLightFromFile(String pseudo) throws Exception, IOException, ParseException {
String path = Configuration.SAVE_DIR + File.separator + pseudo + ".json"; @Override
File userFile = new File(path); public void identify(String login, String password, String address) throws Exception {
if (!userFile.exists()) // blank playername or password
throw new Exception("Data error: User profile does not exist"); if (login.isEmpty() || password.isEmpty()) {