diff --git a/src/main/scala/scatan/model/components/Award.scala b/src/main/scala/scatan/model/components/Award.scala index 9a5bf06..f9e35dc 100644 --- a/src/main/scala/scatan/model/components/Award.scala +++ b/src/main/scala/scatan/model/components/Award.scala @@ -2,12 +2,18 @@ package scatan.model.components import scatan.model.game.config.ScatanPlayer +/** Type of possible awards. + */ enum AwardType: case LongestRoad case LargestArmy +/** An award + */ final case class Award(awardType: AwardType) +/** The assigned awards to the current holder player and the number of points. + */ type Awards = Map[Award, Option[(ScatanPlayer, Int)]] object Awards: diff --git a/src/main/scala/scatan/model/components/Building.scala b/src/main/scala/scatan/model/components/Building.scala index 533f700..cbc232e 100644 --- a/src/main/scala/scatan/model/components/Building.scala +++ b/src/main/scala/scatan/model/components/Building.scala @@ -14,6 +14,8 @@ type Cost = Map[ResourceType, Int] object Cost: def apply(resourceCosts: ResourceCost*): Cost = resourceCosts.toMap +/** A building type and its cost. + */ enum BuildingType(val cost: Cost): case Settlement extends BuildingType( diff --git a/src/main/scala/scatan/model/components/DevelopmentCard.scala b/src/main/scala/scatan/model/components/DevelopmentCard.scala index eeb34e9..6a40daa 100644 --- a/src/main/scala/scatan/model/components/DevelopmentCard.scala +++ b/src/main/scala/scatan/model/components/DevelopmentCard.scala @@ -2,6 +2,8 @@ package scatan.model.components import scatan.model.game.config.ScatanPlayer +/** Type of possible development cards. + */ enum DevelopmentType: case Knight case RoadBuilding @@ -9,12 +11,16 @@ enum DevelopmentType: case Monopoly case VictoryPoint +/** A development card. + */ final case class DevelopmentCard( developmentType: DevelopmentType, drewAt: Option[Int] = None, played: Boolean = false ) +/** The development cards hold by the players. + */ type DevelopmentCards = Map[ScatanPlayer, Seq[DevelopmentCard]] object DevelopmentCards: diff --git a/src/main/scala/scatan/model/components/ResourceCard.scala b/src/main/scala/scatan/model/components/ResourceCard.scala index 0beac3e..3cb542d 100644 --- a/src/main/scala/scatan/model/components/ResourceCard.scala +++ b/src/main/scala/scatan/model/components/ResourceCard.scala @@ -2,6 +2,8 @@ package scatan.model.components import scatan.model.game.config.ScatanPlayer +/** Type of possible resources. + */ enum ResourceType: case Wood case Brick @@ -9,10 +11,14 @@ enum ResourceType: case Wheat case Rock +/** A resource card. + */ final case class ResourceCard(resourceType: ResourceType) extension (card: ResourceCard) def **(amount: Int): Seq[ResourceCard] = Seq.fill(amount)(card) +/** The resource cards hold by the players. + */ type ResourceCards = Map[ScatanPlayer, Seq[ResourceCard]] object ResourceCards: diff --git a/src/main/scala/scatan/model/components/Terrain.scala b/src/main/scala/scatan/model/components/Terrain.scala index 499b43a..8ecc854 100644 --- a/src/main/scala/scatan/model/components/Terrain.scala +++ b/src/main/scala/scatan/model/components/Terrain.scala @@ -17,4 +17,6 @@ object Listable: enum UnproductiveTerrain: case Desert, Sea +/** All possible kind of terrains. + */ type Terrain = ResourceType | UnproductiveTerrain diff --git a/src/main/scala/scatan/model/game/state/ops/BuildingOps.scala b/src/main/scala/scatan/model/game/state/ops/BuildingOps.scala index 6f50423..163eef8 100644 --- a/src/main/scala/scatan/model/game/state/ops/BuildingOps.scala +++ b/src/main/scala/scatan/model/game/state/ops/BuildingOps.scala @@ -109,10 +109,26 @@ object BuildingOps: else None case _ => None + /** The default rules for building a settlement. + * @param spot + * the spot where to build + * @param player + * the player that want to build + * @return + * true if the player can build a settlement on the spot, false otherwise + */ private def defaultRulesForSettlementBuilding(spot: StructureSpot, player: ScatanPlayer): Boolean = state.emptyStructureSpots.contains(spot) && state.gameMap.neighboursOf(spot).flatMap(state.assignedBuildings.get).isEmpty + /** The default rules for building a road. + * @param spot + * the spot where to build + * @param player + * the player that want to build + * @return + * true if the player can build a road on the spot, false otherwise + */ private def defaultRulesForRoadBuilding(spot: RoadSpot, player: ScatanPlayer): Boolean = val structureSpot1 = spot._1 val structureSpot2 = spot._2 diff --git a/src/main/scala/scatan/views/game/SetUpView.scala b/src/main/scala/scatan/views/game/SetUpView.scala index 42c5b03..49b188d 100644 --- a/src/main/scala/scatan/views/game/SetUpView.scala +++ b/src/main/scala/scatan/views/game/SetUpView.scala @@ -38,7 +38,7 @@ private class ScalaJsSetUpView(container: String, requirements: View.Requirement val mapSelectionMode: Var[MapSelectionMode] = Var(MapSelectionMode.Default) val reactiveGameMap: Var[GameMap] = Var(GameMapFactory.defaultMap) - def changeMap: Unit = + private def changeMap: Unit = mapSelectionMode.now() match case Default => reactiveGameMap.set(GameMapFactory.defaultMap) diff --git a/src/main/scala/scatan/views/game/components/GameViewClickHandler.scala b/src/main/scala/scatan/views/game/components/GameViewClickHandler.scala index d42b288..ae354b4 100644 --- a/src/main/scala/scatan/views/game/components/GameViewClickHandler.scala +++ b/src/main/scala/scatan/views/game/components/GameViewClickHandler.scala @@ -14,17 +14,64 @@ import scatan.views.game.GameView import scatan.views.game.components.CardContextMap.CardType trait GameViewClickHandler: + /** Handles a click on a road spot. + * @param roadSpot + * the road spot that was clicked + */ def onRoadClick(roadSpot: RoadSpot): Unit + + /** Handles a click on a structure spot. + * @param roadSpot + * the structure spot that was clicked + */ def onStructureClick(structureSpot: StructureSpot): Unit + + /** Handles a click on an hexagon. + * @param roadSpot + * the hexagon that was clicked + */ def onHexagonClick(hexagon: Hexagon): Unit + /** Handles a click on the roll dice button. + */ def onRollDiceClick(): Unit + + /** Handles a click on the buy development card button. + */ def onBuyDevelopmentCardClick(): Unit + + /** Handles a click on the end turn button. + */ def onEndTurnClick(): Unit + + /** Handles a click on the steal card button. + * @param player + * the player to steal a card from + */ def onStealCardClick(player: ScatanPlayer): Unit + /** Handles a click on a card. + * @param cardType + * the card that was clicked + */ def onCardClick(cardType: CardType): Unit + + /** Handles a click on the trade with bank button. + * @param offer + * the resource type to offer + * @param request + * the resource type to request + */ def onTradeWithBank(offer: ResourceType, request: ResourceType): Unit + + /** Handles a click on the trade with player button. + * @param receiver + * the player to trade with + * @param offer + * the resource type to offer + * @param request + * the resource type to request + */ def onTradeWithPlayer( receiver: ScatanPlayer, offer: Map[ResourceType, Int], diff --git a/src/main/scala/scatan/views/game/components/LeftTabComponent.scala b/src/main/scala/scatan/views/game/components/LeftTabComponent.scala index 1eccd1e..572d133 100644 --- a/src/main/scala/scatan/views/game/components/LeftTabComponent.scala +++ b/src/main/scala/scatan/views/game/components/LeftTabComponent.scala @@ -55,6 +55,10 @@ object LeftTabComponent: ) ) + /** Displays the buttons to perform actions. + * @return + * the component + */ def buttonsComponent: DisplayableSource[Element] = div( div( diff --git a/src/main/scala/scatan/views/utils/Coordinate.scala b/src/main/scala/scatan/views/utils/Coordinate.scala index 8365348..e92a588 100644 --- a/src/main/scala/scatan/views/utils/Coordinate.scala +++ b/src/main/scala/scatan/views/utils/Coordinate.scala @@ -3,6 +3,7 @@ package scatan.views.utils import scatan.model.map.{Hexagon, StructureSpot} /** @param value + * the value of the double to wrap. */ final case class DoubleWithPrecision(value: Double): override def equals(x: Any): Boolean = diff --git a/src/main/scala/scatan/views/utils/TypeUtils.scala b/src/main/scala/scatan/views/utils/TypeUtils.scala index ce5ef54..e176015 100644 --- a/src/main/scala/scatan/views/utils/TypeUtils.scala +++ b/src/main/scala/scatan/views/utils/TypeUtils.scala @@ -6,12 +6,28 @@ import scatan.model.game.state.ScatanState import scatan.views.game.components.GameViewClickHandler import scatan.views.viewmodel.{GameViewModel, ScatanViewModel} +/** Utils of types that can be useful in views. + */ object TypeUtils: + /** A type that can be displayed in the view. + */ type Displayable[T] = ScatanViewModel ?=> T + + /** A type can be clicked. + */ type InputSource[T] = GameViewClickHandler ?=> T + + /** A type that can be displayed in the view and clicked. + */ type DisplayableSource[T] = Displayable[InputSource[T]] + + /** A type bring the knowledge of the game state. + */ type GameStateKnowledge[T] = ScatanState ?=> T + + /** A type can be clicked enriched by the knowledge of the game state. + */ type InputSourceWithState[T] = InputSource[GameStateKnowledge[T]] private[views] def reactiveState(using Signal[ApplicationState]): Signal[ApplicationState] =