Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Alexandre Ducarne
ai12-othello
Commits
51662116
Commit
51662116
authored
Nov 24, 2019
by
William Sha
Browse files
Auto stash before cherrypick of "Add interfaces client/server"
Debug de l'affichage des vues, debug du démarrage de l'application
parent
5a3e58c4
Changes
63
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
51662116
#
# Project specific excludes
#
tomcat
#
# Default excludes
#
# Binaries
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
*.war
*.ear
*.sar
*.class
# Maven
target/
# IntelliJ project files
*.iml
*.iws
*.ipr
.idea/
# eclipse project file
.settings/
.classpath
.project
# NetBeans specific
nbproject/private/
build/
nbbuild/
dist/
nbdist/
nbactions.xml
nb-configuration.xml
# VS Code
.vscode/
# OS
.DS_Store
# Misc
*.swp
release.properties
pom.xml.releaseBackup
pom.xml.tag
/bin/
#
# Project specific excludes
#
tomcat
#
# Default excludes
#
# Binaries
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
*.war
*.ear
*.sar
*.class
# Maven
target/
# IntelliJ project files
*.iml
*.iws
*.ipr
.idea/
# eclipse project file
.settings/
.classpath
.project
# NetBeans specific
nbproject/private/
build/
nbbuild/
dist/
nbdist/
nbactions.xml
nb-configuration.xml
# VS Code
.vscode/
# OS
.DS_Store
# Misc
*.swp
release.properties
pom.xml.releaseBackup
pom.xml.tag
/bin/
out/
output
...
...
pom.xml
View file @
51662116
...
...
@@ -42,6 +42,16 @@
<artifactId>
vavr
</artifactId>
<version>
0.10.2
</version>
</dependency>
<dependency>
<groupId>
com.fasterxml.jackson.core
</groupId>
<artifactId>
jackson-databind
</artifactId>
<version>
2.9.8
</version>
</dependency>
<dependency>
<groupId>
com.google.code.gson
</groupId>
<artifactId>
gson
</artifactId>
<version>
2.8.0
</version>
</dependency>
</dependencies>
<build>
...
...
@@ -55,6 +65,23 @@
<mainClass>
baleine.client.ClientApp
</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>
org.openjfx
</groupId>
<artifactId>
javafx-maven-plugin
</artifactId>
<version>
0.0.3
</version>
<configuration>
<mainClass>
baleine.client.ClientApp
</mainClass>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<targetPath>
baleine/client/main/fxml
</targetPath>
<directory>
src/baleine/client/main/fxml
</directory>
<includes>
<include>
**/*.fxml
</include>
</includes>
</resource>
</resources>
</build>
</project>
src/baleine/client/ClientApp.java
View file @
51662116
package
baleine.client
;
import
baleine.client.data.DataCoreClient
;
import
baleine.client.game.controller.TransApplicationController
;
import
baleine.client.game.view.TransApplicationView
;
import
baleine.client.network.WebSocketStompSessionInitializer
;
import
baleine.client.network.ComCoreClient
;
import
baleine.client.main.controller.MainCore
;
import
baleine.client.main.controller.MainControllerFX
;
import
javafx.application.Application
;
import
javafx.scene.Scene
;
import
javafx.stage.Stage
;
import
java.io.File
;
/**
* Main application
*
...
...
@@ -14,31 +18,42 @@ import javafx.stage.Stage;
*/
public
class
ClientApp
extends
Application
{
private
TransApplicationView
view
;
private
TransApplicationController
controller
;
private
static
ComCoreClient
comCoreClient
;
private
static
DataCoreClient
dataCoreClient
;
public
static
MainCore
mainCore
=
new
MainCore
(
new
MainControllerFX
());
public
static
final
String
APPLICATION_NAME
=
"Othello"
;
public
static
final
int
APPLICATION_WIDTH
=
889
;
public
static
final
int
APPLICATION_HEIGHT
=
500
;
//css definition
private
static
final
File
cssFile
=
new
File
(
"src/baleine/client/main/ressources/main.css"
);
public
static
final
String
CSS_FILE_PATH
=
"file:///"
+
ClientApp
.
cssFile
.
getAbsolutePath
().
replace
(
"\\"
,
"/"
);
/**
* Run the client app (JavaFX)
*
* @param args additional args
* @throws Exception TODO: remove once the Websocket is initialized in the proper class
*/
public
static
void
main
(
String
[]
args
)
throws
Exception
{
// TODO: call this method right when the user connects to a server instead of here
WebSocketStompSessionInitializer
.
init
(
"localhost"
,
8080
);
public
static
void
main
(
String
[]
args
)
{
initCores
();
// TODO: call this method once user is connected to a server in ihm main.
comCoreClient
.
initWebSocketConnection
(
"localhost"
,
8080
);
launch
(
args
);
}
private
static
void
initCores
()
{
comCoreClient
=
new
ComCoreClient
();
dataCoreClient
=
new
DataCoreClient
();
dataCoreClient
.
setDataToCom
(
comCoreClient
.
getDataToComClientImpl
());
dataCoreClient
.
setDataToMain
(
mainCore
.
getDataToMainImpl
());
comCoreClient
.
setComToDataClient
(
dataCoreClient
.
getClientComToDataImpl
());
mainCore
.
setMainToData
(
dataCoreClient
.
getMainToDataImpl
());
}
@Override
public
void
start
(
Stage
stage
)
{
view
=
new
TransApplicationView
();
controller
=
new
TransApplicationController
(
view
);
// Application content display
stage
.
setTitle
(
"Translator"
);
stage
.
setScene
(
new
Scene
(
view
,
600
,
400
));
stage
.
setResizable
(
false
);
stage
.
show
();
public
void
start
(
Stage
stage
)
throws
Exception
{
System
.
out
.
println
(
ClientApp
.
APPLICATION_NAME
+
" is starting..."
);
ClientApp
.
mainCore
.
getFX
().
initialize
(
"../fxml/login.fxml"
,
stage
);
}
}
src/baleine/client/data/.gitkeep
deleted
100644 → 0
View file @
5a3e58c4
src/baleine/c
ommon/interfaces/c
lient/ComToDataImpl.java
→
src/baleine/client
/data
/ComToData
Client
Impl.java
View file @
51662116
package
baleine.c
ommon.interfaces.c
lient
;
package
baleine.client
.data
;
import
baleine.common.dataModel.*
;
import
baleine.common.interfaces.client.IComToData
;
import
java.util.ArrayList
;
import
java.util.
Optional
;
import
java.util.
List
;
import
java.util.UUID
;
public
class
ComToDataImpl
implements
IComToData
{
private
static
ComToDataImpl
instance
=
new
ComToDataImpl
()
;
public
class
ComToData
Client
Impl
implements
IComToData
{
DataCoreClient
dataCoreClient
;
private
ComToDataImpl
()
{
}
public
static
ComToDataImpl
getInstance
()
{
return
Optional
.
of
(
instance
).
orElseGet
(
ComToDataImpl:
:
new
);
ComToDataClientImpl
(
DataCoreClient
dataCoreClient
)
{
this
.
dataCoreClient
=
dataCoreClient
;
}
@Override
public
void
forwardPlayerProfile
(
UserLight
user
)
{
// TODO Auto-generated method stub
}
@Override
public
void
addAuthenticatedPlayer
(
UserLight
user
)
{
// TODO Auto-generated method stub
}
@Override
public
void
receiveGameData
(
ArrayList
<
UserLight
>
user
)
{
// TODO Auto-generated method stub
}
@Override
public
void
addNewUser
(
UserLight
user
)
{
// TODO Auto-generated method stub
dataCoreClient
.
getListConnectedUsers
().
add
(
user
);
}
@Override
public
void
notifyNewGame
(
GameLight
newGameCreated
)
{
// TODO Auto-generated method stub
}
@Override
public
void
sendGameSave
(
GameHeavy
game
,
UUID
userId
)
{
// TODO Auto-generated method stub
}
@Override
public
void
receiveChatMessage
(
Message
message
)
{
// TODO Auto-generated method stub
}
@Override
public
void
removeDisconnectedUser
(
UUID
user
)
{
// TODO Auto-generated method stub
}
@Override
public
void
addSpectatorToGame
(
UserLight
spectator
)
{
// TODO Auto-generated method stub
}
@Override
public
void
receiveJoinRequestAnswer
(
boolean
isAccepted
,
UUID
gameUUID
)
{
// TODO Auto-generated method stub
}
@Override
public
void
receiveJoinRequest
(
UUID
userProposingUUID
,
UUID
gameUUID
)
{
// TODO Auto-generated method stub
}
@Override
public
void
notifyEndGame
(
GameLight
game
)
{
// TODO Auto-generated method stub
}
@Override
public
void
updateBoard
(
Board
board
)
{
// TODO Auto-generated method stub
}
@Override
public
void
endGame
(
GameLight
endGameInfo
)
{
// TODO Auto-generated method stub
}
@Override
public
void
receiveServerStateOnConnection
(
ArrayList
<
UserLight
>
usersOnline
,
ArrayList
<
GameLight
>
gamesOnline
)
{
//FIXME Fake implementation in order for Data to connect
public
void
receivePlayersnGames
(
List
<
UserLight
>
players
,
List
<
GameLight
>
gamesAvailable
)
{
dataCoreClient
.
setListConnectedUsers
(
players
);
dataCoreClient
.
setListGameLight
(
gamesAvailable
);
dataCoreClient
.
getDataToMain
().
sendLists
(
players
,
gamesAvailable
);
}
@Override
public
void
receiveServerStateOnConnection
(
ArrayList
<
UserLight
>
usersOnline
,
ArrayList
<
GameLight
>
gamesOnline
)
{
}
}
src/baleine/client/data/Configuration.java
0 → 100644
View file @
51662116
package
baleine.client.data
;
import
java.io.File
;
public
class
Configuration
{
public
static
final
String
SAVE_DIR
=
System
.
getProperty
(
"user.home"
)
+
File
.
separator
+
"OthelloData"
;
}
src/baleine/client/data/DataCoreClient.java
0 → 100644
View file @
51662116
package
baleine.client.data
;
import
baleine.common.dataModel.*
;
import
baleine.common.interfaces.client.IComToData
;
import
baleine.common.interfaces.client.IDataToCom
;
import
baleine.common.interfaces.client.IDataToMain
;
import
baleine.common.interfaces.client.IMainToData
;
import
java.util.List
;
public
class
DataCoreClient
{
private
UserHeavy
localUserHeavy
;
private
UserLight
localUserLight
;
private
List
<
UserLight
>
listConnectedUsers
;
private
List
<
GameLight
>
listGameLight
;
private
MainToDataImpl
mainToDataImpl
;
private
ComToDataClientImpl
comToDataClientImpl
;
private
IDataToCom
dataToCom
;
private
IDataToMain
dataToMain
;
public
DataCoreClient
()
{
mainToDataImpl
=
new
MainToDataImpl
(
this
);
comToDataClientImpl
=
new
ComToDataClientImpl
(
this
);
}
public
List
<
UserLight
>
getListConnectedUsers
()
{
return
listConnectedUsers
;
}
public
void
setListConnectedUsers
(
List
<
UserLight
>
listConnectedUsers
)
{
this
.
listConnectedUsers
=
listConnectedUsers
;
}
public
UserHeavy
getLocalUserHeavy
()
{
return
localUserHeavy
;
}
public
void
setLocalUserHeavy
(
UserHeavy
localUserHeavy
)
{
this
.
localUserHeavy
=
localUserHeavy
;
}
public
void
setLocalUserLight
(
UserLight
localUserLight
)
{
this
.
localUserLight
=
localUserLight
;
}
public
IComToData
getClientComToDataImpl
()
{
return
comToDataClientImpl
;
}
public
IMainToData
getMainToDataImpl
()
{
return
mainToDataImpl
;
}
public
IDataToCom
getDataToCom
()
{
return
dataToCom
;
}
public
void
setDataToCom
(
IDataToCom
dataToCom
)
{
this
.
dataToCom
=
dataToCom
;
}
public
void
setListGameLight
(
List
<
GameLight
>
listGameLight
)
{
this
.
listGameLight
=
listGameLight
;
}
private
boolean
isMoveValid
(
Move
playerMove
,
Board
boardGame
)
{
return
false
;
}
public
IDataToMain
getDataToMain
()
{
return
dataToMain
;
}
public
void
setDataToMain
(
IDataToMain
dataToMain
)
{
this
.
dataToMain
=
dataToMain
;
}
}
src/baleine/client/data/MainToDataImpl.java
0 → 100644
View file @
51662116
package
baleine.client.data
;
import
baleine.common.dataModel.GameHeavy
;
import
baleine.common.dataModel.GameLight
;
import
baleine.common.dataModel.UserHeavy
;
import
baleine.common.dataModel.UserLight
;
import
baleine.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.FileWriter
;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.UUID
;
public
class
MainToDataImpl
implements
IMainToData
{
DataCoreClient
dataCoreClient
;
public
MainToDataImpl
(
DataCoreClient
dataCoreClient
)
{
this
.
dataCoreClient
=
dataCoreClient
;
}
public
static
void
createUser
(
UserLight
userLight
,
UserHeavy
userHeavy
)
throws
Exception
{
String
userFilePath
=
Configuration
.
SAVE_DIR
+
File
.
separator
+
userLight
.
getPseudo
()
+
".json"
;
File
userFile
=
new
File
(
userFilePath
);
if
(
userFile
.
exists
())
throw
new
Exception
(
"This user already exists on this computer"
);
JsonObject
userJson
=
new
JsonObject
();
userJson
.
addProperty
(
"id"
,
userLight
.
getId
().
toString
());
userJson
.
addProperty
(
"pseudo"
,
userLight
.
getPseudo
());
userJson
.
addProperty
(
"lastName"
,
userLight
.
getLastName
());
userJson
.
addProperty
(
"firstName"
,
userLight
.
getFirstName
());
if
(
userLight
.
getDateOfBirth
()
==
null
)
userJson
.
addProperty
(
"dateOfBirth"
,
(
String
)
null
);
else
userJson
.
addProperty
(
"dateOfBirth"
,
new
SimpleDateFormat
(
"dd-MM-yyyy"
).
format
(
userLight
.
getDateOfBirth
()));
userJson
.
addProperty
(
"avatarId"
,
userLight
.
getAvatarId
());
userJson
.
addProperty
(
"playedGames"
,
userLight
.
getPlayedGames
());
userJson
.
addProperty
(
"wonGames"
,
userLight
.
getWonGames
());
userJson
.
addProperty
(
"password"
,
userHeavy
.
getPassword
());
userJson
.
addProperty
(
"serverAddress"
,
userHeavy
.
getServerAddress
());
userJson
.
addProperty
(
"serverPort"
,
userHeavy
.
getServerPort
());
userFile
.
getParentFile
().
mkdirs
();
FileWriter
fw
=
new
FileWriter
(
userFilePath
);
fw
.
write
(
userJson
.
toString
());
fw
.
close
();
}
@Override
public
void
selectGames
(
GameLight
g
)
{
}
@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
void
updatedProfile
(
UserLight
profile
)
{
}
@Override
public
void
requestToDataToSpecialGame
(
GameLight
game
,
UserLight
user
,
Scene
sceneFx
)
{
}
@Override
public
void
sendServerParams
(
String
ip
,
int
port
)
{
}
@Override
public
ArrayList
<
GameLight
>
displaySavedGames
(
UUID
id
)
{
return
null
;
}
@Override
public
GameHeavy
getSavedGame
(
UUID
id
)
{
return
null
;
}
@Override
public
void
sendUserInfo
(
String
pseudo
,
String
lastName
,
String
firstName
,
Date
dateOfBirth
,
int
avatarId
,
String
password
)
throws
Exception
{
if
(
lastName
==
null
||
firstName
==
null
||
password
==
null
)
throw
new
Exception
(
"One or more required field is empty"
);
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
downloadUserProfile
(
String
filePath
)
{
}
@Override
public
void
updateProfile
(
UserLight
profileLight
,
UserHeavy
profileHeavy
)
throws
Exception
{
String
userFilePath
=
Configuration
.
SAVE_DIR
+
File
.
separator
+
dataCoreClient
.
getLocalUserHeavy
().
getPseudo
()
+
".json"
;
File
userFile
=
new
File
(
userFilePath
);
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
);
if
(
oldFile
.
exists
())
throw
new
Exception
(
"Error while backuping old data"
);
userFile
.
renameTo
(
oldFile
);
try
{
createUser
(
profileLight
,
profileHeavy
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
oldFile
.
renameTo
(
userFile
);
}
oldFile
.
delete
();
}
@Override
public
void
identify
(
String
login
,
String
password
,
String
address
)
throws
Exception
{
//blank playername or password
if
(
login
.
isEmpty
()
||
password
.
isEmpty
())
{
throw
new
Exception
(
"Data error: due to empty login or password"
);
}
login
(
login
,
password
);
dataCoreClient
.
getDataToCom
().
connectUserOnline
(
getUserLightFromFile
(
login
),
address
);
}
public
UserLight
getUserLightFromFile
(
String
pseudo
)
throws
Exception
,
IOException
,
ParseException
{
String
path
=
Configuration
.
SAVE_DIR
+
File
.
separator
+
pseudo
+
".json"
;
File
userFile
=
new
File
(
path
);
if
(!
userFile
.
exists
())
throw
new
Exception
(
"Data error: User profile does not exist"
);
JsonParser
parser
=
new
JsonParser
();
JsonObject
userObject
=
parser
.
parse
(
new
String
(
Files
.
readAllBytes
(
Paths
.
get
(
path
)))).
getAsJsonObject
();
UserLight
userLight
=
new
UserLight
(
UUID
.
fromString
(
userObject
.
get
(
"id"
).
getAsString
()),
userObject
.
get
(
"pseudo"
).
getAsString
(),
userObject
.
get
(
"lastName"
).
getAsString
(),
userObject
.
get
(
"firstName"
).
getAsString
(),
userObject
.
get
(
"dateOfBirth"
).
isJsonNull
()
?
null
:
new
SimpleDateFormat
(
"dd-MM-yyyy"
).
parse
(
userObject
.
get
(
"dateOfBirth"
).
getAsString
()),
userObject
.
get
(
"avatarId"
).
getAsInt
(),
userObject
.
get
(
"playedGames"
).
getAsInt
(),
userObject
.
get
(
"wonGames"
).
getAsInt
());
return
userLight
;
}