From 0419776c292c16f908c8652c79ea95b8d2080429 Mon Sep 17 00:00:00 2001 From: Enrico Siboni Date: Tue, 14 Aug 2018 15:45:43 +0200 Subject: [PATCH 01/35] Solved TODOs in client, removed useless code --- .../client/controller/ClientControllerActor.scala | 7 +------ .../it/cwmp/client/controller/PlayerActor.scala | 11 +---------- .../scala/it/cwmp/client/view/FXInputChecks.scala | 2 +- .../it/cwmp/client/view/game/GameViewActor.scala | 14 ++------------ 4 files changed, 5 insertions(+), 29 deletions(-) diff --git a/client/src/main/scala/it/cwmp/client/controller/ClientControllerActor.scala b/client/src/main/scala/it/cwmp/client/controller/ClientControllerActor.scala index 1b6302d4..b7e2be62 100644 --- a/client/src/main/scala/it/cwmp/client/controller/ClientControllerActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/ClientControllerActor.scala @@ -231,11 +231,6 @@ case class ClientControllerActor(private val apiClientActor: ActorRef) extends A log.error(s"${errorMessage.getOrElse(UNKNOWN_ERROR)}") } - /** - * @return the behaviour to enable when user is playing - */ - private def inGameBehaviour: Receive = Actor.emptyBehavior // TODO: we can remove thi behaviour, after starting the game there's nothing more to do - /** * @return the Future containing the address of one-time server that will receive the participants */ @@ -264,7 +259,7 @@ case class ClientControllerActor(private val apiClientActor: ActorRef) extends A private def onSuccessFindingOpponents(participants: List[Participant]): Unit = { roomViewActor ! FoundOpponents log.info(s"Setting the behaviour 'in-game'") - context.become(inGameBehaviour) + context.become(Actor.emptyBehavior) roomViewActor ! Hide playerActor ! PrepareForGame(participants, CellWorldGenerationStrategy(GameViewActor.VIEW_SIZE, GameViewActor.VIEW_SIZE, GameConstants.PASSIVE_CELLS_NUMBER)) diff --git a/client/src/main/scala/it/cwmp/client/controller/PlayerActor.scala b/client/src/main/scala/it/cwmp/client/controller/PlayerActor.scala index a0885c1f..35b59c7d 100644 --- a/client/src/main/scala/it/cwmp/client/controller/PlayerActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/PlayerActor.scala @@ -95,20 +95,11 @@ case class PlayerActor() extends Actor with Stash with Logging { * Starts the game */ private def startGame(): Unit = { - context.become(inGameBehaviour) + context.become(Actor.emptyBehavior) gameViewActor ! ShowGUIWithName(playerName) unstashAll() // un-stash distributed change messages } - /** - * @return the behaviour of the actor when it's in game - */ - private def inGameBehaviour: Receive = - distributedState.distributedStateBehaviour orElse { - // TODO: remove this part of receive because we cannot come back to rooms view without stopping acotrSystem - case GameEnded => backToLobbyAction() - } - /** * The action to do when the game is ended */ diff --git a/client/src/main/scala/it/cwmp/client/view/FXInputChecks.scala b/client/src/main/scala/it/cwmp/client/view/FXInputChecks.scala index af53d60b..5cb40a26 100644 --- a/client/src/main/scala/it/cwmp/client/view/FXInputChecks.scala +++ b/client/src/main/scala/it/cwmp/client/view/FXInputChecks.scala @@ -8,7 +8,7 @@ import javafx.scene.control.{CheckBox, Spinner, TextField} */ trait FXInputChecks extends FXAlertsController { - private val WRONG_INPUT_ERROR = "Wrong input!" // TODO parametrize + private val WRONG_INPUT_ERROR = "Wrong input!" /** * Gets a text field value diff --git a/client/src/main/scala/it/cwmp/client/view/game/GameViewActor.scala b/client/src/main/scala/it/cwmp/client/view/game/GameViewActor.scala index ea9c0c3e..270ea355 100644 --- a/client/src/main/scala/it/cwmp/client/view/game/GameViewActor.scala +++ b/client/src/main/scala/it/cwmp/client/view/game/GameViewActor.scala @@ -48,7 +48,7 @@ case class GameViewActor() extends Actor with FXRunOnUIThread with ActorAlertMan override protected def onInfoAlertReceived(title: String, message: String): Unit = { super.onInfoAlertReceived(title, message) - context.become(hideGUIBehaviour orElse newWorldBehaviour orElse guiWorldModificationsBehaviour) + context.become(newWorldBehaviour orElse guiWorldModificationsBehaviour) } /** @@ -63,17 +63,7 @@ case class GameViewActor() extends Actor with FXRunOnUIThread with ActorAlertMan gameFX.showGUI() }) - context.become(alertBehaviour orElse hideGUIBehaviour orElse newWorldBehaviour orElse guiWorldModificationsBehaviour) - } - - /** - * The behaviour of closing the view - */ - private def hideGUIBehaviour: Receive = { // TODO: remove, no-one ever sends this message here - case Hide => - if (updatingSchedule != null) updatingSchedule.cancel() - runOnUIThread { () => gameFX.hideGUI() } - context.become(showGUIBehaviour) + context.become(alertBehaviour orElse newWorldBehaviour orElse guiWorldModificationsBehaviour) } /** From e8d80858eda054932ce87b9214502c7e9e570d6f Mon Sep 17 00:00:00 2001 From: Enrico Siboni Date: Tue, 14 Aug 2018 15:51:10 +0200 Subject: [PATCH 02/35] Moved LayoutRes and StringRes classes into "view" package --- .../main/scala/it/cwmp/client/{utils => view}/LayoutRes.scala | 2 +- .../main/scala/it/cwmp/client/{utils => view}/StringRes.scala | 2 +- .../view/authentication/AuthenticationFXController.scala | 1 - client/src/main/scala/it/cwmp/client/view/game/GameFX.scala | 3 +-- .../main/scala/it/cwmp/client/view/room/RoomFXController.scala | 1 - 5 files changed, 3 insertions(+), 6 deletions(-) rename client/src/main/scala/it/cwmp/client/{utils => view}/LayoutRes.scala (91%) rename client/src/main/scala/it/cwmp/client/{utils => view}/StringRes.scala (87%) diff --git a/client/src/main/scala/it/cwmp/client/utils/LayoutRes.scala b/client/src/main/scala/it/cwmp/client/view/LayoutRes.scala similarity index 91% rename from client/src/main/scala/it/cwmp/client/utils/LayoutRes.scala rename to client/src/main/scala/it/cwmp/client/view/LayoutRes.scala index b78576c6..e0eb29ef 100644 --- a/client/src/main/scala/it/cwmp/client/utils/LayoutRes.scala +++ b/client/src/main/scala/it/cwmp/client/view/LayoutRes.scala @@ -1,4 +1,4 @@ -package it.cwmp.client.utils +package it.cwmp.client.view /** * Utility class that keeps together all the file names of the FXML layout files. diff --git a/client/src/main/scala/it/cwmp/client/utils/StringRes.scala b/client/src/main/scala/it/cwmp/client/view/StringRes.scala similarity index 87% rename from client/src/main/scala/it/cwmp/client/utils/StringRes.scala rename to client/src/main/scala/it/cwmp/client/view/StringRes.scala index 051d0ac5..ca3c500d 100644 --- a/client/src/main/scala/it/cwmp/client/utils/StringRes.scala +++ b/client/src/main/scala/it/cwmp/client/view/StringRes.scala @@ -1,4 +1,4 @@ -package it.cwmp.client.utils +package it.cwmp.client.view /** * Utility class that keeps together all the strings that compose the interface. diff --git a/client/src/main/scala/it/cwmp/client/view/authentication/AuthenticationFXController.scala b/client/src/main/scala/it/cwmp/client/view/authentication/AuthenticationFXController.scala index 46d9a517..0d67d33c 100644 --- a/client/src/main/scala/it/cwmp/client/view/authentication/AuthenticationFXController.scala +++ b/client/src/main/scala/it/cwmp/client/view/authentication/AuthenticationFXController.scala @@ -1,6 +1,5 @@ package it.cwmp.client.view.authentication -import it.cwmp.client.utils.{LayoutRes, StringRes} import it.cwmp.client.view._ import it.cwmp.client.view.authentication.AuthenticationFXController._ import javafx.fxml.FXML diff --git a/client/src/main/scala/it/cwmp/client/view/game/GameFX.scala b/client/src/main/scala/it/cwmp/client/view/game/GameFX.scala index d734e055..c409ad4c 100644 --- a/client/src/main/scala/it/cwmp/client/view/game/GameFX.scala +++ b/client/src/main/scala/it/cwmp/client/view/game/GameFX.scala @@ -2,9 +2,8 @@ package it.cwmp.client.view.game import akka.actor.ActorRef import it.cwmp.client.model.game.impl.{Cell, CellWorld, Point} -import it.cwmp.client.utils.LayoutRes import it.cwmp.client.view.game.model.{CellView, TentacleView} -import it.cwmp.client.view.{FXAlertsController, FXViewController} +import it.cwmp.client.view.{FXAlertsController, FXViewController, LayoutRes} import javafx.fxml.FXML import javafx.scene.canvas.Canvas import javafx.scene.input.MouseEvent diff --git a/client/src/main/scala/it/cwmp/client/view/room/RoomFXController.scala b/client/src/main/scala/it/cwmp/client/view/room/RoomFXController.scala index e7974181..5069ec0a 100644 --- a/client/src/main/scala/it/cwmp/client/view/room/RoomFXController.scala +++ b/client/src/main/scala/it/cwmp/client/view/room/RoomFXController.scala @@ -1,6 +1,5 @@ package it.cwmp.client.view.room -import it.cwmp.client.utils.{LayoutRes, StringRes} import it.cwmp.client.view._ import it.cwmp.client.view.room.RoomFXController._ import javafx.fxml.FXML From 57c3f413b328ef32761a7978623301a146aebbb7 Mon Sep 17 00:00:00 2001 From: Enrico Siboni Date: Tue, 14 Aug 2018 15:54:26 +0200 Subject: [PATCH 03/35] Moved CellWorldObjectDrawer, ColoringStrategy, GameFX into new package it.cwmp.client.view.game.drawing --- .../main/scala/it/cwmp/client/view/game/GameViewActor.scala | 1 + .../client/view/game/{ => drawing}/CellWorldObjectDrawer.scala | 3 ++- .../cwmp/client/view/game/{ => drawing}/ColoringStrategy.scala | 2 +- .../scala/it/cwmp/client/view/game/{ => drawing}/GameFX.scala | 3 ++- .../main/scala/it/cwmp/client/view/game/model/CellView.scala | 3 ++- .../scala/it/cwmp/client/view/game/model/TentacleView.scala | 2 +- 6 files changed, 9 insertions(+), 5 deletions(-) rename client/src/main/scala/it/cwmp/client/view/game/{ => drawing}/CellWorldObjectDrawer.scala (97%) rename client/src/main/scala/it/cwmp/client/view/game/{ => drawing}/ColoringStrategy.scala (78%) rename client/src/main/scala/it/cwmp/client/view/game/{ => drawing}/GameFX.scala (98%) diff --git a/client/src/main/scala/it/cwmp/client/view/game/GameViewActor.scala b/client/src/main/scala/it/cwmp/client/view/game/GameViewActor.scala index 270ea355..c296133c 100644 --- a/client/src/main/scala/it/cwmp/client/view/game/GameViewActor.scala +++ b/client/src/main/scala/it/cwmp/client/view/game/GameViewActor.scala @@ -12,6 +12,7 @@ import it.cwmp.client.model.game.distributed.AkkaDistributedState.UpdateState import it.cwmp.client.model.game.impl._ import it.cwmp.client.utils.GeometricUtils import it.cwmp.client.view.game.GameViewActor._ +import it.cwmp.client.view.game.drawing.GameFX import it.cwmp.client.view.game.model.{CellView, TentacleView} import it.cwmp.client.view.{FXAlertsController, FXRunOnUIThread} import it.cwmp.utils.Logging diff --git a/client/src/main/scala/it/cwmp/client/view/game/CellWorldObjectDrawer.scala b/client/src/main/scala/it/cwmp/client/view/game/drawing/CellWorldObjectDrawer.scala similarity index 97% rename from client/src/main/scala/it/cwmp/client/view/game/CellWorldObjectDrawer.scala rename to client/src/main/scala/it/cwmp/client/view/game/drawing/CellWorldObjectDrawer.scala index d3dd416d..7a6e9637 100644 --- a/client/src/main/scala/it/cwmp/client/view/game/CellWorldObjectDrawer.scala +++ b/client/src/main/scala/it/cwmp/client/view/game/drawing/CellWorldObjectDrawer.scala @@ -1,7 +1,8 @@ -package it.cwmp.client.view.game +package it.cwmp.client.view.game.drawing import java.time.{Duration, Instant} +import it.cwmp.client.view.game.GameViewConstants import it.cwmp.client.view.game.model._ import javafx.scene.layout._ import javafx.scene.paint.Color diff --git a/client/src/main/scala/it/cwmp/client/view/game/ColoringStrategy.scala b/client/src/main/scala/it/cwmp/client/view/game/drawing/ColoringStrategy.scala similarity index 78% rename from client/src/main/scala/it/cwmp/client/view/game/ColoringStrategy.scala rename to client/src/main/scala/it/cwmp/client/view/game/drawing/ColoringStrategy.scala index 0b906344..579807a0 100644 --- a/client/src/main/scala/it/cwmp/client/view/game/ColoringStrategy.scala +++ b/client/src/main/scala/it/cwmp/client/view/game/drawing/ColoringStrategy.scala @@ -1,4 +1,4 @@ -package it.cwmp.client.view.game +package it.cwmp.client.view.game.drawing /** * A trait that describes how to color things diff --git a/client/src/main/scala/it/cwmp/client/view/game/GameFX.scala b/client/src/main/scala/it/cwmp/client/view/game/drawing/GameFX.scala similarity index 98% rename from client/src/main/scala/it/cwmp/client/view/game/GameFX.scala rename to client/src/main/scala/it/cwmp/client/view/game/drawing/GameFX.scala index c409ad4c..c3da9360 100644 --- a/client/src/main/scala/it/cwmp/client/view/game/GameFX.scala +++ b/client/src/main/scala/it/cwmp/client/view/game/drawing/GameFX.scala @@ -1,7 +1,8 @@ -package it.cwmp.client.view.game +package it.cwmp.client.view.game.drawing import akka.actor.ActorRef import it.cwmp.client.model.game.impl.{Cell, CellWorld, Point} +import it.cwmp.client.view.game.GameViewActor import it.cwmp.client.view.game.model.{CellView, TentacleView} import it.cwmp.client.view.{FXAlertsController, FXViewController, LayoutRes} import javafx.fxml.FXML diff --git a/client/src/main/scala/it/cwmp/client/view/game/model/CellView.scala b/client/src/main/scala/it/cwmp/client/view/game/model/CellView.scala index 5a236927..e4e292ab 100644 --- a/client/src/main/scala/it/cwmp/client/view/game/model/CellView.scala +++ b/client/src/main/scala/it/cwmp/client/view/game/model/CellView.scala @@ -6,7 +6,8 @@ import it.cwmp.client.model.game.SizingStrategy import it.cwmp.client.model.game.impl.{Cell, Point} import it.cwmp.client.utils.GeometricUtils import it.cwmp.client.view.game.GameViewConstants.{GAME_DEFAULT_FONT_COLOR, GAME_TIME_TEXT_COLOR, RGB_RANGE} -import it.cwmp.client.view.game.{ColoringStrategy, GameViewConstants} +import it.cwmp.client.view.game.GameViewConstants +import it.cwmp.client.view.game.drawing.ColoringStrategy import javafx.scene.layout._ import javafx.scene.paint.Color import javafx.scene.text.Font diff --git a/client/src/main/scala/it/cwmp/client/view/game/model/TentacleView.scala b/client/src/main/scala/it/cwmp/client/view/game/model/TentacleView.scala index b3d4c234..8c0e03e7 100644 --- a/client/src/main/scala/it/cwmp/client/view/game/model/TentacleView.scala +++ b/client/src/main/scala/it/cwmp/client/view/game/model/TentacleView.scala @@ -5,7 +5,7 @@ import java.time.{Duration, Instant} import it.cwmp.client.model.game.SizingStrategy import it.cwmp.client.model.game.impl.{Point, Tentacle} import it.cwmp.client.utils.GeometricUtils -import it.cwmp.client.view.game.ColoringStrategy +import it.cwmp.client.view.game.drawing.ColoringStrategy import javafx.scene.paint.Color import scala.language.implicitConversions From 8d954d150d3b8ba65993f98f98f813285ade2627 Mon Sep 17 00:00:00 2001 From: Enrico Siboni Date: Tue, 14 Aug 2018 15:57:26 +0200 Subject: [PATCH 04/35] Moved CellView and TentacleView out of "model" package --- .../client/controller/game/CellWorldGenerationStrategy.scala | 2 +- .../scala/it/cwmp/client/view/game/{model => }/CellView.scala | 3 +-- .../main/scala/it/cwmp/client/view/game/GameViewActor.scala | 2 -- .../it/cwmp/client/view/game/{model => }/TentacleView.scala | 2 +- .../cwmp/client/view/game/drawing/CellWorldObjectDrawer.scala | 3 +-- .../main/scala/it/cwmp/client/view/game/drawing/GameFX.scala | 3 +-- 6 files changed, 5 insertions(+), 10 deletions(-) rename client/src/main/scala/it/cwmp/client/view/game/{model => }/CellView.scala (99%) rename client/src/main/scala/it/cwmp/client/view/game/{model => }/TentacleView.scala (98%) diff --git a/client/src/main/scala/it/cwmp/client/controller/game/CellWorldGenerationStrategy.scala b/client/src/main/scala/it/cwmp/client/controller/game/CellWorldGenerationStrategy.scala index 2950c853..dfc7f760 100644 --- a/client/src/main/scala/it/cwmp/client/controller/game/CellWorldGenerationStrategy.scala +++ b/client/src/main/scala/it/cwmp/client/controller/game/CellWorldGenerationStrategy.scala @@ -5,7 +5,7 @@ import java.time.Instant import it.cwmp.client.controller.game.CellWorldGenerationStrategy.{MINIMUM_DISTANCE_BETWEEN_CELLS, MINIMUM_DISTANCE_FROM_BORDER, randomPoint} import it.cwmp.client.model.game.impl.{Cell, CellWorld, Point} import it.cwmp.client.utils.GeometricUtils -import it.cwmp.client.view.game.model.CellView +import it.cwmp.client.view.game.CellView import it.cwmp.model.User import scala.util.Random diff --git a/client/src/main/scala/it/cwmp/client/view/game/model/CellView.scala b/client/src/main/scala/it/cwmp/client/view/game/CellView.scala similarity index 99% rename from client/src/main/scala/it/cwmp/client/view/game/model/CellView.scala rename to client/src/main/scala/it/cwmp/client/view/game/CellView.scala index e4e292ab..f189b776 100644 --- a/client/src/main/scala/it/cwmp/client/view/game/model/CellView.scala +++ b/client/src/main/scala/it/cwmp/client/view/game/CellView.scala @@ -1,4 +1,4 @@ -package it.cwmp.client.view.game.model +package it.cwmp.client.view.game import com.github.tkqubo.colorHash.{ColorHash, Rgb} import it.cwmp.client.controller.game.GameConstants @@ -6,7 +6,6 @@ import it.cwmp.client.model.game.SizingStrategy import it.cwmp.client.model.game.impl.{Cell, Point} import it.cwmp.client.utils.GeometricUtils import it.cwmp.client.view.game.GameViewConstants.{GAME_DEFAULT_FONT_COLOR, GAME_TIME_TEXT_COLOR, RGB_RANGE} -import it.cwmp.client.view.game.GameViewConstants import it.cwmp.client.view.game.drawing.ColoringStrategy import javafx.scene.layout._ import javafx.scene.paint.Color diff --git a/client/src/main/scala/it/cwmp/client/view/game/GameViewActor.scala b/client/src/main/scala/it/cwmp/client/view/game/GameViewActor.scala index c296133c..1cf6a173 100644 --- a/client/src/main/scala/it/cwmp/client/view/game/GameViewActor.scala +++ b/client/src/main/scala/it/cwmp/client/view/game/GameViewActor.scala @@ -3,7 +3,6 @@ package it.cwmp.client.view.game import java.util.concurrent.ThreadLocalRandom import akka.actor.{Actor, ActorRef, Cancellable} -import it.cwmp.client.controller.ViewVisibilityMessages.Hide import it.cwmp.client.controller.game.GameConstants.{MAX_TIME_BETWEEN_CLIENT_SYNCHRONIZATION, MIN_TIME_BETWEEN_CLIENT_SYNCHRONIZATION} import it.cwmp.client.controller.game.GameEngine import it.cwmp.client.controller.messages.Initialize @@ -13,7 +12,6 @@ import it.cwmp.client.model.game.impl._ import it.cwmp.client.utils.GeometricUtils import it.cwmp.client.view.game.GameViewActor._ import it.cwmp.client.view.game.drawing.GameFX -import it.cwmp.client.view.game.model.{CellView, TentacleView} import it.cwmp.client.view.{FXAlertsController, FXRunOnUIThread} import it.cwmp.utils.Logging import it.cwmp.utils.Utils.stringToOption diff --git a/client/src/main/scala/it/cwmp/client/view/game/model/TentacleView.scala b/client/src/main/scala/it/cwmp/client/view/game/TentacleView.scala similarity index 98% rename from client/src/main/scala/it/cwmp/client/view/game/model/TentacleView.scala rename to client/src/main/scala/it/cwmp/client/view/game/TentacleView.scala index 8c0e03e7..d17bcb66 100644 --- a/client/src/main/scala/it/cwmp/client/view/game/model/TentacleView.scala +++ b/client/src/main/scala/it/cwmp/client/view/game/TentacleView.scala @@ -1,4 +1,4 @@ -package it.cwmp.client.view.game.model +package it.cwmp.client.view.game import java.time.{Duration, Instant} diff --git a/client/src/main/scala/it/cwmp/client/view/game/drawing/CellWorldObjectDrawer.scala b/client/src/main/scala/it/cwmp/client/view/game/drawing/CellWorldObjectDrawer.scala index 7a6e9637..ae503049 100644 --- a/client/src/main/scala/it/cwmp/client/view/game/drawing/CellWorldObjectDrawer.scala +++ b/client/src/main/scala/it/cwmp/client/view/game/drawing/CellWorldObjectDrawer.scala @@ -2,8 +2,7 @@ package it.cwmp.client.view.game.drawing import java.time.{Duration, Instant} -import it.cwmp.client.view.game.GameViewConstants -import it.cwmp.client.view.game.model._ +import it.cwmp.client.view.game.{CellView, GameViewConstants, TentacleView} import javafx.scene.layout._ import javafx.scene.paint.Color import javafx.scene.shape.{Line, SVGPath} diff --git a/client/src/main/scala/it/cwmp/client/view/game/drawing/GameFX.scala b/client/src/main/scala/it/cwmp/client/view/game/drawing/GameFX.scala index c3da9360..8d24b541 100644 --- a/client/src/main/scala/it/cwmp/client/view/game/drawing/GameFX.scala +++ b/client/src/main/scala/it/cwmp/client/view/game/drawing/GameFX.scala @@ -2,8 +2,7 @@ package it.cwmp.client.view.game.drawing import akka.actor.ActorRef import it.cwmp.client.model.game.impl.{Cell, CellWorld, Point} -import it.cwmp.client.view.game.GameViewActor -import it.cwmp.client.view.game.model.{CellView, TentacleView} +import it.cwmp.client.view.game.{CellView, GameViewActor, TentacleView} import it.cwmp.client.view.{FXAlertsController, FXViewController, LayoutRes} import javafx.fxml.FXML import javafx.scene.canvas.Canvas From dba3225df461bd8b579d29f38dd79c853155a5f5 Mon Sep 17 00:00:00 2001 From: Enrico Siboni Date: Tue, 14 Aug 2018 16:01:46 +0200 Subject: [PATCH 05/35] Moved GameViewActor to "controller" package --- client/src/main/scala/it/cwmp/client/GameMain.scala | 4 ++-- .../it/cwmp/client/controller/ClientControllerActor.scala | 1 - .../client/{view/game => controller}/GameViewActor.scala | 6 +++--- .../main/scala/it/cwmp/client/controller/PlayerActor.scala | 5 ++--- .../scala/it/cwmp/client/view/game/drawing/GameFX.scala | 3 ++- 5 files changed, 9 insertions(+), 10 deletions(-) rename client/src/main/scala/it/cwmp/client/{view/game => controller}/GameViewActor.scala (98%) diff --git a/client/src/main/scala/it/cwmp/client/GameMain.scala b/client/src/main/scala/it/cwmp/client/GameMain.scala index e4b7cfd4..93d3e478 100644 --- a/client/src/main/scala/it/cwmp/client/GameMain.scala +++ b/client/src/main/scala/it/cwmp/client/GameMain.scala @@ -4,10 +4,10 @@ import java.time.{Duration, Instant} import akka.actor.{ActorSystem, Props} import com.typesafe.config.ConfigFactory +import it.cwmp.client.controller.GameViewActor +import it.cwmp.client.controller.GameViewActor.{NewWorld, ShowGUIWithName} import it.cwmp.client.controller.messages.Initialize import it.cwmp.client.model.game.impl.{Cell, CellWorld, Point, Tentacle} -import it.cwmp.client.view.game.GameViewActor -import it.cwmp.client.view.game.GameViewActor._ import it.cwmp.model.User /** diff --git a/client/src/main/scala/it/cwmp/client/controller/ClientControllerActor.scala b/client/src/main/scala/it/cwmp/client/controller/ClientControllerActor.scala index b7e2be62..156b77fa 100644 --- a/client/src/main/scala/it/cwmp/client/controller/ClientControllerActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/ClientControllerActor.scala @@ -12,7 +12,6 @@ import it.cwmp.client.controller.messages.Initialize import it.cwmp.client.controller.messages.RoomsRequests._ import it.cwmp.client.controller.messages.RoomsResponses._ import it.cwmp.client.view.authentication.AuthenticationViewActor -import it.cwmp.client.view.game.GameViewActor import it.cwmp.client.view.room.RoomViewActor import it.cwmp.client.view.room.RoomViewActor.{FoundOpponents, ShowToken, WaitingForOthers} import it.cwmp.model.{Address, Participant} diff --git a/client/src/main/scala/it/cwmp/client/view/game/GameViewActor.scala b/client/src/main/scala/it/cwmp/client/controller/GameViewActor.scala similarity index 98% rename from client/src/main/scala/it/cwmp/client/view/game/GameViewActor.scala rename to client/src/main/scala/it/cwmp/client/controller/GameViewActor.scala index 1cf6a173..5caebbed 100644 --- a/client/src/main/scala/it/cwmp/client/view/game/GameViewActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/GameViewActor.scala @@ -1,17 +1,17 @@ -package it.cwmp.client.view.game +package it.cwmp.client.controller import java.util.concurrent.ThreadLocalRandom import akka.actor.{Actor, ActorRef, Cancellable} +import it.cwmp.client.controller.GameViewActor._ import it.cwmp.client.controller.game.GameConstants.{MAX_TIME_BETWEEN_CLIENT_SYNCHRONIZATION, MIN_TIME_BETWEEN_CLIENT_SYNCHRONIZATION} import it.cwmp.client.controller.game.GameEngine import it.cwmp.client.controller.messages.Initialize -import it.cwmp.client.controller.{ActorAlertManagement, AlertMessages} import it.cwmp.client.model.game.distributed.AkkaDistributedState.UpdateState import it.cwmp.client.model.game.impl._ import it.cwmp.client.utils.GeometricUtils -import it.cwmp.client.view.game.GameViewActor._ import it.cwmp.client.view.game.drawing.GameFX +import it.cwmp.client.view.game.{CellView, TentacleView} import it.cwmp.client.view.{FXAlertsController, FXRunOnUIThread} import it.cwmp.utils.Logging import it.cwmp.utils.Utils.stringToOption diff --git a/client/src/main/scala/it/cwmp/client/controller/PlayerActor.scala b/client/src/main/scala/it/cwmp/client/controller/PlayerActor.scala index 35b59c7d..53c92b27 100644 --- a/client/src/main/scala/it/cwmp/client/controller/PlayerActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/PlayerActor.scala @@ -4,14 +4,13 @@ import akka.actor.{Actor, ActorRef, AddressFromURIString, Props, Stash} import akka.cluster.Cluster import akka.cluster.ClusterEvent._ import akka.cluster.ddata.DistributedData -import it.cwmp.client.controller.PlayerActor.{GameEnded, PrepareForGame, RetrieveAddress, RetrieveAddressResponse} +import it.cwmp.client.controller.GameViewActor.{NewWorld, ShowGUIWithName} +import it.cwmp.client.controller.PlayerActor.{PrepareForGame, RetrieveAddress, RetrieveAddressResponse} import it.cwmp.client.controller.game.GenerationStrategy import it.cwmp.client.controller.messages.{Initialize, Request, Response} import it.cwmp.client.model.game.distributed.AkkaDistributedState import it.cwmp.client.model.game.distributed.impl.MergingStateCellWorld import it.cwmp.client.model.game.impl.CellWorld -import it.cwmp.client.view.game.GameViewActor -import it.cwmp.client.view.game.GameViewActor._ import it.cwmp.model.Participant import it.cwmp.utils.Logging diff --git a/client/src/main/scala/it/cwmp/client/view/game/drawing/GameFX.scala b/client/src/main/scala/it/cwmp/client/view/game/drawing/GameFX.scala index 8d24b541..2de7c9d3 100644 --- a/client/src/main/scala/it/cwmp/client/view/game/drawing/GameFX.scala +++ b/client/src/main/scala/it/cwmp/client/view/game/drawing/GameFX.scala @@ -1,8 +1,9 @@ package it.cwmp.client.view.game.drawing import akka.actor.ActorRef +import it.cwmp.client.controller.GameViewActor import it.cwmp.client.model.game.impl.{Cell, CellWorld, Point} -import it.cwmp.client.view.game.{CellView, GameViewActor, TentacleView} +import it.cwmp.client.view.game.{CellView, TentacleView} import it.cwmp.client.view.{FXAlertsController, FXViewController, LayoutRes} import javafx.fxml.FXML import javafx.scene.canvas.Canvas From 84110551053e942d0a68ee1d91a06fca09a47000 Mon Sep 17 00:00:00 2001 From: Enrico Siboni Date: Tue, 14 Aug 2018 16:03:41 +0200 Subject: [PATCH 06/35] Removed GameMain debug class --- .../main/scala/it/cwmp/client/GameMain.scala | 45 ------------------- 1 file changed, 45 deletions(-) delete mode 100644 client/src/main/scala/it/cwmp/client/GameMain.scala diff --git a/client/src/main/scala/it/cwmp/client/GameMain.scala b/client/src/main/scala/it/cwmp/client/GameMain.scala deleted file mode 100644 index 93d3e478..00000000 --- a/client/src/main/scala/it/cwmp/client/GameMain.scala +++ /dev/null @@ -1,45 +0,0 @@ -package it.cwmp.client - -import java.time.{Duration, Instant} - -import akka.actor.{ActorSystem, Props} -import com.typesafe.config.ConfigFactory -import it.cwmp.client.controller.GameViewActor -import it.cwmp.client.controller.GameViewActor.{NewWorld, ShowGUIWithName} -import it.cwmp.client.controller.messages.Initialize -import it.cwmp.client.model.game.impl.{Cell, CellWorld, Point, Tentacle} -import it.cwmp.model.User - -/** - * An object to start a fake game world to test gameView - */ -object GameMain extends App { - val APP_NAME = "ClientApp" - - private val config = ConfigFactory.parseString("akka.remote.netty.tcp.port=0").withFallback(ConfigFactory.load()) - - val system = ActorSystem(APP_NAME, config) - - val gameActor = system.actorOf(Props[GameViewActor], GameViewActor.getClass.getName) - - gameActor ! Initialize - gameActor ! ShowGUIWithName("Candle") - gameActor ! NewWorld(debugWorld) - - def debugWorld: CellWorld = { - // scalastyle:off magic.number - val cells = - Cell(User("Winner"), Point(20, 20), 20) :: - Cell(User("Mantis"), Point(90, 400), 40) :: - Cell(User("Candle"), Point(200, 150), 200) :: - Cell(User("Enrico"), Point(400, 500), 150) :: - Nil - // scalastyle:on magic.number - - CellWorld(Instant.now().plus(Duration.ofSeconds(1)), cells, - Tentacle(cells(2), cells(1), Instant.now()) :: - Tentacle(cells(1), cells(2), Instant.now()) :: - Tentacle(cells(3), cells(1), Instant.now()) :: - Nil) - } -} From aca588d492cfbc35cc42cd4e49fa1a415b11571e Mon Sep 17 00:00:00 2001 From: Enrico Siboni Date: Tue, 14 Aug 2018 16:05:01 +0200 Subject: [PATCH 07/35] Moved GameFX out of "drawing" package --- .../main/scala/it/cwmp/client/controller/GameViewActor.scala | 3 +-- .../scala/it/cwmp/client/view/game/{drawing => }/GameFX.scala | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) rename client/src/main/scala/it/cwmp/client/view/game/{drawing => }/GameFX.scala (97%) diff --git a/client/src/main/scala/it/cwmp/client/controller/GameViewActor.scala b/client/src/main/scala/it/cwmp/client/controller/GameViewActor.scala index 5caebbed..e07b6252 100644 --- a/client/src/main/scala/it/cwmp/client/controller/GameViewActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/GameViewActor.scala @@ -10,8 +10,7 @@ import it.cwmp.client.controller.messages.Initialize import it.cwmp.client.model.game.distributed.AkkaDistributedState.UpdateState import it.cwmp.client.model.game.impl._ import it.cwmp.client.utils.GeometricUtils -import it.cwmp.client.view.game.drawing.GameFX -import it.cwmp.client.view.game.{CellView, TentacleView} +import it.cwmp.client.view.game.{CellView, GameFX, TentacleView} import it.cwmp.client.view.{FXAlertsController, FXRunOnUIThread} import it.cwmp.utils.Logging import it.cwmp.utils.Utils.stringToOption diff --git a/client/src/main/scala/it/cwmp/client/view/game/drawing/GameFX.scala b/client/src/main/scala/it/cwmp/client/view/game/GameFX.scala similarity index 97% rename from client/src/main/scala/it/cwmp/client/view/game/drawing/GameFX.scala rename to client/src/main/scala/it/cwmp/client/view/game/GameFX.scala index 2de7c9d3..158e8883 100644 --- a/client/src/main/scala/it/cwmp/client/view/game/drawing/GameFX.scala +++ b/client/src/main/scala/it/cwmp/client/view/game/GameFX.scala @@ -1,9 +1,9 @@ -package it.cwmp.client.view.game.drawing +package it.cwmp.client.view.game import akka.actor.ActorRef import it.cwmp.client.controller.GameViewActor import it.cwmp.client.model.game.impl.{Cell, CellWorld, Point} -import it.cwmp.client.view.game.{CellView, TentacleView} +import it.cwmp.client.view.game.drawing.CellWorldObjectDrawer import it.cwmp.client.view.{FXAlertsController, FXViewController, LayoutRes} import javafx.fxml.FXML import javafx.scene.canvas.Canvas From e02b4d78af7b367ba90ea600b18ea8ca7134185a Mon Sep 17 00:00:00 2001 From: Enrico Siboni Date: Tue, 14 Aug 2018 16:08:21 +0200 Subject: [PATCH 08/35] Moved generation classes to "generation" package --- .../it/cwmp/client/controller/ClientControllerActor.scala | 3 ++- .../main/scala/it/cwmp/client/controller/PlayerActor.scala | 2 +- .../game/{ => generation}/CellWorldGenerationStrategy.scala | 5 +++-- .../game/{ => generation}/GenerationStrategy.scala | 2 +- .../controller/game/CellWorldGenerationStrategyTest.scala | 1 + 5 files changed, 8 insertions(+), 5 deletions(-) rename client/src/main/scala/it/cwmp/client/controller/game/{ => generation}/CellWorldGenerationStrategy.scala (96%) rename client/src/main/scala/it/cwmp/client/controller/game/{ => generation}/GenerationStrategy.scala (85%) diff --git a/client/src/main/scala/it/cwmp/client/controller/ClientControllerActor.scala b/client/src/main/scala/it/cwmp/client/controller/ClientControllerActor.scala index 156b77fa..92c4ccee 100644 --- a/client/src/main/scala/it/cwmp/client/controller/ClientControllerActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/ClientControllerActor.scala @@ -5,7 +5,8 @@ import it.cwmp.client.controller.AlertMessages.{Error, Info} import it.cwmp.client.controller.ClientControllerActor._ import it.cwmp.client.controller.PlayerActor.{PrepareForGame, RetrieveAddress, RetrieveAddressResponse} import it.cwmp.client.controller.ViewVisibilityMessages.{Hide, Show} -import it.cwmp.client.controller.game.{CellWorldGenerationStrategy, GameConstants} +import it.cwmp.client.controller.game.GameConstants +import it.cwmp.client.controller.game.generation.CellWorldGenerationStrategy import it.cwmp.client.controller.messages.AuthenticationRequests.{GUILogOut, LogIn, SignUp} import it.cwmp.client.controller.messages.AuthenticationResponses.{LogInFailure, LogInSuccess, SignUpFailure, SignUpSuccess} import it.cwmp.client.controller.messages.Initialize diff --git a/client/src/main/scala/it/cwmp/client/controller/PlayerActor.scala b/client/src/main/scala/it/cwmp/client/controller/PlayerActor.scala index 53c92b27..3b2d89b4 100644 --- a/client/src/main/scala/it/cwmp/client/controller/PlayerActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/PlayerActor.scala @@ -6,7 +6,7 @@ import akka.cluster.ClusterEvent._ import akka.cluster.ddata.DistributedData import it.cwmp.client.controller.GameViewActor.{NewWorld, ShowGUIWithName} import it.cwmp.client.controller.PlayerActor.{PrepareForGame, RetrieveAddress, RetrieveAddressResponse} -import it.cwmp.client.controller.game.GenerationStrategy +import it.cwmp.client.controller.game.generation.GenerationStrategy import it.cwmp.client.controller.messages.{Initialize, Request, Response} import it.cwmp.client.model.game.distributed.AkkaDistributedState import it.cwmp.client.model.game.distributed.impl.MergingStateCellWorld diff --git a/client/src/main/scala/it/cwmp/client/controller/game/CellWorldGenerationStrategy.scala b/client/src/main/scala/it/cwmp/client/controller/game/generation/CellWorldGenerationStrategy.scala similarity index 96% rename from client/src/main/scala/it/cwmp/client/controller/game/CellWorldGenerationStrategy.scala rename to client/src/main/scala/it/cwmp/client/controller/game/generation/CellWorldGenerationStrategy.scala index dfc7f760..1c8aaacc 100644 --- a/client/src/main/scala/it/cwmp/client/controller/game/CellWorldGenerationStrategy.scala +++ b/client/src/main/scala/it/cwmp/client/controller/game/generation/CellWorldGenerationStrategy.scala @@ -1,8 +1,9 @@ -package it.cwmp.client.controller.game +package it.cwmp.client.controller.game.generation import java.time.Instant -import it.cwmp.client.controller.game.CellWorldGenerationStrategy.{MINIMUM_DISTANCE_BETWEEN_CELLS, MINIMUM_DISTANCE_FROM_BORDER, randomPoint} +import it.cwmp.client.controller.game.GameConstants +import it.cwmp.client.controller.game.generation.CellWorldGenerationStrategy._ import it.cwmp.client.model.game.impl.{Cell, CellWorld, Point} import it.cwmp.client.utils.GeometricUtils import it.cwmp.client.view.game.CellView diff --git a/client/src/main/scala/it/cwmp/client/controller/game/GenerationStrategy.scala b/client/src/main/scala/it/cwmp/client/controller/game/generation/GenerationStrategy.scala similarity index 85% rename from client/src/main/scala/it/cwmp/client/controller/game/GenerationStrategy.scala rename to client/src/main/scala/it/cwmp/client/controller/game/generation/GenerationStrategy.scala index 94a70f45..58a5d75a 100644 --- a/client/src/main/scala/it/cwmp/client/controller/game/GenerationStrategy.scala +++ b/client/src/main/scala/it/cwmp/client/controller/game/generation/GenerationStrategy.scala @@ -1,4 +1,4 @@ -package it.cwmp.client.controller.game +package it.cwmp.client.controller.game.generation /** * A trait that models a generation strategy that given an input returns a randomly generated output diff --git a/client/src/test/scala/it/cwmp/client/controller/game/CellWorldGenerationStrategyTest.scala b/client/src/test/scala/it/cwmp/client/controller/game/CellWorldGenerationStrategyTest.scala index 00458eeb..15d74121 100644 --- a/client/src/test/scala/it/cwmp/client/controller/game/CellWorldGenerationStrategyTest.scala +++ b/client/src/test/scala/it/cwmp/client/controller/game/CellWorldGenerationStrategyTest.scala @@ -1,5 +1,6 @@ package it.cwmp.client.controller.game +import it.cwmp.client.controller.game.generation.CellWorldGenerationStrategy import it.cwmp.client.model.game.impl.Cell import it.cwmp.model.User import org.scalatest.FunSpec From 1a3f581c4dda815562c4a0d0d5d346a6b9ab725b Mon Sep 17 00:00:00 2001 From: Enrico Siboni Date: Tue, 14 Aug 2018 16:12:24 +0200 Subject: [PATCH 09/35] Moved actor classes into "actors" package --- client/src/main/scala/it/cwmp/client/ClientMain.scala | 4 ++-- .../controller/{ => actors}/ApiClientActor.scala | 4 ++-- .../{ => actors}/ClientControllerActor.scala | 11 ++++++----- .../controller/{ => actors}/GameViewActor.scala | 5 +++-- .../client/controller/{ => actors}/PlayerActor.scala | 6 +++--- .../{ => actors/common}/ActorAlertManagement.scala | 4 ++-- .../common}/ActorViewVisibilityManagement.scala | 4 ++-- .../it/cwmp/client/view/FXServiceViewActor.scala | 2 +- .../main/scala/it/cwmp/client/view/game/GameFX.scala | 2 +- .../cwmp/client/controller/ApiClientActorTest.scala | 1 + 10 files changed, 23 insertions(+), 20 deletions(-) rename client/src/main/scala/it/cwmp/client/controller/{ => actors}/ApiClientActor.scala (96%) rename client/src/main/scala/it/cwmp/client/controller/{ => actors}/ClientControllerActor.scala (96%) rename client/src/main/scala/it/cwmp/client/controller/{ => actors}/GameViewActor.scala (98%) rename client/src/main/scala/it/cwmp/client/controller/{ => actors}/PlayerActor.scala (95%) rename client/src/main/scala/it/cwmp/client/controller/{ => actors/common}/ActorAlertManagement.scala (93%) rename client/src/main/scala/it/cwmp/client/controller/{ => actors/common}/ActorViewVisibilityManagement.scala (89%) diff --git a/client/src/main/scala/it/cwmp/client/ClientMain.scala b/client/src/main/scala/it/cwmp/client/ClientMain.scala index 4f72f6f5..f633463c 100644 --- a/client/src/main/scala/it/cwmp/client/ClientMain.scala +++ b/client/src/main/scala/it/cwmp/client/ClientMain.scala @@ -2,9 +2,9 @@ package it.cwmp.client import akka.actor.{ActorSystem, Props} import com.typesafe.config.ConfigFactory -import it.cwmp.client.controller.{ApiClientActor, ClientControllerActor} -import it.cwmp.services.{VertxInstance, discovery} +import it.cwmp.client.controller.actors.{ApiClientActor, ClientControllerActor} import it.cwmp.services.wrapper.{AuthenticationApiWrapper, DiscoveryApiWrapper, RoomsApiWrapper} +import it.cwmp.services.{VertxInstance, discovery} import it.cwmp.utils.{HostAndPortArguments, Logging} import it.cwmp.view.OneAddressInput diff --git a/client/src/main/scala/it/cwmp/client/controller/ApiClientActor.scala b/client/src/main/scala/it/cwmp/client/controller/actors/ApiClientActor.scala similarity index 96% rename from client/src/main/scala/it/cwmp/client/controller/ApiClientActor.scala rename to client/src/main/scala/it/cwmp/client/controller/actors/ApiClientActor.scala index a1118806..388b2048 100644 --- a/client/src/main/scala/it/cwmp/client/controller/ApiClientActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/ApiClientActor.scala @@ -1,11 +1,11 @@ -package it.cwmp.client.controller +package it.cwmp.client.controller.actors import akka.actor.Actor import it.cwmp.client.controller.messages.AuthenticationRequests.{LogIn, SignUp} import it.cwmp.client.controller.messages.AuthenticationResponses.{LogInFailure, LogInSuccess, SignUpFailure, SignUpSuccess} import it.cwmp.client.controller.messages.RoomsRequests._ import it.cwmp.client.controller.messages.RoomsResponses._ -import it.cwmp.services.wrapper.{AuthenticationApiWrapper, DiscoveryApiWrapper, RoomsApiWrapper} +import it.cwmp.services.wrapper.{AuthenticationApiWrapper, RoomsApiWrapper} import it.cwmp.utils.Utils.stringToOption import scala.concurrent.ExecutionContext.Implicits.global diff --git a/client/src/main/scala/it/cwmp/client/controller/ClientControllerActor.scala b/client/src/main/scala/it/cwmp/client/controller/actors/ClientControllerActor.scala similarity index 96% rename from client/src/main/scala/it/cwmp/client/controller/ClientControllerActor.scala rename to client/src/main/scala/it/cwmp/client/controller/actors/ClientControllerActor.scala index 92c4ccee..5609ec94 100644 --- a/client/src/main/scala/it/cwmp/client/controller/ClientControllerActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/ClientControllerActor.scala @@ -1,10 +1,11 @@ -package it.cwmp.client.controller +package it.cwmp.client.controller.actors import akka.actor.{Actor, ActorRef, Props} -import it.cwmp.client.controller.AlertMessages.{Error, Info} -import it.cwmp.client.controller.ClientControllerActor._ -import it.cwmp.client.controller.PlayerActor.{PrepareForGame, RetrieveAddress, RetrieveAddressResponse} -import it.cwmp.client.controller.ViewVisibilityMessages.{Hide, Show} +import it.cwmp.client.controller.ParticipantListReceiver +import it.cwmp.client.controller.actors.ClientControllerActor._ +import it.cwmp.client.controller.actors.PlayerActor.{PrepareForGame, RetrieveAddress, RetrieveAddressResponse} +import it.cwmp.client.controller.actors.common.AlertMessages.{Error, Info} +import it.cwmp.client.controller.actors.common.ViewVisibilityMessages.{Hide, Show} import it.cwmp.client.controller.game.GameConstants import it.cwmp.client.controller.game.generation.CellWorldGenerationStrategy import it.cwmp.client.controller.messages.AuthenticationRequests.{GUILogOut, LogIn, SignUp} diff --git a/client/src/main/scala/it/cwmp/client/controller/GameViewActor.scala b/client/src/main/scala/it/cwmp/client/controller/actors/GameViewActor.scala similarity index 98% rename from client/src/main/scala/it/cwmp/client/controller/GameViewActor.scala rename to client/src/main/scala/it/cwmp/client/controller/actors/GameViewActor.scala index e07b6252..6bffb479 100644 --- a/client/src/main/scala/it/cwmp/client/controller/GameViewActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/GameViewActor.scala @@ -1,9 +1,10 @@ -package it.cwmp.client.controller +package it.cwmp.client.controller.actors import java.util.concurrent.ThreadLocalRandom import akka.actor.{Actor, ActorRef, Cancellable} -import it.cwmp.client.controller.GameViewActor._ +import it.cwmp.client.controller.actors.GameViewActor._ +import it.cwmp.client.controller.actors.common.{ActorAlertManagement, AlertMessages} import it.cwmp.client.controller.game.GameConstants.{MAX_TIME_BETWEEN_CLIENT_SYNCHRONIZATION, MIN_TIME_BETWEEN_CLIENT_SYNCHRONIZATION} import it.cwmp.client.controller.game.GameEngine import it.cwmp.client.controller.messages.Initialize diff --git a/client/src/main/scala/it/cwmp/client/controller/PlayerActor.scala b/client/src/main/scala/it/cwmp/client/controller/actors/PlayerActor.scala similarity index 95% rename from client/src/main/scala/it/cwmp/client/controller/PlayerActor.scala rename to client/src/main/scala/it/cwmp/client/controller/actors/PlayerActor.scala index 3b2d89b4..3cf6d310 100644 --- a/client/src/main/scala/it/cwmp/client/controller/PlayerActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/PlayerActor.scala @@ -1,11 +1,11 @@ -package it.cwmp.client.controller +package it.cwmp.client.controller.actors import akka.actor.{Actor, ActorRef, AddressFromURIString, Props, Stash} import akka.cluster.Cluster import akka.cluster.ClusterEvent._ import akka.cluster.ddata.DistributedData -import it.cwmp.client.controller.GameViewActor.{NewWorld, ShowGUIWithName} -import it.cwmp.client.controller.PlayerActor.{PrepareForGame, RetrieveAddress, RetrieveAddressResponse} +import it.cwmp.client.controller.actors.GameViewActor.{NewWorld, ShowGUIWithName} +import it.cwmp.client.controller.actors.PlayerActor.{PrepareForGame, RetrieveAddress, RetrieveAddressResponse} import it.cwmp.client.controller.game.generation.GenerationStrategy import it.cwmp.client.controller.messages.{Initialize, Request, Response} import it.cwmp.client.model.game.distributed.AkkaDistributedState diff --git a/client/src/main/scala/it/cwmp/client/controller/ActorAlertManagement.scala b/client/src/main/scala/it/cwmp/client/controller/actors/common/ActorAlertManagement.scala similarity index 93% rename from client/src/main/scala/it/cwmp/client/controller/ActorAlertManagement.scala rename to client/src/main/scala/it/cwmp/client/controller/actors/common/ActorAlertManagement.scala index cdb63afa..4dd33e69 100644 --- a/client/src/main/scala/it/cwmp/client/controller/ActorAlertManagement.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/common/ActorAlertManagement.scala @@ -1,7 +1,7 @@ -package it.cwmp.client.controller +package it.cwmp.client.controller.actors.common import akka.actor.Actor.Receive -import it.cwmp.client.controller.AlertMessages._ +import it.cwmp.client.controller.actors.common.AlertMessages._ import it.cwmp.client.view.FXAlertsController /** diff --git a/client/src/main/scala/it/cwmp/client/controller/ActorViewVisibilityManagement.scala b/client/src/main/scala/it/cwmp/client/controller/actors/common/ActorViewVisibilityManagement.scala similarity index 89% rename from client/src/main/scala/it/cwmp/client/controller/ActorViewVisibilityManagement.scala rename to client/src/main/scala/it/cwmp/client/controller/actors/common/ActorViewVisibilityManagement.scala index a7e6de3b..c531a773 100644 --- a/client/src/main/scala/it/cwmp/client/controller/ActorViewVisibilityManagement.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/common/ActorViewVisibilityManagement.scala @@ -1,7 +1,7 @@ -package it.cwmp.client.controller +package it.cwmp.client.controller.actors.common import akka.actor.Actor.Receive -import it.cwmp.client.controller.ViewVisibilityMessages.{Hide, Show} +import it.cwmp.client.controller.actors.common.ViewVisibilityMessages.{Hide, Show} import it.cwmp.client.view.{FXRunOnUIThread, FXViewController} /** diff --git a/client/src/main/scala/it/cwmp/client/view/FXServiceViewActor.scala b/client/src/main/scala/it/cwmp/client/view/FXServiceViewActor.scala index b3efe0d2..3e2ccb01 100644 --- a/client/src/main/scala/it/cwmp/client/view/FXServiceViewActor.scala +++ b/client/src/main/scala/it/cwmp/client/view/FXServiceViewActor.scala @@ -1,8 +1,8 @@ package it.cwmp.client.view import akka.actor.{Actor, ActorRef} +import it.cwmp.client.controller.actors.common.{ActorAlertManagement, ActorViewVisibilityManagement} import it.cwmp.client.controller.messages.Initialize -import it.cwmp.client.controller.{ActorAlertManagement, ActorViewVisibilityManagement} /** * A base class representing a Service View actor with JavaFX underlying diff --git a/client/src/main/scala/it/cwmp/client/view/game/GameFX.scala b/client/src/main/scala/it/cwmp/client/view/game/GameFX.scala index 158e8883..fc7610f5 100644 --- a/client/src/main/scala/it/cwmp/client/view/game/GameFX.scala +++ b/client/src/main/scala/it/cwmp/client/view/game/GameFX.scala @@ -1,7 +1,7 @@ package it.cwmp.client.view.game import akka.actor.ActorRef -import it.cwmp.client.controller.GameViewActor +import it.cwmp.client.controller.actors.GameViewActor import it.cwmp.client.model.game.impl.{Cell, CellWorld, Point} import it.cwmp.client.view.game.drawing.CellWorldObjectDrawer import it.cwmp.client.view.{FXAlertsController, FXViewController, LayoutRes} diff --git a/client/src/test/scala/it/cwmp/client/controller/ApiClientActorTest.scala b/client/src/test/scala/it/cwmp/client/controller/ApiClientActorTest.scala index 8ab18951..cd65f8b7 100644 --- a/client/src/test/scala/it/cwmp/client/controller/ApiClientActorTest.scala +++ b/client/src/test/scala/it/cwmp/client/controller/ApiClientActorTest.scala @@ -2,6 +2,7 @@ package it.cwmp.client.controller import akka.actor.{ActorRef, ActorSystem, Props} import akka.testkit.{ImplicitSender, TestKit} +import it.cwmp.client.controller.actors.ApiClientActor import it.cwmp.client.controller.messages.{AuthenticationRequests, AuthenticationResponses, RoomsRequests, RoomsResponses} import it.cwmp.model.Address import it.cwmp.services.wrapper.{FakeAuthenticationApiWrapper, FakeRoomsApiWrapper} From 042f50fa81f9e004a31b3cb29c3048fa3c861428 Mon Sep 17 00:00:00 2001 From: Enrico Siboni Date: Tue, 14 Aug 2018 16:19:19 +0200 Subject: [PATCH 10/35] Renamed GameFX to GameFXController --- .../it/cwmp/client/controller/actors/GameViewActor.scala | 6 +++--- .../view/game/{GameFX.scala => GameFXController.scala} | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) rename client/src/main/scala/it/cwmp/client/view/game/{GameFX.scala => GameFXController.scala} (97%) diff --git a/client/src/main/scala/it/cwmp/client/controller/actors/GameViewActor.scala b/client/src/main/scala/it/cwmp/client/controller/actors/GameViewActor.scala index 6bffb479..3067a51a 100644 --- a/client/src/main/scala/it/cwmp/client/controller/actors/GameViewActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/GameViewActor.scala @@ -11,7 +11,7 @@ import it.cwmp.client.controller.messages.Initialize import it.cwmp.client.model.game.distributed.AkkaDistributedState.UpdateState import it.cwmp.client.model.game.impl._ import it.cwmp.client.utils.GeometricUtils -import it.cwmp.client.view.game.{CellView, GameFX, TentacleView} +import it.cwmp.client.view.game.{CellView, GameFXController, TentacleView} import it.cwmp.client.view.{FXAlertsController, FXRunOnUIThread} import it.cwmp.utils.Logging import it.cwmp.utils.Utils.stringToOption @@ -32,7 +32,7 @@ case class GameViewActor() extends Actor with FXRunOnUIThread with ActorAlertMan private val WAIT_TIME_BEFORE_AUTOMATIC_SYNCHRONIZATION = ThreadLocalRandom.current() .nextInt(MIN_TIME_BETWEEN_CLIENT_SYNCHRONIZATION, MAX_TIME_BETWEEN_CLIENT_SYNCHRONIZATION).millis - private var gameFX: GameFX = _ + private var gameFX: GameFXController = _ private var parentActor: ActorRef = _ private var updatingSchedule: Cancellable = _ private var synchronizationSchedule: Cancellable = _ @@ -58,7 +58,7 @@ case class GameViewActor() extends Actor with FXRunOnUIThread with ActorAlertMan playerName = name runOnUIThread(() => { - gameFX = GameFX(self, VIEW_TITLE_PREFIX + name, VIEW_SIZE, name) + gameFX = GameFXController(self, VIEW_TITLE_PREFIX + name, VIEW_SIZE, name) gameFX.showGUI() }) diff --git a/client/src/main/scala/it/cwmp/client/view/game/GameFX.scala b/client/src/main/scala/it/cwmp/client/view/game/GameFXController.scala similarity index 97% rename from client/src/main/scala/it/cwmp/client/view/game/GameFX.scala rename to client/src/main/scala/it/cwmp/client/view/game/GameFXController.scala index fc7610f5..f1c3f33d 100644 --- a/client/src/main/scala/it/cwmp/client/view/game/GameFX.scala +++ b/client/src/main/scala/it/cwmp/client/view/game/GameFXController.scala @@ -22,7 +22,7 @@ import scala.language.implicitConversions * @author Davide Borficchia * @author contributor Enrico Siboni */ -case class GameFX(viewManagerActor: ActorRef, override val title: String, viewSize: Int, playerName: String) +case class GameFXController(viewManagerActor: ActorRef, override val title: String, viewSize: Int, playerName: String) extends CellWorldObjectDrawer with FXViewController with FXAlertsController { @FXML private var root: Group = _ From c89fd59edf9818a70a8014db09236ed3acaa4251 Mon Sep 17 00:00:00 2001 From: Enrico Siboni Date: Tue, 14 Aug 2018 16:21:48 +0200 Subject: [PATCH 11/35] Made test packages follow new structure --- .../client/controller/{ => actors}/ApiClientActorTest.scala | 3 +-- .../{ => generation}/CellWorldGenerationStrategyTest.scala | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) rename client/src/test/scala/it/cwmp/client/controller/{ => actors}/ApiClientActorTest.scala (99%) rename client/src/test/scala/it/cwmp/client/controller/game/{ => generation}/CellWorldGenerationStrategyTest.scala (93%) diff --git a/client/src/test/scala/it/cwmp/client/controller/ApiClientActorTest.scala b/client/src/test/scala/it/cwmp/client/controller/actors/ApiClientActorTest.scala similarity index 99% rename from client/src/test/scala/it/cwmp/client/controller/ApiClientActorTest.scala rename to client/src/test/scala/it/cwmp/client/controller/actors/ApiClientActorTest.scala index cd65f8b7..f4358b6f 100644 --- a/client/src/test/scala/it/cwmp/client/controller/ApiClientActorTest.scala +++ b/client/src/test/scala/it/cwmp/client/controller/actors/ApiClientActorTest.scala @@ -1,8 +1,7 @@ -package it.cwmp.client.controller +package it.cwmp.client.controller.actors import akka.actor.{ActorRef, ActorSystem, Props} import akka.testkit.{ImplicitSender, TestKit} -import it.cwmp.client.controller.actors.ApiClientActor import it.cwmp.client.controller.messages.{AuthenticationRequests, AuthenticationResponses, RoomsRequests, RoomsResponses} import it.cwmp.model.Address import it.cwmp.services.wrapper.{FakeAuthenticationApiWrapper, FakeRoomsApiWrapper} diff --git a/client/src/test/scala/it/cwmp/client/controller/game/CellWorldGenerationStrategyTest.scala b/client/src/test/scala/it/cwmp/client/controller/game/generation/CellWorldGenerationStrategyTest.scala similarity index 93% rename from client/src/test/scala/it/cwmp/client/controller/game/CellWorldGenerationStrategyTest.scala rename to client/src/test/scala/it/cwmp/client/controller/game/generation/CellWorldGenerationStrategyTest.scala index 15d74121..a30bb8a0 100644 --- a/client/src/test/scala/it/cwmp/client/controller/game/CellWorldGenerationStrategyTest.scala +++ b/client/src/test/scala/it/cwmp/client/controller/game/generation/CellWorldGenerationStrategyTest.scala @@ -1,6 +1,5 @@ -package it.cwmp.client.controller.game +package it.cwmp.client.controller.game.generation -import it.cwmp.client.controller.game.generation.CellWorldGenerationStrategy import it.cwmp.client.model.game.impl.Cell import it.cwmp.model.User import org.scalatest.FunSpec From 9eb0425caddbf263e8e652c15e850370bae71e14 Mon Sep 17 00:00:00 2001 From: Enrico Siboni Date: Tue, 14 Aug 2018 16:25:24 +0200 Subject: [PATCH 12/35] Moved actor classes to "controller.actors" package --- .../actors}/AuthenticationViewActor.scala | 5 +++-- .../client/controller/actors/ClientControllerActor.scala | 4 +--- .../{view/room => controller/actors}/RoomViewActor.scala | 5 +++-- 3 files changed, 7 insertions(+), 7 deletions(-) rename client/src/main/scala/it/cwmp/client/{view/authentication => controller/actors}/AuthenticationViewActor.scala (87%) rename client/src/main/scala/it/cwmp/client/{view/room => controller/actors}/RoomViewActor.scala (95%) diff --git a/client/src/main/scala/it/cwmp/client/view/authentication/AuthenticationViewActor.scala b/client/src/main/scala/it/cwmp/client/controller/actors/AuthenticationViewActor.scala similarity index 87% rename from client/src/main/scala/it/cwmp/client/view/authentication/AuthenticationViewActor.scala rename to client/src/main/scala/it/cwmp/client/controller/actors/AuthenticationViewActor.scala index 28bc0e45..bd663e13 100644 --- a/client/src/main/scala/it/cwmp/client/view/authentication/AuthenticationViewActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/AuthenticationViewActor.scala @@ -1,8 +1,9 @@ -package it.cwmp.client.view.authentication +package it.cwmp.client.controller.actors +import it.cwmp.client.controller.actors.AuthenticationViewActor._ import it.cwmp.client.controller.messages.AuthenticationRequests.{LogIn, SignUp} import it.cwmp.client.view.FXServiceViewActor -import it.cwmp.client.view.authentication.AuthenticationViewActor.{LOGGING_IN_MESSAGE, SIGNING_UP_MESSAGE} +import it.cwmp.client.view.authentication.{AuthenticationFXController, AuthenticationStrategy} /** * Actor assigned to the management of the display of the authentication screen and of the events generated by it. diff --git a/client/src/main/scala/it/cwmp/client/controller/actors/ClientControllerActor.scala b/client/src/main/scala/it/cwmp/client/controller/actors/ClientControllerActor.scala index 5609ec94..ba62208f 100644 --- a/client/src/main/scala/it/cwmp/client/controller/actors/ClientControllerActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/ClientControllerActor.scala @@ -4,6 +4,7 @@ import akka.actor.{Actor, ActorRef, Props} import it.cwmp.client.controller.ParticipantListReceiver import it.cwmp.client.controller.actors.ClientControllerActor._ import it.cwmp.client.controller.actors.PlayerActor.{PrepareForGame, RetrieveAddress, RetrieveAddressResponse} +import it.cwmp.client.controller.actors.RoomViewActor.{FoundOpponents, ShowToken, WaitingForOthers} import it.cwmp.client.controller.actors.common.AlertMessages.{Error, Info} import it.cwmp.client.controller.actors.common.ViewVisibilityMessages.{Hide, Show} import it.cwmp.client.controller.game.GameConstants @@ -13,9 +14,6 @@ import it.cwmp.client.controller.messages.AuthenticationResponses.{LogInFailure, import it.cwmp.client.controller.messages.Initialize import it.cwmp.client.controller.messages.RoomsRequests._ import it.cwmp.client.controller.messages.RoomsResponses._ -import it.cwmp.client.view.authentication.AuthenticationViewActor -import it.cwmp.client.view.room.RoomViewActor -import it.cwmp.client.view.room.RoomViewActor.{FoundOpponents, ShowToken, WaitingForOthers} import it.cwmp.model.{Address, Participant} import it.cwmp.utils.Logging diff --git a/client/src/main/scala/it/cwmp/client/view/room/RoomViewActor.scala b/client/src/main/scala/it/cwmp/client/controller/actors/RoomViewActor.scala similarity index 95% rename from client/src/main/scala/it/cwmp/client/view/room/RoomViewActor.scala rename to client/src/main/scala/it/cwmp/client/controller/actors/RoomViewActor.scala index 956cf0ba..2e50898e 100644 --- a/client/src/main/scala/it/cwmp/client/view/room/RoomViewActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/RoomViewActor.scala @@ -1,10 +1,11 @@ -package it.cwmp.client.view.room +package it.cwmp.client.controller.actors +import it.cwmp.client.controller.actors.RoomViewActor._ import it.cwmp.client.controller.messages.AuthenticationRequests.GUILogOut import it.cwmp.client.controller.messages.GUIRequest import it.cwmp.client.controller.messages.RoomsRequests._ import it.cwmp.client.view.FXServiceViewActor -import it.cwmp.client.view.room.RoomViewActor._ +import it.cwmp.client.view.room.{RoomFXController, RoomStrategy} /** * This class represents the actor that manages the rooms From cbc2a0e72ceabea7b4b69c2cb92a5b610e905aa0 Mon Sep 17 00:00:00 2001 From: Enrico Siboni Date: Tue, 14 Aug 2018 16:27:01 +0200 Subject: [PATCH 13/35] Moved FXServiceViewActor to "controller.actors" package --- .../client/controller/actors/AuthenticationViewActor.scala | 1 - .../{view => controller/actors}/FXServiceViewActor.scala | 3 ++- .../scala/it/cwmp/client/controller/actors/RoomViewActor.scala | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) rename client/src/main/scala/it/cwmp/client/{view => controller/actors}/FXServiceViewActor.scala (90%) diff --git a/client/src/main/scala/it/cwmp/client/controller/actors/AuthenticationViewActor.scala b/client/src/main/scala/it/cwmp/client/controller/actors/AuthenticationViewActor.scala index bd663e13..738ce7e6 100644 --- a/client/src/main/scala/it/cwmp/client/controller/actors/AuthenticationViewActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/AuthenticationViewActor.scala @@ -2,7 +2,6 @@ package it.cwmp.client.controller.actors import it.cwmp.client.controller.actors.AuthenticationViewActor._ import it.cwmp.client.controller.messages.AuthenticationRequests.{LogIn, SignUp} -import it.cwmp.client.view.FXServiceViewActor import it.cwmp.client.view.authentication.{AuthenticationFXController, AuthenticationStrategy} /** diff --git a/client/src/main/scala/it/cwmp/client/view/FXServiceViewActor.scala b/client/src/main/scala/it/cwmp/client/controller/actors/FXServiceViewActor.scala similarity index 90% rename from client/src/main/scala/it/cwmp/client/view/FXServiceViewActor.scala rename to client/src/main/scala/it/cwmp/client/controller/actors/FXServiceViewActor.scala index 3e2ccb01..660c553d 100644 --- a/client/src/main/scala/it/cwmp/client/view/FXServiceViewActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/FXServiceViewActor.scala @@ -1,8 +1,9 @@ -package it.cwmp.client.view +package it.cwmp.client.controller.actors import akka.actor.{Actor, ActorRef} import it.cwmp.client.controller.actors.common.{ActorAlertManagement, ActorViewVisibilityManagement} import it.cwmp.client.controller.messages.Initialize +import it.cwmp.client.view.{FXAlertsController, FXInputViewController, FXViewController} /** * A base class representing a Service View actor with JavaFX underlying diff --git a/client/src/main/scala/it/cwmp/client/controller/actors/RoomViewActor.scala b/client/src/main/scala/it/cwmp/client/controller/actors/RoomViewActor.scala index 2e50898e..0b821804 100644 --- a/client/src/main/scala/it/cwmp/client/controller/actors/RoomViewActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/RoomViewActor.scala @@ -4,7 +4,6 @@ import it.cwmp.client.controller.actors.RoomViewActor._ import it.cwmp.client.controller.messages.AuthenticationRequests.GUILogOut import it.cwmp.client.controller.messages.GUIRequest import it.cwmp.client.controller.messages.RoomsRequests._ -import it.cwmp.client.view.FXServiceViewActor import it.cwmp.client.view.room.{RoomFXController, RoomStrategy} /** From 448c5c5e95aacc2b04d0039741f397288e7cf87b Mon Sep 17 00:00:00 2001 From: Enrico Siboni Date: Tue, 14 Aug 2018 16:30:41 +0200 Subject: [PATCH 14/35] Created "controller.actors.view" package for Actors dealing with GUI --- .../cwmp/client/controller/actors/ClientControllerActor.scala | 3 ++- .../scala/it/cwmp/client/controller/actors/PlayerActor.scala | 3 ++- .../actors/{ => view}/AuthenticationViewActor.scala | 4 ++-- .../controller/actors/{ => view}/FXServiceViewActor.scala | 2 +- .../client/controller/actors/{ => view}/GameViewActor.scala | 4 ++-- .../client/controller/actors/{ => view}/RoomViewActor.scala | 4 ++-- .../scala/it/cwmp/client/view/game/GameFXController.scala | 2 +- 7 files changed, 12 insertions(+), 10 deletions(-) rename client/src/main/scala/it/cwmp/client/controller/actors/{ => view}/AuthenticationViewActor.scala (92%) rename client/src/main/scala/it/cwmp/client/controller/actors/{ => view}/FXServiceViewActor.scala (96%) rename client/src/main/scala/it/cwmp/client/controller/actors/{ => view}/GameViewActor.scala (98%) rename client/src/main/scala/it/cwmp/client/controller/actors/{ => view}/RoomViewActor.scala (96%) diff --git a/client/src/main/scala/it/cwmp/client/controller/actors/ClientControllerActor.scala b/client/src/main/scala/it/cwmp/client/controller/actors/ClientControllerActor.scala index ba62208f..1ef8619b 100644 --- a/client/src/main/scala/it/cwmp/client/controller/actors/ClientControllerActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/ClientControllerActor.scala @@ -4,9 +4,10 @@ import akka.actor.{Actor, ActorRef, Props} import it.cwmp.client.controller.ParticipantListReceiver import it.cwmp.client.controller.actors.ClientControllerActor._ import it.cwmp.client.controller.actors.PlayerActor.{PrepareForGame, RetrieveAddress, RetrieveAddressResponse} -import it.cwmp.client.controller.actors.RoomViewActor.{FoundOpponents, ShowToken, WaitingForOthers} import it.cwmp.client.controller.actors.common.AlertMessages.{Error, Info} import it.cwmp.client.controller.actors.common.ViewVisibilityMessages.{Hide, Show} +import it.cwmp.client.controller.actors.view.RoomViewActor.{FoundOpponents, ShowToken, WaitingForOthers} +import it.cwmp.client.controller.actors.view.{AuthenticationViewActor, GameViewActor, RoomViewActor} import it.cwmp.client.controller.game.GameConstants import it.cwmp.client.controller.game.generation.CellWorldGenerationStrategy import it.cwmp.client.controller.messages.AuthenticationRequests.{GUILogOut, LogIn, SignUp} diff --git a/client/src/main/scala/it/cwmp/client/controller/actors/PlayerActor.scala b/client/src/main/scala/it/cwmp/client/controller/actors/PlayerActor.scala index 3cf6d310..35960285 100644 --- a/client/src/main/scala/it/cwmp/client/controller/actors/PlayerActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/PlayerActor.scala @@ -4,8 +4,9 @@ import akka.actor.{Actor, ActorRef, AddressFromURIString, Props, Stash} import akka.cluster.Cluster import akka.cluster.ClusterEvent._ import akka.cluster.ddata.DistributedData -import it.cwmp.client.controller.actors.GameViewActor.{NewWorld, ShowGUIWithName} import it.cwmp.client.controller.actors.PlayerActor.{PrepareForGame, RetrieveAddress, RetrieveAddressResponse} +import it.cwmp.client.controller.actors.view.GameViewActor +import it.cwmp.client.controller.actors.view.GameViewActor.{NewWorld, ShowGUIWithName} import it.cwmp.client.controller.game.generation.GenerationStrategy import it.cwmp.client.controller.messages.{Initialize, Request, Response} import it.cwmp.client.model.game.distributed.AkkaDistributedState diff --git a/client/src/main/scala/it/cwmp/client/controller/actors/AuthenticationViewActor.scala b/client/src/main/scala/it/cwmp/client/controller/actors/view/AuthenticationViewActor.scala similarity index 92% rename from client/src/main/scala/it/cwmp/client/controller/actors/AuthenticationViewActor.scala rename to client/src/main/scala/it/cwmp/client/controller/actors/view/AuthenticationViewActor.scala index 738ce7e6..f7704117 100644 --- a/client/src/main/scala/it/cwmp/client/controller/actors/AuthenticationViewActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/view/AuthenticationViewActor.scala @@ -1,6 +1,6 @@ -package it.cwmp.client.controller.actors +package it.cwmp.client.controller.actors.view -import it.cwmp.client.controller.actors.AuthenticationViewActor._ +import it.cwmp.client.controller.actors.view.AuthenticationViewActor._ import it.cwmp.client.controller.messages.AuthenticationRequests.{LogIn, SignUp} import it.cwmp.client.view.authentication.{AuthenticationFXController, AuthenticationStrategy} diff --git a/client/src/main/scala/it/cwmp/client/controller/actors/FXServiceViewActor.scala b/client/src/main/scala/it/cwmp/client/controller/actors/view/FXServiceViewActor.scala similarity index 96% rename from client/src/main/scala/it/cwmp/client/controller/actors/FXServiceViewActor.scala rename to client/src/main/scala/it/cwmp/client/controller/actors/view/FXServiceViewActor.scala index 660c553d..de28bcee 100644 --- a/client/src/main/scala/it/cwmp/client/controller/actors/FXServiceViewActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/view/FXServiceViewActor.scala @@ -1,4 +1,4 @@ -package it.cwmp.client.controller.actors +package it.cwmp.client.controller.actors.view import akka.actor.{Actor, ActorRef} import it.cwmp.client.controller.actors.common.{ActorAlertManagement, ActorViewVisibilityManagement} diff --git a/client/src/main/scala/it/cwmp/client/controller/actors/GameViewActor.scala b/client/src/main/scala/it/cwmp/client/controller/actors/view/GameViewActor.scala similarity index 98% rename from client/src/main/scala/it/cwmp/client/controller/actors/GameViewActor.scala rename to client/src/main/scala/it/cwmp/client/controller/actors/view/GameViewActor.scala index 3067a51a..09fd3e32 100644 --- a/client/src/main/scala/it/cwmp/client/controller/actors/GameViewActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/view/GameViewActor.scala @@ -1,10 +1,10 @@ -package it.cwmp.client.controller.actors +package it.cwmp.client.controller.actors.view import java.util.concurrent.ThreadLocalRandom import akka.actor.{Actor, ActorRef, Cancellable} -import it.cwmp.client.controller.actors.GameViewActor._ import it.cwmp.client.controller.actors.common.{ActorAlertManagement, AlertMessages} +import it.cwmp.client.controller.actors.view.GameViewActor._ import it.cwmp.client.controller.game.GameConstants.{MAX_TIME_BETWEEN_CLIENT_SYNCHRONIZATION, MIN_TIME_BETWEEN_CLIENT_SYNCHRONIZATION} import it.cwmp.client.controller.game.GameEngine import it.cwmp.client.controller.messages.Initialize diff --git a/client/src/main/scala/it/cwmp/client/controller/actors/RoomViewActor.scala b/client/src/main/scala/it/cwmp/client/controller/actors/view/RoomViewActor.scala similarity index 96% rename from client/src/main/scala/it/cwmp/client/controller/actors/RoomViewActor.scala rename to client/src/main/scala/it/cwmp/client/controller/actors/view/RoomViewActor.scala index 0b821804..d7502f22 100644 --- a/client/src/main/scala/it/cwmp/client/controller/actors/RoomViewActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/view/RoomViewActor.scala @@ -1,6 +1,6 @@ -package it.cwmp.client.controller.actors +package it.cwmp.client.controller.actors.view -import it.cwmp.client.controller.actors.RoomViewActor._ +import it.cwmp.client.controller.actors.view.RoomViewActor._ import it.cwmp.client.controller.messages.AuthenticationRequests.GUILogOut import it.cwmp.client.controller.messages.GUIRequest import it.cwmp.client.controller.messages.RoomsRequests._ diff --git a/client/src/main/scala/it/cwmp/client/view/game/GameFXController.scala b/client/src/main/scala/it/cwmp/client/view/game/GameFXController.scala index f1c3f33d..1cb3f2d4 100644 --- a/client/src/main/scala/it/cwmp/client/view/game/GameFXController.scala +++ b/client/src/main/scala/it/cwmp/client/view/game/GameFXController.scala @@ -1,7 +1,7 @@ package it.cwmp.client.view.game import akka.actor.ActorRef -import it.cwmp.client.controller.actors.GameViewActor +import it.cwmp.client.controller.actors.view.GameViewActor import it.cwmp.client.model.game.impl.{Cell, CellWorld, Point} import it.cwmp.client.view.game.drawing.CellWorldObjectDrawer import it.cwmp.client.view.{FXAlertsController, FXViewController, LayoutRes} From 5d5516da7586483f873005eea7202753c2c201f3 Mon Sep 17 00:00:00 2001 From: Enrico Siboni Date: Tue, 14 Aug 2018 16:35:30 +0200 Subject: [PATCH 15/35] Moved "messages" package into "actors" one --- .../cwmp/client/controller/actors/ApiClientActor.scala | 8 ++++---- .../controller/actors/ClientControllerActor.scala | 10 +++++----- .../it/cwmp/client/controller/actors/PlayerActor.scala | 2 +- .../{ => actors}/messages/AuthenticationRequests.scala | 2 +- .../messages/AuthenticationResponses.scala | 2 +- .../controller/{ => actors}/messages/Common.scala | 2 +- .../{ => actors}/messages/RoomsRequests.scala | 2 +- .../{ => actors}/messages/RoomsResponses.scala | 2 +- .../actors/view/AuthenticationViewActor.scala | 2 +- .../controller/actors/view/FXServiceViewActor.scala | 2 +- .../client/controller/actors/view/GameViewActor.scala | 2 +- .../client/controller/actors/view/RoomViewActor.scala | 6 +++--- .../client/controller/actors/ApiClientActorTest.scala | 2 +- 13 files changed, 22 insertions(+), 22 deletions(-) rename client/src/main/scala/it/cwmp/client/controller/{ => actors}/messages/AuthenticationRequests.scala (94%) rename client/src/main/scala/it/cwmp/client/controller/{ => actors}/messages/AuthenticationResponses.scala (95%) rename client/src/main/scala/it/cwmp/client/controller/{ => actors}/messages/Common.scala (89%) rename client/src/main/scala/it/cwmp/client/controller/{ => actors}/messages/RoomsRequests.scala (98%) rename client/src/main/scala/it/cwmp/client/controller/{ => actors}/messages/RoomsResponses.scala (97%) diff --git a/client/src/main/scala/it/cwmp/client/controller/actors/ApiClientActor.scala b/client/src/main/scala/it/cwmp/client/controller/actors/ApiClientActor.scala index 388b2048..7ac4f8d1 100644 --- a/client/src/main/scala/it/cwmp/client/controller/actors/ApiClientActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/ApiClientActor.scala @@ -1,10 +1,10 @@ package it.cwmp.client.controller.actors import akka.actor.Actor -import it.cwmp.client.controller.messages.AuthenticationRequests.{LogIn, SignUp} -import it.cwmp.client.controller.messages.AuthenticationResponses.{LogInFailure, LogInSuccess, SignUpFailure, SignUpSuccess} -import it.cwmp.client.controller.messages.RoomsRequests._ -import it.cwmp.client.controller.messages.RoomsResponses._ +import it.cwmp.client.controller.actors.messages.AuthenticationRequests.{LogIn, SignUp} +import it.cwmp.client.controller.actors.messages.AuthenticationResponses.{LogInFailure, LogInSuccess, SignUpFailure, SignUpSuccess} +import it.cwmp.client.controller.actors.messages.RoomsRequests._ +import it.cwmp.client.controller.actors.messages.RoomsResponses._ import it.cwmp.services.wrapper.{AuthenticationApiWrapper, RoomsApiWrapper} import it.cwmp.utils.Utils.stringToOption diff --git a/client/src/main/scala/it/cwmp/client/controller/actors/ClientControllerActor.scala b/client/src/main/scala/it/cwmp/client/controller/actors/ClientControllerActor.scala index 1ef8619b..93590200 100644 --- a/client/src/main/scala/it/cwmp/client/controller/actors/ClientControllerActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/ClientControllerActor.scala @@ -6,15 +6,15 @@ import it.cwmp.client.controller.actors.ClientControllerActor._ import it.cwmp.client.controller.actors.PlayerActor.{PrepareForGame, RetrieveAddress, RetrieveAddressResponse} import it.cwmp.client.controller.actors.common.AlertMessages.{Error, Info} import it.cwmp.client.controller.actors.common.ViewVisibilityMessages.{Hide, Show} +import it.cwmp.client.controller.actors.messages.AuthenticationRequests.{GUILogOut, LogIn, SignUp} +import it.cwmp.client.controller.actors.messages.AuthenticationResponses.{LogInFailure, LogInSuccess, SignUpFailure, SignUpSuccess} +import it.cwmp.client.controller.actors.messages.Initialize +import it.cwmp.client.controller.actors.messages.RoomsRequests._ +import it.cwmp.client.controller.actors.messages.RoomsResponses._ import it.cwmp.client.controller.actors.view.RoomViewActor.{FoundOpponents, ShowToken, WaitingForOthers} import it.cwmp.client.controller.actors.view.{AuthenticationViewActor, GameViewActor, RoomViewActor} import it.cwmp.client.controller.game.GameConstants import it.cwmp.client.controller.game.generation.CellWorldGenerationStrategy -import it.cwmp.client.controller.messages.AuthenticationRequests.{GUILogOut, LogIn, SignUp} -import it.cwmp.client.controller.messages.AuthenticationResponses.{LogInFailure, LogInSuccess, SignUpFailure, SignUpSuccess} -import it.cwmp.client.controller.messages.Initialize -import it.cwmp.client.controller.messages.RoomsRequests._ -import it.cwmp.client.controller.messages.RoomsResponses._ import it.cwmp.model.{Address, Participant} import it.cwmp.utils.Logging diff --git a/client/src/main/scala/it/cwmp/client/controller/actors/PlayerActor.scala b/client/src/main/scala/it/cwmp/client/controller/actors/PlayerActor.scala index 35960285..0dc743e6 100644 --- a/client/src/main/scala/it/cwmp/client/controller/actors/PlayerActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/PlayerActor.scala @@ -5,10 +5,10 @@ import akka.cluster.Cluster import akka.cluster.ClusterEvent._ import akka.cluster.ddata.DistributedData import it.cwmp.client.controller.actors.PlayerActor.{PrepareForGame, RetrieveAddress, RetrieveAddressResponse} +import it.cwmp.client.controller.actors.messages.{Initialize, Request, Response} import it.cwmp.client.controller.actors.view.GameViewActor import it.cwmp.client.controller.actors.view.GameViewActor.{NewWorld, ShowGUIWithName} import it.cwmp.client.controller.game.generation.GenerationStrategy -import it.cwmp.client.controller.messages.{Initialize, Request, Response} import it.cwmp.client.model.game.distributed.AkkaDistributedState import it.cwmp.client.model.game.distributed.impl.MergingStateCellWorld import it.cwmp.client.model.game.impl.CellWorld diff --git a/client/src/main/scala/it/cwmp/client/controller/messages/AuthenticationRequests.scala b/client/src/main/scala/it/cwmp/client/controller/actors/messages/AuthenticationRequests.scala similarity index 94% rename from client/src/main/scala/it/cwmp/client/controller/messages/AuthenticationRequests.scala rename to client/src/main/scala/it/cwmp/client/controller/actors/messages/AuthenticationRequests.scala index 86b5e184..00fd98d8 100644 --- a/client/src/main/scala/it/cwmp/client/controller/messages/AuthenticationRequests.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/messages/AuthenticationRequests.scala @@ -1,4 +1,4 @@ -package it.cwmp.client.controller.messages +package it.cwmp.client.controller.actors.messages /** * Collection of Authentication request messages diff --git a/client/src/main/scala/it/cwmp/client/controller/messages/AuthenticationResponses.scala b/client/src/main/scala/it/cwmp/client/controller/actors/messages/AuthenticationResponses.scala similarity index 95% rename from client/src/main/scala/it/cwmp/client/controller/messages/AuthenticationResponses.scala rename to client/src/main/scala/it/cwmp/client/controller/actors/messages/AuthenticationResponses.scala index 73115fb7..74894718 100644 --- a/client/src/main/scala/it/cwmp/client/controller/messages/AuthenticationResponses.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/messages/AuthenticationResponses.scala @@ -1,4 +1,4 @@ -package it.cwmp.client.controller.messages +package it.cwmp.client.controller.actors.messages /** * Collection of Authentication response messages diff --git a/client/src/main/scala/it/cwmp/client/controller/messages/Common.scala b/client/src/main/scala/it/cwmp/client/controller/actors/messages/Common.scala similarity index 89% rename from client/src/main/scala/it/cwmp/client/controller/messages/Common.scala rename to client/src/main/scala/it/cwmp/client/controller/actors/messages/Common.scala index 3e59c79d..7a6d53bd 100644 --- a/client/src/main/scala/it/cwmp/client/controller/messages/Common.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/messages/Common.scala @@ -1,4 +1,4 @@ -package it.cwmp.client.controller.messages +package it.cwmp.client.controller.actors.messages /** * Identifies a request message diff --git a/client/src/main/scala/it/cwmp/client/controller/messages/RoomsRequests.scala b/client/src/main/scala/it/cwmp/client/controller/actors/messages/RoomsRequests.scala similarity index 98% rename from client/src/main/scala/it/cwmp/client/controller/messages/RoomsRequests.scala rename to client/src/main/scala/it/cwmp/client/controller/actors/messages/RoomsRequests.scala index cbd7bc74..2b34a67a 100644 --- a/client/src/main/scala/it/cwmp/client/controller/messages/RoomsRequests.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/messages/RoomsRequests.scala @@ -1,4 +1,4 @@ -package it.cwmp.client.controller.messages +package it.cwmp.client.controller.actors.messages import it.cwmp.model.Address diff --git a/client/src/main/scala/it/cwmp/client/controller/messages/RoomsResponses.scala b/client/src/main/scala/it/cwmp/client/controller/actors/messages/RoomsResponses.scala similarity index 97% rename from client/src/main/scala/it/cwmp/client/controller/messages/RoomsResponses.scala rename to client/src/main/scala/it/cwmp/client/controller/actors/messages/RoomsResponses.scala index 4c7e7995..bde8f5f3 100644 --- a/client/src/main/scala/it/cwmp/client/controller/messages/RoomsResponses.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/messages/RoomsResponses.scala @@ -1,4 +1,4 @@ -package it.cwmp.client.controller.messages +package it.cwmp.client.controller.actors.messages /** * The collection of Rooms response messages diff --git a/client/src/main/scala/it/cwmp/client/controller/actors/view/AuthenticationViewActor.scala b/client/src/main/scala/it/cwmp/client/controller/actors/view/AuthenticationViewActor.scala index f7704117..3c280b19 100644 --- a/client/src/main/scala/it/cwmp/client/controller/actors/view/AuthenticationViewActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/view/AuthenticationViewActor.scala @@ -1,7 +1,7 @@ package it.cwmp.client.controller.actors.view +import it.cwmp.client.controller.actors.messages.AuthenticationRequests.{LogIn, SignUp} import it.cwmp.client.controller.actors.view.AuthenticationViewActor._ -import it.cwmp.client.controller.messages.AuthenticationRequests.{LogIn, SignUp} import it.cwmp.client.view.authentication.{AuthenticationFXController, AuthenticationStrategy} /** diff --git a/client/src/main/scala/it/cwmp/client/controller/actors/view/FXServiceViewActor.scala b/client/src/main/scala/it/cwmp/client/controller/actors/view/FXServiceViewActor.scala index de28bcee..e9e84561 100644 --- a/client/src/main/scala/it/cwmp/client/controller/actors/view/FXServiceViewActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/view/FXServiceViewActor.scala @@ -2,7 +2,7 @@ package it.cwmp.client.controller.actors.view import akka.actor.{Actor, ActorRef} import it.cwmp.client.controller.actors.common.{ActorAlertManagement, ActorViewVisibilityManagement} -import it.cwmp.client.controller.messages.Initialize +import it.cwmp.client.controller.actors.messages.Initialize import it.cwmp.client.view.{FXAlertsController, FXInputViewController, FXViewController} /** diff --git a/client/src/main/scala/it/cwmp/client/controller/actors/view/GameViewActor.scala b/client/src/main/scala/it/cwmp/client/controller/actors/view/GameViewActor.scala index 09fd3e32..594b2bb2 100644 --- a/client/src/main/scala/it/cwmp/client/controller/actors/view/GameViewActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/view/GameViewActor.scala @@ -4,10 +4,10 @@ import java.util.concurrent.ThreadLocalRandom import akka.actor.{Actor, ActorRef, Cancellable} import it.cwmp.client.controller.actors.common.{ActorAlertManagement, AlertMessages} +import it.cwmp.client.controller.actors.messages.Initialize import it.cwmp.client.controller.actors.view.GameViewActor._ import it.cwmp.client.controller.game.GameConstants.{MAX_TIME_BETWEEN_CLIENT_SYNCHRONIZATION, MIN_TIME_BETWEEN_CLIENT_SYNCHRONIZATION} import it.cwmp.client.controller.game.GameEngine -import it.cwmp.client.controller.messages.Initialize import it.cwmp.client.model.game.distributed.AkkaDistributedState.UpdateState import it.cwmp.client.model.game.impl._ import it.cwmp.client.utils.GeometricUtils diff --git a/client/src/main/scala/it/cwmp/client/controller/actors/view/RoomViewActor.scala b/client/src/main/scala/it/cwmp/client/controller/actors/view/RoomViewActor.scala index d7502f22..d7523271 100644 --- a/client/src/main/scala/it/cwmp/client/controller/actors/view/RoomViewActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/view/RoomViewActor.scala @@ -1,9 +1,9 @@ package it.cwmp.client.controller.actors.view +import it.cwmp.client.controller.actors.messages.AuthenticationRequests.GUILogOut +import it.cwmp.client.controller.actors.messages.GUIRequest +import it.cwmp.client.controller.actors.messages.RoomsRequests._ import it.cwmp.client.controller.actors.view.RoomViewActor._ -import it.cwmp.client.controller.messages.AuthenticationRequests.GUILogOut -import it.cwmp.client.controller.messages.GUIRequest -import it.cwmp.client.controller.messages.RoomsRequests._ import it.cwmp.client.view.room.{RoomFXController, RoomStrategy} /** diff --git a/client/src/test/scala/it/cwmp/client/controller/actors/ApiClientActorTest.scala b/client/src/test/scala/it/cwmp/client/controller/actors/ApiClientActorTest.scala index f4358b6f..59958514 100644 --- a/client/src/test/scala/it/cwmp/client/controller/actors/ApiClientActorTest.scala +++ b/client/src/test/scala/it/cwmp/client/controller/actors/ApiClientActorTest.scala @@ -2,7 +2,7 @@ package it.cwmp.client.controller.actors import akka.actor.{ActorRef, ActorSystem, Props} import akka.testkit.{ImplicitSender, TestKit} -import it.cwmp.client.controller.messages.{AuthenticationRequests, AuthenticationResponses, RoomsRequests, RoomsResponses} +import it.cwmp.client.controller.actors.messages.{AuthenticationRequests, AuthenticationResponses, RoomsRequests, RoomsResponses} import it.cwmp.model.Address import it.cwmp.services.wrapper.{FakeAuthenticationApiWrapper, FakeRoomsApiWrapper} import it.cwmp.utils.Utils From 8e00abef300f577b4997714d9a89539a13c88d8a Mon Sep 17 00:00:00 2001 From: Enrico Siboni Date: Thu, 16 Aug 2018 20:16:02 +0200 Subject: [PATCH 16/35] Removed multi-jvm project leavings --- client/project/build.properties | 1 - client/project/plugins.sbt | 2 -- 2 files changed, 3 deletions(-) delete mode 100644 client/project/build.properties delete mode 100644 client/project/plugins.sbt diff --git a/client/project/build.properties b/client/project/build.properties deleted file mode 100644 index 27e88aa1..00000000 --- a/client/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=0.13.13 diff --git a/client/project/plugins.sbt b/client/project/plugins.sbt deleted file mode 100644 index 502de2b6..00000000 --- a/client/project/plugins.sbt +++ /dev/null @@ -1,2 +0,0 @@ -addSbtPlugin("com.typesafe.sbt" % "sbt-multi-jvm" % "0.3.8") -addSbtPlugin("com.dwijnand" % "sbt-dynver" % "1.1.1") From 9811a71bd1c64c2f75fc98f2fe1b229769d53f7f Mon Sep 17 00:00:00 2001 From: iugin Date: Fri, 17 Aug 2018 18:23:59 +0200 Subject: [PATCH 17/35] Aggiunto documentazione --- .../wrapper/AuthenticationApiWrapper.scala | 15 ++++++++++++++- .../authentication/AuthenticationTesting.scala | 6 +++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/core/src/main/scala/it/cwmp/services/wrapper/AuthenticationApiWrapper.scala b/core/src/main/scala/it/cwmp/services/wrapper/AuthenticationApiWrapper.scala index edb02816..434a6dd0 100644 --- a/core/src/main/scala/it/cwmp/services/wrapper/AuthenticationApiWrapper.scala +++ b/core/src/main/scala/it/cwmp/services/wrapper/AuthenticationApiWrapper.scala @@ -15,9 +15,22 @@ import scala.concurrent.Future */ trait AuthenticationApiWrapper extends Validation[String, User] { - // TODO: doc + /** + * It tries to execute a sign up on the system. The implementation specifies how the operation should be executed. + * + * @param username the username to register + * @param password the password for that user + * @return a future that may be satisfied when the operation completes successfully, otherwise it fails. + */ def signUp(username: String, password: String): Future[String] + /** + * It tries to execute a login on the system. The implementation specifies how the operation should be executed. + * + * @param username the username of the user that is trying to authenticate itself + * @param password the password for that user + * @return a future that may be satisfied when the operation completes successfully, otherwise it fails. + */ def login(username: String, password: String): Future[String] } diff --git a/services/authentication/src/test/scala/it/cwmp/services/testing/authentication/AuthenticationTesting.scala b/services/authentication/src/test/scala/it/cwmp/services/testing/authentication/AuthenticationTesting.scala index 2fa3eaf2..112a96dd 100644 --- a/services/authentication/src/test/scala/it/cwmp/services/testing/authentication/AuthenticationTesting.scala +++ b/services/authentication/src/test/scala/it/cwmp/services/testing/authentication/AuthenticationTesting.scala @@ -24,7 +24,11 @@ abstract class AuthenticationTesting extends VertxTest with Matchers { "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6InRpemlvIn0.f6eS98GeBmPau4O58NwQa_XRu3Opv6qWxYISWU78F68" )).flatten - // TODO: add doc + /** + * Returns the next valid token. It iterates over a list of token using Round Robin algorithm. + * + * @return a new valid token + */ protected def nextToken: String = tokens.next() protected val invalidToken: String = "INVALID" From d06fa5123a42ef9c5152b4369ae0ad2fbe8a02fb Mon Sep 17 00:00:00 2001 From: iugin Date: Fri, 17 Aug 2018 19:09:22 +0200 Subject: [PATCH 18/35] Implementato e testato il sign-out --- .../AuthenticationServiceVerticle.scala | 2 +- .../AuthenticationServiceVerticleTest.scala | 39 ++++++++++++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/services/authentication/src/main/scala/it/cwmp/services/authentication/AuthenticationServiceVerticle.scala b/services/authentication/src/main/scala/it/cwmp/services/authentication/AuthenticationServiceVerticle.scala index b02ca4da..8526456d 100644 --- a/services/authentication/src/main/scala/it/cwmp/services/authentication/AuthenticationServiceVerticle.scala +++ b/services/authentication/src/main/scala/it/cwmp/services/authentication/AuthenticationServiceVerticle.scala @@ -21,7 +21,7 @@ case class AuthenticationServiceVerticle(override protected val serverPort: Int override protected def initRouter(router: Router): Unit = { router post API_SIGN_UP handler handlerSignUp - router post API_SIGN_OUT handler handlerSignOut + router delete API_SIGN_OUT handler handlerSignOut router get API_LOGIN handler handlerLogin router get API_VALIDATE handler handlerValidation } diff --git a/services/authentication/src/test/scala/it/cwmp/services/authentication/AuthenticationServiceVerticleTest.scala b/services/authentication/src/test/scala/it/cwmp/services/authentication/AuthenticationServiceVerticleTest.scala index 53e7c65f..40bebde9 100644 --- a/services/authentication/src/test/scala/it/cwmp/services/authentication/AuthenticationServiceVerticleTest.scala +++ b/services/authentication/src/test/scala/it/cwmp/services/authentication/AuthenticationServiceVerticleTest.scala @@ -1,6 +1,6 @@ package it.cwmp.services.authentication -import io.netty.handler.codec.http.HttpResponseStatus.{BAD_REQUEST, CREATED, OK, UNAUTHORIZED} +import io.netty.handler.codec.http.HttpResponseStatus._ import io.vertx.scala.ext.web.client.WebClientOptions import it.cwmp.services.VertxClient import it.cwmp.services.authentication.Service._ @@ -51,7 +51,42 @@ class AuthenticationServiceVerticleTest extends AuthenticationWebServiceTesting } override protected def signOutTests(): Unit = { - // TODO implement + it("when username and password right should succeed") { + val username = nextUsername + val password = nextPassword + + for ( + response <- client.post(API_SIGN_UP) addAuthentication(username, password) sendFuture(); + token = response.bodyAsString().get; + apiRequest = client.delete(API_SIGN_OUT) addAuthentication token sendFuture(); + assertion <- apiRequest shouldAnswerWith ACCEPTED + ) yield assertion + } + + it("when succeeded, should have deleted the user") { + val username = nextUsername + val password = nextPassword + + for ( + response <- client.post(API_SIGN_UP) addAuthentication(username, password) sendFuture(); + token = response.bodyAsString().get; + _ <- client.delete(API_SIGN_OUT) addAuthentication token sendFuture(); + apiRequest = client.get(API_VALIDATE) addAuthentication token sendFuture(); + assertion <- apiRequest shouldAnswerWith UNAUTHORIZED + ) yield assertion + } + + it("when empty header should fail") { + client.delete(API_SIGN_OUT) sendFuture() shouldAnswerWith BAD_REQUEST + } + + it("when invalid header should fail") { + client.delete(API_SIGN_OUT) addAuthentication invalidToken sendFuture() shouldAnswerWith BAD_REQUEST + } + + it("when user does not exists should fail") { + client.delete(API_SIGN_OUT) addAuthentication nextToken sendFuture() shouldAnswerWith UNAUTHORIZED + } } override protected def loginTests(): Unit = { From c19d463bbd8cb8701a9216a5695868f40b837368 Mon Sep 17 00:00:00 2001 From: iugin Date: Fri, 17 Aug 2018 19:39:41 +0200 Subject: [PATCH 19/35] =?UTF-8?q?Aggiunta=20la=20possibilit=C3=A0=20di=20f?= =?UTF-8?q?ornire=20ulteririo=20condizioni=20di=20failure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scala/it/cwmp/testing/FutureMatchers.scala | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/core-testing/src/main/scala/it/cwmp/testing/FutureMatchers.scala b/core-testing/src/main/scala/it/cwmp/testing/FutureMatchers.scala index a02cb255..53935dcd 100644 --- a/core-testing/src/main/scala/it/cwmp/testing/FutureMatchers.scala +++ b/core-testing/src/main/scala/it/cwmp/testing/FutureMatchers.scala @@ -48,9 +48,21 @@ trait FutureMatchers { * @tparam A the type of failure that should be obtained * @return the future containing the result of the verification */ - def shouldFailWith[A <: Exception : ClassTag](implicit executionContext: ExecutionContext): Future[Assertion] = future + def shouldFailWith[A <: Exception : ClassTag](implicit executionContext: ExecutionContext): Future[Assertion] = + shouldFailWith[A]((_: A) => true) + + + /** + * Asserts that the future has the failure requested + * + * @param condition the condition to satisfy when failing + * @param executionContext the implicit execution context + * @tparam A the type of failure that should be obtained + * @return the future containing the result of the verification + */ + def shouldFailWith[A <: Exception : ClassTag](condition: A => Boolean)(implicit executionContext: ExecutionContext): Future[Assertion] = future .transform { - case Failure(e) if classTag[A].runtimeClass.isInstance(e) => Success(succeed) + case Failure(e) if classTag[A].runtimeClass.isInstance(e) && condition(e.asInstanceOf[A]) => Success(succeed) case _ => Failure(FutureTestingException) } From 559b08011f791ad66fb8152e1e1bcb68872eb4e5 Mon Sep 17 00:00:00 2001 From: iugin Date: Fri, 17 Aug 2018 19:40:55 +0200 Subject: [PATCH 20/35] Aggiunto il signout nel wrapper ed scritti i relativi tests. Rifattorizzati i tests. --- .../wrapper/AuthenticationApiWrapper.scala | 19 +++++- .../AuthenticationApiWrapperTest.scala | 64 +++++++++---------- .../FakeAuthenticationApiWrapper.scala | 8 +++ .../AuthenticationServiceVerticleTest.scala | 2 +- 4 files changed, 55 insertions(+), 38 deletions(-) diff --git a/core/src/main/scala/it/cwmp/services/wrapper/AuthenticationApiWrapper.scala b/core/src/main/scala/it/cwmp/services/wrapper/AuthenticationApiWrapper.scala index 434a6dd0..a0da609d 100644 --- a/core/src/main/scala/it/cwmp/services/wrapper/AuthenticationApiWrapper.scala +++ b/core/src/main/scala/it/cwmp/services/wrapper/AuthenticationApiWrapper.scala @@ -1,6 +1,6 @@ package it.cwmp.services.wrapper -import io.netty.handler.codec.http.HttpResponseStatus.{BAD_REQUEST, CREATED, OK} +import io.netty.handler.codec.http.HttpResponseStatus.{BAD_REQUEST, CREATED, OK, ACCEPTED} import io.vertx.scala.ext.web.client.WebClientOptions import it.cwmp.exceptions.HTTPException import it.cwmp.model.User @@ -24,6 +24,14 @@ trait AuthenticationApiWrapper extends Validation[String, User] { */ def signUp(username: String, password: String): Future[String] + /** + * Allow a user to delete his account and sign out from the system. + * + * @param token the authentication token + * @return a future that succeed only if the user has been successfully deleted. + */ + def signOut(token: String): Future[Unit] + /** * It tries to execute a login on the system. The implementation specifies how the operation should be executed. * @@ -58,13 +66,20 @@ object AuthenticationApiWrapper { class AuthenticationApiWrapperImpl(override protected val clientOptions: WebClientOptions) extends AuthenticationApiWrapper with VertxInstance with VertxClient { - def signUp(username: String, password: String): Future[String] = + override def signUp(username: String, password: String): Future[String] = client.post(API_SIGN_UP) .addAuthentication(username, password) .sendFuture() .expectStatus(CREATED) .map(_.bodyAsString().getOrElse("")) + override def signOut(token: String): Future[Unit] = + client.delete(API_SIGN_OUT) + .addAuthentication(token) + .sendFuture() + .expectStatus(ACCEPTED) + .map(_ => ()) + override def login(username: String, password: String): Future[String] = client.get(API_LOGIN) .addAuthentication(username, password) diff --git a/core/src/test/scala/it/cwmp/services/wrapper/AuthenticationApiWrapperTest.scala b/core/src/test/scala/it/cwmp/services/wrapper/AuthenticationApiWrapperTest.scala index a922de9c..6044c0a4 100644 --- a/core/src/test/scala/it/cwmp/services/wrapper/AuthenticationApiWrapperTest.scala +++ b/core/src/test/scala/it/cwmp/services/wrapper/AuthenticationApiWrapperTest.scala @@ -3,15 +3,13 @@ package it.cwmp.services.wrapper import io.netty.handler.codec.http.HttpResponseStatus.{BAD_REQUEST, UNAUTHORIZED} import it.cwmp.exceptions.HTTPException import it.cwmp.services.testing.authentication.AuthenticationWebServiceTesting +import it.cwmp.testing.FutureMatchers import it.cwmp.utils.HttpUtils -import scala.concurrent.Promise -import scala.util.Failure - /** * A test class for AuthenticationApiWrapper */ -class AuthenticationApiWrapperTest extends AuthenticationWebServiceTesting { +class AuthenticationApiWrapperTest extends AuthenticationWebServiceTesting with FutureMatchers { private val auth = AuthenticationApiWrapper() @@ -32,19 +30,35 @@ class AuthenticationApiWrapperTest extends AuthenticationWebServiceTesting { val username = nextUsername val password = nextPassword - val promiseResult: Promise[Unit] = Promise() auth.signUp(username, password) .flatMap(_ => auth.signUp(username, password)) - .onComplete({ - case Failure(HTTPException(statusCode, _)) if statusCode == BAD_REQUEST.code() => promiseResult.success(()) - case _ => promiseResult.failure(new Exception) - }) - promiseResult.future.map(_ => succeed) + .shouldFailWith[HTTPException]((e: HTTPException) => e.statusCode == BAD_REQUEST.code()) } } override protected def signOutTests(): Unit = { - // TODO implementation + it("when user exists, should succeed") { + val username = nextUsername + val password = nextPassword + + auth.signUp(username, password) + .flatMap(token => auth.signOut(HttpUtils.buildJwtAuthentication(token).get)) + .shouldSucceed + } + + it("when invalid token should fail") { + val myToken = invalidToken + + auth.signOut(myToken) + .shouldFailWith[HTTPException]((e: HTTPException) => e.statusCode == BAD_REQUEST.code()) + } + + it("when unauthorized header should fail") { + val myAuthToken = nextToken + + auth.signOut(myAuthToken) + .shouldFailWith[HTTPException]((e: HTTPException) => e.statusCode == UNAUTHORIZED.code()) + } } override protected def loginTests(): Unit = { @@ -61,13 +75,8 @@ class AuthenticationApiWrapperTest extends AuthenticationWebServiceTesting { val username = nextUsername val password = nextPassword - val promiseResult: Promise[Unit] = Promise() auth.login(username, password) - .onComplete({ - case Failure(HTTPException(statusCode, _)) if statusCode == UNAUTHORIZED.code() => promiseResult.success(()) - case _ => promiseResult.failure(new Exception) - }) - promiseResult.future.map(_ => succeed) + .shouldFailWith[HTTPException]((e: HTTPException) => e.statusCode == UNAUTHORIZED.code()) } it("when password is wrong should fail") { @@ -75,14 +84,9 @@ class AuthenticationApiWrapperTest extends AuthenticationWebServiceTesting { val password = nextPassword val passwordWrong = nextPassword - val promiseResult: Promise[Unit] = Promise() auth.signUp(username, password) .flatMap(_ => auth.login(username, passwordWrong)) - .onComplete({ - case Failure(HTTPException(statusCode, _)) if statusCode == UNAUTHORIZED.code() => promiseResult.success(()) - case _ => promiseResult.failure(new Exception) - }) - promiseResult.future.map(_ => succeed) + .shouldFailWith[HTTPException]((e: HTTPException) => e.statusCode == UNAUTHORIZED.code()) } } @@ -99,25 +103,15 @@ class AuthenticationApiWrapperTest extends AuthenticationWebServiceTesting { it("when invalid token should fail") { val myToken = invalidToken - val promiseResult: Promise[Unit] = Promise() auth.validate(myToken) - .onComplete({ - case Failure(HTTPException(statusCode, _)) if statusCode == BAD_REQUEST.code() => promiseResult.success(()) - case _ => promiseResult.failure(new Exception) - }) - promiseResult.future.map(_ => succeed) + .shouldFailWith[HTTPException]((e: HTTPException) => e.statusCode == BAD_REQUEST.code()) } it("when unauthorized header should fail") { val myAuthHeader = nextHeader - val promiseResult: Promise[Unit] = Promise() auth.validate(myAuthHeader) - .onComplete({ - case Failure(HTTPException(statusCode, _)) if statusCode == UNAUTHORIZED.code() => promiseResult.success(()) - case _ => promiseResult.failure(new Exception) - }) - promiseResult.future.map(_ => succeed) + .shouldFailWith[HTTPException]((e: HTTPException) => e.statusCode == UNAUTHORIZED.code()) } } } diff --git a/core/src/test/scala/it/cwmp/services/wrapper/FakeAuthenticationApiWrapper.scala b/core/src/test/scala/it/cwmp/services/wrapper/FakeAuthenticationApiWrapper.scala index 9a276027..f67d416d 100644 --- a/core/src/test/scala/it/cwmp/services/wrapper/FakeAuthenticationApiWrapper.scala +++ b/core/src/test/scala/it/cwmp/services/wrapper/FakeAuthenticationApiWrapper.scala @@ -34,6 +34,14 @@ case class FakeAuthenticationApiWrapper() extends AuthenticationApiWrapper { } }).getOrElse(Future.failed(HTTPException(BAD_REQUEST))) + override def signOut(token: String): Future[Unit] = + participants.get(token) match { + case Some(_) => + participants = participants - token + Future.successful(()) + case _ => Future.failed(HTTPException(UNAUTHORIZED)) + } + override def login(usernameCheck: String, passwordCheck: String): Future[String] = (for ( username <- Option(usernameCheck); password <- Option(passwordCheck) diff --git a/services/authentication/src/test/scala/it/cwmp/services/authentication/AuthenticationServiceVerticleTest.scala b/services/authentication/src/test/scala/it/cwmp/services/authentication/AuthenticationServiceVerticleTest.scala index 40bebde9..92f5f83a 100644 --- a/services/authentication/src/test/scala/it/cwmp/services/authentication/AuthenticationServiceVerticleTest.scala +++ b/services/authentication/src/test/scala/it/cwmp/services/authentication/AuthenticationServiceVerticleTest.scala @@ -51,7 +51,7 @@ class AuthenticationServiceVerticleTest extends AuthenticationWebServiceTesting } override protected def signOutTests(): Unit = { - it("when username and password right should succeed") { + it("when user exists, should succeed") { val username = nextUsername val password = nextPassword From c8739a6999a39469cc381f2afbe44d7b5feb2cd7 Mon Sep 17 00:00:00 2001 From: iugin Date: Fri, 17 Aug 2018 19:43:17 +0200 Subject: [PATCH 21/35] Corretto signout test --- .../it/cwmp/services/wrapper/AuthenticationApiWrapperTest.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/test/scala/it/cwmp/services/wrapper/AuthenticationApiWrapperTest.scala b/core/src/test/scala/it/cwmp/services/wrapper/AuthenticationApiWrapperTest.scala index 6044c0a4..55569758 100644 --- a/core/src/test/scala/it/cwmp/services/wrapper/AuthenticationApiWrapperTest.scala +++ b/core/src/test/scala/it/cwmp/services/wrapper/AuthenticationApiWrapperTest.scala @@ -42,7 +42,7 @@ class AuthenticationApiWrapperTest extends AuthenticationWebServiceTesting with val password = nextPassword auth.signUp(username, password) - .flatMap(token => auth.signOut(HttpUtils.buildJwtAuthentication(token).get)) + .flatMap(token => auth.signOut(token)) .shouldSucceed } From c20cc390264c0107e8a02360acac17239a7ed178 Mon Sep 17 00:00:00 2001 From: iugin Date: Mon, 20 Aug 2018 09:39:51 +0200 Subject: [PATCH 22/35] =?UTF-8?q?Corretto=20la=20visibilit=C3=A0=20dei=20c?= =?UTF-8?q?ampi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/main/scala/it/cwmp/services/VertxInstance.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/scala/it/cwmp/services/VertxInstance.scala b/core/src/main/scala/it/cwmp/services/VertxInstance.scala index 6e1b912a..d08a03d5 100644 --- a/core/src/main/scala/it/cwmp/services/VertxInstance.scala +++ b/core/src/main/scala/it/cwmp/services/VertxInstance.scala @@ -13,6 +13,6 @@ import io.vertx.scala.core.Vertx trait VertxInstance { private val vertxContext = Vertx.currentContext().getOrElse(Vertx.vertx.getOrCreateContext()) - val vertx: Vertx = vertxContext.owner() - implicit val vertxExecutionContext: VertxExecutionContext = VertxExecutionContext(vertxContext) + protected val vertx: Vertx = vertxContext.owner() + protected implicit val vertxExecutionContext: VertxExecutionContext = VertxExecutionContext(vertxContext) } From f6a4cba70fc48749681392c3bc168ec5af2213f9 Mon Sep 17 00:00:00 2001 From: iugin Date: Mon, 20 Aug 2018 09:46:21 +0200 Subject: [PATCH 23/35] Rimosso todo di feature non implementata --- .../scala/it/cwmp/services/wrapper/RoomReceiverApiWrapper.scala | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/src/main/scala/it/cwmp/services/wrapper/RoomReceiverApiWrapper.scala b/core/src/main/scala/it/cwmp/services/wrapper/RoomReceiverApiWrapper.scala index 49a43091..1b1180a2 100644 --- a/core/src/main/scala/it/cwmp/services/wrapper/RoomReceiverApiWrapper.scala +++ b/core/src/main/scala/it/cwmp/services/wrapper/RoomReceiverApiWrapper.scala @@ -47,8 +47,6 @@ object RoomReceiverApiWrapper { .sendJsonFuture(toSend.foldLeft(Json emptyArr())(_ add _.toJson)) .logSuccessInfo(s"Sending participant to $clientAddress succeeded") .map(_ => Future.successful(())) - - // TODO should implement a retry strategy? } override protected def clientOptions: WebClientOptions = WebClientOptions() From 508798d76a0512137e76c6a4df7683aa1217a367 Mon Sep 17 00:00:00 2001 From: iugin Date: Mon, 20 Aug 2018 10:02:48 +0200 Subject: [PATCH 24/35] Aggiunto spazio --- .../it/cwmp/client/controller/actors/view/GameViewActor.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/main/scala/it/cwmp/client/controller/actors/view/GameViewActor.scala b/client/src/main/scala/it/cwmp/client/controller/actors/view/GameViewActor.scala index 594b2bb2..9d7a89e5 100644 --- a/client/src/main/scala/it/cwmp/client/controller/actors/view/GameViewActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/view/GameViewActor.scala @@ -77,8 +77,8 @@ case class GameViewActor() extends Actor with FXRunOnUIThread with ActorAlertMan .schedule(TIME_BETWEEN_FRAMES, TIME_BETWEEN_FRAMES, self, UpdateGUI)(context.dispatcher) } gameEnded(world) match { - case Some(winnerName) if winnerName == playerName => self ! AlertMessages.Info(playerName + YOU_WON_TITLE, YOU_WON) - case Some(_) => self ! AlertMessages.Info(playerName + YOU_LOST_TITLE, YOU_LOST) + case Some(winnerName) if winnerName == playerName => self ! AlertMessages.Info(s"$playerName $YOU_WON_TITLE", YOU_WON) + case Some(_) => self ! AlertMessages.Info(s"$playerName $YOU_LOST_TITLE", YOU_LOST) case None => } From c3b87ea83d05511e704c07d63ebb976558fde66e Mon Sep 17 00:00:00 2001 From: Davide Date: Mon, 20 Aug 2018 10:36:53 +0200 Subject: [PATCH 25/35] Aggiunta documentazione --- .../authentication/utils/JwtUtils.scala | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/services/authentication/src/main/scala/it/cwmp/services/authentication/utils/JwtUtils.scala b/services/authentication/src/main/scala/it/cwmp/services/authentication/utils/JwtUtils.scala index 9c0a35bc..00df4d6b 100644 --- a/services/authentication/src/main/scala/it/cwmp/services/authentication/utils/JwtUtils.scala +++ b/services/authentication/src/main/scala/it/cwmp/services/authentication/utils/JwtUtils.scala @@ -5,7 +5,10 @@ import pdi.jwt.{Jwt, JwtAlgorithm, JwtClaim} import scala.util.{Failure, Success} -// TODO: add doc to all class methods +/** + * Questa classe serve per effettuare le funzioni basi con i JWT tokens + * @author Davide Borficchia + */ object JwtUtils { val USERNAME_FIELD_NAME: String = "username" @@ -13,10 +16,20 @@ object JwtUtils { private val secretKey = "secretKey" private val algorithm = JwtAlgorithm.HS256 + /** + * Crea un token a partire da un claim + * @param claim è il testo che verrà inserito dentro il token + * @return il token da utilizzare nelle richieste + */ def encodeToken(claim: JwtClaim): Option[String] = if (claim != null) Some(Jwt.encode(claim, secretKey, algorithm)) else None + /** + * Dato un token lo decodifica + * @param token il token da decodificare + * @return il contenuto in chiaro del token + */ def decodeToken(token: String): Option[JwtClaim] = { Jwt.decodeRawAll(token, secretKey, Seq(algorithm)) match { case Success((_, b, _)) => @@ -25,15 +38,30 @@ object JwtUtils { } } + /** + * Controlla la validità di un token + * @param token token da validare + * @return true se il token è valido, false in caso contrario + */ def validateToken(token: String): Boolean = { Jwt.isValid(token, secretKey, Seq(algorithm)) } + /** + * Crea il token contenente l'username + * @param username username da inserire nel token + * @return il token da utilizzare nelle richieste + */ def encodeUsernameToken(username: String): Option[String] = { if (username == null) None else encodeToken(JwtClaim(new JsonObject().put(USERNAME_FIELD_NAME, username).encode())) } + /** + * Dato un token lo decodifica e risale all'username + * @param token token da decodificare + * @return username dell'utente + */ def decodeUsernameToken(token: String): Option[String] = { decodeToken(token).map(decoded => new JsonObject(decoded.content).getString(USERNAME_FIELD_NAME)) } From 32b7fa43f9398282296bc6518981ee6415f7bfd2 Mon Sep 17 00:00:00 2001 From: Enrico Siboni Date: Mon, 20 Aug 2018 18:04:09 +0200 Subject: [PATCH 26/35] Added AbstractAddressInput strategy on dialog cancel - Implemented this strategy to close JVM in services and client --- .../scala/it/cwmp/client/ClientMain.scala | 6 ++-- .../it/cwmp/view/AbstractAddressInput.scala | 29 +++++++++++++------ .../scala/it/cwmp/view/OneAddressInput.scala | 12 ++++---- .../it/cwmp/view/TwoAddressesInput.scala | 12 ++++---- .../AuthenticationServiceMain.scala | 6 ++-- .../services/rooms/RoomsServiceMain.scala | 6 ++-- 6 files changed, 46 insertions(+), 25 deletions(-) diff --git a/client/src/main/scala/it/cwmp/client/ClientMain.scala b/client/src/main/scala/it/cwmp/client/ClientMain.scala index f633463c..6a9cd8b0 100644 --- a/client/src/main/scala/it/cwmp/client/ClientMain.scala +++ b/client/src/main/scala/it/cwmp/client/ClientMain.scala @@ -31,9 +31,11 @@ object ClientMain extends App with VertxInstance with Logging { launch(discoveryService._1, discoveryService._2) } catch { case _: IllegalArgumentException => - OneAddressInput(APP_NAME, "You should insert DiscoveryService host-port", discoveryServiceHostPortPair => { + OneAddressInput(APP_NAME, "You should insert DiscoveryService host-port")(discoveryServiceHostPortPair => { launch(discoveryServiceHostPortPair._1, discoveryServiceHostPortPair._2) - })(defaultPort = discovery.Service.DEFAULT_PORT.toString) + }, + _ => System.exit(0) + )(defaultPort = discovery.Service.DEFAULT_PORT.toString) } /** diff --git a/core/src/main/scala/it/cwmp/view/AbstractAddressInput.scala b/core/src/main/scala/it/cwmp/view/AbstractAddressInput.scala index 8adbd366..912950f5 100644 --- a/core/src/main/scala/it/cwmp/view/AbstractAddressInput.scala +++ b/core/src/main/scala/it/cwmp/view/AbstractAddressInput.scala @@ -6,20 +6,23 @@ import it.cwmp.view.AbstractAddressInput._ import javafx.application.Platform import javafx.embed.swing.JFXPanel import javafx.scene.control._ +import javafx.scene.input.KeyCode import javafx.scene.layout.GridPane /** * A view to select an IP address and port * - * @param viewTitle the view title - * @param message the message to show the user - * @param onResultReady the action on result ready - * @param defaultIP the default IP for IP field - * @param defaultPort default port for Port field + * @param viewTitle the view title + * @param message the message to show the user + * @param onResultReady the action on result ready + * @param onDialogCanceled the action to do on dialog canceled + * @param defaultIP the default IP for IP field + * @param defaultPort default port for Port field * @tparam Result the type of result * @author Enrico Siboni */ -abstract class AbstractAddressInput[Result](viewTitle: String, message: String, onResultReady: Result => Unit) +abstract class AbstractAddressInput[Result](viewTitle: String, message: String, + onResultReady: Result => Unit, onDialogCanceled: Unit => Unit) (defaultIP: String = localIP, defaultPort: String = defaultPort) { new JFXPanel // initializes JavaFX @@ -27,6 +30,8 @@ abstract class AbstractAddressInput[Result](viewTitle: String, message: String, private val dialogButtonType: ButtonType = ButtonType.FINISH private var bodyGrid: GridPane = _ + private var mouseOverOkButton = false + private var enterKeyPressed = false private var ipAddressValid = true private var portValid = true @@ -119,14 +124,20 @@ abstract class AbstractAddressInput[Result](viewTitle: String, message: String, dialog.setHeaderText(message) dialog.getDialogPane.getButtonTypes.add(dialogButtonType) + val buttonOk = dialog.getDialogPane.lookupButton(dialogButtonType) + buttonOk.setOnMouseEntered(_ => mouseOverOkButton = true) + buttonOk.setOnMouseExited(_ => mouseOverOkButton = false) + + dialog.getDialogPane.setOnKeyPressed(event => if (event.getCode == KeyCode.ENTER) enterKeyPressed = true) + bodyGrid = new GridPane bodyGridFill(bodyGrid) dialog.getDialogPane.setContent(bodyGrid) - dialog.setOnCloseRequest((event) => { - if (wholeInputValid) onResultReady(getResult) - else event.consume() + dialog.setOnCloseRequest(_ => { + if (wholeInputValid && (mouseOverOkButton || enterKeyPressed)) onResultReady(getResult) + else onDialogCanceled() }) dialog.show() diff --git a/core/src/main/scala/it/cwmp/view/OneAddressInput.scala b/core/src/main/scala/it/cwmp/view/OneAddressInput.scala index 22620ee0..0e5832d6 100644 --- a/core/src/main/scala/it/cwmp/view/OneAddressInput.scala +++ b/core/src/main/scala/it/cwmp/view/OneAddressInput.scala @@ -5,13 +5,15 @@ import it.cwmp.view.AbstractAddressInput.{defaultPort, localIP} /** * Class to request user a single pair IP and port * - * @param viewTitle the view title - * @param message the message to show the user - * @param onResultReady the action on result ready + * @param viewTitle the view title + * @param message the message to show the user + * @param onResultReady the action on result ready + * @param onDialogCanceled the action on dialog canceled */ -case class OneAddressInput(viewTitle: String, message: String, onResultReady: ((String, String)) => Unit) +case class OneAddressInput(viewTitle: String, message: String) + (onResultReady: ((String, String)) => Unit, onDialogCanceled: Unit => Unit) (defaultIP: String = localIP, defaultPort: String = defaultPort) - extends AbstractAddressInput[(String, String)](viewTitle, message, onResultReady)(defaultIP, defaultPort) { + extends AbstractAddressInput[(String, String)](viewTitle, message, onResultReady, onDialogCanceled)(defaultIP, defaultPort) { override protected def getResult: (String, String) = (addressIpField.getText, addressPortField.getText) } diff --git a/core/src/main/scala/it/cwmp/view/TwoAddressesInput.scala b/core/src/main/scala/it/cwmp/view/TwoAddressesInput.scala index 54076b47..f387633f 100644 --- a/core/src/main/scala/it/cwmp/view/TwoAddressesInput.scala +++ b/core/src/main/scala/it/cwmp/view/TwoAddressesInput.scala @@ -7,14 +7,16 @@ import javafx.scene.layout.GridPane /** * A class to request user to insert two addresses * - * @param viewTitle the view title - * @param message the message to show the user - * @param onResultReady the action on result ready + * @param viewTitle the view title + * @param message the message to show the user + * @param onResultReady the action on result ready + * @param onDialogCanceled the action to do on dialog canceled */ -case class TwoAddressesInput(viewTitle: String, message: String, onResultReady: (((String, String), (String, String))) => Unit) +case class TwoAddressesInput(viewTitle: String, message: String) + (onResultReady: (((String, String), (String, String))) => Unit, onDialogCanceled: Unit => Unit) (firstDefaultIP: String = localIP, firstDefaultPort: String = defaultPort, secondDefaultIP: String = localIP, secondDefaultPort: String = defaultPort) - extends AbstractAddressInput[((String, String), (String, String))](viewTitle, message, onResultReady)(firstDefaultIP, firstDefaultPort) { + extends AbstractAddressInput[((String, String), (String, String))](viewTitle, message, onResultReady, onDialogCanceled)(firstDefaultIP, firstDefaultPort) { private var secondIpAddressValid = true private var secondPortValid = true diff --git a/services/authentication/src/main/scala/it/cwmp/services/authentication/AuthenticationServiceMain.scala b/services/authentication/src/main/scala/it/cwmp/services/authentication/AuthenticationServiceMain.scala index f26605c5..1e2d6de2 100644 --- a/services/authentication/src/main/scala/it/cwmp/services/authentication/AuthenticationServiceMain.scala +++ b/services/authentication/src/main/scala/it/cwmp/services/authentication/AuthenticationServiceMain.scala @@ -20,12 +20,14 @@ object AuthenticationServiceMain extends App with VertxInstance with Logging wit launch(discoveryService._1, discoveryService._2, myService._1, myService._2) } catch { case _: IllegalArgumentException => - TwoAddressesInput(Service.COMMON_NAME, ServiceLauncher.GUI_INSERTION_MESSAGE, discoveryAndMyHostPortPairs => { + TwoAddressesInput(Service.COMMON_NAME, ServiceLauncher.GUI_INSERTION_MESSAGE)(discoveryAndMyHostPortPairs => { val discoveryService = discoveryAndMyHostPortPairs._1 val myService = discoveryAndMyHostPortPairs._2 launch(discoveryService._1, discoveryService._2, myService._1, myService._2) - })(firstDefaultPort = discovery.Service.DEFAULT_PORT.toString, + }, + _ => System.exit(0) + )(firstDefaultPort = discovery.Service.DEFAULT_PORT.toString, secondDefaultPort = Service.DEFAULT_PORT.toString) } diff --git a/services/rooms/src/main/scala/it/cwmp/services/rooms/RoomsServiceMain.scala b/services/rooms/src/main/scala/it/cwmp/services/rooms/RoomsServiceMain.scala index 65723ee1..0e4baa93 100644 --- a/services/rooms/src/main/scala/it/cwmp/services/rooms/RoomsServiceMain.scala +++ b/services/rooms/src/main/scala/it/cwmp/services/rooms/RoomsServiceMain.scala @@ -22,12 +22,14 @@ object RoomsServiceMain extends App with VertxInstance with Logging with Service launch(discoveryService._1, discoveryService._2, myService._1, myService._2) } catch { case _: IllegalArgumentException => - TwoAddressesInput(Service.COMMON_NAME, ServiceLauncher.GUI_INSERTION_MESSAGE, discoveryAndMyHostPortPairs => { + TwoAddressesInput(Service.COMMON_NAME, ServiceLauncher.GUI_INSERTION_MESSAGE)(discoveryAndMyHostPortPairs => { val discoveryService = discoveryAndMyHostPortPairs._1 val myService = discoveryAndMyHostPortPairs._2 launch(discoveryService._1, discoveryService._2, myService._1, myService._2) - })(firstDefaultPort = discovery.Service.DEFAULT_PORT.toString, + }, + _ => System.exit(0) + )(firstDefaultPort = discovery.Service.DEFAULT_PORT.toString, secondDefaultPort = Service.DEFAULT_PORT.toString) } From 1998af7a6c04b8c209c7644147462ead6db0993b Mon Sep 17 00:00:00 2001 From: Enrico Siboni Date: Mon, 20 Aug 2018 18:22:56 +0200 Subject: [PATCH 27/35] Solved warning --- core/src/main/scala/it/cwmp/view/AbstractAddressInput.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/scala/it/cwmp/view/AbstractAddressInput.scala b/core/src/main/scala/it/cwmp/view/AbstractAddressInput.scala index 912950f5..bae617ce 100644 --- a/core/src/main/scala/it/cwmp/view/AbstractAddressInput.scala +++ b/core/src/main/scala/it/cwmp/view/AbstractAddressInput.scala @@ -137,7 +137,7 @@ abstract class AbstractAddressInput[Result](viewTitle: String, message: String, dialog.setOnCloseRequest(_ => { if (wholeInputValid && (mouseOverOkButton || enterKeyPressed)) onResultReady(getResult) - else onDialogCanceled() + else onDialogCanceled(()) }) dialog.show() From 778910ef7273638e81b055aec380dd07ce02974f Mon Sep 17 00:00:00 2001 From: Davide Date: Mon, 20 Aug 2018 19:27:21 +0200 Subject: [PATCH 28/35] tradotta documentazione --- .../authentication/utils/JwtUtils.scala | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/services/authentication/src/main/scala/it/cwmp/services/authentication/utils/JwtUtils.scala b/services/authentication/src/main/scala/it/cwmp/services/authentication/utils/JwtUtils.scala index 00df4d6b..39a36d86 100644 --- a/services/authentication/src/main/scala/it/cwmp/services/authentication/utils/JwtUtils.scala +++ b/services/authentication/src/main/scala/it/cwmp/services/authentication/utils/JwtUtils.scala @@ -6,7 +6,7 @@ import pdi.jwt.{Jwt, JwtAlgorithm, JwtClaim} import scala.util.{Failure, Success} /** - * Questa classe serve per effettuare le funzioni basi con i JWT tokens + * This class is used to perform the basic functions with the JWT tokens * @author Davide Borficchia */ object JwtUtils { @@ -17,18 +17,18 @@ object JwtUtils { private val algorithm = JwtAlgorithm.HS256 /** - * Crea un token a partire da un claim - * @param claim è il testo che verrà inserito dentro il token - * @return il token da utilizzare nelle richieste + * Buid a token from a claim + * @param claim is the text that will use to build the token + * @return the token to use in the request */ def encodeToken(claim: JwtClaim): Option[String] = if (claim != null) Some(Jwt.encode(claim, secretKey, algorithm)) else None /** - * Dato un token lo decodifica - * @param token il token da decodificare - * @return il contenuto in chiaro del token + * Decode a token + * @param token the token to decode + * @return the content of token decoded */ def decodeToken(token: String): Option[JwtClaim] = { Jwt.decodeRawAll(token, secretKey, Seq(algorithm)) match { @@ -39,18 +39,18 @@ object JwtUtils { } /** - * Controlla la validità di un token - * @param token token da validare - * @return true se il token è valido, false in caso contrario + * Validate a token + * @param token token to validate + * @return true if token is valid, false in opposite case */ def validateToken(token: String): Boolean = { Jwt.isValid(token, secretKey, Seq(algorithm)) } /** - * Crea il token contenente l'username - * @param username username da inserire nel token - * @return il token da utilizzare nelle richieste + * Build the token from the username + * @param username username to encode + * @return the token to use in the request */ def encodeUsernameToken(username: String): Option[String] = { if (username == null) None @@ -58,9 +58,9 @@ object JwtUtils { } /** - * Dato un token lo decodifica e risale all'username - * @param token token da decodificare - * @return username dell'utente + * Get the username from the token + * @param token token to decode + * @return user's username */ def decodeUsernameToken(token: String): Option[String] = { decodeToken(token).map(decoded => new JsonObject(decoded.content).getString(USERNAME_FIELD_NAME)) From 1feffa985cca123122978a0e81b19cc83bbd2d71 Mon Sep 17 00:00:00 2001 From: Enrico Siboni Date: Tue, 21 Aug 2018 12:11:52 +0200 Subject: [PATCH 29/35] Solved bug introduced during code cleanUp --- .../it/cwmp/client/controller/actors/PlayerActor.scala | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/client/src/main/scala/it/cwmp/client/controller/actors/PlayerActor.scala b/client/src/main/scala/it/cwmp/client/controller/actors/PlayerActor.scala index 0dc743e6..20b8790d 100644 --- a/client/src/main/scala/it/cwmp/client/controller/actors/PlayerActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/PlayerActor.scala @@ -69,6 +69,7 @@ case class PlayerActor() extends Actor with Stash with Logging { roomSize = participants.size cluster.join(AddressFromURIString(participants.head.address)) // all join first player cluster if (getAddress == participants.head.address) { // first player injects start world + log.debug("First World injection by : " + getAddress) distributedState.initialize(worldGenerationStrategy(participants)) } playerName = participants.find(participant => participant.address == getAddress).get.username @@ -95,16 +96,11 @@ case class PlayerActor() extends Actor with Stash with Logging { * Starts the game */ private def startGame(): Unit = { - context.become(Actor.emptyBehavior) + context.become(distributedState.distributedStateBehaviour) gameViewActor ! ShowGUIWithName(playerName) unstashAll() // un-stash distributed change messages } - /** - * The action to do when the game is ended - */ - private def backToLobbyAction(): Unit = context.become(beforeInGameBehaviour orElse clusterBehaviour) - /** * Action that will be executed every time the world will be updated * From 165486935412c205c5cfd433585c545fab74d81b Mon Sep 17 00:00:00 2001 From: Enrico Siboni Date: Tue, 21 Aug 2018 12:36:36 +0200 Subject: [PATCH 30/35] Made Client ask for it's IP --- .../main/scala/it/cwmp/client/ClientMain.scala | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/client/src/main/scala/it/cwmp/client/ClientMain.scala b/client/src/main/scala/it/cwmp/client/ClientMain.scala index 6a9cd8b0..ae251921 100644 --- a/client/src/main/scala/it/cwmp/client/ClientMain.scala +++ b/client/src/main/scala/it/cwmp/client/ClientMain.scala @@ -6,7 +6,7 @@ import it.cwmp.client.controller.actors.{ApiClientActor, ClientControllerActor} import it.cwmp.services.wrapper.{AuthenticationApiWrapper, DiscoveryApiWrapper, RoomsApiWrapper} import it.cwmp.services.{VertxInstance, discovery} import it.cwmp.utils.{HostAndPortArguments, Logging} -import it.cwmp.view.OneAddressInput +import it.cwmp.view.TwoAddressesInput import scala.util.Failure @@ -16,6 +16,10 @@ import scala.util.Failure object ClientMain extends App with VertxInstance with Logging { val APP_NAME = "CellWarsClient" + val INITIAL_GUI_INSERTION_MESSAGE = + """First pair -> DiscoveryService host-port + |Second pair -> Your host IP, port will be ignored + """.stripMargin private val COMMAND_LINE_ARGUMENTS_ERROR = """ @@ -31,11 +35,15 @@ object ClientMain extends App with VertxInstance with Logging { launch(discoveryService._1, discoveryService._2) } catch { case _: IllegalArgumentException => - OneAddressInput(APP_NAME, "You should insert DiscoveryService host-port")(discoveryServiceHostPortPair => { - launch(discoveryServiceHostPortPair._1, discoveryServiceHostPortPair._2) + TwoAddressesInput(APP_NAME, INITIAL_GUI_INSERTION_MESSAGE)(discoveryAndMyHostPortPairs => { + val discoveryService = discoveryAndMyHostPortPairs._1 + val myHostIP = discoveryAndMyHostPortPairs._2._1 + + launch(discoveryService._1, discoveryService._2) }, _ => System.exit(0) - )(defaultPort = discovery.Service.DEFAULT_PORT.toString) + )(firstDefaultPort = discovery.Service.DEFAULT_PORT.toString, + secondDefaultPort = 0.toString) } /** From 38d650837ef6013d9c19d4c5b5c0bfef87a61e42 Mon Sep 17 00:00:00 2001 From: iugin Date: Tue, 21 Aug 2018 10:16:58 +0200 Subject: [PATCH 31/35] Rimosso logging dei contenuti delle risposte --- core/src/main/scala/it/cwmp/services/VertxServer.scala | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/core/src/main/scala/it/cwmp/services/VertxServer.scala b/core/src/main/scala/it/cwmp/services/VertxServer.scala index bb38cb1f..04164361 100644 --- a/core/src/main/scala/it/cwmp/services/VertxServer.scala +++ b/core/src/main/scala/it/cwmp/services/VertxServer.scala @@ -69,13 +69,10 @@ trait VertxServer extends ScalaVerticle { message: Option[String] = None) (implicit routingContext: RoutingContext): Unit = { response.setStatusCode(httpCode) + log.info(s"Sending $httpCode response to client") message match { - case Some(messageString) => - log.info(s"Sending $httpCode response to client with message: $messageString") - response.end(messageString) - case None => - log.info(s"Sending $httpCode response to client") - response.end() + case Some(messageString) => response.end(messageString) + case None => response.end() } } From 2d3bef59d536c43b53ec5b632cd700a6a3b9b7a8 Mon Sep 17 00:00:00 2001 From: iugin Date: Tue, 21 Aug 2018 13:07:30 +0200 Subject: [PATCH 32/35] Utilizzato ip in input per la configurazione del room-receiver nel client --- client/src/main/scala/it/cwmp/client/ClientMain.scala | 10 ++++++---- .../client/controller/ParticipantListReceiver.scala | 6 +++--- .../controller/actors/ClientControllerActor.scala | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/client/src/main/scala/it/cwmp/client/ClientMain.scala b/client/src/main/scala/it/cwmp/client/ClientMain.scala index ae251921..6d1df438 100644 --- a/client/src/main/scala/it/cwmp/client/ClientMain.scala +++ b/client/src/main/scala/it/cwmp/client/ClientMain.scala @@ -31,15 +31,16 @@ object ClientMain extends App with VertxInstance with Logging { try { val hostPortPairs = HostAndPortArguments(args, 1, COMMAND_LINE_ARGUMENTS_ERROR).pairs val discoveryService = hostPortPairs.head + val myHostIP = hostPortPairs(1)._1 - launch(discoveryService._1, discoveryService._2) + launch(discoveryService._1, discoveryService._2, myHostIP) } catch { case _: IllegalArgumentException => TwoAddressesInput(APP_NAME, INITIAL_GUI_INSERTION_MESSAGE)(discoveryAndMyHostPortPairs => { val discoveryService = discoveryAndMyHostPortPairs._1 val myHostIP = discoveryAndMyHostPortPairs._2._1 - launch(discoveryService._1, discoveryService._2) + launch(discoveryService._1, discoveryService._2, myHostIP) }, _ => System.exit(0) )(firstDefaultPort = discovery.Service.DEFAULT_PORT.toString, @@ -51,8 +52,9 @@ object ClientMain extends App with VertxInstance with Logging { * * @param discoveryHost the discovery to contact for services * @param discoveryPort the discovery port on which it listens + * @param myHost the host on which the client is executed */ - private def launch(discoveryHost: String, discoveryPort: String): Unit = { + private def launch(discoveryHost: String, discoveryPort: String, myHost: String): Unit = { val config = ConfigFactory.parseString("akka.remote.netty.tcp.port=0").withFallback(ConfigFactory.load()) val system = ActorSystem(APP_NAME, config) val discoveryApiWrapper: DiscoveryApiWrapper = DiscoveryApiWrapper(discoveryHost, discoveryPort.toInt) @@ -69,7 +71,7 @@ object ClientMain extends App with VertxInstance with Logging { AuthenticationApiWrapper(authenticationHost, authenticationPort), RoomsApiWrapper(roomsHost, roomsPort))), ApiClientActor.getClass.getName) log.info(s"Initializing the client controller actor...") - system.actorOf(Props(ClientControllerActor(apiClientActor)), ClientControllerActor.getClass.getName) + system.actorOf(Props(ClientControllerActor(apiClientActor, myHost)), ClientControllerActor.getClass.getName) log.info("Client up and running!") }) andThen { case Failure(ex) => log.info("Error discovering services", ex) diff --git a/client/src/main/scala/it/cwmp/client/controller/ParticipantListReceiver.scala b/client/src/main/scala/it/cwmp/client/controller/ParticipantListReceiver.scala index d4cd1a56..edc914a9 100644 --- a/client/src/main/scala/it/cwmp/client/controller/ParticipantListReceiver.scala +++ b/client/src/main/scala/it/cwmp/client/controller/ParticipantListReceiver.scala @@ -1,7 +1,5 @@ package it.cwmp.client.controller -import java.net.InetAddress - import it.cwmp.client.controller.ParticipantListReceiver.ADDRESS_TOKEN_LENGTH import it.cwmp.model.{Address, Participant} import it.cwmp.services.VertxInstance @@ -20,6 +18,8 @@ trait ParticipantListReceiver extends VertxInstance with Logging { private var deploymentID: Option[String] = None + protected def hostname: String + /** * Listens for a list of participants * @@ -31,7 +31,7 @@ trait ParticipantListReceiver extends VertxInstance with Logging { val verticle = RoomReceiverServiceVerticle(token, participants => onListReceived(participants)) vertx.deployVerticleFuture(verticle) .andThen { case Success(id) => deploymentID = id } - .map(_ => Address(s"http://${InetAddress.getLocalHost.getHostAddress}:${verticle.port}" + .map(_ => Address(s"http://$hostname:${verticle.port}" + createParticipantReceiverUrl(token))) } diff --git a/client/src/main/scala/it/cwmp/client/controller/actors/ClientControllerActor.scala b/client/src/main/scala/it/cwmp/client/controller/actors/ClientControllerActor.scala index 93590200..1d545834 100644 --- a/client/src/main/scala/it/cwmp/client/controller/actors/ClientControllerActor.scala +++ b/client/src/main/scala/it/cwmp/client/controller/actors/ClientControllerActor.scala @@ -29,7 +29,7 @@ import scala.util.{Failure, Success} * @author Eugenio Pierfederici * @author contributor Enrico Siboni */ -case class ClientControllerActor(private val apiClientActor: ActorRef) extends Actor with ParticipantListReceiver with Logging { +case class ClientControllerActor(private val apiClientActor: ActorRef, protected val hostname: String) extends Actor with ParticipantListReceiver with Logging { private val UNKNOWN_ERROR = "Unknown Error" From 745520e803891e581c3618f6856957ca95f9b6c3 Mon Sep 17 00:00:00 2001 From: Enrico Siboni Date: Tue, 21 Aug 2018 14:28:59 +0200 Subject: [PATCH 33/35] Solved a problem in merge function in distributed state implementation --- .../game/distributed/impl/MergingStateCellWorld.scala | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/client/src/main/scala/it/cwmp/client/model/game/distributed/impl/MergingStateCellWorld.scala b/client/src/main/scala/it/cwmp/client/model/game/distributed/impl/MergingStateCellWorld.scala index dc68f45b..ed5a5684 100644 --- a/client/src/main/scala/it/cwmp/client/model/game/distributed/impl/MergingStateCellWorld.scala +++ b/client/src/main/scala/it/cwmp/client/model/game/distributed/impl/MergingStateCellWorld.scala @@ -1,5 +1,6 @@ package it.cwmp.client.model.game.distributed.impl +import java.text.ParseException import java.time.Instant import akka.actor.Actor.Receive @@ -45,8 +46,14 @@ case class MergingStateCellWorld(onWorldUpdate: CellWorld => Unit)(implicit repl override protected def distributedModify(oldDistributedState: ORMultiMap[String, ReplicatedData], newState: CellWorld): ORMultiMap[String, ReplicatedData] = { - - val distributedInstant = LWWRegister[Instant](newState.instant) + val distributedInstant = LWWRegister[Instant]( + try { + val oldInstant = parseFromDistributed(oldDistributedState).instant + if (oldInstant.isBefore(newState.instant)) newState.instant else oldInstant + } catch { + case _: ParseException => newState.instant + } + ) val distributedCharacters = newState.characters.foldLeft(ORSet.empty[Cell])(_ + _) val distributedAttacks = newState.attacks.foldLeft(ORSet.empty[Tentacle])(_ + _) From 6f5ad15d9ed39cf9179e4c62cbc3b679cca800ca Mon Sep 17 00:00:00 2001 From: Enrico Siboni Date: Tue, 21 Aug 2018 14:56:37 +0200 Subject: [PATCH 34/35] Modified game constants to have better game-play --- .../scala/it/cwmp/client/controller/game/GameConstants.scala | 4 ++-- .../main/scala/it/cwmp/client/view/game/TentacleView.scala | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/src/main/scala/it/cwmp/client/controller/game/GameConstants.scala b/client/src/main/scala/it/cwmp/client/controller/game/GameConstants.scala index 9497a576..e39f1429 100644 --- a/client/src/main/scala/it/cwmp/client/controller/game/GameConstants.scala +++ b/client/src/main/scala/it/cwmp/client/controller/game/GameConstants.scala @@ -38,14 +38,14 @@ object GameConstants { * * Amount of time expressed in milliseconds that will be converted to a movement step of the tentacle */ - val MILLIS_TO_MOVEMENT_CONVERSION_RATE = 100 + val MILLIS_TO_MOVEMENT_CONVERSION_RATE = 50 /** * ==CellWorld== * * Amount of length that will be converted in one energy reduction in attacker cell */ - val LENGTH_TO_ENERGY_REDUCTION_RATE = 2d + val LENGTH_TO_ENERGY_REDUCTION_RATE = 4d /** * ==CellWorld== diff --git a/client/src/main/scala/it/cwmp/client/view/game/TentacleView.scala b/client/src/main/scala/it/cwmp/client/view/game/TentacleView.scala index d17bcb66..7ffd0b6a 100644 --- a/client/src/main/scala/it/cwmp/client/view/game/TentacleView.scala +++ b/client/src/main/scala/it/cwmp/client/view/game/TentacleView.scala @@ -30,7 +30,7 @@ object TentacleView { /** * Provides default value for tentacle thickness */ - val TENTACLE_DEFAULT_THICKNESS = 3d + val TENTACLE_DEFAULT_THICKNESS = 6d /** * Provides tentacle default color opacity From 265b963c034338c7f670c02063207a09d8ee8a9d Mon Sep 17 00:00:00 2001 From: iugin Date: Tue, 21 Aug 2018 18:02:06 +0200 Subject: [PATCH 35/35] Aggiornamento alla versione 8 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 37666d7a..0a755232 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ projectGroup = it.unibo.cwmp artifactId = cwmp -projectVersion = 0.0.7 +projectVersion = 0.0.8 longName = CellWars-MultiPlayer projectDescription = Cell Wars MultiPlayer - multiplayer game