Skip to content

Commit

Permalink
docs: add some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
manuandru committed Oct 14, 2023
1 parent 3edb1e6 commit 0f25c6b
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/main/scala/scatan/model/components/Award.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/scatan/model/components/Building.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions src/main/scala/scatan/model/components/DevelopmentCard.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@ package scatan.model.components

import scatan.model.game.config.ScatanPlayer

/** Type of possible development cards.
*/
enum DevelopmentType:
case Knight
case RoadBuilding
case YearOfPlenty
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:
Expand Down
6 changes: 6 additions & 0 deletions src/main/scala/scatan/model/components/ResourceCard.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@ package scatan.model.components

import scatan.model.game.config.ScatanPlayer

/** Type of possible resources.
*/
enum ResourceType:
case Wood
case Brick
case Sheep
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:
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/scatan/model/components/Terrain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ object Listable:
enum UnproductiveTerrain:
case Desert, Sea

/** All possible kind of terrains.
*/
type Terrain = ResourceType | UnproductiveTerrain
16 changes: 16 additions & 0 deletions src/main/scala/scatan/model/game/state/ops/BuildingOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/scatan/views/game/SetUpView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ object LeftTabComponent:
)
)

/** Displays the buttons to perform actions.
* @return
* the component
*/
def buttonsComponent: DisplayableSource[Element] =
div(
div(
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/scatan/views/utils/Coordinate.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
16 changes: 16 additions & 0 deletions src/main/scala/scatan/views/utils/TypeUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Expand Down

0 comments on commit 0f25c6b

Please sign in to comment.