Created
April 29, 2022 15:28
-
-
Save sjrd/c57a9f08ab6938ffe53c4465ac71cbf3 to your computer and use it in GitHub Desktop.
Introducing fewerBraces in an application codebase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/main/scala/be/doeraene/barrage/Barrage.scala b/src/main/scala/be/doeraene/barrage/Barrage.scala | |
index 74a0904..c08a44d 100644 | |
--- a/src/main/scala/be/doeraene/barrage/Barrage.scala | |
+++ b/src/main/scala/be/doeraene/barrage/Barrage.scala | |
@@ -307,9 +307,8 @@ final class Barrage(networkBridge: NetworkBridge, gameConfiguration: GameConfigu | |
) | |
private val companyEngineerGraphics: Map[Company, Graphic[Material.Bitmap]] = | |
- companyEngineerAssetNames.transform { (company, assetName) => | |
+ companyEngineerAssetNames.transform (company, assetName) => | |
Graphic(20, 30, Material.Bitmap(companyEngineerAssetNames(company))) | |
- } | |
private val victoryPointsGraphic: Graphic[Material.Bitmap] = Graphic(30, 30, Material.Bitmap(victoryPointsAssetName)) | |
private val energyGraphic: Graphic[Material.Bitmap] = Graphic(30, 30, Material.Bitmap(energyAssetName)) | |
@@ -521,9 +520,8 @@ final class Barrage(networkBridge: NetworkBridge, gameConfiguration: GameConfigu | |
caseSensitive = true | |
) | |
- maybeFontInfo.getOrElse { | |
+ maybeFontInfo.getOrElse: | |
throw new IllegalArgumentException(s"cannot build font $fontKey") | |
- } | |
end buildFontInfo | |
def buildDigitsFontInfo(fontKey: FontKey): FontInfo = | |
@@ -570,18 +568,16 @@ final class Barrage(networkBridge: NetworkBridge, gameConfiguration: GameConfigu | |
Outcome(model) | |
case GameInterfaceElementClick(element) => | |
- element.applyTo(model).toOutcome(model).createGlobalEvents { newModel => | |
+ element.applyTo(model).toOutcome(model).createGlobalEvents newModel => | |
if newModel eq model then | |
Nil | |
else | |
val send = NetworkSubSystem.NetworkEvent.Send(NetworkBridge.Message.GameInterfaceElementClick(element)) | |
send :: updateActiveCompanyEvent(model, newModel) | |
- } | |
case NetworkSubSystem.NetworkEvent.Receive(NetworkBridge.Message.GameInterfaceElementClick(element)) => | |
- element.applyTo(model).toOutcome(model).createGlobalEvents { newModel => | |
+ element.applyTo(model).toOutcome(model).createGlobalEvents newModel => | |
updateActiveCompanyEvent(model, newModel) | |
- } | |
case _ => | |
Outcome(model) | |
@@ -810,7 +806,7 @@ final class Barrage(networkBridge: NetworkBridge, gameConfiguration: GameConfigu | |
val reserveTiles = companyProps.technologyTiles.zipWithIndex | |
.filter(t => !removedTile.contains(t._1)) | |
- .flatMap { (tile, index) => | |
+ .flatMap (tile, index) => | |
val topLeft = | |
Point(0, 60) | |
+ Point(technologyTileSpace.width * (index % 4), technologyTileSpace.height * (index / 4)) | |
@@ -825,13 +821,11 @@ final class Barrage(networkBridge: NetworkBridge, gameConfiguration: GameConfigu | |
List(tileG, highlightBox) | |
else | |
List(tileG) | |
- } | |
end reserveTiles | |
- val contracts = companyProps.contracts.zipWithIndex.map { (contract, index) => | |
+ val contracts = companyProps.contracts.zipWithIndex.map (contract, index) => | |
drawContract(model, viewModel, contract) | |
.moveTo(contractSpace.width * index, 150) | |
- } | |
val wheelPosition = Point(450, 0) | |
val wheelRadius = 210 / 2 | |
@@ -991,10 +985,9 @@ final class Barrage(networkBridge: NetworkBridge, gameConfiguration: GameConfigu | |
List(iconG, countT) | |
end fulfilledContractsNodes | |
- val tempXOAbility = companyProps.temporaryExecutiveOfficerForMahiriSekibo.toList.map { tempOfficer => | |
+ val tempXOAbility = companyProps.temporaryExecutiveOfficerForMahiriSekibo.toList.map tempOfficer => | |
drawExecutiveOfficer(model, viewModel, tempOfficer, RGBA.White) | |
.moveBy(executiveOfficerArea.topLeft.moveBy(0, -60)) | |
- } | |
val xoAbility = | |
drawExecutiveOfficer(model, viewModel, executiveOfficer, RGBA.White) | |
@@ -1085,9 +1078,8 @@ final class Barrage(networkBridge: NetworkBridge, gameConfiguration: GameConfigu | |
case _ => | |
val rewards = company.incomeBoard.get((structureKind, rowCount)).getOrElse(Nil) | |
val positions = incomeRewardPositionsByCount(rewards.size) | |
- rewards.zip(positions).map { (reward, pos) => | |
+ rewards.zip(positions).map (reward, pos) => | |
drawReward(reward, center + pos) | |
- } | |
end bonusContent | |
bgRect :: bonusContent | |
@@ -1129,19 +1121,17 @@ final class Barrage(networkBridge: NetworkBridge, gameConfiguration: GameConfigu | |
val negOffset = actionBoardArea.topLeft * -1 | |
- val nationalContracts = model.nationalContractSpaces.toList.flatMap { (space, optContract) => | |
+ val nationalContracts = model.nationalContractSpaces.toList.flatMap (space, optContract) => | |
for contract <- optContract.toList yield | |
drawContract(model, viewModel, contract) | |
.moveTo(viewModel.componentCoords(space).topLeft) | |
.moveBy(negOffset) | |
- } | |
- val privateContracts = model.privateContractSpaces.toList.flatMap { (space, optContract) => | |
+ val privateContracts = model.privateContractSpaces.toList.flatMap (space, optContract) => | |
for contract <- optContract.toList yield | |
drawContract(model, viewModel, contract) | |
.moveTo(viewModel.componentCoords(space).topLeft) | |
.moveBy(negOffset) | |
- } | |
board :: nationalContracts ::: privateContracts | |
end drawContractBoard | |
@@ -1152,12 +1142,11 @@ final class Barrage(networkBridge: NetworkBridge, gameConfiguration: GameConfigu | |
val negOffset = actionBoardArea.topLeft * -1 | |
- val patents = model.patentSpaces.toList.flatMap { (space, optPatent) => | |
+ val patents = model.patentSpaces.toList.flatMap (space, optPatent) => | |
for patent <- optPatent.toList yield | |
Graphic(Rectangle(technologyTileSize), Material.Bitmap(technologyTileAssetNames(patent))) | |
.moveTo(viewModel.componentCoords(space).topLeft) | |
.moveBy(negOffset) | |
- } | |
board :: patents | |
end drawPatentBoard | |
@@ -1350,9 +1339,8 @@ final class Barrage(networkBridge: NetworkBridge, gameConfiguration: GameConfigu | |
.moveTo(20, 28) | |
val rewardPositions = contractRewardPositionsByCount(contract.rewards.size) | |
- val rewardIcons = contract.rewards.zip(rewardPositions).map { (reward, pos) => | |
+ val rewardIcons = contract.rewards.zip(rewardPositions).map (reward, pos) => | |
drawReward(reward, pos) | |
- } | |
Group(background :: requiredEnergyText :: rewardIcons) | |
end drawContract | |
@@ -1487,10 +1475,9 @@ final class Barrage(networkBridge: NetworkBridge, gameConfiguration: GameConfigu | |
.withRefAtCenter | |
allDrops.flatMap { case (position, (count, highlightedCount)) => | |
- (1 to count).map { i => | |
+ (1 to count).map i => | |
val g = if i > count - highlightedCount then highlightedG else regularG | |
g.moveTo(position.x + 10 * i - 5 * count, position.y) | |
- } | |
} | |
end drawWaterDrops | |
@@ -1742,7 +1729,7 @@ final class Barrage(networkBridge: NetworkBridge, gameConfiguration: GameConfigu | |
end drawMainButtons | |
def drawOccupiedActions(model: BarrageModel, viewModel: BarrageViewModel): List[SceneNode] = | |
- model.occupiedActions.toList.flatMap { (action, company) => | |
+ model.occupiedActions.toList.flatMap (action, company) => | |
viewModel.componentCoords.get(action) match | |
case Some(actionRect) => | |
val engineers = action.engineers | |
@@ -1754,7 +1741,6 @@ final class Barrage(networkBridge: NetworkBridge, gameConfiguration: GameConfigu | |
case None => | |
// This action is currently not displayed | |
Nil | |
- } | |
end drawOccupiedActions | |
def drawEngineersOnBankAction(model: BarrageModel, viewModel: BarrageViewModel): List[SceneNode] = | |
@@ -1764,12 +1750,11 @@ final class Barrage(networkBridge: NetworkBridge, gameConfiguration: GameConfigu | |
val offset = 5 | |
val width = 20 + offset * (count - 1) | |
val leftMost = actionRect.center.moveBy(-width / 2, 0) | |
- model.engineersOnBankAction.zipWithIndex.map { (company, index) => | |
+ model.engineersOnBankAction.zipWithIndex.map (company, index) => | |
val assetName = companyEngineerAssetNames(company) | |
Graphic(20, 30, Material.Bitmap(assetName)) | |
.withRef(0, 15) | |
.moveTo(leftMost + Point(offset * index, 0)) | |
- } | |
case None => | |
// This action is currently not displayed | |
Nil | |
diff --git a/src/main/scala/be/doeraene/barrage/BarrageViewModel.scala b/src/main/scala/be/doeraene/barrage/BarrageViewModel.scala | |
index dcecf6c..4477e5b 100644 | |
--- a/src/main/scala/be/doeraene/barrage/BarrageViewModel.scala | |
+++ b/src/main/scala/be/doeraene/barrage/BarrageViewModel.scala | |
@@ -167,7 +167,7 @@ object BarrageViewModel: | |
private def filterComponentCoords(allComponentCoords: ComponentCoordsMap, | |
activeCompany: Company, activeCompanyBoardTab: CompanyBoardTab, | |
activeActionBoardTab: ActionBoardTab): ComponentCoordsMap = | |
- allComponentCoords.filter { (key, coords) => | |
+ allComponentCoords.filter (key, coords) => | |
key match | |
case component: Component => | |
true | |
@@ -183,7 +183,6 @@ object BarrageViewModel: | |
activeActionBoardTab == ActionBoardTab.PatentBoard | |
case _: Action => | |
activeActionBoardTab == ActionBoardTab.ActionBoard | |
- } | |
private def buildHitBoxes(componentCoords: ComponentCoordsMap, | |
mapDescription: MapDescription): List[(Rectangle, ComponentKey)] = | |
diff --git a/src/main/scala/be/doeraene/barrage/NetworkSubSystem.scala b/src/main/scala/be/doeraene/barrage/NetworkSubSystem.scala | |
index 7ba60a9..5e396c8 100644 | |
--- a/src/main/scala/be/doeraene/barrage/NetworkSubSystem.scala | |
+++ b/src/main/scala/be/doeraene/barrage/NetworkSubSystem.scala | |
@@ -17,9 +17,8 @@ final case class NetworkSubSystem(bridge: NetworkBridge) extends SubSystem: | |
private val eventQueue: mutable.Queue[NetworkEvent.Receive] = | |
new mutable.Queue[NetworkEvent.Receive]() | |
- bridge.registerReceiver { message => | |
+ bridge.registerReceiver message => | |
eventQueue.enqueue(NetworkEvent.Receive(message)) | |
- } | |
def eventFilter: GlobalEvent => Option[EventType] = | |
case FrameTick => Some(NetworkSubSystemEnqueue) | |
diff --git a/src/main/scala/be/doeraene/barrage/mainui/Main.scala b/src/main/scala/be/doeraene/barrage/mainui/Main.scala | |
index c7a658b..92c9563 100644 | |
--- a/src/main/scala/be/doeraene/barrage/mainui/Main.scala | |
+++ b/src/main/scala/be/doeraene/barrage/mainui/Main.scala | |
@@ -81,9 +81,8 @@ object ServerState: | |
case (ConstructingGame(clients), | |
PeerEvent.ConnectionMessageEvent(connection, Messages.SetDisplayName(setDisplayName))) => | |
- val newClients = clients.updatedWith(connection.uuid) { optClientInfo => | |
+ val newClients = clients.updatedWith(connection.uuid) optClientInfo => | |
optClientInfo.map(_.copy(displayName = setDisplayName.displayName)) | |
- } | |
ConstructingGame(newClients) | |
case (ConstructingGame(clients), UIEvent.KickClient(uuid)) => | |
@@ -116,14 +115,14 @@ object ServerState: | |
do | |
val playerCount0 = playerCount | |
val rngSeed0 = rngSeed | |
- connection.send(new Messages.StartGame { | |
+ connection.send(new Messages.StartGame: | |
val messageType = "start-game" | |
val introductoryRules = gameConfiguration.introductoryRules | |
val playerCount = playerCount0 | |
val rngSeed = rngSeed0 | |
val controllerIndex = clientInfo.controllerIndex | |
val replay = js.Array() | |
- }) | |
+ ) | |
RunningGame(newClients, gameConfiguration, rngSeed, initialModel, Nil, initialModel) | |
@@ -168,14 +167,14 @@ object ServerState: | |
println("unknown client asks for replay") | |
state | |
case Some(clientInfo) => | |
- sender.send(new Messages.StartGame { | |
+ sender.send(new Messages.StartGame: | |
val messageType = "start-game" | |
val introductoryRules = gameConfiguration.introductoryRules | |
val playerCount = clients.size | |
val rngSeed = rngSeed0 | |
val controllerIndex = clientInfo.controllerIndex | |
val replay = inputHistory.map(Messages.serializeGameMessage(_)).toJSArray | |
- }) | |
+ ) | |
state | |
case (RunningGame(clients, gameConfiguration, rngSeed, initialModel, inputHistory, gameModel), | |
@@ -230,10 +229,10 @@ object ClientState: | |
def send(message: NetworkBridge.Message): Unit = | |
val serialized = Messages.serializeGameMessage(message) | |
- server.send(new Messages.GameMessage { | |
+ server.send(new Messages.GameMessage: | |
val messageType = "game-message" | |
val message = serialized | |
- }) | |
+ ) | |
end Bridge | |
def update(state: ClientState, event: NetworkOrUIEvent, gameConfigToApply: Var[Option[FullGameConfig]]): ClientState = | |
@@ -242,16 +241,16 @@ object ClientState: | |
ClientState.Exit | |
case (ConnectingToServer, PeerEvent.ConnectionOpen(server)) => | |
- server.send(new Messages.AskForReplay { | |
+ server.send(new Messages.AskForReplay: | |
val messageType = "ask-for-replay" | |
- }) | |
+ ) | |
ConstructingGame(server) | |
case (ConstructingGame(server), UIEvent.SetDisplayName(displayName0)) => | |
- server.send(new Messages.SetDisplayName { | |
+ server.send(new Messages.SetDisplayName: | |
val messageType = "set-display-name" | |
val displayName = displayName0 | |
- }) | |
+ ) | |
state | |
case (ConstructingGame(server), UIEvent.Leave) => | |
@@ -313,7 +312,7 @@ object Main: | |
val gameConfigToApply: Var[Option[FullGameConfig]] = Var(None) | |
- val networkMode: Signal[Mode] = allEvents.foldLeft(Mode.Undecided) { (mode, event) => | |
+ val networkMode: Signal[Mode] = allEvents.foldLeft(Mode.Undecided) (mode, event) => | |
val mode1 = (mode, event) match | |
case (Mode.Undecided, UIEvent.StartServer) => | |
Mode.Server(ServerState.initial()) | |
@@ -340,14 +339,12 @@ object Main: | |
Mode.Undecided | |
case _ => | |
mode1 | |
- } | |
def gameConfigurationComponent(): (Div, Signal[GameConfiguration]) = | |
val gameConfiguration: Var[GameConfiguration] = Var(GameConfiguration.Default) | |
- val introductoryRulesUpdater = gameConfiguration.updater[Boolean] { (config, introductoryRules) => | |
+ val introductoryRulesUpdater = gameConfiguration.updater[Boolean] (config, introductoryRules) => | |
config.withIntroductoryRules(introductoryRules) | |
- } | |
val resultDiv = div( | |
p( | |
@@ -456,10 +453,10 @@ object Main: | |
def joinGame(uuid: UUID, peerID: String): Unit = | |
println(s"should join $peerID") | |
- peerJS.connect(peerID, new { | |
+ peerJS.connect(peerID, new: | |
metadata = uuid.toString() | |
reliable = true | |
- }) | |
+ ) | |
println("connection just created:") | |
def uuidFromStringOption(s: String): Option[UUID] = | |
@@ -514,7 +511,7 @@ object Main: | |
case None => Left("need between 2 and 4 players") | |
val gameConfig: Signal[Option[FullGameConfig]] = | |
- Signal.combine(gameConfiguration, playerCount).map { | |
+ Signal.combine(gameConfiguration, playerCount).map: | |
(gameConfiguration, playerCountEither) => | |
for | |
playerCount <- playerCountEither.toOption | |
@@ -526,7 +523,6 @@ object Main: | |
scala.util.Random.nextInt(), | |
controllerIndex = -1, | |
) | |
- } | |
end gameConfig | |
div( | |
diff --git a/src/main/scala/be/doeraene/barrage/mainui/ReactivePeerJS.scala b/src/main/scala/be/doeraene/barrage/mainui/ReactivePeerJS.scala | |
index 1dc1224..da264d1 100644 | |
--- a/src/main/scala/be/doeraene/barrage/mainui/ReactivePeerJS.scala | |
+++ b/src/main/scala/be/doeraene/barrage/mainui/ReactivePeerJS.scala | |
@@ -38,32 +38,27 @@ object ReactivePeerJS: | |
private val uPeer = new PeerJS.Peer[M]() | |
- uPeer.on("open") { (id: String) => | |
+ uPeer.on("open") (id: String) => | |
eventBus.emit(PeerEvent.Open(id)) | |
- } | |
- uPeer.on("connection") { (uConnection: PeerJS.DataConnection[M]) => | |
+ uPeer.on("connection") (uConnection: PeerJS.DataConnection[M]) => | |
eventBus.emit(PeerEvent.Connection(new DataConnection(this, uConnection))) | |
- } | |
- uPeer.on("closed") { () => | |
+ uPeer.on("closed") () => | |
eventBus.emit(PeerEvent.Closed()) | |
- } | |
- uPeer.on("disconnected") { () => | |
+ uPeer.on("disconnected") () => | |
eventBus.emit(PeerEvent.Disconnected()) | |
- } | |
- uPeer.on("error") { (error: PeerJS.Peer.Error) => | |
+ uPeer.on("error") (error: PeerJS.Peer.Error) => | |
eventBus.emit(PeerEvent.Error(error)) | |
- } | |
- private final class AsOwner extends OneTimeOwner(onAccessAfterKilled = { () => | |
+ private final class AsOwner extends OneTimeOwner(onAccessAfterKilled = () => | |
println(s"warning: Peer onAccessAfterKilled") | |
- }): | |
+ ): | |
override def killSubscriptions(): Unit = super.killSubscriptions() | |
end AsOwner | |
private val asOwner: AsOwner = new AsOwner | |
private val state: Signal[PeerState[M]] = | |
- events.foldLeft[PeerState[M]](PeerState()) { (state, event) => | |
+ events.foldLeft[PeerState[M]](PeerState()) (state, event) => | |
val state1 = state.copy(id = uPeer.id.toOption, disconnected = uPeer.disconnected, uPeer.destroyed) | |
event match | |
case PeerEvent.Connect(connection) => | |
@@ -75,7 +70,6 @@ object ReactivePeerJS: | |
state1.copy(connections = state1.connections.filter(_ != connection)) | |
case _ => | |
state1 | |
- } | |
end state | |
val id: Signal[Option[String]] = state.map(_.id) | |
@@ -114,26 +108,21 @@ object ReactivePeerJS: | |
private val asOwner: Owner = new OneTimeOwner(onAccessAfterKilled = { () => | |
println(s"warning: onAccessAfterKilled") | |
}) { | |
- uConnection.on("close") { () => | |
+ uConnection.on("close") () => | |
this.killSubscriptions() | |
incomingEventBus.emit(PeerEvent.ConnectionClosed(DataConnection.this)) | |
- } | |
} | |
- uConnection.on("data") { (message: M) => | |
+ uConnection.on("data") (message: M) => | |
println(s"receiving: ${scala.scalajs.js.JSON.stringify(message.asInstanceOf[scala.scalajs.js.Any])}") | |
incomingEventBus.emit(PeerEvent.ConnectionMessageEvent(this, message)) | |
- } | |
- uConnection.on("open") { () => | |
+ uConnection.on("open") () => | |
incomingEventBus.emit(PeerEvent.ConnectionOpen(this)) | |
- } | |
- uConnection.on("error") { (error: Any) => | |
+ uConnection.on("error") (error: Any) => | |
incomingEventBus.emit(PeerEvent.ConnectionError(this, error)) | |
- } | |
- val open: Signal[Boolean] = incomingEvents.foldLeft(uConnection.open) { (prev, event) => | |
+ val open: Signal[Boolean] = incomingEvents.foldLeft(uConnection.open) (prev, event) => | |
uConnection.open | |
- } | |
def send(message: M): Unit = | |
println(s"sending: ${scala.scalajs.js.JSON.stringify(message.asInstanceOf[scala.scalajs.js.Any])}") | |
diff --git a/src/main/scala/be/doeraene/barrage/model/BarrageModel.scala b/src/main/scala/be/doeraene/barrage/model/BarrageModel.scala | |
index 18c557d..ee04a61 100644 | |
--- a/src/main/scala/be/doeraene/barrage/model/BarrageModel.scala | |
+++ b/src/main/scala/be/doeraene/barrage/model/BarrageModel.scala | |
@@ -115,7 +115,7 @@ final case class BarrageModel( | |
copy(privateContractSpaces = privateContractSpaces.updated(space, None)) | |
def refillPrivateContractSpaces(): BarrageModel = | |
- PrivateContractSpace.AllSpaces.foldLeft(this) { (model, space) => | |
+ PrivateContractSpace.AllSpaces.foldLeft(this) (model, space) => | |
model.privateContractSpaces(space) match | |
case Some(_) => | |
model | |
@@ -131,13 +131,11 @@ final case class BarrageModel( | |
case Nil => | |
// There are no more contracts in that deck, so ignore | |
model | |
- } | |
end refillPrivateContractSpaces | |
def resetTemporaryExecutiveOfficers(): BarrageModel = | |
- companies.foldLeft(this) { (model, company) => | |
+ companies.foldLeft(this) (model, company) => | |
model.withCompanyProperties(company, _.withoutTemporaryExecutiveOfficerForMahiriSekibo()) | |
- } | |
end resetTemporaryExecutiveOfficers | |
def withoutNationalContract(contract: Contract): BarrageModel = | |
@@ -152,7 +150,7 @@ final case class BarrageModel( | |
copy(patentSpaces = patentSpaces.updated(space, None)) | |
def refillPatentSpaces(): BarrageModel = | |
- PatentSpace.AllSpaces.foldLeft(this) { (model, space) => | |
+ PatentSpace.AllSpaces.foldLeft(this) (model, space) => | |
model.patentDeck match | |
case top :: rest => | |
model.copy( | |
@@ -163,7 +161,6 @@ final case class BarrageModel( | |
case Nil => | |
// This happens with the introductory rules | |
model | |
- } | |
end refillPatentSpaces | |
def withState(state: MainState): BarrageModel = | |
@@ -241,14 +238,13 @@ object BarrageModel: | |
else roundBonusesDeck.filter(_ != RoundBonus.AcquiredAdvancedTechnologyTiles) | |
val roundBonuses = Round.values.toList.zip(roundBonusesDeck1).toMap | |
- val damProps = mapDescription.allDams.map { damComp => | |
+ val damProps = mapDescription.allDams.map damComp => | |
val dam = | |
if neutralDamIDs.contains(damComp.id) then | |
Some(DamProperties(NeutralCompany, areaToNeutralDamLevel(damComp.area), 1)) | |
else | |
None | |
damComp -> dam | |
- } | |
val conduitProps = mapDescription.allConduits.map(_ -> None) | |
val powerhouseProps = mapDescription.allPowerhouses.map(_ -> None) | |
@@ -274,13 +270,12 @@ object BarrageModel: | |
end companyProperties | |
val allActions = | |
- Action.AllGenericActions ++ companies.flatMap { company => | |
+ Action.AllGenericActions ++ companies.flatMap company => | |
val allSpecificActions = Action.makeCompanySpecificActions(company) | |
if companyProperties(company).executiveOfficer == ExecutiveOfficer.MahiriSekibo then | |
allSpecificActions | |
else | |
allSpecificActions.filterNot(_.isInstanceOf[Action.MahiriSekiboCopyAction]) | |
- } | |
val currentCompany = companies.head | |
diff --git a/src/main/scala/be/doeraene/barrage/model/CompanyProperties.scala b/src/main/scala/be/doeraene/barrage/model/CompanyProperties.scala | |
index ff47555..ca47ea8 100644 | |
--- a/src/main/scala/be/doeraene/barrage/model/CompanyProperties.scala | |
+++ b/src/main/scala/be/doeraene/barrage/model/CompanyProperties.scala | |
@@ -135,9 +135,8 @@ final case class CompanyProperties( | |
def acquiredAdvancedTechnologyTiles: Int = | |
val countInReserve = technologyTiles.count(_.isAdvancedTile) | |
- val countOnWheel = constructionWheel.segments.count { segment => | |
+ val countOnWheel = constructionWheel.segments.count segment => | |
segment.tile.exists(_.isAdvancedTile) | |
- } | |
countInReserve + countOnWheel | |
def addBuiltStructure(structureKind: StructureKind): CompanyProperties = | |
diff --git a/src/main/scala/be/doeraene/barrage/model/MainState.scala b/src/main/scala/be/doeraene/barrage/model/MainState.scala | |
index c63d045..6e27c94 100644 | |
--- a/src/main/scala/be/doeraene/barrage/model/MainState.scala | |
+++ b/src/main/scala/be/doeraene/barrage/model/MainState.scala | |
@@ -81,9 +81,8 @@ object MainState: | |
val producedEnergy = producedEnergyWithSpecialAbility + conditions.bonus | |
(fee, producedEnergy) | |
val (fee, producedEnergy) = feeAndEnergy.unzip | |
- val actualContract = contract.filter { c => | |
+ val actualContract = contract.filter c => | |
producedEnergy.exists(_ >= Mechanics.requiredEnergyForContract(model, c)) | |
- } | |
ProduceEnergyAction(conditions, source, conduit, powerhouse, | |
fee.filter(_._1 > 0), producedEnergy, actualContract) | |
end apply | |
diff --git a/src/main/scala/be/doeraene/barrage/model/Mechanics.scala b/src/main/scala/be/doeraene/barrage/model/Mechanics.scala | |
index 1a8ca30..f11060e 100644 | |
--- a/src/main/scala/be/doeraene/barrage/model/Mechanics.scala | |
+++ b/src/main/scala/be/doeraene/barrage/model/Mechanics.scala | |
@@ -310,9 +310,8 @@ private[model] object Mechanics: | |
end selectPowerhouseForProduction | |
private def conduitToPowerhouse(model: BarrageModel, conduit: ConduitComponent): Option[PowerhouseComponent] = | |
- conduit.connectedTo.powerhouses.find { powerhouse => | |
+ conduit.connectedTo.powerhouses.find powerhouse => | |
model.powerhouseProperties(powerhouse).exists(_.company == model.currentCompany) | |
- } | |
end conduitToPowerhouse | |
private def conduitToSources(model: BarrageModel, conduit: ConduitComponent): List[(DamComponent, Int)] = | |
@@ -328,10 +327,9 @@ private[model] object Mechanics: | |
end conduitToSources | |
private def powerhouseToConduits(model: BarrageModel, powerhouse: PowerhouseComponent): List[ConduitComponent] = | |
- model.mapDescription.allConduits.filter { conduit => | |
+ model.mapDescription.allConduits.filter conduit => | |
conduit.connectedTo == powerhouse | |
&& model.conduitProperties(conduit).isDefined | |
- } | |
end powerhouseToConduits | |
def selectContractForProduction(model: BarrageModel, contract: Contract): Result[BarrageModel] = | |
@@ -569,12 +567,11 @@ private[model] object Mechanics: | |
val model1Result = | |
if flow then dropWaterDrop(model, headstreamComp) | |
else Result.Success(addWaterDrop(model, headstreamComp)) | |
- model1Result.flatMap { model1 => | |
+ model1Result.flatMap model1 => | |
if waterDrops > 1 then | |
Result.Success(model1.withState(MainState.AddWaterDrops(waterDrops - 1, flow, didSomething = true))) | |
else | |
processFollowUpEvents(model1) | |
- } | |
case _ => | |
Result.Error("illegal state: not adding water drops") | |
end addWaterDropsSelect | |
@@ -670,10 +667,9 @@ private[model] object Mechanics: | |
private def canCopyTileFromWheel(model: BarrageModel): Boolean = | |
val companyProps = model.currentCompanyProps | |
- companyProps.hasSpecialAbility(SpecialAbility.CopyTechnologyTile) && { | |
+ companyProps.hasSpecialAbility(SpecialAbility.CopyTechnologyTile) && : | |
companyProps.executiveOfficer == ExecutiveOfficer.MahiriSekibo | |
|| companyProps.technologyTiles.exists(_.specialEffect == TechnologyTileSpecialEffect.CopyTileOnWheel) | |
- } | |
def constructionActionSelectComponent(model: BarrageModel, component: BuildableComponent): Result[BarrageModel] = | |
model.state match | |
@@ -708,7 +704,7 @@ private[model] object Mechanics: | |
Result.Error("you cannot build there with this technology tile") | |
case tileChoice: TechnologyTileChoice.NonEmpty => | |
- checkBuildStructure(model, component, structureKind).flatMap { _ => | |
+ checkBuildStructure(model, component, structureKind).flatMap _ => | |
val costAlternatives = computeConstructionCostAlternatives(model, tileChoice.tile, component, structureKind) | |
if costAlternatives.isEmpty then | |
Result.Error("you do not have enough resources to build there") | |
@@ -716,7 +712,6 @@ private[model] object Mechanics: | |
val defaultCost = defaultConstructionCost(costAlternatives, structureKind, oldTarget) | |
val target = ConstructionTarget(component, structureKind, defaultCost) | |
installConstructionTarget(model, tileChoice, target, costAlternatives) | |
- } | |
case _ => | |
Result.Error("illegal state: not in a construction action") | |
@@ -799,7 +794,7 @@ private[model] object Mechanics: | |
if !canUseCredits then | |
altsForMix | |
else | |
- altsForMix.flatMap { mixedCost => | |
+ altsForMix.flatMap mixedCost => | |
mixedCost match | |
case ConstructionCost(excavators, 0, 0) if !canMix => | |
for payedForInCredits <- (0 to excavators).toList yield | |
@@ -809,7 +804,6 @@ private[model] object Mechanics: | |
ConstructionCost(excavators, concreteMixers - payedForInCredits, payedForInCredits * 3) | |
case _ => | |
throw new AssertionError(s"impossible base cost: $baseCost") | |
- } | |
val altsForBuildConduitsWithConcreteMixers = | |
if structureKind == StructureKind.Conduit && companyProps.hasSpecialAbility(BuildConduitsWithConcreteMixers) then | |
@@ -821,11 +815,10 @@ private[model] object Mechanics: | |
val allAlternatives = altsForBuildConduitsWithConcreteMixers | |
- val viableAlternatives = allAlternatives.filter { cost => | |
+ val viableAlternatives = allAlternatives.filter cost => | |
companyProps.excavators >= cost.excavators | |
&& companyProps.concreteMixers >= cost.concreteMixers | |
&& companyProps.credits >= cost.credits | |
- } | |
viableAlternatives | |
end computeConstructionCostAlternatives | |
@@ -944,9 +937,8 @@ private[model] object Mechanics: | |
val damsToUpdate = model.damProperties.collect { | |
case (dam, Some(DamProperties(`company`, _, 0))) => dam | |
}.toList | |
- val newModel = damsToUpdate.foldLeft(model) { (model, dam) => | |
+ val newModel = damsToUpdate.foldLeft(model) (model, dam) => | |
model.withDamProps(dam, model.damProperties(dam).get.withWaterDrops(1)) | |
- } | |
Result.Success(newModel) | |
case RotateWheelForEachElevation => | |
@@ -1028,9 +1020,8 @@ private[model] object Mechanics: | |
val headstream = model.headstreamProperties(headstreamComp) | |
val waterDrops = headstream.waterDrops | |
val model1 = model.withHeadstreamProps(headstreamComp, headstream.withWaterDrops(0)) | |
- dropWaterDrops(model1, waterDrops, headstreamComp).flatMap { model2 => | |
+ dropWaterDrops(model1, waterDrops, headstreamComp).flatMap model2 => | |
loop(model2, rest) | |
- } | |
loop(model, model.mapDescription.allHeadstreams) | |
end executeWaterFlow | |
@@ -1080,9 +1071,8 @@ private[model] object Mechanics: | |
yield | |
powerhouse | |
- val modelResult1 = Result.flatFoldLeft(model, powerhousesThatCreateEnergy) { (model, powerhouse) => | |
+ val modelResult1 = Result.flatFoldLeft(model, powerhousesThatCreateEnergy) (model, powerhouse) => | |
Animated.produceEnergy(model, powerhouse, waterDrops, waterDropsPendingInGroup = waterDrops) | |
- } | |
modelResult1.flatMap(dropWaterDrops(_, waterDrops, powerhouseGroup)) | |
case Some(component) => | |
@@ -1385,7 +1375,7 @@ private[model] object Mechanics: | |
def scoreEnergyTrack(model: BarrageModel): Result[BarrageModel] = | |
val sortedEnergyToCompanies = companiesSortedByEnergy(model).filter(_._1 > 0) | |
- Result.animation(model, Animation.HighlightResources(None, Set(Animation.ResourceKind.Energy))).flatMap { _ => | |
+ Result.animation(model, Animation.HighlightResources(None, Set(Animation.ResourceKind.Energy))).flatMap _ => | |
sortedEnergyToCompanies match | |
case Nil => | |
// No one produced any energy | |
@@ -1393,7 +1383,7 @@ private[model] object Mechanics: | |
case (_, first :: Nil) :: rest => | |
// The first company wins 6 points | |
- Animated.addVictoryPoints(model, first, 6).flatMap { model1 => | |
+ Animated.addVictoryPoints(model, first, 6).flatMap model1 => | |
rest match | |
case Nil => | |
// No other company produced any energy | |
@@ -1405,18 +1395,14 @@ private[model] object Mechanics: | |
case (_, seconds) :: _ => | |
// All the seconds win 1 point | |
- Result.flatFoldLeft(model1, seconds) { (model, company) => | |
+ Result.flatFoldLeft(model1, seconds) (model, company) => | |
Animated.addVictoryPoints(model, company, 1) | |
- } | |
- } | |
case (_, firsts) :: _ => | |
// All the firsts share 8 points | |
val points = ceilDiv(8, firsts.size) | |
- Result.flatFoldLeft(model, firsts) { (model, company) => | |
+ Result.flatFoldLeft(model, firsts) (model, company) => | |
Animated.addVictoryPoints(model, company, points) | |
- } | |
- } | |
end scoreEnergyTrack | |
private def companiesSortedByEnergy(model: BarrageModel): List[(Int, List[Company])] = | |
@@ -1431,8 +1417,8 @@ private[model] object Mechanics: | |
end companiesSortedBy | |
def creditsEnergyTrack(model: BarrageModel): Result[BarrageModel] = | |
- Result.flatFoldLeft(model, model.companies) { (model, company) => | |
- Result.animation(model, Animation.HighlightResources(Some(company), Set(Animation.ResourceKind.Energy))).flatMap { _ => | |
+ Result.flatFoldLeft(model, model.companies) (model, company) => | |
+ Result.animation(model, Animation.HighlightResources(Some(company), Set(Animation.ResourceKind.Energy))).flatMap _ => | |
val energy = model.companyProperties(company).energy | |
if energy == 0 then | |
for | |
@@ -1445,15 +1431,13 @@ private[model] object Mechanics: | |
energy >= requiredEnergy | |
}.get._2 | |
Animated.addCredits(model, company, credits) | |
- } | |
- } | |
end creditsEnergyTrack | |
def scoreRoundBonus(model: BarrageModel): Result[BarrageModel] = | |
val requiredEnergy = model.round.energyRequiredForBonus | |
val bonus = model.roundBonuses(model.round) | |
- Result.flatFoldLeft(model, model.companies) { (model, company) => | |
+ Result.flatFoldLeft(model, model.companies) (model, company) => | |
val props = model.companyProperties(company) | |
val energy = props.energy | |
if energy < MinEnergyRequiredForRoundBonus then | |
@@ -1516,7 +1500,6 @@ private[model] object Mechanics: | |
result2 | |
else | |
result2.flatMap(Animated.addVictoryPoints(_, company, points)) | |
- } | |
end scoreRoundBonus | |
def processEndOfRegularRound(model: BarrageModel, nextRound: Round): Result[BarrageModel] = | |
@@ -1548,17 +1531,15 @@ private[model] object Mechanics: | |
end reorderCompanies | |
def resetEnergy(model: BarrageModel): Result[BarrageModel] = | |
- val newModel = model.companies.foldLeft(model) { (model, company) => | |
+ val newModel = model.companies.foldLeft(model) (model, company) => | |
model.withCompanyProperties(company, _.resetEnergy()) | |
- } | |
Result.Success(newModel) | |
end resetEnergy | |
def resetEngineers(model: BarrageModel): Result[BarrageModel] = | |
val model1 = model.withoutAnyOccupiedAction() | |
- val newModel = model1.companies.foldLeft(model1) { (model2, company) => | |
+ val newModel = model1.companies.foldLeft(model1) (model2, company) => | |
model2.withCompanyProperties(company, _.resetEngineers()) | |
- } | |
Result.Success(newModel) | |
end resetEngineers | |
@@ -1567,9 +1548,8 @@ private[model] object Mechanics: | |
end refillPatentSpaces | |
def goToNextRound(model: BarrageModel, nextRound: Round): Result[BarrageModel] = | |
- val model1 = model.companies.foldLeft(model) { (model, company) => | |
+ val model1 = model.companies.foldLeft(model) (model, company) => | |
model.withCompanyProperties(company, _.withPassed(false)) | |
- } | |
val newModel = model1 | |
.withRound(model1.round.nextRound.get) | |
.withCurrentCompany(model1.companies.head) | |
@@ -1578,17 +1558,16 @@ private[model] object Mechanics: | |
def produceWaterInHeadstreams(model: BarrageModel): Result[BarrageModel] = | |
val round = model.round | |
- val newModel = model.mapDescription.allHeadstreams.foldLeft(model) { (model, headstreamComp) => | |
+ val newModel = model.mapDescription.allHeadstreams.foldLeft(model) (model, headstreamComp) => | |
val HeadstreamProperties(productionCard, waterDrops) = model.headstreamProperties(headstreamComp) | |
assert(waterDrops == 0) | |
val newHeadstream = HeadstreamProperties(productionCard, productionCard.productions(round)) | |
model.withHeadstreamProps(headstreamComp, newHeadstream) | |
- } | |
Result.Success(newModel) | |
end produceWaterInHeadstreams | |
def companyIncome(model: BarrageModel): Result[BarrageModel] = | |
- val events: List[BarrageModel.FollowUpEvent] = model.companies.flatMap { company => | |
+ val events: List[BarrageModel.FollowUpEvent] = model.companies.flatMap company => | |
val props = model.companyProperties(company) | |
val setCurrentCompanyEvent = FollowUpEventSpecial.SetCurrentCompany(company) | |
val companyEventss: List[List[BarrageModel.FollowUpEvent]] = | |
@@ -1598,7 +1577,7 @@ private[model] object Mechanics: | |
yield | |
FollowUpEventSpecial.HighlightIncome(company, structureKind, requiredAmount) :: rewards | |
setCurrentCompanyEvent :: companyEventss.flatten | |
- } | |
+ end events | |
val eventsThenStartRound = events :+ FollowUpEventSpecial.StartRound | |
@@ -1627,9 +1606,8 @@ private[model] object Mechanics: | |
val count = companies.size | |
val (tiersToShare, restTiers) = tiers.splitAt(count) | |
val pointsPerCompany = ceilDiv(tiersToShare.sum, count) | |
- val modelResult1 = Result.flatFoldLeft(model, companies) { (model, company) => | |
+ val modelResult1 = Result.flatFoldLeft(model, companies) (model, company) => | |
Animated.addVictoryPoints(model, company, pointsPerCompany) | |
- } | |
modelResult1.flatMap(loop(_, restCompanies, restTiers)) | |
end loop | |
@@ -1694,21 +1672,17 @@ private[model] object Mechanics: | |
model.objective match | |
case Objective.BasesAndPowerhousesOnRedSpaces => | |
- val baseCount = mapDesc.allDams.count { dam => | |
+ val baseCount = mapDesc.allDams.count dam => | |
dam.hasRedCost && ownsDam(dam) | |
- } | |
- val powerhouseCount = mapDesc.allPowerhouses.count { powerhouse => | |
+ val powerhouseCount = mapDesc.allPowerhouses.count powerhouse => | |
powerhouse.hasRedCost && ownsPowerhouse(powerhouse) | |
- } | |
baseCount + powerhouseCount | |
case Objective.BasesWithFullCircuit => | |
- mapDesc.allDams.count { dam => | |
- ownsDam(dam) && dam.connectedTo.exists { conduit => | |
+ mapDesc.allDams.count dam => | |
+ ownsDam(dam) && dam.connectedTo.exists conduit => | |
ownsConduit(conduit) | |
&& conduit.connectedTo.powerhouses.exists(ownsPowerhouse(_)) | |
- } | |
- } | |
case Objective.StructuresInMostBuiltArea => | |
computeStructuresInAreas().max | |
@@ -1724,7 +1698,7 @@ private[model] object Mechanics: | |
end computeCompanyObjectiveCount | |
def scoreResourcesLeft(model: BarrageModel): Result[BarrageModel] = | |
- Result.flatFoldLeft(model, model.companies) { (model, company) => | |
+ Result.flatFoldLeft(model, model.companies) (model, company) => | |
val props = model.companyProperties(company) | |
val resourcesLeft = props.credits + props.excavators + props.concreteMixers | |
val points = resourcesLeft / 5 | |
@@ -1735,11 +1709,10 @@ private[model] object Mechanics: | |
Result.animation(model, Animation.HighlightResources(Some(company), resourceKinds)) | |
.flatMap(Animated.addVictoryPoints(_, company, points)) | |
- } | |
end scoreResourcesLeft | |
def scoreWaterDrops(model: BarrageModel): Result[BarrageModel] = | |
- Result.flatFoldLeft(model, model.companies) { (model, company) => | |
+ Result.flatFoldLeft(model, model.companies) (model, company) => | |
val (dams, waterDropss) = ( | |
for | |
case (dam, Some(DamProperties(`company`, _, waterDrops))) <- model.damProperties.toList | |
@@ -1752,14 +1725,12 @@ private[model] object Mechanics: | |
else | |
Result.animation(model, Animation.HighlightWaterDropsInDams(dams)) | |
.flatMap(Animated.addVictoryPoints(_, company, waterDrops)) | |
- } | |
end scoreWaterDrops | |
def reorderCompaniesForEndOfGame(model: BarrageModel): Result[BarrageModel] = | |
- val sortedCompanies = model.companies.sortBy { company => | |
+ val sortedCompanies = model.companies.sortBy company => | |
val props = model.companyProperties(company) | |
(-props.victoryPoints, -props.energy) | |
- } | |
Animated.reorderCompanies(model, sortedCompanies) | |
end reorderCompaniesForEndOfGame | |
diff --git a/src/test/scala/be/doeraene/barrage/model/TestModel.scala b/src/test/scala/be/doeraene/barrage/model/TestModel.scala | |
index 233360f..8cf9e05 100644 | |
--- a/src/test/scala/be/doeraene/barrage/model/TestModel.scala | |
+++ b/src/test/scala/be/doeraene/barrage/model/TestModel.scala | |
@@ -71,10 +71,10 @@ object TestModel: | |
case NeutralCompany => throw new AssertionError(s"cannot setup a neutral dam") | |
model.withDamProps(dam, damProps) | |
- .withCompanyProperties(company, { props => | |
+ .withCompanyProperties(company, props => | |
val props1 = props.addBuiltStructure(StructureKind.Base) | |
(2 to damProps.level).foldLeft(props1)((props1, _) => props1.addBuiltStructure(StructureKind.Elevation)) | |
- }) | |
+ ) | |
case ModelProps.ConduitProps(conduitID, conduitProps) => | |
val conduit = model.mapDescription.conduits(conduitID) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/main/scala/be/doeraene/barrage/Barrage.scala b/src/main/scala/be/doeraene/barrage/Barrage.scala | |
index c08a44d..bbacfda 100644 | |
--- a/src/main/scala/be/doeraene/barrage/Barrage.scala | |
+++ b/src/main/scala/be/doeraene/barrage/Barrage.scala | |
@@ -145,27 +145,35 @@ final class Barrage(networkBridge: NetworkBridge, gameConfiguration: GameConfigu | |
end technologyTileAssetNames | |
val bootAssets: Set[AssetType] = | |
- val perCompany: Set[AssetType] = Company.AllCompanies.flatMap { company => | |
- Set( | |
- AssetType.Image(companyConduitAssetNames(company), AssetPath(s"assets/conduit-${company.stringID}.png")), | |
- AssetType.Image(companyPowerhouseAssetNames(company), AssetPath(s"assets/powerhouse-${company.stringID}.png")), | |
- AssetType.Image(companyEngineerAssetNames(company), AssetPath(s"assets/engineer-${company.stringID}.png")), | |
- AssetType.Image(companySpecialAbilityAssetNames(company), AssetPath(s"assets/special-ability-${company.stringID}.png")), | |
- ) | |
- }.toSet | |
- val perCompanyOrNeutral: Set[AssetType] = Company.AllCompaniesAndNeutral.flatMap { company => | |
- companyDamAssetNames(company).map { (level, assetName) => | |
- AssetType.Image(assetName, AssetPath(s"assets/dam$level-${company.stringID}.png")) | |
+ val perCompany: Set[AssetType] = Company.AllCompanies | |
+ .flatMap { company => | |
+ Set( | |
+ AssetType.Image(companyConduitAssetNames(company), AssetPath(s"assets/conduit-${company.stringID}.png")), | |
+ AssetType.Image(companyPowerhouseAssetNames(company), AssetPath(s"assets/powerhouse-${company.stringID}.png")), | |
+ AssetType.Image(companyEngineerAssetNames(company), AssetPath(s"assets/engineer-${company.stringID}.png")), | |
+ AssetType.Image(companySpecialAbilityAssetNames(company), AssetPath(s"assets/special-ability-${company.stringID}.png")), | |
+ ) | |
}.toSet | |
- }.toSet | |
- val perExecutiveOfficer: Set[AssetType] = ExecutiveOfficer.AllExecutiveOfficers.flatMap { officer => | |
- Set( | |
- AssetType.Image(executiveOfficerSpecialAbilityAssetNames(officer), AssetPath(s"assets/special-ability-${officer.stringID}.png")), | |
- ) | |
- }.toSet | |
+ | |
+ val perCompanyOrNeutral: Set[AssetType] = Company.AllCompaniesAndNeutral | |
+ .flatMap { company => | |
+ companyDamAssetNames(company) | |
+ .map { (level, assetName) => | |
+ AssetType.Image(assetName, AssetPath(s"assets/dam$level-${company.stringID}.png")) | |
+ }.toSet | |
+ }.toSet | |
+ | |
+ val perExecutiveOfficer: Set[AssetType] = ExecutiveOfficer.AllExecutiveOfficers | |
+ .flatMap { officer => | |
+ Set( | |
+ AssetType.Image(executiveOfficerSpecialAbilityAssetNames(officer), AssetPath(s"assets/special-ability-${officer.stringID}.png")), | |
+ ) | |
+ }.toSet | |
+ | |
val forTechnologyTiles = technologyTileAssetNames.map { (tile, assetName) => | |
AssetType.Image(assetName, AssetPath(s"assets/$assetName.png")) | |
} | |
+ | |
val global: Set[AssetType] = Set( | |
AssetType.Image(ayarFontAssetName, AssetPath("assets/ayar-font.png")), | |
AssetType.Text(ayarFontInfoAssetName, AssetPath("assets/ayar-font-info.json")), | |
@@ -468,11 +476,13 @@ final class Barrage(networkBridge: NetworkBridge, gameConfiguration: GameConfigu | |
s"patent-space-$index" | |
end id | |
- val (element, offset) = docs.iterator.map((doc, offset) => (doc.getElementById(id), offset)).find { | |
- _._1 != null | |
- }.getOrElse { | |
- throw new IllegalArgumentException(s"#$id not found") | |
- } | |
+ val (element, offset) = docs.iterator | |
+ .map((doc, offset) => (doc.getElementById(id), offset)) | |
+ .find(_._1 != null) | |
+ .getOrElse { | |
+ throw new IllegalArgumentException(s"#$id not found") | |
+ } | |
+ | |
element match | |
case rect: dom.SVGRectElement => | |
def value(dim: dom.SVGAnimatedLength): Int = | |
@@ -593,118 +603,122 @@ final class Barrage(networkBridge: NetworkBridge, gameConfiguration: GameConfigu | |
import be.doeraene.barrage.{GameInterfaceElement => GIE} | |
import be.doeraene.barrage.BarrageEvents.{GameInterfaceElementClick => GIEC} | |
println("click at " + pt) | |
- viewModel.hitBoxes.find { | |
- (rect, key) => rect.contains(pt) | |
- } match | |
- case Some((_, key)) => | |
- println("component: " + key) | |
- val element = key match | |
- case component: Component => GIE.Component(component.id) | |
- case componentID: ComponentID => GIE.Component(componentID) | |
- case action: Action => GIE.Action(action) | |
- case space: PrivateContractSpace => GIE.PrivateContractSpace(space) | |
- case space: NationalContractSpace => GIE.NationalContractSpace(space) | |
- case space: PatentSpace => ??? | |
- Outcome(viewModel) | |
- .addGlobalEvents(GIEC(element)) | |
- case _ => | |
- mainButtonRects.find { | |
- (button, rect) => rect.contains(pt) && isButtonEnabled(model, button) | |
- } match | |
- case Some((button, _)) => | |
- println("button: " + button) | |
- Outcome(viewModel) | |
- .addGlobalEvents(GIEC(GIE.MainButton(button))) | |
- case None => | |
- if companyCardsArea.contains(pt) then | |
- val pt2 = pt.moveBy(-companyCardsArea.left, -companyCardsArea.top) | |
- val index = pt2.x / companyCardSpace.width | |
- val companies = model.companies | |
- if index >= 0 && index < companies.size then | |
- val company = companies(index) | |
- println("company card: " + company) | |
- val outcome1 = Outcome(viewModel.withActiveCompany(company)) | |
- if model.state.isInstanceOf[MainState.ChooseCompanies] then | |
- outcome1.addGlobalEvents(GIEC(GIE.Company(company))) | |
- else | |
- outcome1 | |
- else | |
- println("nothing") | |
- Outcome(viewModel) | |
- else if model.state.isInstanceOf[MainState.ChooseCompanies] && contractsInStatusAreaRect.contains(pt) then | |
- val pt2 = pt.moveBy(-contractsInStatusAreaRect.left, -contractsInStatusAreaRect.top) | |
- val index = pt2.x / contractSpace.width | |
- val contracts = model.state.asInstanceOf[MainState.ChooseCompanies].availableContracts | |
- if index >= 0 && index < contracts.size then | |
- val contract = contracts(index) | |
- println("contract: " + contract) | |
- Outcome(viewModel) | |
- .addGlobalEvents(GIEC(GIE.Contract(contract))) | |
- else | |
- println("nothing") | |
- Outcome(viewModel) | |
- else if model.state == MainState.ChooseExecutiveOfficerForMahiriSekibo && executiveOfficersInStatusAreaRect.contains(pt) then | |
- val pt2 = pt.moveBy(-executiveOfficersInStatusAreaRect.left, -executiveOfficersInStatusAreaRect.top) | |
- val index = pt2.x / executiveOfficerSpace.width | |
- val executiveOfficers = model.availableOfficersForMahiriSekibo | |
- if index >= 0 && index < executiveOfficers.size then | |
- val executiveOfficer = executiveOfficers(index) | |
- println("executive officer: " + executiveOfficer) | |
- Outcome(viewModel) | |
- .addGlobalEvents(GIEC(GIE.ExecutiveOfficer(executiveOfficer))) | |
- else | |
- println("nothing") | |
+ viewModel.hitBoxes | |
+ .find { (rect, key) => | |
+ rect.contains(pt) | |
+ } | |
+ .match | |
+ case Some((_, key)) => | |
+ println("component: " + key) | |
+ val element = key match | |
+ case component: Component => GIE.Component(component.id) | |
+ case componentID: ComponentID => GIE.Component(componentID) | |
+ case action: Action => GIE.Action(action) | |
+ case space: PrivateContractSpace => GIE.PrivateContractSpace(space) | |
+ case space: NationalContractSpace => GIE.NationalContractSpace(space) | |
+ case space: PatentSpace => ??? | |
+ Outcome(viewModel) | |
+ .addGlobalEvents(GIEC(element)) | |
+ case _ => | |
+ mainButtonRects | |
+ .find { (button, rect) => | |
+ rect.contains(pt) && isButtonEnabled(model, button) | |
+ } | |
+ .match | |
+ case Some((button, _)) => | |
+ println("button: " + button) | |
Outcome(viewModel) | |
- else if viewModel.activeCompanyBoardTab == CompanyBoardTab.RegularBoard && viewModel.activeCompany == model.currentCompany then | |
- if technologyTilesOnBoardRect.contains(pt) then | |
- val pt2 = pt.moveBy(-technologyTilesOnBoardRect.left, -technologyTilesOnBoardRect.top) | |
- val index = (pt2.y / technologyTileSpace.height) * 4 + (pt2.x / technologyTileSpace.width) | |
- val tiles = model.companyProperties(viewModel.activeCompany).technologyTiles | |
- if index >= 0 && index < tiles.size then | |
- val tile = tiles(index) | |
- println("tile: " + tile) | |
- Outcome(viewModel) | |
- .addGlobalEvents(GIEC(GIE.TechnologyTile(tile))) | |
- else | |
- println("nothing") | |
- Outcome(viewModel) | |
- else if constructionWheelOnBoardRect.contains(pt) && pt.distanceTo(constructionWheelOnBoardRect.center) <= 105.0 | |
- && !model.state.isInstanceOf[MainState.DiscardContracts] then | |
- val vector = (pt - constructionWheelOnBoardRect.center).toVector | |
- if vector.length >= 75.0 then | |
- val angle = vector.angle // range -pi to pi (+- error) | |
- val segmentIndex = angleToSegmentIndex(angle + (Radians.`2PI` / 6.0) * 2.0) | |
- val constructionWheel = model.companyProperties(viewModel.activeCompany).constructionWheel | |
- val optTile = constructionWheel.segments(segmentIndex).tile | |
- optTile match | |
- case Some(tile) => | |
+ .addGlobalEvents(GIEC(GIE.MainButton(button))) | |
+ case None => | |
+ if companyCardsArea.contains(pt) then | |
+ val pt2 = pt.moveBy(-companyCardsArea.left, -companyCardsArea.top) | |
+ val index = pt2.x / companyCardSpace.width | |
+ val companies = model.companies | |
+ if index >= 0 && index < companies.size then | |
+ val company = companies(index) | |
+ println("company card: " + company) | |
+ val outcome1 = Outcome(viewModel.withActiveCompany(company)) | |
+ if model.state.isInstanceOf[MainState.ChooseCompanies] then | |
+ outcome1.addGlobalEvents(GIEC(GIE.Company(company))) | |
+ else | |
+ outcome1 | |
+ else | |
+ println("nothing") | |
+ Outcome(viewModel) | |
+ else if model.state.isInstanceOf[MainState.ChooseCompanies] && contractsInStatusAreaRect.contains(pt) then | |
+ val pt2 = pt.moveBy(-contractsInStatusAreaRect.left, -contractsInStatusAreaRect.top) | |
+ val index = pt2.x / contractSpace.width | |
+ val contracts = model.state.asInstanceOf[MainState.ChooseCompanies].availableContracts | |
+ if index >= 0 && index < contracts.size then | |
+ val contract = contracts(index) | |
+ println("contract: " + contract) | |
+ Outcome(viewModel) | |
+ .addGlobalEvents(GIEC(GIE.Contract(contract))) | |
+ else | |
+ println("nothing") | |
+ Outcome(viewModel) | |
+ else if model.state == MainState.ChooseExecutiveOfficerForMahiriSekibo && executiveOfficersInStatusAreaRect.contains(pt) then | |
+ val pt2 = pt.moveBy(-executiveOfficersInStatusAreaRect.left, -executiveOfficersInStatusAreaRect.top) | |
+ val index = pt2.x / executiveOfficerSpace.width | |
+ val executiveOfficers = model.availableOfficersForMahiriSekibo | |
+ if index >= 0 && index < executiveOfficers.size then | |
+ val executiveOfficer = executiveOfficers(index) | |
+ println("executive officer: " + executiveOfficer) | |
+ Outcome(viewModel) | |
+ .addGlobalEvents(GIEC(GIE.ExecutiveOfficer(executiveOfficer))) | |
+ else | |
+ println("nothing") | |
+ Outcome(viewModel) | |
+ else if viewModel.activeCompanyBoardTab == CompanyBoardTab.RegularBoard && viewModel.activeCompany == model.currentCompany then | |
+ if technologyTilesOnBoardRect.contains(pt) then | |
+ val pt2 = pt.moveBy(-technologyTilesOnBoardRect.left, -technologyTilesOnBoardRect.top) | |
+ val index = (pt2.y / technologyTileSpace.height) * 4 + (pt2.x / technologyTileSpace.width) | |
+ val tiles = model.companyProperties(viewModel.activeCompany).technologyTiles | |
+ if index >= 0 && index < tiles.size then | |
+ val tile = tiles(index) | |
println("tile: " + tile) | |
Outcome(viewModel) | |
.addGlobalEvents(GIEC(GIE.TechnologyTile(tile))) | |
- case None => | |
+ else | |
println("nothing") | |
Outcome(viewModel) | |
+ else if constructionWheelOnBoardRect.contains(pt) && pt.distanceTo(constructionWheelOnBoardRect.center) <= 105.0 | |
+ && !model.state.isInstanceOf[MainState.DiscardContracts] then | |
+ val vector = (pt - constructionWheelOnBoardRect.center).toVector | |
+ if vector.length >= 75.0 then | |
+ val angle = vector.angle // range -pi to pi (+- error) | |
+ val segmentIndex = angleToSegmentIndex(angle + (Radians.`2PI` / 6.0) * 2.0) | |
+ val constructionWheel = model.companyProperties(viewModel.activeCompany).constructionWheel | |
+ val optTile = constructionWheel.segments(segmentIndex).tile | |
+ optTile match | |
+ case Some(tile) => | |
+ println("tile: " + tile) | |
+ Outcome(viewModel) | |
+ .addGlobalEvents(GIEC(GIE.TechnologyTile(tile))) | |
+ case None => | |
+ println("nothing") | |
+ Outcome(viewModel) | |
+ else | |
+ println("nothing") | |
+ Outcome(viewModel) | |
+ else if contractsOnBoardRect.contains(pt) then | |
+ val pt2 = pt.moveBy(-contractsOnBoardRect.left, -contractsOnBoardRect.top) | |
+ val index = pt2.x / contractSpace.width | |
+ val contracts = model.companyProperties(viewModel.activeCompany).contracts | |
+ if index >= 0 && index < contracts.size then | |
+ val contract = contracts(index) | |
+ println("contract: " + contract) | |
+ Outcome(viewModel) | |
+ .addGlobalEvents(GIEC(GIE.Contract(contract))) | |
+ else | |
+ println("nothing") | |
+ Outcome(viewModel) | |
+ else | |
+ println("nothing") | |
+ Outcome(viewModel) | |
else | |
println("nothing") | |
Outcome(viewModel) | |
- else if contractsOnBoardRect.contains(pt) then | |
- val pt2 = pt.moveBy(-contractsOnBoardRect.left, -contractsOnBoardRect.top) | |
- val index = pt2.x / contractSpace.width | |
- val contracts = model.companyProperties(viewModel.activeCompany).contracts | |
- if index >= 0 && index < contracts.size then | |
- val contract = contracts(index) | |
- println("contract: " + contract) | |
- Outcome(viewModel) | |
- .addGlobalEvents(GIEC(GIE.Contract(contract))) | |
- else | |
- println("nothing") | |
- Outcome(viewModel) | |
- else | |
- println("nothing") | |
- Outcome(viewModel) | |
- else | |
- println("nothing") | |
- Outcome(viewModel) | |
case InsertAnimationSteps(animationSteps, eventualModel) => | |
Outcome(viewModel.addAnimationSteps(animationSteps, eventualModel)) | |
@@ -1425,29 +1439,31 @@ final class Barrage(networkBridge: NetworkBridge, gameConfiguration: GameConfigu | |
case comp: HeadstreamComponent => center.moveBy(0, 10) | |
case _ => center | |
- val headstreamsDrops = model.headstreamProperties.map { (headstream, headstreamProps) => | |
- posOf(headstream) -> (headstreamProps.waterDrops, 0) | |
- }.toList | |
+ val headstreamsDrops = model.headstreamProperties | |
+ .map { (headstream, headstreamProps) => | |
+ posOf(headstream) -> (headstreamProps.waterDrops, 0) | |
+ }.toList | |
val (highlightedDam, highlightedWaterDrops) = model.state match | |
case MainState.ProduceEnergyAction(_, Some((dam, waterDrops)), _, _, _, _, _) => | |
(dam, waterDrops) | |
case _ => | |
(model.mapDescription.allDams.head, 0) | |
- val damDrops = model.damProperties.map { (dam, damProps) => | |
- val pos = posOf(dam) | |
- val waterDrops = damProps.fold(0)(_.waterDrops) | |
- val highlightedCount = | |
- if dam == highlightedDam then | |
- highlightedWaterDrops | |
- else | |
- viewModel.currentAnimation match | |
- case Some((Animation.HighlightWaterDropsInDams(dams), _, _)) if dams.contains(dam) => | |
- waterDrops | |
- case _ => | |
- 0 | |
- pos -> (waterDrops, highlightedCount) | |
- }.toList | |
+ val damDrops = model.damProperties | |
+ .map { (dam, damProps) => | |
+ val pos = posOf(dam) | |
+ val waterDrops = damProps.fold(0)(_.waterDrops) | |
+ val highlightedCount = | |
+ if dam == highlightedDam then | |
+ highlightedWaterDrops | |
+ else | |
+ viewModel.currentAnimation match | |
+ case Some((Animation.HighlightWaterDropsInDams(dams), _, _)) if dams.contains(dam) => | |
+ waterDrops | |
+ case _ => | |
+ 0 | |
+ pos -> (waterDrops, highlightedCount) | |
+ }.toList | |
val animatedDrops = viewModel.currentAnimation match | |
case Some((Animation.WaterDropFlow(waterDrops, from), progress, _)) => | |
@@ -1474,10 +1490,11 @@ final class Barrage(networkBridge: NetworkBridge, gameConfiguration: GameConfigu | |
val highlightedG = Graphic(Rectangle(0, 0, 20, 32), Material.Bitmap(waterDropHighlightedAssetName)) | |
.withRefAtCenter | |
- allDrops.flatMap { case (position, (count, highlightedCount)) => | |
- (1 to count).map i => | |
- val g = if i > count - highlightedCount then highlightedG else regularG | |
- g.moveTo(position.x + 10 * i - 5 * count, position.y) | |
+ allDrops.flatMap { | |
+ case (position, (count, highlightedCount)) => | |
+ (1 to count).map i => | |
+ val g = if i > count - highlightedCount then highlightedG else regularG | |
+ g.moveTo(position.x + 10 * i - 5 * count, position.y) | |
} | |
end drawWaterDrops | |
diff --git a/src/main/scala/be/doeraene/barrage/mainui/Main.scala b/src/main/scala/be/doeraene/barrage/mainui/Main.scala | |
index 92c9563..2f0b54b 100644 | |
--- a/src/main/scala/be/doeraene/barrage/mainui/Main.scala | |
+++ b/src/main/scala/be/doeraene/barrage/mainui/Main.scala | |
@@ -101,9 +101,11 @@ object ServerState: | |
assert(playerCount >= 2 && playerCount <= 4) | |
// Assign controller indices | |
- val newClients = scala.util.Random.shuffle(clients).zipWithIndex.map { case ((connection, info), index) => | |
- connection -> info.copy(controllerIndex = index) | |
- }.to(ListMap) | |
+ val newClients = scala.util.Random.shuffle(clients).zipWithIndex | |
+ .map { | |
+ case ((connection, info), index) => | |
+ connection -> info.copy(controllerIndex = index) | |
+ }.to(ListMap) | |
val rngSeed = scala.util.Random.nextInt() | |
val initialModel = model.BarrageModel.create( | |
@@ -381,21 +383,22 @@ object Main: | |
h1("Create a game"), | |
p(child <-- peerJS.id.map(id => s"My ID: ${id.getOrElse("<unknown>")}")), | |
ul( | |
- children <-- serverState.map { | |
- case ServerState.ConstructingGame(clients) => clients.values.toList | |
- case ServerState.RunningGame(clients, _, _, _, _, _) => clients.values.toList | |
- }.split(_.uuid) { (uuid, initial, clientInfoSignal) => | |
- li( | |
- child <-- clientInfoSignal.map { clientInfo => | |
- val statusIcon = if clientInfo.connection.isDefined then "✔️" else "❌" | |
- s"${uuid} (${clientInfo.displayName}) $statusIcon " | |
- }, | |
- button( | |
- "🗑️", | |
- onClick.mapTo(UIEvent.KickClient(uuid)) --> uiEventBus, | |
- ), | |
- ) | |
- }, | |
+ children <-- serverState | |
+ .map { | |
+ case ServerState.ConstructingGame(clients) => clients.values.toList | |
+ case ServerState.RunningGame(clients, _, _, _, _, _) => clients.values.toList | |
+ }.split(_.uuid) { (uuid, initial, clientInfoSignal) => | |
+ li( | |
+ child <-- clientInfoSignal.map { clientInfo => | |
+ val statusIcon = if clientInfo.connection.isDefined then "✔️" else "❌" | |
+ s"${uuid} (${clientInfo.displayName}) $statusIcon " | |
+ }, | |
+ button( | |
+ "🗑️", | |
+ onClick.mapTo(UIEvent.KickClient(uuid)) --> uiEventBus, | |
+ ), | |
+ ) | |
+ }, | |
), | |
child <-- serverState.splitOne(_.ordinal) { (ord, initialState, stateSignal) => | |
initialState match | |
@@ -560,22 +563,25 @@ object Main: | |
def indigoGameElement(config: FullGameConfig): Div = | |
div( | |
idAttr := "indigo-container", | |
- onMountUnmountCallbackWithState[Div, Barrage]({ ctx => | |
- println(s"starting the game with $config") | |
- val indigoUI = Barrage(config.networkBridge, config.gameConfiguration) | |
- indigoUI.launch( | |
- ctx.thisNode.ref.id, | |
- "width" -> "1500", | |
- "height" -> "950", | |
- "playerCount" -> config.playerCount.toString(), | |
- "rngSeed" -> config.rngSeed.toString(), | |
- "controllerIndex" -> config.controllerIndex.toString(), | |
- ) | |
- indigoUI | |
- }, { (thisNode, optIndigoUI) => | |
- for indigoUI <- optIndigoUI do | |
- indigoUI.halt() | |
- }), | |
+ onMountUnmountCallbackWithState[Div, Barrage]( | |
+ { ctx => | |
+ println(s"starting the game with $config") | |
+ val indigoUI = Barrage(config.networkBridge, config.gameConfiguration) | |
+ indigoUI.launch( | |
+ ctx.thisNode.ref.id, | |
+ "width" -> "1500", | |
+ "height" -> "950", | |
+ "playerCount" -> config.playerCount.toString(), | |
+ "rngSeed" -> config.rngSeed.toString(), | |
+ "controllerIndex" -> config.controllerIndex.toString(), | |
+ ) | |
+ indigoUI | |
+ }, | |
+ { (thisNode, optIndigoUI) => | |
+ for indigoUI <- optIndigoUI do | |
+ indigoUI.halt() | |
+ } | |
+ ), | |
) | |
lazy val rootAppElement: Div = | |
diff --git a/src/main/scala/be/doeraene/barrage/mainui/ReactivePeerJS.scala b/src/main/scala/be/doeraene/barrage/mainui/ReactivePeerJS.scala | |
index da264d1..740b3b3 100644 | |
--- a/src/main/scala/be/doeraene/barrage/mainui/ReactivePeerJS.scala | |
+++ b/src/main/scala/be/doeraene/barrage/mainui/ReactivePeerJS.scala | |
@@ -105,13 +105,15 @@ object ReactivePeerJS: | |
case PeerEvent.ConnectionMessageEvent(connection, message) => message | |
} | |
- private val asOwner: Owner = new OneTimeOwner(onAccessAfterKilled = { () => | |
- println(s"warning: onAccessAfterKilled") | |
- }) { | |
- uConnection.on("close") () => | |
- this.killSubscriptions() | |
- incomingEventBus.emit(PeerEvent.ConnectionClosed(DataConnection.this)) | |
- } | |
+ private val asOwner: Owner = | |
+ new OneTimeOwner(onAccessAfterKilled = { () => | |
+ println(s"warning: onAccessAfterKilled") | |
+ }) { | |
+ uConnection.on("close") () => | |
+ this.killSubscriptions() | |
+ incomingEventBus.emit(PeerEvent.ConnectionClosed(DataConnection.this)) | |
+ } | |
+ end asOwner | |
uConnection.on("data") (message: M) => | |
println(s"receiving: ${scala.scalajs.js.JSON.stringify(message.asInstanceOf[scala.scalajs.js.Any])}") | |
diff --git a/src/main/scala/be/doeraene/barrage/model/BarrageModel.scala b/src/main/scala/be/doeraene/barrage/model/BarrageModel.scala | |
index ee04a61..61bbff4 100644 | |
--- a/src/main/scala/be/doeraene/barrage/model/BarrageModel.scala | |
+++ b/src/main/scala/be/doeraene/barrage/model/BarrageModel.scala | |
@@ -225,9 +225,10 @@ object BarrageModel: | |
): BarrageModel = | |
val playerCount = companies.size | |
- val reservedActionFakeCompany = Company.AllCompanies.find { company => | |
- !companies.contains(company) | |
- }.getOrElse(Company.USA) // arbitrary choice | |
+ val reservedActionFakeCompany = Company.AllCompanies | |
+ .find { company => | |
+ !companies.contains(company) | |
+ }.getOrElse(Company.USA) // arbitrary choice | |
val reservedActions = | |
Action.ActionsReservedByPlayerCount(playerCount) | |
.map(action => action -> reservedActionFakeCompany) | |
@@ -255,18 +256,20 @@ object BarrageModel: | |
val companyProperties = | |
if gameConfiguration.introductoryRules then | |
- companies.zipWithIndex.map { (company, index) => | |
- val executiveOfficer = ExecutiveOfficer.ByCompanyForIntroductoryGame(company) | |
- val props = CompanyProperties.create(gameConfiguration, executiveOfficer) | |
- .addContract(Contract.StartContractsByCompany(company)) | |
- .withController(Controller.Fixed(index)) | |
- company -> props | |
- }.toMap | |
+ companies.zipWithIndex | |
+ .map { (company, index) => | |
+ val executiveOfficer = ExecutiveOfficer.ByCompanyForIntroductoryGame(company) | |
+ val props = CompanyProperties.create(gameConfiguration, executiveOfficer) | |
+ .addContract(Contract.StartContractsByCompany(company)) | |
+ .withController(Controller.Fixed(index)) | |
+ company -> props | |
+ }.toMap | |
else | |
- companies.zip(executiveOfficerDeck).map { (company, executiveOfficer) => | |
- val props = CompanyProperties.create(gameConfiguration, executiveOfficer) | |
- company -> props | |
- }.toMap | |
+ companies.zip(executiveOfficerDeck) | |
+ .map { (company, executiveOfficer) => | |
+ val props = CompanyProperties.create(gameConfiguration, executiveOfficer) | |
+ company -> props | |
+ }.toMap | |
end companyProperties | |
val allActions = | |
@@ -283,9 +286,10 @@ object BarrageModel: | |
PrivateContractSpace.Spaces.flatMap((_, spaces) => spaces).map(_ -> None).toMap | |
val nationalContractSpaces: Map[NationalContractSpace, Option[Contract]] = | |
- NationalContractSpace.AllSpaces.zip(nationalContractDeck).take(playerCount - 1).map { (space, contract) => | |
- space -> Some(contract) | |
- }.toMap | |
+ NationalContractSpace.AllSpaces.zip(nationalContractDeck).take(playerCount - 1) | |
+ .map { (space, contract) => | |
+ space -> Some(contract) | |
+ }.toMap | |
val actualPatentDeck = | |
if gameConfiguration.introductoryRules then Nil | |
diff --git a/src/main/scala/be/doeraene/barrage/model/Mechanics.scala b/src/main/scala/be/doeraene/barrage/model/Mechanics.scala | |
index f11060e..91e5011 100644 | |
--- a/src/main/scala/be/doeraene/barrage/model/Mechanics.scala | |
+++ b/src/main/scala/be/doeraene/barrage/model/Mechanics.scala | |
@@ -211,23 +211,25 @@ private[model] object Mechanics: | |
case Some(conduit) if damComp.connectedTo(conduit) => | |
(optConduit, optPowerhouse) | |
case _ => | |
- val alternatives = damComp.connectedTo.toList.filter { conduit => | |
- model.conduitProperties(conduit).isDefined | |
- }.flatMap { conduit => | |
- conduitToPowerhouse(model, conduit) match | |
- case Some(powerhouseComp) if conditions.excludedPowerhouse.contains(powerhouseComp) => Nil | |
- case Some(powerhouseComp) => List((Some(conduit), Some(powerhouseComp))) | |
- case None => Nil | |
- } | |
+ val alternatives = damComp.connectedTo.toList | |
+ .filter { conduit => | |
+ model.conduitProperties(conduit).isDefined | |
+ }.flatMap { conduit => | |
+ conduitToPowerhouse(model, conduit) match | |
+ case Some(powerhouseComp) if conditions.excludedPowerhouse.contains(powerhouseComp) => Nil | |
+ case Some(powerhouseComp) => List((Some(conduit), Some(powerhouseComp))) | |
+ case None => Nil | |
+ } | |
alternatives match | |
case Nil => | |
(None, None) | |
case onlyAlternative :: Nil => | |
onlyAlternative | |
case _ => | |
- alternatives.find { | |
- (_, somePowerhouse) => somePowerhouse == optPowerhouse | |
- }.getOrElse((None, None)) | |
+ alternatives | |
+ .find { (_, somePowerhouse) => | |
+ somePowerhouse == optPowerhouse | |
+ }.getOrElse((None, None)) | |
end newConduitAndPowerhouse | |
val (newConduit, newPowerhouse) = newConduitAndPowerhouse | |
val newState = | |
@@ -315,15 +317,16 @@ private[model] object Mechanics: | |
end conduitToPowerhouse | |
private def conduitToSources(model: BarrageModel, conduit: ConduitComponent): List[(DamComponent, Int)] = | |
- model.mapDescription.allDams.filter { dam => | |
- dam.connectedTo(conduit) | |
- }.map { dam => | |
- dam -> model.damProperties(dam) | |
- }.collect { | |
- case (dam, Some(DamProperties(company, _, waterDrops))) | |
- if waterDrops > 0 && company == model.currentCompany || company == NeutralCompany => | |
- dam -> waterDrops | |
- } | |
+ model.mapDescription.allDams | |
+ .filter { dam => | |
+ dam.connectedTo(conduit) | |
+ }.map { dam => | |
+ dam -> model.damProperties(dam) | |
+ }.collect { | |
+ case (dam, Some(DamProperties(company, _, waterDrops))) | |
+ if waterDrops > 0 && company == model.currentCompany || company == NeutralCompany => | |
+ dam -> waterDrops | |
+ } | |
end conduitToSources | |
private def powerhouseToConduits(model: BarrageModel, powerhouse: PowerhouseComponent): List[ConduitComponent] = | |
@@ -934,9 +937,10 @@ private[model] object Mechanics: | |
tileSpecialEffect match | |
case Dam0To1WaterDrop => | |
- val damsToUpdate = model.damProperties.collect { | |
- case (dam, Some(DamProperties(`company`, _, 0))) => dam | |
- }.toList | |
+ val damsToUpdate = model.damProperties | |
+ .collect { | |
+ case (dam, Some(DamProperties(`company`, _, 0))) => dam | |
+ }.toList | |
val newModel = damsToUpdate.foldLeft(model) (model, dam) => | |
model.withDamProps(dam, model.damProperties(dam).get.withWaterDrops(1)) | |
Result.Success(newModel) | |
@@ -1427,9 +1431,10 @@ private[model] object Mechanics: | |
yield | |
model2 | |
else | |
- val credits = Constants.CreditsEarnedForEnergyTrack.findLast { (requiredEnergy, credits) => | |
- energy >= requiredEnergy | |
- }.get._2 | |
+ val credits = Constants.CreditsEarnedForEnergyTrack | |
+ .findLast { (requiredEnergy, credits) => | |
+ energy >= requiredEnergy | |
+ }.get._2 | |
Animated.addCredits(model, company, credits) | |
end creditsEnergyTrack | |
@@ -1457,21 +1462,25 @@ private[model] object Mechanics: | |
val applicableCount = props.builtStructures(structureKind) | |
val components: List[Component] = structureKind match | |
case StructureKind.Base => | |
- model.damProperties.iterator.collect { | |
- case (dam, Some(DamProperties(`company`, _, _))) => dam | |
- }.toList | |
+ model.damProperties.iterator | |
+ .collect { | |
+ case (dam, Some(DamProperties(`company`, _, _))) => dam | |
+ }.toList | |
case StructureKind.Elevation => | |
- model.damProperties.iterator.collect { | |
- case (dam, Some(DamProperties(`company`, level, _))) if level > 1 => dam | |
- }.toList | |
+ model.damProperties.iterator | |
+ .collect { | |
+ case (dam, Some(DamProperties(`company`, level, _))) if level > 1 => dam | |
+ }.toList | |
case StructureKind.Conduit => | |
- model.conduitProperties.iterator.collect { | |
- case (conduit, Some(ConduitProperties(`company`))) => conduit | |
- }.toList | |
+ model.conduitProperties.iterator | |
+ .collect { | |
+ case (conduit, Some(ConduitProperties(`company`))) => conduit | |
+ }.toList | |
case StructureKind.Powerhouse => | |
- model.powerhouseProperties.iterator.collect { | |
- case (powerhouse, Some(PowerhouseProperties(`company`))) => powerhouse | |
- }.toList | |
+ model.powerhouseProperties.iterator | |
+ .collect { | |
+ case (powerhouse, Some(PowerhouseProperties(`company`))) => powerhouse | |
+ }.toList | |
val animation = Animation.HighlightComponents(components) | |
(applicableCount, animation) | |
case RoundBonus.FulfilledContracts => | |
@@ -1629,14 +1638,15 @@ private[model] object Mechanics: | |
model.damProperties(dam).filter(_.company == company).fold(0)(_.level) | |
def computeStructuresInArea(area: Area): Int = | |
- mapDesc.components.valuesIterator.filter { component => | |
- component.area == area | |
- }.map { | |
- case dam: DamComponent => ownDamLevel(dam) | |
- case conduit: ConduitComponent => if ownsConduit(conduit) then 1 else 0 | |
- case powerhouse: PowerhouseComponent => if ownsPowerhouse(powerhouse) then 1 else 0 | |
- case _ => 0 | |
- }.sum | |
+ mapDesc.components.valuesIterator | |
+ .filter { component => | |
+ component.area == area | |
+ }.map { | |
+ case dam: DamComponent => ownDamLevel(dam) | |
+ case conduit: ConduitComponent => if ownsConduit(conduit) then 1 else 0 | |
+ case powerhouse: PowerhouseComponent => if ownsPowerhouse(powerhouse) then 1 else 0 | |
+ case _ => 0 | |
+ }.sum | |
def computeStructuresInAreas(): List[Int] = | |
Area.values.toList.map(computeStructuresInArea(_)) | |
diff --git a/src/test/scala/be/doeraene/barrage/model/TestModel.scala b/src/test/scala/be/doeraene/barrage/model/TestModel.scala | |
index 8cf9e05..398e31d 100644 | |
--- a/src/test/scala/be/doeraene/barrage/model/TestModel.scala | |
+++ b/src/test/scala/be/doeraene/barrage/model/TestModel.scala | |
@@ -6,9 +6,10 @@ import DefaultMap.* | |
object TestModel: | |
def apply(props: ModelProps*): BarrageModel = | |
- val (companies0, officers0) = props.collect { | |
- case ModelProps.SelectCompany(company, officer) => (company, officer) | |
- }.toList.unzip | |
+ val (companies0, officers0) = props | |
+ .collect { | |
+ case ModelProps.SelectCompany(company, officer) => (company, officer) | |
+ }.toList.unzip | |
val companies = if companies0.isEmpty then Company.AllCompanies else companies0 | |
val officers = | |
if officers0.isEmpty then companies.map(ExecutiveOfficer.ByCompanyForIntroductoryGame(_)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/main/scala/be/doeraene/barrage/Barrage.scala b/src/main/scala/be/doeraene/barrage/Barrage.scala | |
index bbacfda..d578a66 100644 | |
--- a/src/main/scala/be/doeraene/barrage/Barrage.scala | |
+++ b/src/main/scala/be/doeraene/barrage/Barrage.scala | |
@@ -146,33 +146,32 @@ final class Barrage(networkBridge: NetworkBridge, gameConfiguration: GameConfigu | |
val bootAssets: Set[AssetType] = | |
val perCompany: Set[AssetType] = Company.AllCompanies | |
- .flatMap { company => | |
+ .flatMap company => | |
Set( | |
AssetType.Image(companyConduitAssetNames(company), AssetPath(s"assets/conduit-${company.stringID}.png")), | |
AssetType.Image(companyPowerhouseAssetNames(company), AssetPath(s"assets/powerhouse-${company.stringID}.png")), | |
AssetType.Image(companyEngineerAssetNames(company), AssetPath(s"assets/engineer-${company.stringID}.png")), | |
AssetType.Image(companySpecialAbilityAssetNames(company), AssetPath(s"assets/special-ability-${company.stringID}.png")), | |
) | |
- }.toSet | |
+ .toSet | |
val perCompanyOrNeutral: Set[AssetType] = Company.AllCompaniesAndNeutral | |
- .flatMap { company => | |
+ .flatMap company => | |
companyDamAssetNames(company) | |
- .map { (level, assetName) => | |
+ .map (level, assetName) => | |
AssetType.Image(assetName, AssetPath(s"assets/dam$level-${company.stringID}.png")) | |
- }.toSet | |
- }.toSet | |
+ .toSet | |
+ .toSet | |
val perExecutiveOfficer: Set[AssetType] = ExecutiveOfficer.AllExecutiveOfficers | |
- .flatMap { officer => | |
+ .flatMap officer => | |
Set( | |
AssetType.Image(executiveOfficerSpecialAbilityAssetNames(officer), AssetPath(s"assets/special-ability-${officer.stringID}.png")), | |
) | |
- }.toSet | |
+ .toSet | |
- val forTechnologyTiles = technologyTileAssetNames.map { (tile, assetName) => | |
+ val forTechnologyTiles = technologyTileAssetNames.map (tile, assetName) => | |
AssetType.Image(assetName, AssetPath(s"assets/$assetName.png")) | |
- } | |
val global: Set[AssetType] = Set( | |
AssetType.Image(ayarFontAssetName, AssetPath("assets/ayar-font.png")), | |
@@ -479,10 +478,8 @@ final class Barrage(networkBridge: NetworkBridge, gameConfiguration: GameConfigu | |
val (element, offset) = docs.iterator | |
.map((doc, offset) => (doc.getElementById(id), offset)) | |
.find(_._1 != null) | |
- .getOrElse { | |
+ .getOrElse: | |
throw new IllegalArgumentException(s"#$id not found") | |
- } | |
- | |
element match | |
case rect: dom.SVGRectElement => | |
def value(dim: dom.SVGAnimatedLength): Int = | |
@@ -604,9 +601,8 @@ final class Barrage(networkBridge: NetworkBridge, gameConfiguration: GameConfigu | |
import be.doeraene.barrage.BarrageEvents.{GameInterfaceElementClick => GIEC} | |
println("click at " + pt) | |
viewModel.hitBoxes | |
- .find { (rect, key) => | |
+ .find (rect, key) => | |
rect.contains(pt) | |
- } | |
.match | |
case Some((_, key)) => | |
println("component: " + key) | |
@@ -621,9 +617,8 @@ final class Barrage(networkBridge: NetworkBridge, gameConfiguration: GameConfigu | |
.addGlobalEvents(GIEC(element)) | |
case _ => | |
mainButtonRects | |
- .find { (button, rect) => | |
+ .find (button, rect) => | |
rect.contains(pt) && isButtonEnabled(model, button) | |
- } | |
.match | |
case Some((button, _)) => | |
println("button: " + button) | |
@@ -1440,9 +1435,9 @@ final class Barrage(networkBridge: NetworkBridge, gameConfiguration: GameConfigu | |
case _ => center | |
val headstreamsDrops = model.headstreamProperties | |
- .map { (headstream, headstreamProps) => | |
+ .map (headstream, headstreamProps) => | |
posOf(headstream) -> (headstreamProps.waterDrops, 0) | |
- }.toList | |
+ .toList | |
val (highlightedDam, highlightedWaterDrops) = model.state match | |
case MainState.ProduceEnergyAction(_, Some((dam, waterDrops)), _, _, _, _, _) => | |
@@ -1450,7 +1445,7 @@ final class Barrage(networkBridge: NetworkBridge, gameConfiguration: GameConfigu | |
case _ => | |
(model.mapDescription.allDams.head, 0) | |
val damDrops = model.damProperties | |
- .map { (dam, damProps) => | |
+ .map (dam, damProps) => | |
val pos = posOf(dam) | |
val waterDrops = damProps.fold(0)(_.waterDrops) | |
val highlightedCount = | |
@@ -1463,7 +1458,7 @@ final class Barrage(networkBridge: NetworkBridge, gameConfiguration: GameConfigu | |
case _ => | |
0 | |
pos -> (waterDrops, highlightedCount) | |
- }.toList | |
+ .toList | |
val animatedDrops = viewModel.currentAnimation match | |
case Some((Animation.WaterDropFlow(waterDrops, from), progress, _)) => | |
diff --git a/src/main/scala/be/doeraene/barrage/mainui/Main.scala b/src/main/scala/be/doeraene/barrage/mainui/Main.scala | |
index 2f0b54b..16938bc 100644 | |
--- a/src/main/scala/be/doeraene/barrage/mainui/Main.scala | |
+++ b/src/main/scala/be/doeraene/barrage/mainui/Main.scala | |
@@ -577,10 +577,9 @@ object Main: | |
) | |
indigoUI | |
}, | |
- { (thisNode, optIndigoUI) => | |
+ (thisNode, optIndigoUI) => | |
for indigoUI <- optIndigoUI do | |
indigoUI.halt() | |
- } | |
), | |
) | |
diff --git a/src/main/scala/be/doeraene/barrage/mainui/ReactivePeerJS.scala b/src/main/scala/be/doeraene/barrage/mainui/ReactivePeerJS.scala | |
index 740b3b3..7c99489 100644 | |
--- a/src/main/scala/be/doeraene/barrage/mainui/ReactivePeerJS.scala | |
+++ b/src/main/scala/be/doeraene/barrage/mainui/ReactivePeerJS.scala | |
@@ -106,13 +106,12 @@ object ReactivePeerJS: | |
} | |
private val asOwner: Owner = | |
- new OneTimeOwner(onAccessAfterKilled = { () => | |
+ new OneTimeOwner(onAccessAfterKilled = () => | |
println(s"warning: onAccessAfterKilled") | |
- }) { | |
+ ): | |
uConnection.on("close") () => | |
this.killSubscriptions() | |
incomingEventBus.emit(PeerEvent.ConnectionClosed(DataConnection.this)) | |
- } | |
end asOwner | |
uConnection.on("data") (message: M) => | |
diff --git a/src/main/scala/be/doeraene/barrage/model/BarrageModel.scala b/src/main/scala/be/doeraene/barrage/model/BarrageModel.scala | |
index 61bbff4..4c1c60b 100644 | |
--- a/src/main/scala/be/doeraene/barrage/model/BarrageModel.scala | |
+++ b/src/main/scala/be/doeraene/barrage/model/BarrageModel.scala | |
@@ -226,9 +226,9 @@ object BarrageModel: | |
val playerCount = companies.size | |
val reservedActionFakeCompany = Company.AllCompanies | |
- .find { company => | |
+ .find company => | |
!companies.contains(company) | |
- }.getOrElse(Company.USA) // arbitrary choice | |
+ .getOrElse(Company.USA) // arbitrary choice | |
val reservedActions = | |
Action.ActionsReservedByPlayerCount(playerCount) | |
.map(action => action -> reservedActionFakeCompany) | |
@@ -257,19 +257,19 @@ object BarrageModel: | |
val companyProperties = | |
if gameConfiguration.introductoryRules then | |
companies.zipWithIndex | |
- .map { (company, index) => | |
+ .map (company, index) => | |
val executiveOfficer = ExecutiveOfficer.ByCompanyForIntroductoryGame(company) | |
val props = CompanyProperties.create(gameConfiguration, executiveOfficer) | |
.addContract(Contract.StartContractsByCompany(company)) | |
.withController(Controller.Fixed(index)) | |
company -> props | |
- }.toMap | |
+ .toMap | |
else | |
companies.zip(executiveOfficerDeck) | |
- .map { (company, executiveOfficer) => | |
+ .map (company, executiveOfficer) => | |
val props = CompanyProperties.create(gameConfiguration, executiveOfficer) | |
company -> props | |
- }.toMap | |
+ .toMap | |
end companyProperties | |
val allActions = | |
@@ -287,9 +287,9 @@ object BarrageModel: | |
val nationalContractSpaces: Map[NationalContractSpace, Option[Contract]] = | |
NationalContractSpace.AllSpaces.zip(nationalContractDeck).take(playerCount - 1) | |
- .map { (space, contract) => | |
+ .map (space, contract) => | |
space -> Some(contract) | |
- }.toMap | |
+ .toMap | |
val actualPatentDeck = | |
if gameConfiguration.introductoryRules then Nil | |
diff --git a/src/main/scala/be/doeraene/barrage/model/Mechanics.scala b/src/main/scala/be/doeraene/barrage/model/Mechanics.scala | |
index 91e5011..ba58884 100644 | |
--- a/src/main/scala/be/doeraene/barrage/model/Mechanics.scala | |
+++ b/src/main/scala/be/doeraene/barrage/model/Mechanics.scala | |
@@ -212,14 +212,13 @@ private[model] object Mechanics: | |
(optConduit, optPowerhouse) | |
case _ => | |
val alternatives = damComp.connectedTo.toList | |
- .filter { conduit => | |
+ .filter conduit => | |
model.conduitProperties(conduit).isDefined | |
- }.flatMap { conduit => | |
+ .flatMap conduit => | |
conduitToPowerhouse(model, conduit) match | |
case Some(powerhouseComp) if conditions.excludedPowerhouse.contains(powerhouseComp) => Nil | |
case Some(powerhouseComp) => List((Some(conduit), Some(powerhouseComp))) | |
case None => Nil | |
- } | |
alternatives match | |
case Nil => | |
(None, None) | |
@@ -318,11 +317,11 @@ private[model] object Mechanics: | |
private def conduitToSources(model: BarrageModel, conduit: ConduitComponent): List[(DamComponent, Int)] = | |
model.mapDescription.allDams | |
- .filter { dam => | |
+ .filter dam => | |
dam.connectedTo(conduit) | |
- }.map { dam => | |
+ .map dam => | |
dam -> model.damProperties(dam) | |
- }.collect { | |
+ .collect { | |
case (dam, Some(DamProperties(company, _, waterDrops))) | |
if waterDrops > 0 && company == model.currentCompany || company == NeutralCompany => | |
dam -> waterDrops | |
@@ -1432,9 +1431,9 @@ private[model] object Mechanics: | |
model2 | |
else | |
val credits = Constants.CreditsEarnedForEnergyTrack | |
- .findLast { (requiredEnergy, credits) => | |
+ .findLast (requiredEnergy, credits) => | |
energy >= requiredEnergy | |
- }.get._2 | |
+ .get._2 | |
Animated.addCredits(model, company, credits) | |
end creditsEnergyTrack | |
@@ -1639,9 +1638,9 @@ private[model] object Mechanics: | |
def computeStructuresInArea(area: Area): Int = | |
mapDesc.components.valuesIterator | |
- .filter { component => | |
+ .filter component => | |
component.area == area | |
- }.map { | |
+ .map { | |
case dam: DamComponent => ownDamLevel(dam) | |
case conduit: ConduitComponent => if ownsConduit(conduit) then 1 else 0 | |
case powerhouse: PowerhouseComponent => if ownsPowerhouse(powerhouse) then 1 else 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/main/scala/be/doeraene/barrage/BarrageViewModel.scala b/src/main/scala/be/doeraene/barrage/BarrageViewModel.scala | |
index 4477e5b..306bdc6 100644 | |
--- a/src/main/scala/be/doeraene/barrage/BarrageViewModel.scala | |
+++ b/src/main/scala/be/doeraene/barrage/BarrageViewModel.scala | |
@@ -142,11 +142,10 @@ object BarrageViewModel: | |
type ComponentCoordsMap = Map[ComponentKey, Rectangle] | |
def apply(model: BarrageModel, allComponentCoords: ComponentCoordsMap): BarrageViewModel = | |
- val allComponentCoords1 = allComponentCoords.filter { (key, _) => | |
+ val allComponentCoords1 = allComponentCoords.filter (key, coords) => | |
key match | |
case action: Action => model.allActions.contains(action) | |
case _ => true | |
- } | |
new BarrageViewModel( | |
model.mapDescription, | |
diff --git a/src/main/scala/be/doeraene/barrage/model/Mechanics.scala b/src/main/scala/be/doeraene/barrage/model/Mechanics.scala | |
index ba58884..ae77b8a 100644 | |
--- a/src/main/scala/be/doeraene/barrage/model/Mechanics.scala | |
+++ b/src/main/scala/be/doeraene/barrage/model/Mechanics.scala | |
@@ -226,9 +226,9 @@ private[model] object Mechanics: | |
onlyAlternative | |
case _ => | |
alternatives | |
- .find { (_, somePowerhouse) => | |
+ .find (someConduit, somePowerhouse) => | |
somePowerhouse == optPowerhouse | |
- }.getOrElse((None, None)) | |
+ .getOrElse((None, None)) | |
end newConduitAndPowerhouse | |
val (newConduit, newPowerhouse) = newConduitAndPowerhouse | |
val newState = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/main/scala/be/doeraene/barrage/Barrage.scala b/src/main/scala/be/doeraene/barrage/Barrage.scala | |
index d578a66..5d9bbcc 100644 | |
--- a/src/main/scala/be/doeraene/barrage/Barrage.scala | |
+++ b/src/main/scala/be/doeraene/barrage/Barrage.scala | |
@@ -856,7 +856,7 @@ final class Barrage(networkBridge: NetworkBridge, gameConfiguration: GameConfigu | |
case _ => | |
actualSegments | |
- val wheelItems: List[SceneNode] = segments.zipWithIndex.flatMap { | |
+ val wheelItems: List[SceneNode] = segments.zipWithIndex.flatMap: | |
case ((ConstructionWheel.Segment(optTile, excavators, concreteMixers), reuse), segmentIndex) => | |
val angle = segmentIndexToAngle(segmentIndex) + animationRotationAngle | |
@@ -929,7 +929,7 @@ final class Barrage(networkBridge: NetworkBridge, gameConfiguration: GameConfigu | |
List(countT, concreteMixerG) | |
tileNodes ::: (excavatorsNodes ::: concreteMixersNodes).map(_.withDepth(Depth(1))) | |
- } | |
+ end wheelItems | |
val wheel = Graphic(Rectangle(0, 0, 210, 210), Material.Bitmap(constructionWheelAssetName)) | |
.withRefAtCenter | |
@@ -1485,12 +1485,11 @@ final class Barrage(networkBridge: NetworkBridge, gameConfiguration: GameConfigu | |
val highlightedG = Graphic(Rectangle(0, 0, 20, 32), Material.Bitmap(waterDropHighlightedAssetName)) | |
.withRefAtCenter | |
- allDrops.flatMap { | |
+ allDrops.flatMap: | |
case (position, (count, highlightedCount)) => | |
(1 to count).map i => | |
val g = if i > count - highlightedCount then highlightedG else regularG | |
g.moveTo(position.x + 10 * i - 5 * count, position.y) | |
- } | |
end drawWaterDrops | |
def drawDams(model: BarrageModel, viewModel: BarrageViewModel): List[Graphic[_]] = | |
diff --git a/src/main/scala/be/doeraene/barrage/mainui/Main.scala b/src/main/scala/be/doeraene/barrage/mainui/Main.scala | |
index 16938bc..8448dbd 100644 | |
--- a/src/main/scala/be/doeraene/barrage/mainui/Main.scala | |
+++ b/src/main/scala/be/doeraene/barrage/mainui/Main.scala | |
@@ -102,10 +102,10 @@ object ServerState: | |
// Assign controller indices | |
val newClients = scala.util.Random.shuffle(clients).zipWithIndex | |
- .map { | |
+ .map: | |
case ((connection, info), index) => | |
connection -> info.copy(controllerIndex = index) | |
- }.to(ListMap) | |
+ .to(ListMap) | |
val rngSeed = scala.util.Random.nextInt() | |
val initialModel = model.BarrageModel.create( | |
@@ -384,10 +384,10 @@ object Main: | |
p(child <-- peerJS.id.map(id => s"My ID: ${id.getOrElse("<unknown>")}")), | |
ul( | |
children <-- serverState | |
- .map { | |
+ .map: | |
case ServerState.ConstructingGame(clients) => clients.values.toList | |
case ServerState.RunningGame(clients, _, _, _, _, _) => clients.values.toList | |
- }.split(_.uuid) { (uuid, initial, clientInfoSignal) => | |
+ .split(_.uuid) { (uuid, initial, clientInfoSignal) => | |
li( | |
child <-- clientInfoSignal.map { clientInfo => | |
val statusIcon = if clientInfo.connection.isDefined then "✔️" else "❌" | |
diff --git a/src/main/scala/be/doeraene/barrage/mainui/ReactivePeerJS.scala b/src/main/scala/be/doeraene/barrage/mainui/ReactivePeerJS.scala | |
index 7c99489..345ced4 100644 | |
--- a/src/main/scala/be/doeraene/barrage/mainui/ReactivePeerJS.scala | |
+++ b/src/main/scala/be/doeraene/barrage/mainui/ReactivePeerJS.scala | |
@@ -101,9 +101,8 @@ object ReactivePeerJS: | |
private val incomingEventBus = new EventBus[PeerEvent[M]] | |
val incomingEvents: EventStream[PeerEvent[M]] = incomingEventBus.events | |
- val incomingMessages: EventStream[M] = incomingEvents.collect { | |
+ val incomingMessages: EventStream[M] = incomingEvents.collect: | |
case PeerEvent.ConnectionMessageEvent(connection, message) => message | |
- } | |
private val asOwner: Owner = | |
new OneTimeOwner(onAccessAfterKilled = () => | |
diff --git a/src/main/scala/be/doeraene/barrage/model/Mechanics.scala b/src/main/scala/be/doeraene/barrage/model/Mechanics.scala | |
index ae77b8a..cd962a8 100644 | |
--- a/src/main/scala/be/doeraene/barrage/model/Mechanics.scala | |
+++ b/src/main/scala/be/doeraene/barrage/model/Mechanics.scala | |
@@ -321,11 +321,10 @@ private[model] object Mechanics: | |
dam.connectedTo(conduit) | |
.map dam => | |
dam -> model.damProperties(dam) | |
- .collect { | |
+ .collect: | |
case (dam, Some(DamProperties(company, _, waterDrops))) | |
if waterDrops > 0 && company == model.currentCompany || company == NeutralCompany => | |
dam -> waterDrops | |
- } | |
end conduitToSources | |
private def powerhouseToConduits(model: BarrageModel, powerhouse: PowerhouseComponent): List[ConduitComponent] = | |
@@ -937,9 +936,9 @@ private[model] object Mechanics: | |
tileSpecialEffect match | |
case Dam0To1WaterDrop => | |
val damsToUpdate = model.damProperties | |
- .collect { | |
+ .collect: | |
case (dam, Some(DamProperties(`company`, _, 0))) => dam | |
- }.toList | |
+ .toList | |
val newModel = damsToUpdate.foldLeft(model) (model, dam) => | |
model.withDamProps(dam, model.damProperties(dam).get.withWaterDrops(1)) | |
Result.Success(newModel) | |
@@ -972,10 +971,9 @@ private[model] object Mechanics: | |
Result.Success(newModel) | |
case Earn3VictoryPointsForEachLevel2Dam => | |
- val count = model.damProperties.valuesIterator.count { | |
+ val count = model.damProperties.valuesIterator.count: | |
case Some(DamProperties(`company`, level, _)) => level >= 2 | |
case _ => false | |
- } | |
val points = 3 * count | |
val newModel = model.insertFollowUpEvent(Reward.VictoryPoints(points)) | |
Result.Success(newModel) | |
@@ -1148,10 +1146,9 @@ private[model] object Mechanics: | |
def checkBuildBase(model: BarrageModel, dam: DamComponent): Result[Unit] = | |
val basin = model.mapDescription.allBuildableComponentsByBasin.find(_.contains(dam)).get | |
- val alreadyBuiltInBasin = basin.exists { | |
+ val alreadyBuiltInBasin = basin.exists: | |
case otherDam: DamComponent => model.damProperties(otherDam).exists(_.company == model.currentCompany) | |
case _ => false | |
- } | |
if alreadyBuiltInBasin then | |
Result.Error("you have already built a base in this basin") | |
else if model.damProperties(dam).isDefined then | |
@@ -1462,24 +1459,24 @@ private[model] object Mechanics: | |
val components: List[Component] = structureKind match | |
case StructureKind.Base => | |
model.damProperties.iterator | |
- .collect { | |
+ .collect: | |
case (dam, Some(DamProperties(`company`, _, _))) => dam | |
- }.toList | |
+ .toList | |
case StructureKind.Elevation => | |
model.damProperties.iterator | |
- .collect { | |
+ .collect: | |
case (dam, Some(DamProperties(`company`, level, _))) if level > 1 => dam | |
- }.toList | |
+ .toList | |
case StructureKind.Conduit => | |
model.conduitProperties.iterator | |
- .collect { | |
+ .collect: | |
case (conduit, Some(ConduitProperties(`company`))) => conduit | |
- }.toList | |
+ .toList | |
case StructureKind.Powerhouse => | |
model.powerhouseProperties.iterator | |
- .collect { | |
+ .collect: | |
case (powerhouse, Some(PowerhouseProperties(`company`))) => powerhouse | |
- }.toList | |
+ .toList | |
val animation = Animation.HighlightComponents(components) | |
(applicableCount, animation) | |
case RoundBonus.FulfilledContracts => | |
@@ -1640,12 +1637,12 @@ private[model] object Mechanics: | |
mapDesc.components.valuesIterator | |
.filter component => | |
component.area == area | |
- .map { | |
+ .map: | |
case dam: DamComponent => ownDamLevel(dam) | |
case conduit: ConduitComponent => if ownsConduit(conduit) then 1 else 0 | |
case powerhouse: PowerhouseComponent => if ownsPowerhouse(powerhouse) then 1 else 0 | |
case _ => 0 | |
- }.sum | |
+ .sum | |
def computeStructuresInAreas(): List[Int] = | |
Area.values.toList.map(computeStructuresInArea(_)) | |
diff --git a/src/test/scala/be/doeraene/barrage/model/TestModel.scala b/src/test/scala/be/doeraene/barrage/model/TestModel.scala | |
index 398e31d..c309c5b 100644 | |
--- a/src/test/scala/be/doeraene/barrage/model/TestModel.scala | |
+++ b/src/test/scala/be/doeraene/barrage/model/TestModel.scala | |
@@ -7,9 +7,9 @@ import DefaultMap.* | |
object TestModel: | |
def apply(props: ModelProps*): BarrageModel = | |
val (companies0, officers0) = props | |
- .collect { | |
+ .collect: | |
case ModelProps.SelectCompany(company, officer) => (company, officer) | |
- }.toList.unzip | |
+ .toList.unzip | |
val companies = if companies0.isEmpty then Company.AllCompanies else companies0 | |
val officers = | |
if officers0.isEmpty then companies.map(ExecutiveOfficer.ByCompanyForIntroductoryGame(_)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/main/scala/be/doeraene/barrage/mainui/Main.scala b/src/main/scala/be/doeraene/barrage/mainui/Main.scala | |
index 8448dbd..927064c 100644 | |
--- a/src/main/scala/be/doeraene/barrage/mainui/Main.scala | |
+++ b/src/main/scala/be/doeraene/barrage/mainui/Main.scala | |
@@ -387,20 +387,18 @@ object Main: | |
.map: | |
case ServerState.ConstructingGame(clients) => clients.values.toList | |
case ServerState.RunningGame(clients, _, _, _, _, _) => clients.values.toList | |
- .split(_.uuid) { (uuid, initial, clientInfoSignal) => | |
+ .split(_.uuid) (uuid, initial, clientInfoSignal) => | |
li( | |
- child <-- clientInfoSignal.map { clientInfo => | |
+ child <-- clientInfoSignal.map clientInfo => | |
val statusIcon = if clientInfo.connection.isDefined then "✔️" else "❌" | |
- s"${uuid} (${clientInfo.displayName}) $statusIcon " | |
- }, | |
+ s"${uuid} (${clientInfo.displayName}) $statusIcon ", | |
button( | |
"🗑️", | |
onClick.mapTo(UIEvent.KickClient(uuid)) --> uiEventBus, | |
), | |
- ) | |
- }, | |
+ ), | |
), | |
- child <-- serverState.splitOne(_.ordinal) { (ord, initialState, stateSignal) => | |
+ child <-- serverState.splitOne(_.ordinal) (ord, initialState, stateSignal) => | |
initialState match | |
case _: ServerState.ConstructingGame => | |
val (gameConfigDiv, gameConfiguration) = gameConfigurationComponent() | |
@@ -409,10 +407,9 @@ object Main: | |
p( | |
button( | |
"Start game", | |
- disabled <-- stateSignal.map { | |
+ disabled <-- stateSignal.map: | |
case ServerState.ConstructingGame(clients) => clients.sizeIs < 2 || clients.sizeIs > 4 | |
- case _ => false | |
- }, | |
+ case _ => false, | |
composeEvents(onClick)(_.sample(gameConfiguration)) | |
--> uiEventBus.writer.contramap(UIEvent.StartGame(_)), | |
), | |
@@ -450,8 +447,7 @@ object Main: | |
), | |
p("Objective: ", child <-- model.map(_.objective.toString)), | |
p("Current player: ", child <-- model.map(_.currentCompany.toString)), | |
- ) | |
- }, | |
+ ), | |
) | |
def joinGame(uuid: UUID, peerID: String): Unit = | |
@@ -564,7 +560,7 @@ object Main: | |
div( | |
idAttr := "indigo-container", | |
onMountUnmountCallbackWithState[Div, Barrage]( | |
- { ctx => | |
+ ctx => | |
println(s"starting the game with $config") | |
val indigoUI = Barrage(config.networkBridge, config.gameConfiguration) | |
indigoUI.launch( | |
@@ -575,8 +571,7 @@ object Main: | |
"rngSeed" -> config.rngSeed.toString(), | |
"controllerIndex" -> config.controllerIndex.toString(), | |
) | |
- indigoUI | |
- }, | |
+ indigoUI, | |
(thisNode, optIndigoUI) => | |
for indigoUI <- optIndigoUI do | |
indigoUI.halt() | |
@@ -591,22 +586,20 @@ object Main: | |
" ; ", | |
child <-- peerJS.id.map(_.toString), | |
), | |
- child <-- gameConfigToApply.signal.map { | |
+ child <-- gameConfigToApply.signal.map: | |
case Some(config) => | |
indigoGameElement(config) | |
case None => | |
div( | |
- child <-- networkMode.splitOne(_.ordinal) { (key, input, inputSig) => | |
+ child <-- networkMode.splitOne(_.ordinal) (key, input, inputSig) => | |
input match | |
case Mode.Undecided => | |
undecidedModeElement | |
case Mode.Server(_) => | |
serverInterface(inputSig.map(_.asInstanceOf[Mode.Server].state)) | |
case Mode.Client(_) => | |
- clientInterface(inputSig.map(_.asInstanceOf[Mode.Client].state)) | |
- }, | |
- ) | |
- }, | |
+ clientInterface(inputSig.map(_.asInstanceOf[Mode.Client].state)), | |
+ ), | |
) | |
def main(args: Array[String]): Unit = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/main/scala/be/doeraene/barrage/mainui/Main.scala b/src/main/scala/be/doeraene/barrage/mainui/Main.scala | |
index 927064c..e65467d 100644 | |
--- a/src/main/scala/be/doeraene/barrage/mainui/Main.scala | |
+++ b/src/main/scala/be/doeraene/barrage/mainui/Main.scala | |
@@ -603,7 +603,8 @@ object Main: | |
) | |
def main(args: Array[String]): Unit = | |
- documentEvents.onDomContentLoaded.foreach { _ => | |
- render(dom.document.getElementById("main-container"), rootAppElement) | |
- } (unsafeWindowOwner) | |
+ documentEvents.onDomContentLoaded.foreach( | |
+ _ => | |
+ render(dom.document.getElementById("main-container"), rootAppElement) | |
+ )(unsafeWindowOwner) | |
end main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/main/scala/be/doeraene/barrage/mainui/Main.scala b/src/main/scala/be/doeraene/barrage/mainui/Main.scala | |
index e65467d..d187265 100644 | |
--- a/src/main/scala/be/doeraene/barrage/mainui/Main.scala | |
+++ b/src/main/scala/be/doeraene/barrage/mainui/Main.scala | |
@@ -483,9 +483,9 @@ object Main: | |
button( | |
"Join", | |
disabled <-- myClientUUID.signal.map(_.isEmpty), | |
- composeEvents(onClick)(_.sample(myClientUUID.signal.combineWith(peerID))) --> { x => | |
- joinGame(x._1.get, x._2) | |
- }, | |
+ composeEvents(onClick)(_.sample(myClientUUID.signal.combineWith(peerID))) --> : | |
+ x => | |
+ joinGame(x._1.get, x._2), | |
), | |
), | |
h1("Create a game"), | |
@@ -545,11 +545,12 @@ object Main: | |
h1("Joining game"), | |
p( | |
label("Your name: "), | |
- input(typ := "text", defaultValue := "", onInput.mapToValue --> { displayName => | |
- if displayName != "" then | |
- println(s"setting display name to $displayName") | |
- uiEventBus.emit(UIEvent.SetDisplayName(displayName)) | |
- }), | |
+ input(typ := "text", defaultValue := "", onInput.mapToValue --> : | |
+ displayName => | |
+ if displayName != "" then | |
+ println(s"setting display name to $displayName") | |
+ uiEventBus.emit(UIEvent.SetDisplayName(displayName)) | |
+ ), | |
), | |
p( | |
button("Leave", onClick.mapTo(UIEvent.Leave) --> uiEventBus) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment