Skip to content

Commit

Permalink
Merge pull request #96 from iuginP/develop
Browse files Browse the repository at this point in the history
Sprint 5 - closed
  • Loading branch information
siboxd authored Jul 30, 2018
2 parents 71c6d1b + d6a4622 commit 5f6a0e6
Show file tree
Hide file tree
Showing 104 changed files with 3,649 additions and 2,204 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fabric.properties
### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
*.iml
# modules.xml
# .idea/misc.xml
# *.ipr
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ env:
global:
- secure: "dRKFshApyl4AUJFX35C3GfeYoV7jFjZirDj9YbNMSegvEMf6eIiapdBP/GfnCYKmOCO9cuZU3p2hUHGNNZYRdDcuP12SlrCVfxDnLkqPgwuZKGm0T0yAsACVJZRD/uNfy5HMiCPMDyT+h9pqMlBj+LsCov46AlaQdmwS9luIjPWNA+Ter17javVpLLzsRH+8Vsh1UtiEk4seIHkhOlxQLaAEvoTr2kRrI048C3aVYY8hDIMNrK/OPiVwF+83ZeXbZL0Q9E+QnmXimAB/lS7VleW4DD1g4JI9NL3HHAJbe3yDHdwRb/fYLX/ZpT0MA0qgYSlxwT2hrpFYQa/HgRUN2jREpSLWxnfKd1QQYXuxTGQaI9WUd+j+8ppvvJZHqdqc8QGMRHrodtdYcDJhYk5Z1nOlkVux+Axt/x4o63RJtZ7dX8JTsHyFW415FhnK56iGfRTLe7aipYuepZcxeydWrEis8+hy7eVuPwxH0qiCHugHRlzyTJZLR9z6peXg0IeDpCULm4Wy7LX/xHSagk4CFbqHghzdMtcaCSn9q7ooFv5RWqHYEq+szAAl/usYN5MuN2g1ZD7T4BooWJdUbntELiLh4yBpAkFaW0VTN1A5N+UK/QdCzFG0Sl6VXYGxU3/93fgbhf7Q1v+Q/H7wc5GrGQy+4R425WCYXilOksFJkWk="
script:
- './gradlew'
- './gradlew clean build -x test javadoc scaladoc reportScoverage'
after_success:
- 'bash scripts/commit_and_upload.sh -r iuginP/pps-17-cw-mp -b master -s latest-docs/scala -d scala'
- 'bash scripts/commit_and_upload.sh -r iuginP/pps-17-cw-mp -b master -s latest-docs/java -d java'
Expand Down
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def scalaStyleOutputPath = "${buildDir.path}$scalaStyleOutput"
allprojects {
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: "com.dorongold.task-tree"

repositories {
// Repositories where to find libraries
Expand Down Expand Up @@ -112,6 +113,8 @@ buildscript {
}
}
dependencies {
classpath "gradle.plugin.com.dorongold.plugins:task-tree:1.3"

classpath "gradle.plugin.org.scoverage:gradle-scoverage:2.3.0"
classpath "gradle.plugin.com.github.maiflai:gradle-scalatest:0.22"

Expand All @@ -121,4 +124,4 @@ buildscript {
}
}

defaultTasks 'clean', 'build', 'javadoc', 'scaladoc', 'reportScoverage', 'shadowJar'
defaultTasks 'clean', 'build', 'javadoc', 'scaladoc', 'reportScoverage'
24 changes: 12 additions & 12 deletions client/src/main/resources/layouts/roomManagerLayout.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,26 @@
</font>
</Label>
<TextField GridPane.rowIndex="0" GridPane.columnIndex="1" id="pr_cr_roomName"
fx:id="pr_cr_roomName" layoutX="115.0" layoutY="28.0"/>
fx:id="tfPrivateCreateRoomName" layoutX="115.0" layoutY="28.0"/>
<Label GridPane.rowIndex="1" GridPane.columnIndex="0" layoutX="240.0"
layoutY="68.0" text="Numero dei giocatori">
<font>
<Font size="24.0"/>
</font>
</Label>
<Spinner fx:id="pr_cr_numPlayer" id="numPlayer" GridPane.rowIndex="1"
<Spinner fx:id="spPrivateCreateNumPlayer" id="numPlayer" GridPane.rowIndex="1"
GridPane.columnIndex="1">
<valueFactory>
<SpinnerValueFactory.IntegerSpinnerValueFactory min="2" max="4"/>
</valueFactory>
</Spinner>
<Button GridPane.rowIndex="4" GridPane.columnIndex="0"
<Button fx:id="btnPrivateCreate" GridPane.rowIndex="4" GridPane.columnIndex="0"
GridPane.halignment="CENTER" layoutX="111.0" layoutY="95.0"
mnemonicParsing="false" onAction="#onClickCreate" prefHeight="25.0"
mnemonicParsing="false" onAction="#onClickCreatePrivate" prefHeight="25.0"
prefWidth="70.0" text="Crea"/>
<Button GridPane.rowIndex="4" GridPane.columnIndex="0"
<Button fx:id="btnPrivateReset" GridPane.rowIndex="4" GridPane.columnIndex="0"
GridPane.halignment="RIGHT" layoutX="111.0" layoutY="95.0"
mnemonicParsing="false" onAction="#onClickReset" prefHeight="25.0"
mnemonicParsing="false" onAction="#onClickResetPrivate" prefHeight="25.0"
prefWidth="70.0" text="Reset"/>
</GridPane>
</TitledPane>
Expand All @@ -55,10 +55,10 @@
</font>
</Label>
<TextField GridPane.rowIndex="0" GridPane.columnIndex="1" id="pr_et_roomID"
fx:id="pr_et_roomID" layoutX="115.0" layoutY="28.0"/>
<Button GridPane.rowIndex="2" GridPane.columnIndex="0"
fx:id="tfPrivateEnterRoomID" layoutX="115.0" layoutY="28.0"/>
<Button fx:id="btnPrivateEnter" GridPane.rowIndex="2" GridPane.columnIndex="0"
GridPane.halignment="RIGHT" layoutX="111.0" layoutY="95.0"
mnemonicParsing="false" onAction="#onClickEnter" prefHeight="25.0"
mnemonicParsing="false" onAction="#onClickEnterPrivate" prefHeight="25.0"
prefWidth="70.0" text="Entra"/>
</GridPane>
</TitledPane>
Expand All @@ -69,15 +69,15 @@
<!-- Pane per entrare in una stanza pubblica -->
<!-- Contenuto pane -->
<GridPane hgap="30" vgap="10" alignment="TOP_CENTER">
<Spinner fx:id="pub_et_numPlayer" id="numPlayer" GridPane.rowIndex="1"
<Spinner fx:id="spPublicEnterNumPlayer" id="numPlayer" GridPane.rowIndex="1"
GridPane.columnIndex="1">
<valueFactory>
<SpinnerValueFactory.IntegerSpinnerValueFactory min="2" max="4"/>
</valueFactory>
</Spinner>
<Button GridPane.rowIndex="1" GridPane.columnIndex="2"
<Button fx:id="btnPublicEnter" GridPane.rowIndex="1" GridPane.columnIndex="2"
GridPane.halignment="CENTER" layoutX="111.0" layoutY="95.0"
mnemonicParsing="false" onAction="#onClickRoomPublic" prefHeight="25.0"
mnemonicParsing="false" onAction="#onClickEnterPublic" prefHeight="25.0"
text="Entra" />
</GridPane>
</VBox>
Expand Down
7 changes: 4 additions & 3 deletions client/src/main/scala/it/cwmp/client/ClientMain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import akka.actor.{ActorSystem, Props}
import com.typesafe.config.ConfigFactory
import it.cwmp.client.controller.ClientControllerActor

/**
* The client entry point
*/
object ClientMain extends App {
val APP_NAME = "ClientApp"
val APP_NAME = "CellWarsClient"

private val config = ConfigFactory.parseString("akka.remote.netty.tcp.port=0").withFallback(ConfigFactory.load())

val system = ActorSystem(APP_NAME, config)

val clientControllerActor = system.actorOf(Props(classOf[ClientControllerActor], system), ClientControllerActor.getClass.getName)
}
2 changes: 1 addition & 1 deletion client/src/main/scala/it/cwmp/client/GameMain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object GameMain extends App {

val system = ActorSystem(APP_NAME, config)

val gameActor = system.actorOf(Props(classOf[GameViewActor]), GameViewActor.getClass.getName)
val gameActor = system.actorOf(Props(classOf[GameViewActor], null), GameViewActor.getClass.getName)

import GameViewActor._

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package it.cwmp.client.controller

import akka.actor.Actor.Receive
import it.cwmp.client.controller.AlertMessages._
import it.cwmp.client.view.FXAlertsController

/**
* A trait that gives autonomous management of alert messages;
*
* To use it you need to add "alertBehaviour" to your Actor receive
*
* @author Eugenio Pierfederici
* @author contributor Enrico Siboni
*/
trait ActorAlertManagement {

/**
* @return the alerts controller
*/
protected def fxController: FXAlertsController

/**
* @return the behaviour that manages alert messages
*/
protected def alertBehaviour: Receive = {
case Info(title, message) => onInfoAlertReceived(title, message)
case Error(title, message) => onErrorAlertReceived(title, message)
}

/**
* Called when a info alert is received
*
* @param title the title of the info
* @param message the message of the info
*/
protected def onInfoAlertReceived(title: String, message: String): Unit =
fxController showInfo(title, message)

/**
* Called when an error alert is received
*
* @param title the title of the error
* @param message the message of the error
*/
protected def onErrorAlertReceived(title: String, message: String): Unit =
fxController showError(title, message)
}

/**
* A collection of AlertMessages
*/
object AlertMessages {

/**
* Tells to show info message
*
* @param title the title
* @param message the message
*/
case class Info(title: String, message: String)

/**
* Tells to show an error message
*
* @param title the title
* @param message the message
*/
case class Error(title: String, message: String)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package it.cwmp.client.controller

import akka.actor.Actor.Receive
import it.cwmp.client.controller.ViewVisibilityMessages.{Hide, Show}
import it.cwmp.client.view.{FXRunOnUIThread, FXViewController}

/**
* A trait that give autonomous management to view visibility
*
* To use it you need to add "visibilityBehaviour" to your Actor receive
*
* @author Enrico Siboni
*/
trait ActorViewVisibilityManagement extends FXRunOnUIThread {

/**
* @return the visibility controller
*/
protected def fxController: FXViewController

/**
* @return the behaviour that manages alert messages
*/
protected def visibilityBehaviour: Receive = {
case Show => onShowGUI()
case Hide => onHideGUI()
}

/**
* Called when GUI is shown
*/
protected def onShowGUI(): Unit = runOnUIThread(() => fxController showGUI())

/**
* Called when GUI is hidden
*/
protected def onHideGUI(): Unit = runOnUIThread(() => fxController hideGUI())
}


/**
* A collection of view visibility messages
*/
object ViewVisibilityMessages {

/**
* Shows the underlying graphical interface
*/
case object Show

/**
* Hides the underlying graphical interface
*/
case object Hide

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package it.cwmp.client.controller

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.{ServiceCreate, ServiceEnterPrivate, ServiceEnterPublic}
import it.cwmp.client.controller.messages.RoomsResponses._
import it.cwmp.services.wrapper.{AuthenticationApiWrapper, RoomsApiWrapper}
import it.cwmp.utils.Utils.stringToOption

import scala.concurrent.ExecutionContext.Implicits.global
import scala.language.implicitConversions
import scala.util.{Failure, Success, Try}

/**
* A class that implements the actor that will manage communications with services APIs
*/
case class ApiClientActor() extends Actor {

override def receive: Receive = authenticationBehaviour orElse roomsBehaviour

/**
* @return the behaviour of authenticating user online
*/
private def authenticationBehaviour: Receive = {
val authenticationApiWrapper = AuthenticationApiWrapper()
//noinspection ScalaStyle
import authenticationApiWrapper._
{
case LogIn(username, password) =>
val senderTmp = sender
login(username, password).onComplete(replyWith(
token => senderTmp ! LogInSuccess(token),
exception => senderTmp ! LogInFailure(exception.getMessage)
))
case SignUp(username, password) =>
val senderTmp = sender
signUp(username, password).onComplete(replyWith(
token => senderTmp ! SignUpSuccess(token),
exception => senderTmp ! SignUpFailure(exception.getMessage)
))
}
}

/**
* @return the behaviour of managing the rooms online
*/
private def roomsBehaviour: Receive = {
val roomApiWrapper = RoomsApiWrapper()
//noinspection ScalaStyle
import roomApiWrapper._
{
case ServiceCreate(roomName, playersNumber, token) =>
val senderTmp = sender
createRoom(roomName, playersNumber)(token).onComplete(replyWith(
token => senderTmp ! CreateSuccess(token),
exception => senderTmp ! CreateFailure(exception.getMessage)
))
case ServiceEnterPrivate(idRoom, address, webAddress, token) =>
val senderTmp = sender
enterRoom(idRoom, address, webAddress)(token).onComplete(replyWith(
_ => senderTmp ! EnterPrivateSuccess,
exception => senderTmp ! EnterPrivateFailure(exception.getMessage)
))
case ServiceEnterPublic(nPlayer, address, webAddress, token) =>
val senderTmp = sender
enterPublicRoom(nPlayer, address, webAddress)(token).onComplete(replyWith(
_ => senderTmp ! EnterPublicSuccess,
exception => senderTmp ! EnterPublicFailure(exception.getMessage)
))
}
}

/**
* A utility method to match Success or failure of a try and do something with results
*
* @param onSuccess the action to do on success
* @param onFailure the action to do on failure
* @param toCheck the try to check
* @tparam T the type of the result if present
*/
private def replyWith[T](onSuccess: => T => Unit, onFailure: => Throwable => Unit)
(toCheck: Try[T]): Unit = toCheck match {
case Success(value) => onSuccess(value)
case Failure(ex) => onFailure(ex)
}
}
Loading

0 comments on commit 5f6a0e6

Please sign in to comment.