60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
import type { OnitamaScene } from "@/scenes/OnitamaScene";
|
|
|
|
import { CELL_SIZE, COLORS, FONTS, VISUAL } from "@/config";
|
|
|
|
export type PawnType = "master" | "student";
|
|
export type PawnOwner = "red" | "black";
|
|
|
|
export interface PawnRenderOptions {
|
|
owner: PawnOwner;
|
|
type: PawnType;
|
|
}
|
|
|
|
/**
|
|
* Renderer for pawn game objects
|
|
* Extracts visual creation logic from PawnContainer
|
|
*/
|
|
export class PawnRenderer {
|
|
constructor(private readonly scene: OnitamaScene) {}
|
|
|
|
/**
|
|
* Render pawn visuals into a container
|
|
* @param container - The container to add visuals to
|
|
* @param options - Pawn rendering options
|
|
*/
|
|
render(
|
|
container: Phaser.GameObjects.Container,
|
|
options: PawnRenderOptions,
|
|
): void {
|
|
const { owner, type } = options;
|
|
|
|
// Create background circle
|
|
const bgColor = owner === "red" ? COLORS.red : COLORS.black;
|
|
const circle = this.scene.add
|
|
.circle(0, 0, VISUAL.pawnRadius, bgColor, 1)
|
|
.setStrokeStyle(VISUAL.pawnStrokeWidth, COLORS.pawnStroke);
|
|
container.add(circle);
|
|
|
|
// Create label text
|
|
const label = type === "master" ? "M" : "S";
|
|
const text = this.scene.add
|
|
.text(0, 0, label, FONTS.pawnLabel)
|
|
.setOrigin(0.5);
|
|
container.add(text);
|
|
}
|
|
|
|
/**
|
|
* Create a standalone pawn visual (circle + text) at the specified position
|
|
* Useful for previews or temporary displays
|
|
*/
|
|
createStandalone(
|
|
x: number,
|
|
y: number,
|
|
options: PawnRenderOptions,
|
|
): Phaser.GameObjects.Container {
|
|
const container = this.scene.add.container(x, y);
|
|
this.render(container, options);
|
|
return container;
|
|
}
|
|
}
|