diff --git a/TODO.txt b/TODO.txt index c6ba34fa1..3899bc54e 100644 --- a/TODO.txt +++ b/TODO.txt @@ -139,8 +139,9 @@ * make radial menu buttons grayed out DONE 9/27/2024 * add request alliance radial button DONE 9/27/2024 * add break alliance radial button DONE 9/27/2024 -* add send boat radial button DONE 9/27/2024 -* attack radial center button only on enemy +* add send boat radial button DONE 9/28/2024 +* attack radial center button only on enemy DONE 9/28/2024 +* radial center button "spawn" during spawn phase DONE 9/28/2024 * Make buttons icons * better color scheme radial menu * test on mobile diff --git a/src/client/ClientGame.ts b/src/client/ClientGame.ts index da7f760ed..b52a496fb 100644 --- a/src/client/ClientGame.ts +++ b/src/client/ClientGame.ts @@ -13,10 +13,11 @@ import {WinCheckExecution} from "../core/execution/WinCheckExecution"; import {SendAttackIntentEvent, SendBoatAttackIntentEvent, SendBreakAllianceIntentEvent, SendSpawnIntentEvent, Transport} from "./Transport"; import {createCanvas} from "./graphics/Utils"; import {DisplayMessageEvent, MessageType} from "./graphics/layers/EventsDisplay"; +import {placeName} from "./graphics/NameBoxCalculator"; -export function createClientGame(name: string, clientID: ClientID, playerID: PlayerID, ip: string | null, gameID: GameID, config: Config, terrainMap: TerrainMap): ClientGame { +export function createClientGame(playerName: string, clientID: ClientID, playerID: PlayerID, ip: string | null, gameID: GameID, config: Config, terrainMap: TerrainMap): ClientGame { let eventBus = new EventBus() let game = createGame(terrainMap, eventBus, config) @@ -27,11 +28,11 @@ export function createClientGame(name: string, clientID: ClientID, playerID: Pla const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; const socket = new WebSocket(`${wsProtocol}//${wsHost}`) - const transport = new Transport(socket, eventBus, gameID, clientID, playerID) + const transport = new Transport(socket, eventBus, gameID, clientID, playerID, playerName) return new ClientGame( - name, + playerName, clientID, playerID, ip, @@ -194,7 +195,7 @@ export class ClientGame { } const tile = this.gs.tile(cell) if (tile.isLand() && !tile.hasOwner() && this.gs.inSpawnPhase()) { - this.eventBus.emit(new SendSpawnIntentEvent(cell, this.playerName)) + this.eventBus.emit(new SendSpawnIntentEvent(cell)) return } if (this.gs.inSpawnPhase()) { diff --git a/src/client/Transport.ts b/src/client/Transport.ts index a292dc646..a8d63fc10 100644 --- a/src/client/Transport.ts +++ b/src/client/Transport.ts @@ -26,7 +26,6 @@ export class SendAllianceReplyIntentEvent implements GameEvent { export class SendSpawnIntentEvent implements GameEvent { constructor( public readonly cell: Cell, - public readonly playerName: string, ) { } } @@ -52,6 +51,7 @@ export class Transport { private gameID: GameID, private clientID: ClientID, private playerID: PlayerID, + private playerName: string, ) { this.eventBus.on(SendAllianceRequestIntentEvent, (e) => this.onSendAllianceRequest(e)) this.eventBus.on(SendAllianceReplyIntentEvent, (e) => this.onAllianceRequestReplyUIEvent(e)) @@ -94,7 +94,7 @@ export class Transport { type: "spawn", clientID: this.clientID, playerID: this.playerID, - name: event.playerName, + name: this.playerName, playerType: PlayerType.Human, x: event.cell.x, y: event.cell.y diff --git a/src/client/graphics/layers/RadialMenu.ts b/src/client/graphics/layers/RadialMenu.ts index 42c28356e..e1bd9ea34 100644 --- a/src/client/graphics/layers/RadialMenu.ts +++ b/src/client/graphics/layers/RadialMenu.ts @@ -3,7 +3,7 @@ import {Cell, Game, Player, PlayerID} from "../../../core/game/Game"; import {ClientID} from "../../../core/Schemas"; import {manhattanDist, sourceDstOceanShore} from "../../../core/Util"; import {ContextMenuEvent, MouseUpEvent} from "../../InputHandler"; -import {SendAllianceRequestIntentEvent, SendAttackIntentEvent, SendBoatAttackIntentEvent, SendBreakAllianceIntentEvent} from "../../Transport"; +import {SendAllianceRequestIntentEvent, SendAttackIntentEvent, SendBoatAttackIntentEvent, SendBreakAllianceIntentEvent, SendSpawnIntentEvent} from "../../Transport"; import {TransformHandler} from "../TransformHandler"; import {MessageType} from "./EventsDisplay"; import {Layer} from "./Layer"; @@ -188,11 +188,6 @@ export class RadialMenu implements Layer { item.disabled = true this.updateMenuItemState(item) } - const myPlayer = this.game.players().find(p => p.clientID() == this.clientID) - if (!myPlayer) { - console.warn('my player not found') - return - } this.clickedCell = this.transformHandler.screenToWorldCoordinates(event.x, event.y) if (!this.game.isOnMap(this.clickedCell)) { @@ -201,6 +196,20 @@ export class RadialMenu implements Layer { const tile = this.game.tile(this.clickedCell) const other = tile.owner() + if (this.game.inSpawnPhase()) { + if (tile.isLand() && !tile.hasOwner()) { + this.isCenterButtonEnabled = true + this.updateCenterButtonState() + } + return + } + + const myPlayer = this.game.players().find(p => p.clientID() == this.clientID) + if (!myPlayer) { + console.warn('my player not found') + return + } + if (tile.owner() != myPlayer && tile.isLand() && myPlayer.sharesBorderWith(other)) { if (!other.isPlayer() || !myPlayer.isAlliedWith(other)) { this.isCenterButtonEnabled = true @@ -303,10 +312,17 @@ export class RadialMenu implements Layer { } private handleCenterButtonClick() { + if (!this.isCenterButtonEnabled) { + return + } console.log('Center button clicked'); const clicked = this.game.tile(this.clickedCell) - if (clicked.owner().clientID() != this.clientID) { - this.eventBus.emit(new SendAttackIntentEvent(clicked.owner().id())) + if (this.game.inSpawnPhase()) { + this.eventBus.emit(new SendSpawnIntentEvent(this.clickedCell)) + } else { + if (clicked.owner().clientID() != this.clientID) { + this.eventBus.emit(new SendAttackIntentEvent(clicked.owner().id())) + } } this.hideRadialMenu(); } diff --git a/src/core/configuration/DevConfig.ts b/src/core/configuration/DevConfig.ts index 4d1daf00c..1e0458b4b 100644 --- a/src/core/configuration/DevConfig.ts +++ b/src/core/configuration/DevConfig.ts @@ -7,7 +7,7 @@ export const devConfig = new class extends DefaultConfig { return 95 } numSpawnPhaseTurns(): number { - return 40 + return 80 } gameCreationRate(): number { return 2 * 1000