Compare commits
No commits in common. "82df3f2a2f83242b062a69ba1be04c711523ef41" and "c25759d1472662948c95e8f024995221a20556d1" have entirely different histories.
82df3f2a2f
...
c25759d147
|
|
@ -13,7 +13,7 @@ packages/my-game/
|
||||||
│ ├── game/ # Pure game logic (re-exported from boardgame-core)
|
│ ├── game/ # Pure game logic (re-exported from boardgame-core)
|
||||||
│ ├── scenes/ # Phaser scenes (MenuScene, GameScene)
|
│ ├── scenes/ # Phaser scenes (MenuScene, GameScene)
|
||||||
│ ├── spawners/ # Data-driven object lifecycle
|
│ ├── spawners/ # Data-driven object lifecycle
|
||||||
│ ├── gameobjects/ # Phaser GameObject or Container extensions
|
│ ├── renderers/ # Renderers for game objects
|
||||||
│ ├── state/ # UI-only reactive state
|
│ ├── state/ # UI-only reactive state
|
||||||
│ ├── config.ts # Centralized layout & style constants
|
│ ├── config.ts # Centralized layout & style constants
|
||||||
│ └── ui/App.tsx # Preact root component
|
│ └── ui/App.tsx # Preact root component
|
||||||
|
|
@ -24,7 +24,7 @@ packages/my-game/
|
||||||
| `game/` | State, commands, prompts, validation (pure logic) |
|
| `game/` | State, commands, prompts, validation (pure logic) |
|
||||||
| `scenes/` | Phaser lifecycle, input handling, visual composition |
|
| `scenes/` | Phaser lifecycle, input handling, visual composition |
|
||||||
| `spawners/` | Reactive game object spawn/update/despawn |
|
| `spawners/` | Reactive game object spawn/update/despawn |
|
||||||
| `gameobjects/` | Phaser GameObjects or containers |
|
| `renderers/` | Phaser visual representation of game objects |
|
||||||
| `state/` | UI-only reactive state (selection, hover, etc.) |
|
| `state/` | UI-only reactive state (selection, hover, etc.) |
|
||||||
| `ui/` | Preact components bridging Phaser and DOM |
|
| `ui/` | Preact components bridging Phaser and DOM |
|
||||||
|
|
||||||
|
|
@ -51,9 +51,9 @@ Use `MutableSignal` for UI-only state, separate from game state.
|
||||||
- Clean up effects on object `'destroy'` to prevent leaks.
|
- Clean up effects on object `'destroy'` to prevent leaks.
|
||||||
- See: `packages/onitama-game/src/state/ui.ts`
|
- See: `packages/onitama-game/src/state/ui.ts`
|
||||||
|
|
||||||
### 4. Custom GameObjects / Containers
|
### 4. Custom Containers
|
||||||
Extend `Phaser.GameObjects.Container` to encapsulate visuals and state.
|
Extend `Phaser.GameObjects.Container` to encapsulate visuals and state.
|
||||||
- Use signals from `states/`, avoid relying on complex interal state.
|
- Store logical state as private signals.
|
||||||
- Use `effect()` for reactive highlights/selections.
|
- Use `effect()` for reactive highlights/selections.
|
||||||
|
|
||||||
### 5. Tween Interruption
|
### 5. Tween Interruption
|
||||||
|
|
@ -66,12 +66,6 @@ Otherwise the game logic will hang.
|
||||||
Use `await this.sceneController.launch('SceneKey')`.
|
Use `await this.sceneController.launch('SceneKey')`.
|
||||||
Register scenes in `App.tsx` via `<PhaserScene>`. Pass data via `data` prop.
|
Register scenes in `App.tsx` via `<PhaserScene>`. Pass data via `data` prop.
|
||||||
|
|
||||||
### 7. Central Config
|
|
||||||
Use `src/config/layout.ts` for shared constants like `CELL_SIZE`, `BOARD_OFFSET`, etc.
|
|
||||||
Use `src/config/colors.ts` for shared colors.
|
|
||||||
Use `src/config/text.ts` for text styles.
|
|
||||||
|
|
||||||
|
|
||||||
## Best Practices
|
## Best Practices
|
||||||
|
|
||||||
- **Centralize Config**: Keep `CELL_SIZE`, `BOARD_OFFSET`, colors, etc., in `src/config.ts` with `as const`. Avoid magic numbers.
|
- **Centralize Config**: Keep `CELL_SIZE`, `BOARD_OFFSET`, colors, etc., in `src/config.ts` with `as const`. Avoid magic numbers.
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ export type { IDisposable, DisposableItem } from "./utils";
|
||||||
|
|
||||||
// Drag & drop utilities
|
// Drag & drop utilities
|
||||||
export { dragDropEventEffect, DragDropEventType } from "./utils";
|
export { dragDropEventEffect, DragDropEventType } from "./utils";
|
||||||
export type { DragDropEvent, DragDropCallback } from "./utils";
|
export type { DragDropEvent } from "./utils";
|
||||||
|
|
||||||
// Data-driven object spawning
|
// Data-driven object spawning
|
||||||
export { spawnEffect } from "./spawner";
|
export { spawnEffect } from "./spawner";
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,8 @@ export type DragDropEvent = {
|
||||||
deltaY: number;
|
deltaY: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type DragDropCallback = (event: DragDropEvent) => void;
|
|
||||||
|
|
||||||
export function dragDropEventEffect(
|
export function dragDropEventEffect(
|
||||||
gameObject: Phaser.GameObjects.GameObject,
|
gameObject: Phaser.GameObjects.GameObject,
|
||||||
callback: DragDropCallback,
|
|
||||||
disposables?: DisposableBag,
|
disposables?: DisposableBag,
|
||||||
): () => void {
|
): () => void {
|
||||||
let isDragging = false;
|
let isDragging = false;
|
||||||
|
|
@ -38,7 +35,8 @@ export function dragDropEventEffect(
|
||||||
deltaX: 0,
|
deltaX: 0,
|
||||||
deltaY: 0,
|
deltaY: 0,
|
||||||
};
|
};
|
||||||
callback(event);
|
gameObject.emit("drag", event);
|
||||||
|
gameObject.emit("dragstart", event);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onPointerUp(pointer: Phaser.Input.Pointer) {
|
function onPointerUp(pointer: Phaser.Input.Pointer) {
|
||||||
|
|
@ -48,7 +46,8 @@ export function dragDropEventEffect(
|
||||||
const deltaX = pointer.x - down.x;
|
const deltaX = pointer.x - down.x;
|
||||||
const deltaY = pointer.y - down.y;
|
const deltaY = pointer.y - down.y;
|
||||||
const event: DragDropEvent = { type: DragDropEventType.UP, deltaX, deltaY };
|
const event: DragDropEvent = { type: DragDropEventType.UP, deltaX, deltaY };
|
||||||
callback(event);
|
gameObject.emit("drag", event);
|
||||||
|
gameObject.emit("dragend", event);
|
||||||
down = null;
|
down = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -62,7 +61,8 @@ export function dragDropEventEffect(
|
||||||
deltaX,
|
deltaX,
|
||||||
deltaY,
|
deltaY,
|
||||||
};
|
};
|
||||||
callback(event);
|
gameObject.emit("drag", event);
|
||||||
|
gameObject.emit("dragmove", event);
|
||||||
}
|
}
|
||||||
|
|
||||||
gameObject.on("pointerdown", onPointerDown);
|
gameObject.on("pointerdown", onPointerDown);
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,4 @@ export {
|
||||||
dragDropEventEffect,
|
dragDropEventEffect,
|
||||||
DragDropEventType,
|
DragDropEventType,
|
||||||
type DragDropEvent,
|
type DragDropEvent,
|
||||||
type DragDropCallback,
|
|
||||||
} from "./dnd";
|
} from "./dnd";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue