fix: fix ui bugs
This commit is contained in:
@@ -4,14 +4,12 @@ import { prompts } from '@/game/onitama';
|
||||
import { GameHostScene } from 'boardgame-phaser';
|
||||
import { spawnEffect } from 'boardgame-phaser';
|
||||
import { effect } from '@preact/signals-core';
|
||||
import type { Signal } from '@preact/signals';
|
||||
import { PawnSpawner, CardSpawner, BOARD_OFFSET, CELL_SIZE, CARD_WIDTH, CARD_HEIGHT } from '@/spawners';
|
||||
import type { MutableSignal } from 'boardgame-core';
|
||||
import { PawnSpawner, CardSpawner, BOARD_OFFSET, CELL_SIZE, CARD_WIDTH, CARD_HEIGHT, boardToScreen, BOARD_SIZE } from '@/spawners';
|
||||
import type { HighlightData } from '@/spawners/HighlightSpawner';
|
||||
import { createOnitamaUIState, clearSelection, selectPiece, selectCard, deselectCard, setValidMoves } from '@/state';
|
||||
import type { OnitamaUIState, ValidMove } from '@/state';
|
||||
|
||||
const BOARD_SIZE = 5;
|
||||
|
||||
export class OnitamaScene extends GameHostScene<OnitamaState> {
|
||||
private boardContainer!: Phaser.GameObjects.Container;
|
||||
private gridGraphics!: Phaser.GameObjects.Graphics;
|
||||
@@ -19,8 +17,8 @@ export class OnitamaScene extends GameHostScene<OnitamaState> {
|
||||
private winnerOverlay?: Phaser.GameObjects.Container;
|
||||
private cardLabelContainers: Map<string, Phaser.GameObjects.Text> = new Map();
|
||||
|
||||
// UI State managed by signal
|
||||
public uiState!: Signal<OnitamaUIState>;
|
||||
// UI State managed by MutableSignal
|
||||
public uiState!: MutableSignal<OnitamaUIState>;
|
||||
private highlightContainers: Map<string, Phaser.GameObjects.GameObject> = new Map();
|
||||
private highlightDispose?: () => void;
|
||||
|
||||
@@ -189,10 +187,9 @@ export class OnitamaScene extends GameHostScene<OnitamaState> {
|
||||
// Board cell clicks
|
||||
for (let row = 0; row < BOARD_SIZE; row++) {
|
||||
for (let col = 0; col < BOARD_SIZE; col++) {
|
||||
const x = BOARD_OFFSET.x + col * CELL_SIZE + CELL_SIZE / 2;
|
||||
const y = BOARD_OFFSET.y + row * CELL_SIZE + CELL_SIZE / 2;
|
||||
const pos = boardToScreen(col, row);
|
||||
|
||||
const zone = this.add.zone(x, y, CELL_SIZE, CELL_SIZE).setInteractive();
|
||||
const zone = this.add.zone(pos.x, pos.y, CELL_SIZE, CELL_SIZE).setInteractive();
|
||||
|
||||
zone.on('pointerdown', () => {
|
||||
if (this.state.winner) return;
|
||||
@@ -308,16 +305,15 @@ export class OnitamaScene extends GameHostScene<OnitamaState> {
|
||||
// Create new highlights
|
||||
for (const move of validMoves) {
|
||||
const key = `${move.card}-${move.toX}-${move.toY}`;
|
||||
const x = BOARD_OFFSET.x + move.toX * CELL_SIZE + CELL_SIZE / 2;
|
||||
const y = BOARD_OFFSET.y + move.toY * CELL_SIZE + CELL_SIZE / 2;
|
||||
const pos = boardToScreen(move.toX, move.toY);
|
||||
|
||||
const circle = this.add.circle(x, y, CELL_SIZE / 3, 0x3b82f6, 0.3).setDepth(100);
|
||||
const circle = this.add.circle(pos.x, pos.y, CELL_SIZE / 3, 0x3b82f6, 0.3).setDepth(100);
|
||||
circle.setInteractive({ useHandCursor: true });
|
||||
circle.on('pointerdown', () => {
|
||||
this.onHighlightClick({
|
||||
key,
|
||||
x,
|
||||
y,
|
||||
x: pos.x,
|
||||
y: pos.y,
|
||||
card: move.card,
|
||||
fromX: move.fromX,
|
||||
fromY: move.fromY,
|
||||
|
||||
Reference in New Issue
Block a user