-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
220 additions
and
491 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
|
||
# production | ||
/build | ||
/dist | ||
|
||
# misc | ||
.DS_Store | ||
|
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
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
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import {Room} from "bastoni/model/room" | ||
import {CardSuit, CardRank} from "bastoni/model/card" | ||
import {Stage, Text} from "@pixi/react"; | ||
import Card from "./Card.tsx"; | ||
import {CardStyle} from "../view/CardStyle.ts"; | ||
import {TextStyle} from "pixi.js"; | ||
|
||
interface RoomProps { | ||
room: Room | ||
} | ||
|
||
export function GameRoom({room}: RoomProps) { | ||
return ( | ||
<Stage options={{antialias: true, autoDensity: false, resolution: 1}} | ||
width={window.innerWidth} | ||
height={window.innerHeight} | ||
> | ||
<Text | ||
text={room.players[room.me]?.name} | ||
style={new TextStyle({fill: 0xFFFFFF, fontSize: 40})} | ||
/> | ||
|
||
<Card | ||
card={{ | ||
rank: CardRank.Tre, | ||
suit: CardSuit.Bastoni, | ||
ref: 3 | ||
}} | ||
width={200} | ||
topLeft={{x: 0, y: 0}} | ||
style={CardStyle.Napoletane} | ||
/> | ||
<Card | ||
card={{ | ||
rank: CardRank.Asso, | ||
suit: CardSuit.Spade, | ||
ref: 3 | ||
}} | ||
width={200} | ||
topLeft={{x: 900, y: 500}} | ||
style={CardStyle.Napoletane} | ||
rotation={{deg: 2}} | ||
/> | ||
<Card | ||
card={{ref: 2}} | ||
width={200} | ||
topLeft={{x: 100, y: 200}} | ||
style={CardStyle.Napoletane} | ||
/> | ||
</Stage> | ||
) | ||
} |
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
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const retro = './cards/retro.svg' | ||
|
||
export default retro |
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
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
54 changes: 54 additions & 0 deletions
54
modules/domain/src/test/scala/bastoni/domain/logic/PlayerConnectionSpec.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package bastoni.domain.logic | ||
|
||
import bastoni.domain.AsyncIOFreeSpec | ||
import bastoni.domain.model.Event.{PlayerJoinedTable, PlayerLeftTable} | ||
import bastoni.domain.model.{RoomId, User, UserId} | ||
import bastoni.domain.view.{FromPlayer, ToPlayer} | ||
import cats.effect.IO | ||
|
||
class PlayerConnectionSpec extends AsyncIOFreeSpec: | ||
private val me = User(UserId.newId, "me") | ||
private val roomId = RoomId.newId | ||
|
||
"A player can connect and join a table" in { | ||
val input = fs2.Stream( | ||
FromPlayer.Connect, | ||
FromPlayer.JoinTable, | ||
FromPlayer.LeaveTable | ||
) | ||
|
||
Services | ||
.inMemory[IO] | ||
.use { case (controller, run) => | ||
controller | ||
.connectPlayer(me, roomId) | ||
.take(3) | ||
.concurrently(controller.publish(me, roomId)(input)) | ||
.concurrently(run) | ||
.compile | ||
.toList | ||
} | ||
.asserting { | ||
case (msg1, room1) :: (msg2, room2) :: (msg3, room3) :: Nil => | ||
msg1 shouldBe a[ToPlayer.Connected] | ||
msg2 match | ||
case ToPlayer.GameEvent(PlayerJoinedTable(joiner, _)) => | ||
joiner shouldBe me | ||
case _ => | ||
fail("Unexpected message #2") | ||
msg3 match | ||
case ToPlayer.GameEvent(PlayerLeftTable(leaver, _)) => | ||
leaver shouldBe me | ||
case _ => | ||
fail("Unexpected message #3") | ||
|
||
room1.fold(fail("Room not returned"))(_.players.get(me.id) shouldBe None) | ||
room2.fold(fail("Room not returned"))(_.players.get(me.id) shouldBe Some(me)) | ||
room2.fold(fail("Room not returned"))(_.seatFor(me) shouldBe defined) | ||
room3.fold(fail("Room not returned"))(_.players.get(me.id) shouldBe Some(me)) | ||
room3.fold(fail("Room not returned"))(_.seatFor(me) should not be defined) | ||
|
||
case msgs => fail(s"Unexpected number of messages produced: ${msgs.length}") | ||
} | ||
} | ||
end PlayerConnectionSpec |
26 changes: 26 additions & 0 deletions
26
modules/domain/src/test/scala/bastoni/domain/model/RoomViewSpec.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package bastoni.domain.model | ||
|
||
import bastoni.domain.model.Event.PlayerJoinedTable | ||
import org.scalatest.freespec.AnyFreeSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class RoomViewSpec extends AnyFreeSpec with Matchers: | ||
|
||
val me: User = User(UserId.newId, "me") | ||
val emptyRoom: RoomPlayerView = RoomPlayerView( | ||
me.id, | ||
List( | ||
EmptySeat(1, Nil, Nil), | ||
EmptySeat(2, Nil, Nil) | ||
), | ||
Nil, | ||
Nil, | ||
None, | ||
None, | ||
Map.empty | ||
) | ||
|
||
"Player joining an empty table" in { | ||
val room: RoomPlayerView = emptyRoom.update(PlayerJoinedTable(me, 1)) | ||
room.players.get(me.id) shouldBe Some(me) | ||
} |
Oops, something went wrong.