Purchase delays
This commit is contained in:
@ -14,7 +14,7 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<main class="container-fluid container">
|
<main class="container-fluid main-container">
|
||||||
<h1 class="mt-1 mb-2">
|
<h1 class="mt-1 mb-2">
|
||||||
FairHopper Visualisation Client
|
FairHopper Visualisation Client
|
||||||
</h1>
|
</h1>
|
||||||
|
|||||||
@ -85,6 +85,8 @@ function renderDestination(position) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renderGameDump(data) {
|
function renderGameDump(data) {
|
||||||
|
closePurchaseWindow();
|
||||||
|
|
||||||
createBoard(data.board);
|
createBoard(data.board);
|
||||||
renderObstacles(data.layers);
|
renderObstacles(data.layers);
|
||||||
renderDestination(data.destination.position);
|
renderDestination(data.destination.position);
|
||||||
@ -101,7 +103,7 @@ function productPurchaseStart(products, purchaseTimeout) {
|
|||||||
const html = products
|
const html = products
|
||||||
.map((product) => {
|
.map((product) => {
|
||||||
return `
|
return `
|
||||||
<div class="card product">
|
<div class="card product" id="product-${product.id}">
|
||||||
<img src="img/products/${product.name}.jpeg" class="card-img-topx" alt="${product.name}">
|
<img src="img/products/${product.name}.jpeg" class="card-img-topx" alt="${product.name}">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h5 class="card-title">${product.name}</h5>
|
<h5 class="card-title">${product.name}</h5>
|
||||||
@ -121,16 +123,16 @@ function productPurchaseTimerTick(timeLeft) {
|
|||||||
purchaseTimeoutElement.innerText = timeLeft;
|
purchaseTimeoutElement.innerText = timeLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
function productPurchased(product) {
|
function closePurchaseWindow() {
|
||||||
console.log("productPurchased:", product);
|
|
||||||
}
|
|
||||||
|
|
||||||
function productPurchaseDone() {
|
|
||||||
console.log("productPurchaseDone");
|
|
||||||
const container = document.getElementById("purchase-container");
|
const container = document.getElementById("purchase-container");
|
||||||
container.classList.add("d-none");
|
container.classList.add("d-none");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function productPurchaseDone(product) {
|
||||||
|
const cardContainer = document.getElementById(`product-${product.id}`);
|
||||||
|
cardContainer.classList.add("selected");
|
||||||
|
}
|
||||||
|
|
||||||
function wsConnect() {
|
function wsConnect() {
|
||||||
let ws = new WebSocket("ws://localhost:8011");
|
let ws = new WebSocket("ws://localhost:8011");
|
||||||
ws.onopen = () => {
|
ws.onopen = () => {
|
||||||
@ -151,11 +153,8 @@ function wsConnect() {
|
|||||||
case "product_purchase_timer_tick":
|
case "product_purchase_timer_tick":
|
||||||
productPurchaseTimerTick(wsMessage.data.time_left);
|
productPurchaseTimerTick(wsMessage.data.time_left);
|
||||||
break;
|
break;
|
||||||
case "product_purchased":
|
|
||||||
productPurchased(wsMessage.data);
|
|
||||||
break;
|
|
||||||
case "product_purchase_done":
|
case "product_purchase_done":
|
||||||
productPurchaseDone();
|
productPurchaseDone(wsMessage.data.product);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.error("Unknown message:", wsMessage);
|
console.error("Unknown message:", wsMessage);
|
||||||
|
|||||||
@ -2,7 +2,7 @@ body {
|
|||||||
background-color: whitesmoke;
|
background-color: whitesmoke;
|
||||||
}
|
}
|
||||||
|
|
||||||
main.container {
|
main.main-container {
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,8 +84,13 @@ ul.players {
|
|||||||
grid-template-columns: 1fr 1fr 1fr;
|
grid-template-columns: 1fr 1fr 1fr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.purchase-container .products-content .product.selected {
|
||||||
|
background-color: pink;
|
||||||
|
}
|
||||||
|
|
||||||
.purchase-container .products-content .product .card-title {
|
.purchase-container .products-content .product .card-title {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
font-size: 12pt;
|
||||||
}
|
}
|
||||||
|
|
||||||
.purchase-container .products-content .product img {
|
.purchase-container .products-content .product img {
|
||||||
|
|||||||
@ -212,6 +212,8 @@ class GameEngine:
|
|||||||
)
|
)
|
||||||
self._purchase_countdown_timer.start()
|
self._purchase_countdown_timer.start()
|
||||||
|
|
||||||
|
await asyncio.sleep(settings.game.PURCHASE_START_DELAY)
|
||||||
|
|
||||||
async def purchase_product(self, player: Player, product: Product) -> None:
|
async def purchase_product(self, player: Player, product: Product) -> None:
|
||||||
if not player.state == PlayerState.ON_DESTINATION:
|
if not player.state == PlayerState.ON_DESTINATION:
|
||||||
raise PurchaseForbiddenForPlayer()
|
raise PurchaseForbiddenForPlayer()
|
||||||
@ -220,6 +222,7 @@ class GameEngine:
|
|||||||
await self.ws_server.send_product_purchase_done_message(
|
await self.ws_server.send_product_purchase_done_message(
|
||||||
player=player, product=product
|
player=player, product=product
|
||||||
)
|
)
|
||||||
|
await asyncio.sleep(settings.game.PURCHASE_FINISHED_DELAY)
|
||||||
await self.reset_game()
|
await self.reset_game()
|
||||||
|
|
||||||
def _reset_player(self, player) -> None:
|
def _reset_player(self, player) -> None:
|
||||||
|
|||||||
@ -9,6 +9,8 @@ from hopper.models.product import Product
|
|||||||
@dataclass
|
@dataclass
|
||||||
class GameSettings:
|
class GameSettings:
|
||||||
MOVE_DELAY: float = 0.5 # seconds
|
MOVE_DELAY: float = 0.5 # seconds
|
||||||
|
PURCHASE_START_DELAY: float = 2 # seconds
|
||||||
|
PURCHASE_FINISHED_DELAY: float = 2 # seconds
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|||||||
Reference in New Issue
Block a user