@waica/cli 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/editor/assets/{cssMode-DfLN2qUF.js → cssMode-eS4pAOyh.js} +1 -1
- package/dist/editor/assets/{freemarker2-BM-wWcXR.js → freemarker2-FMQjZKQk.js} +1 -1
- package/dist/editor/assets/{handlebars-C68SV5M9.js → handlebars-dDYOnqat.js} +1 -1
- package/dist/editor/assets/{html-dQgLbIki.js → html-Ba6xZh4T.js} +1 -1
- package/dist/editor/assets/{htmlMode-Dx91fUdd.js → htmlMode-DC9qJr2p.js} +1 -1
- package/dist/editor/assets/{index-592ABIaz.js → index-CoyeInOT.js} +2031 -269
- package/dist/editor/assets/{javascript-BmsSq5ka.js → javascript-DOwFvmvM.js} +1 -1
- package/dist/editor/assets/{jsonMode-CWoPtX2M.js → jsonMode-CcG7zlSf.js} +1 -1
- package/dist/editor/assets/{liquid-DwnJlNJZ.js → liquid-Dfp71r7J.js} +1 -1
- package/dist/editor/assets/{mdx-DaLkvlR1.js → mdx-Ci7vVeht.js} +1 -1
- package/dist/editor/assets/{python-Cs5X5zFp.js → python-Bluv3Y9Q.js} +1 -1
- package/dist/editor/assets/{razor-PTwWoRk8.js → razor-BtwTXMaK.js} +1 -1
- package/dist/editor/assets/{tsMode-BqUQdgsR.js → tsMode-D3_D-H85.js} +1 -1
- package/dist/editor/assets/{typescript-BsJ7r2RJ.js → typescript-Ch_PS5f7.js} +1 -1
- package/dist/editor/assets/{xml-DyyoPey4.js → xml-CI_bH_MX.js} +1 -1
- package/dist/editor/assets/{yaml-Cjqtlp29.js → yaml-LD9GTZyy.js} +1 -1
- package/dist/editor/index.html +1 -1
- package/dist/mcp/archetypes.js +6 -2
- package/dist/mcp/create-project.js +12 -6
- package/dist/mcp/known-archetypes.js +19 -0
- package/dist/mcp/node_modules/@waica/archetype-platformer/dist/prefabs.js +1 -1
- package/dist/mcp/node_modules/@waica/archetype-platformer/dist/scene-default.js +9 -1
- package/dist/mcp/node_modules/@waica/archetype-platformer/package.json +3 -3
- package/dist/mcp/node_modules/@waica/archetype-topdown/assets/ATTRIBUTION.md +28 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/assets/waica-blob.png +0 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/assets/waica-fence.png +0 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/assets/waica-grass.png +0 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/assets/waica-hero.png +0 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/assets/waica-npc.png +0 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/assets/waica-path.png +0 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/assets/waica-potion.png +0 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/assets/waica-tree.png +0 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/assets/waica-water.png +0 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/dist/animation.d.ts +7 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/dist/animation.js +10 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/dist/art.d.ts +10 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/dist/art.js +19 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/dist/bundle.d.ts +3 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/dist/bundle.js +10 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/dist/controls.d.ts +5 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/dist/controls.js +16 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/dist/index.d.ts +25 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/dist/index.js +16 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/dist/manifest.d.ts +16 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/dist/manifest.js +29 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/dist/prefabs.d.ts +11 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/dist/prefabs.js +178 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/dist/registry-data.d.ts +9 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/dist/registry-data.js +54 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/dist/registry.d.ts +6 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/dist/registry.js +21 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/dist/scene-default.d.ts +57 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/dist/scene-default.js +110 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/dist/ui.d.ts +10 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/dist/ui.js +43 -0
- package/dist/mcp/node_modules/@waica/archetype-topdown/package.json +30 -0
- package/dist/mcp/node_modules/@waica/behaviors/dist/index.d.ts +3 -0
- package/dist/mcp/node_modules/@waica/behaviors/dist/index.js +3 -0
- package/dist/mcp/node_modules/@waica/behaviors/dist/interactable.d.ts +31 -0
- package/dist/mcp/node_modules/@waica/behaviors/dist/interactable.js +49 -0
- package/dist/mcp/node_modules/@waica/behaviors/dist/platformer-motor.d.ts +4 -2
- package/dist/mcp/node_modules/@waica/behaviors/dist/platformer-motor.js +5 -1
- package/dist/mcp/node_modules/@waica/behaviors/dist/topdown-motor.d.ts +72 -0
- package/dist/mcp/node_modules/@waica/behaviors/dist/topdown-motor.js +102 -0
- package/dist/mcp/node_modules/@waica/behaviors/dist/topdown-player-states.d.ts +18 -0
- package/dist/mcp/node_modules/@waica/behaviors/dist/topdown-player-states.js +86 -0
- package/dist/mcp/node_modules/@waica/behaviors/package.json +2 -2
- package/dist/mcp/node_modules/@waica/engine/dist/animation/directional.d.ts +48 -0
- package/dist/mcp/node_modules/@waica/engine/dist/animation/directional.js +68 -0
- package/dist/mcp/node_modules/@waica/engine/dist/archetype.d.ts +3 -0
- package/dist/mcp/node_modules/@waica/engine/dist/camera.d.ts +19 -0
- package/dist/mcp/node_modules/@waica/engine/dist/camera.js +10 -0
- package/dist/mcp/node_modules/@waica/engine/dist/components/animated-sprite.d.ts +8 -1
- package/dist/mcp/node_modules/@waica/engine/dist/components/animated-sprite.js +19 -2
- package/dist/mcp/node_modules/@waica/engine/dist/components/sprite.d.ts +4 -1
- package/dist/mcp/node_modules/@waica/engine/dist/components/sprite.js +5 -0
- package/dist/mcp/node_modules/@waica/engine/dist/game.d.ts +9 -1
- package/dist/mcp/node_modules/@waica/engine/dist/game.js +32 -3
- package/dist/mcp/node_modules/@waica/engine/dist/index.d.ts +7 -3
- package/dist/mcp/node_modules/@waica/engine/dist/index.js +3 -1
- package/dist/mcp/node_modules/@waica/engine/dist/render-sort.d.ts +31 -0
- package/dist/mcp/node_modules/@waica/engine/dist/render-sort.js +39 -0
- package/dist/mcp/node_modules/@waica/engine/dist/scene.d.ts +10 -0
- package/dist/mcp/node_modules/@waica/engine/dist/scene.js +1 -0
- package/dist/mcp/node_modules/@waica/engine/dist/state/hooks.d.ts +1 -1
- package/dist/mcp/node_modules/@waica/engine/dist/state/hooks.js +3 -1
- package/dist/mcp/node_modules/@waica/engine/dist/state/state-machine.d.ts +18 -0
- package/dist/mcp/node_modules/@waica/engine/dist/state/state-machine.js +57 -1
- package/dist/mcp/node_modules/@waica/engine/package.json +1 -1
- package/dist/mcp/package-resolver.js +10 -4
- package/dist/mcp/project-component-loader.js +2 -1
- package/dist/mcp/project-component-runner.js +4 -0
- package/dist/mcp/server.js +18 -1
- package/dist/mcp/template/package.json.tpl +1 -1
- package/dist/mcp/template/src/characters/player.character.json +1 -1
- package/dist/mcp/template/src/main.ts +8 -4
- package/dist/mcp/template/src/scenes/main.scene.json +7 -1
- package/dist/mcp/workspace-runtime.js +41 -10
- package/package.json +1 -1
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The archetype's default UI pieces: self-contained HTML fragments
|
|
3
|
+
* (markup + <style>, {{stat}} bindings) keyed by piece name. Projects
|
|
4
|
+
* override them with src/ui/<name>.html files; scenes list the pieces
|
|
5
|
+
* they start with in their "ui" field.
|
|
6
|
+
*
|
|
7
|
+
* TS template literals (not .html files) because this package builds
|
|
8
|
+
* with plain tsc — no bundler to inline raw imports.
|
|
9
|
+
*/
|
|
10
|
+
export const TOPDOWN_UI = {
|
|
11
|
+
'potion-counter': `<style>
|
|
12
|
+
.potion-counter {
|
|
13
|
+
position: absolute;
|
|
14
|
+
top: 12px;
|
|
15
|
+
left: 12px;
|
|
16
|
+
font: 600 20px system-ui, sans-serif;
|
|
17
|
+
color: #ff6b6b;
|
|
18
|
+
text-shadow: 0 1px 3px #000a;
|
|
19
|
+
user-select: none;
|
|
20
|
+
}
|
|
21
|
+
</style>
|
|
22
|
+
<div class="potion-counter">🧪 {{points}}</div>
|
|
23
|
+
`,
|
|
24
|
+
'npc-line': `<style>
|
|
25
|
+
.npc-line {
|
|
26
|
+
position: absolute;
|
|
27
|
+
left: 50%;
|
|
28
|
+
bottom: 24px;
|
|
29
|
+
transform: translateX(-50%);
|
|
30
|
+
max-width: 70%;
|
|
31
|
+
padding: 10px 18px;
|
|
32
|
+
border-radius: 8px;
|
|
33
|
+
background: #1a1a2ecc;
|
|
34
|
+
border: 1px solid #ffffff2e;
|
|
35
|
+
font: 500 18px system-ui, sans-serif;
|
|
36
|
+
color: #f5f5f5;
|
|
37
|
+
text-shadow: 0 1px 2px #000a;
|
|
38
|
+
user-select: none;
|
|
39
|
+
}
|
|
40
|
+
</style>
|
|
41
|
+
<div class="npc-line">{{npcLine}}</div>
|
|
42
|
+
`,
|
|
43
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@waica/archetype-topdown",
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"description": "Waica top-down archetype — opinionated setup for Zelda-like overhead adventures",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/chichex/waica",
|
|
10
|
+
"directory": "packages/archetype-topdown"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"assets"
|
|
15
|
+
],
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./manifest": {
|
|
22
|
+
"types": "./dist/manifest.d.ts",
|
|
23
|
+
"default": "./dist/manifest.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@waica/behaviors": "^0.7.0",
|
|
28
|
+
"@waica/engine": "^0.7.0"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export { PlatformerMotor } from './platformer-motor.js';
|
|
2
2
|
export { PLAYER_ROLE, PLAYER_STATE_GRAPH, playerUpdate } from './player-states.js';
|
|
3
|
+
export { TopDownMotor, type TopDownFacing } from './topdown-motor.js';
|
|
4
|
+
export { TOPDOWN_PLAYER_ROLE, TOPDOWN_PLAYER_STATE_GRAPH, topdownPlayerUpdate, } from './topdown-player-states.js';
|
|
5
|
+
export { Interactable, interactUpdate } from './interactable.js';
|
|
3
6
|
export { Collectible } from './collectible.js';
|
|
4
7
|
export { Patrol, PATROLLER_ROLE, PATROLLER_STATE_GRAPH, type PatrolAxis } from './patrol.js';
|
|
5
8
|
export { Chaser, CHASER_ROLE, CHASER_STATE_GRAPH, type ChaserMode } from './chaser.js';
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export { PlatformerMotor } from './platformer-motor.js';
|
|
2
2
|
export { PLAYER_ROLE, PLAYER_STATE_GRAPH, playerUpdate } from './player-states.js';
|
|
3
|
+
export { TopDownMotor } from './topdown-motor.js';
|
|
4
|
+
export { TOPDOWN_PLAYER_ROLE, TOPDOWN_PLAYER_STATE_GRAPH, topdownPlayerUpdate, } from './topdown-player-states.js';
|
|
5
|
+
export { Interactable, interactUpdate } from './interactable.js';
|
|
3
6
|
export { Collectible } from './collectible.js';
|
|
4
7
|
export { Patrol, PATROLLER_ROLE, PATROLLER_STATE_GRAPH } from './patrol.js';
|
|
5
8
|
export { Chaser, CHASER_ROLE, CHASER_STATE_GRAPH } from './chaser.js';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Component, type StateContext } from '@waica/engine';
|
|
2
|
+
/**
|
|
3
|
+
* Something the player can talk to or examine: a dialogue line and the
|
|
4
|
+
* radius it can be triggered from. The component is pure data — the
|
|
5
|
+
* player role's always-hook does the lookup (see interactUpdate), so an
|
|
6
|
+
* NPC stays code-free: Interactable + the npc role is a whole villager.
|
|
7
|
+
*/
|
|
8
|
+
export declare class Interactable extends Component {
|
|
9
|
+
static componentName: string;
|
|
10
|
+
static params: {
|
|
11
|
+
line: {
|
|
12
|
+
label: string;
|
|
13
|
+
};
|
|
14
|
+
radius: {
|
|
15
|
+
label: string;
|
|
16
|
+
min: number;
|
|
17
|
+
max: number;
|
|
18
|
+
step: number;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
/** What pressing interact within the radius says. */
|
|
22
|
+
line: string;
|
|
23
|
+
radius: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The player role's interact lookup, run by its '*' hook in every state:
|
|
27
|
+
* pressing interact near an Interactable publishes its line through the
|
|
28
|
+
* npcLine stat and shows the npc-line UI piece; walking out of every
|
|
29
|
+
* radius hides it again. Nearest one wins when several are in range.
|
|
30
|
+
*/
|
|
31
|
+
export declare function interactUpdate({ entity, game }: StateContext): void;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Component } from '@waica/engine';
|
|
2
|
+
/**
|
|
3
|
+
* Something the player can talk to or examine: a dialogue line and the
|
|
4
|
+
* radius it can be triggered from. The component is pure data — the
|
|
5
|
+
* player role's always-hook does the lookup (see interactUpdate), so an
|
|
6
|
+
* NPC stays code-free: Interactable + the npc role is a whole villager.
|
|
7
|
+
*/
|
|
8
|
+
export class Interactable extends Component {
|
|
9
|
+
static componentName = 'Interactable';
|
|
10
|
+
static params = {
|
|
11
|
+
line: { label: 'Line' },
|
|
12
|
+
radius: { label: 'Radius', min: 0.5, max: 10, step: 0.25 },
|
|
13
|
+
};
|
|
14
|
+
/** What pressing interact within the radius says. */
|
|
15
|
+
line = 'Hello, traveler!';
|
|
16
|
+
radius = 1.5;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The player role's interact lookup, run by its '*' hook in every state:
|
|
20
|
+
* pressing interact near an Interactable publishes its line through the
|
|
21
|
+
* npcLine stat and shows the npc-line UI piece; walking out of every
|
|
22
|
+
* radius hides it again. Nearest one wins when several are in range.
|
|
23
|
+
*/
|
|
24
|
+
export function interactUpdate({ entity, game }) {
|
|
25
|
+
let nearest = null;
|
|
26
|
+
let nearestDistance = Infinity;
|
|
27
|
+
for (const other of game.entities) {
|
|
28
|
+
if (other === entity)
|
|
29
|
+
continue;
|
|
30
|
+
const interactable = other.get(Interactable);
|
|
31
|
+
if (!interactable)
|
|
32
|
+
continue;
|
|
33
|
+
const distance = Math.hypot(other.position.x - entity.position.x, other.position.y - entity.position.y);
|
|
34
|
+
if (distance <= interactable.radius && distance < nearestDistance) {
|
|
35
|
+
nearest = interactable;
|
|
36
|
+
nearestDistance = distance;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (!nearest) {
|
|
40
|
+
game.ui.hide('npc-line');
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (game.input.justPressed('interact') && !game.input.consumed('interact')) {
|
|
44
|
+
// The press is spent: an input:interact edge needs a NEW press.
|
|
45
|
+
game.input.consume('interact');
|
|
46
|
+
game.stats.set('npcLine', nearest.line);
|
|
47
|
+
game.ui.show('npc-line');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Component } from '@waica/engine';
|
|
1
|
+
import { Component, type CameraVelocity, type CameraVelocityProvider } from '@waica/engine';
|
|
2
2
|
/**
|
|
3
3
|
* Passive platformer motor: tuning params, physical state and movement
|
|
4
4
|
* methods for state code to call. It has no onUpdate of its own — the
|
|
@@ -9,7 +9,7 @@ import { Component } from '@waica/engine';
|
|
|
9
9
|
* Per-axis collision against the scene's Solids — deterministic genre
|
|
10
10
|
* movement (Celeste-style), not "realistic" physics.
|
|
11
11
|
*/
|
|
12
|
-
export declare class PlatformerMotor extends Component {
|
|
12
|
+
export declare class PlatformerMotor extends Component implements CameraVelocityProvider {
|
|
13
13
|
static componentName: string;
|
|
14
14
|
static displayName: string;
|
|
15
15
|
static params: {
|
|
@@ -103,6 +103,8 @@ export declare class PlatformerMotor extends Component {
|
|
|
103
103
|
private bufferTimer;
|
|
104
104
|
private squashX;
|
|
105
105
|
private squashY;
|
|
106
|
+
/** The scene camera reads follow velocity through this explicit seam. */
|
|
107
|
+
getCameraVelocity(): CameraVelocity;
|
|
106
108
|
/**
|
|
107
109
|
* Per-frame bookkeeping: forgiveness timers, squash decay and the
|
|
108
110
|
* facing flip. The logic set's '*' hook runs it in every state, so
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Component, resolveSolidAxis, THREE } from '@waica/engine';
|
|
1
|
+
import { Component, resolveSolidAxis, THREE, } from '@waica/engine';
|
|
2
2
|
/**
|
|
3
3
|
* Passive platformer motor: tuning params, physical state and movement
|
|
4
4
|
* methods for state code to call. It has no onUpdate of its own — the
|
|
@@ -60,6 +60,10 @@ export class PlatformerMotor extends Component {
|
|
|
60
60
|
bufferTimer = 0;
|
|
61
61
|
squashX = 1;
|
|
62
62
|
squashY = 1;
|
|
63
|
+
/** The scene camera reads follow velocity through this explicit seam. */
|
|
64
|
+
getCameraVelocity() {
|
|
65
|
+
return { vx: this.vx, vy: this.vy };
|
|
66
|
+
}
|
|
63
67
|
/**
|
|
64
68
|
* Per-frame bookkeeping: forgiveness timers, squash decay and the
|
|
65
69
|
* facing flip. The logic set's '*' hook runs it in every state, so
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Component, type AnimationFacingProvider, type CameraVelocity, type CameraVelocityProvider } from '@waica/engine';
|
|
2
|
+
/** The four facings the top-down animation contract declares. */
|
|
3
|
+
export type TopDownFacing = 'n' | 's' | 'e' | 'w';
|
|
4
|
+
/**
|
|
5
|
+
* Passive top-down motor: tuning params, physical state and movement
|
|
6
|
+
* methods for state code to call. It has no onUpdate of its own — the
|
|
7
|
+
* StateMachine is the only owner of the frame; this is the toolbox the
|
|
8
|
+
* active state moves the body with. Eight-direction movement with the
|
|
9
|
+
* input vector normalized so diagonals match cardinal speed, no gravity,
|
|
10
|
+
* and per-axis collision against the scene's Solids — deterministic
|
|
11
|
+
* genre movement (Zelda-style), not "realistic" physics.
|
|
12
|
+
*/
|
|
13
|
+
export declare class TopDownMotor extends Component implements CameraVelocityProvider, AnimationFacingProvider {
|
|
14
|
+
static componentName: string;
|
|
15
|
+
static displayName: string;
|
|
16
|
+
static params: {
|
|
17
|
+
moveSpeed: {
|
|
18
|
+
label: string;
|
|
19
|
+
min: number;
|
|
20
|
+
max: number;
|
|
21
|
+
step: number;
|
|
22
|
+
};
|
|
23
|
+
acceleration: {
|
|
24
|
+
label: string;
|
|
25
|
+
min: number;
|
|
26
|
+
max: number;
|
|
27
|
+
step: number;
|
|
28
|
+
};
|
|
29
|
+
deceleration: {
|
|
30
|
+
label: string;
|
|
31
|
+
min: number;
|
|
32
|
+
max: number;
|
|
33
|
+
step: number;
|
|
34
|
+
};
|
|
35
|
+
walkThreshold: {
|
|
36
|
+
label: string;
|
|
37
|
+
min: number;
|
|
38
|
+
max: number;
|
|
39
|
+
step: number;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
static transient: string[];
|
|
43
|
+
moveSpeed: number;
|
|
44
|
+
acceleration: number;
|
|
45
|
+
deceleration: number;
|
|
46
|
+
/** Speed above this reads as walking (the idle ↔ walk edge). */
|
|
47
|
+
walkThreshold: number;
|
|
48
|
+
/** The character's AABB hitbox — a footprint, shorter than the sprite. */
|
|
49
|
+
hitboxWidth: number;
|
|
50
|
+
hitboxHeight: number;
|
|
51
|
+
vx: number;
|
|
52
|
+
vy: number;
|
|
53
|
+
/** Four-direction facing; starts looking at the camera. */
|
|
54
|
+
facing: TopDownFacing;
|
|
55
|
+
/** The scene camera reads follow velocity through this explicit seam. */
|
|
56
|
+
getCameraVelocity(): CameraVelocity;
|
|
57
|
+
/** The StateMachine resolves directional clips through this explicit seam. */
|
|
58
|
+
getAnimationFacing(): string;
|
|
59
|
+
/**
|
|
60
|
+
* Accelerates toward the input vector (each axis -1..1) * moveSpeed.
|
|
61
|
+
* The vector is normalized so diagonals move at cardinal speed, and
|
|
62
|
+
* facing follows the dominant input axis — ties keep the last facing.
|
|
63
|
+
*/
|
|
64
|
+
run(inputX: number, inputY: number, dt: number): void;
|
|
65
|
+
/** Live speed, for the idle ↔ walk edge. */
|
|
66
|
+
speed(): number;
|
|
67
|
+
/** Integrates velocity and resolves each axis against Solids. */
|
|
68
|
+
step(dt: number): void;
|
|
69
|
+
halt(): void;
|
|
70
|
+
private resolveAxis;
|
|
71
|
+
private collisionBody;
|
|
72
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { Component, resolveSolidAxis, THREE, } from '@waica/engine';
|
|
2
|
+
/**
|
|
3
|
+
* Passive top-down motor: tuning params, physical state and movement
|
|
4
|
+
* methods for state code to call. It has no onUpdate of its own — the
|
|
5
|
+
* StateMachine is the only owner of the frame; this is the toolbox the
|
|
6
|
+
* active state moves the body with. Eight-direction movement with the
|
|
7
|
+
* input vector normalized so diagonals match cardinal speed, no gravity,
|
|
8
|
+
* and per-axis collision against the scene's Solids — deterministic
|
|
9
|
+
* genre movement (Zelda-style), not "realistic" physics.
|
|
10
|
+
*/
|
|
11
|
+
export class TopDownMotor extends Component {
|
|
12
|
+
static componentName = 'TopDownMotor';
|
|
13
|
+
static displayName = 'Motor';
|
|
14
|
+
static params = {
|
|
15
|
+
moveSpeed: { label: 'Speed', min: 1, max: 30, step: 0.5 },
|
|
16
|
+
acceleration: { label: 'Acceleration', min: 5, max: 200, step: 5 },
|
|
17
|
+
deceleration: { label: 'Deceleration', min: 5, max: 200, step: 5 },
|
|
18
|
+
walkThreshold: { label: 'Walk threshold', min: 0, max: 5, step: 0.1 },
|
|
19
|
+
};
|
|
20
|
+
static transient = ['vx', 'vy', 'facing'];
|
|
21
|
+
moveSpeed = 6;
|
|
22
|
+
acceleration = 60;
|
|
23
|
+
deceleration = 80;
|
|
24
|
+
/** Speed above this reads as walking (the idle ↔ walk edge). */
|
|
25
|
+
walkThreshold = 0.5;
|
|
26
|
+
/** The character's AABB hitbox — a footprint, shorter than the sprite. */
|
|
27
|
+
hitboxWidth = 0.9;
|
|
28
|
+
hitboxHeight = 0.6;
|
|
29
|
+
vx = 0;
|
|
30
|
+
vy = 0;
|
|
31
|
+
/** Four-direction facing; starts looking at the camera. */
|
|
32
|
+
facing = 's';
|
|
33
|
+
/** The scene camera reads follow velocity through this explicit seam. */
|
|
34
|
+
getCameraVelocity() {
|
|
35
|
+
return { vx: this.vx, vy: this.vy };
|
|
36
|
+
}
|
|
37
|
+
/** The StateMachine resolves directional clips through this explicit seam. */
|
|
38
|
+
getAnimationFacing() {
|
|
39
|
+
return this.facing;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Accelerates toward the input vector (each axis -1..1) * moveSpeed.
|
|
43
|
+
* The vector is normalized so diagonals move at cardinal speed, and
|
|
44
|
+
* facing follows the dominant input axis — ties keep the last facing.
|
|
45
|
+
*/
|
|
46
|
+
run(inputX, inputY, dt) {
|
|
47
|
+
let x = inputX;
|
|
48
|
+
let y = inputY;
|
|
49
|
+
const length = Math.hypot(x, y);
|
|
50
|
+
if (length > 1) {
|
|
51
|
+
x /= length;
|
|
52
|
+
y /= length;
|
|
53
|
+
}
|
|
54
|
+
const rateX = x !== 0 ? this.acceleration : this.deceleration;
|
|
55
|
+
const rateY = y !== 0 ? this.acceleration : this.deceleration;
|
|
56
|
+
this.vx = THREE.MathUtils.damp(this.vx, x * this.moveSpeed, rateX / this.moveSpeed, dt);
|
|
57
|
+
this.vy = THREE.MathUtils.damp(this.vy, y * this.moveSpeed, rateY / this.moveSpeed, dt);
|
|
58
|
+
const absX = Math.abs(inputX);
|
|
59
|
+
const absY = Math.abs(inputY);
|
|
60
|
+
if (absX > absY)
|
|
61
|
+
this.facing = inputX < 0 ? 'w' : 'e';
|
|
62
|
+
else if (absY > absX)
|
|
63
|
+
this.facing = inputY < 0 ? 's' : 'n';
|
|
64
|
+
}
|
|
65
|
+
/** Live speed, for the idle ↔ walk edge. */
|
|
66
|
+
speed() {
|
|
67
|
+
return Math.hypot(this.vx, this.vy);
|
|
68
|
+
}
|
|
69
|
+
/** Integrates velocity and resolves each axis against Solids. */
|
|
70
|
+
step(dt) {
|
|
71
|
+
const pos = this.entity.position;
|
|
72
|
+
const previousX = pos.x;
|
|
73
|
+
pos.x += this.vx * dt;
|
|
74
|
+
if (this.resolveAxis('x', previousX))
|
|
75
|
+
this.vx = 0;
|
|
76
|
+
const previousY = pos.y;
|
|
77
|
+
pos.y += this.vy * dt;
|
|
78
|
+
if (this.resolveAxis('y', previousY))
|
|
79
|
+
this.vy = 0;
|
|
80
|
+
}
|
|
81
|
+
halt() {
|
|
82
|
+
this.vx = 0;
|
|
83
|
+
this.vy = 0;
|
|
84
|
+
}
|
|
85
|
+
resolveAxis(axis, previous) {
|
|
86
|
+
return resolveSolidAxis({
|
|
87
|
+
entity: this.entity,
|
|
88
|
+
axis,
|
|
89
|
+
previous,
|
|
90
|
+
body: () => this.collisionBody(),
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
collisionBody() {
|
|
94
|
+
return {
|
|
95
|
+
x: this.entity.position.x,
|
|
96
|
+
y: this.entity.position.y,
|
|
97
|
+
width: this.hitboxWidth,
|
|
98
|
+
height: this.hitboxHeight,
|
|
99
|
+
shape: 'rectangle',
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type RoleDefinition, type RoleGraph, type StateContext } from '@waica/engine';
|
|
2
|
+
/**
|
|
3
|
+
* The top-down 'player' role: the character you control from above. Both
|
|
4
|
+
* default states share one body update; they differ only in the edges
|
|
5
|
+
* their prefab data declares. Extending the player is defineStates
|
|
6
|
+
* ('player', { yourState: {...} }) plus a state in the prefab — never a
|
|
7
|
+
* fight with a parallel controller.
|
|
8
|
+
*/
|
|
9
|
+
/** The state graph new top-down player characters start with, as prefab data. */
|
|
10
|
+
export declare const TOPDOWN_PLAYER_STATE_GRAPH: RoleGraph;
|
|
11
|
+
/**
|
|
12
|
+
* One body update shared by every default state: read the four-direction
|
|
13
|
+
* actions, accelerate, collide, then report what the body is doing as
|
|
14
|
+
* signals. Unmatched signals are no-ops, so each state only reacts to
|
|
15
|
+
* the edges its data declares.
|
|
16
|
+
*/
|
|
17
|
+
export declare function topdownPlayerUpdate({ entity, game, fsm }: StateContext, dt: number): void;
|
|
18
|
+
export declare const TOPDOWN_PLAYER_ROLE: RoleDefinition;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import {} from '@waica/engine';
|
|
2
|
+
import { Health } from './health.js';
|
|
3
|
+
import { interactUpdate } from './interactable.js';
|
|
4
|
+
import { Respawnable } from './respawnable.js';
|
|
5
|
+
import { TopDownMotor } from './topdown-motor.js';
|
|
6
|
+
/**
|
|
7
|
+
* The top-down 'player' role: the character you control from above. Both
|
|
8
|
+
* default states share one body update; they differ only in the edges
|
|
9
|
+
* their prefab data declares. Extending the player is defineStates
|
|
10
|
+
* ('player', { yourState: {...} }) plus a state in the prefab — never a
|
|
11
|
+
* fight with a parallel controller.
|
|
12
|
+
*/
|
|
13
|
+
/** The state graph new top-down player characters start with, as prefab data. */
|
|
14
|
+
export const TOPDOWN_PLAYER_STATE_GRAPH = {
|
|
15
|
+
initial: 'idle',
|
|
16
|
+
states: {
|
|
17
|
+
idle: {
|
|
18
|
+
transitions: [{ on: 'signal:move', to: 'walk' }],
|
|
19
|
+
},
|
|
20
|
+
walk: {
|
|
21
|
+
transitions: [{ on: 'signal:stop', to: 'idle' }],
|
|
22
|
+
},
|
|
23
|
+
dead: {
|
|
24
|
+
// Freeze on idle (resolved directionally) rather than name a death
|
|
25
|
+
// clip the stock sheets do not have and warn every frame.
|
|
26
|
+
clip: 'idle',
|
|
27
|
+
// A beat before control comes back, so death reads as an event.
|
|
28
|
+
transitions: [{ on: 'timer:0.8', to: 'idle' }],
|
|
29
|
+
},
|
|
30
|
+
// Dying is the same from every state, so the edge lives on '*'. Its
|
|
31
|
+
// presence is also the contract Health checks before signalling: a graph
|
|
32
|
+
// without it gets its entity destroyed instead.
|
|
33
|
+
'*': { transitions: [{ on: 'signal:death', to: 'dead' }] },
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* One body update shared by every default state: read the four-direction
|
|
38
|
+
* actions, accelerate, collide, then report what the body is doing as
|
|
39
|
+
* signals. Unmatched signals are no-ops, so each state only reacts to
|
|
40
|
+
* the edges its data declares.
|
|
41
|
+
*/
|
|
42
|
+
export function topdownPlayerUpdate({ entity, game, fsm }, dt) {
|
|
43
|
+
const motor = entity.get(TopDownMotor);
|
|
44
|
+
if (!motor)
|
|
45
|
+
return;
|
|
46
|
+
motor.run(game.input.axis('left', 'right'), game.input.axis('down', 'up'), dt);
|
|
47
|
+
motor.step(dt);
|
|
48
|
+
fsm.signal(motor.speed() > motor.walkThreshold ? 'move' : 'stop');
|
|
49
|
+
}
|
|
50
|
+
export const TOPDOWN_PLAYER_ROLE = {
|
|
51
|
+
description: 'You control this character with the project controls: eight-direction ' +
|
|
52
|
+
'top-down movement with normalized diagonals and no gravity. Its ' +
|
|
53
|
+
'states move the Motor.',
|
|
54
|
+
driver: 'TopDownMotor',
|
|
55
|
+
graph: TOPDOWN_PLAYER_STATE_GRAPH,
|
|
56
|
+
signals: {
|
|
57
|
+
move: 'moving',
|
|
58
|
+
stop: 'standing still',
|
|
59
|
+
},
|
|
60
|
+
states: {
|
|
61
|
+
// Always-hook: the interact lookup must survive custom states like an
|
|
62
|
+
// attack, so it runs in every state.
|
|
63
|
+
'*': {
|
|
64
|
+
onUpdate(ctx) {
|
|
65
|
+
interactUpdate(ctx);
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
// Fallback: a custom state without its own onUpdate keeps the full
|
|
69
|
+
// body update — its file only has to say what makes it special.
|
|
70
|
+
default: { onUpdate: topdownPlayerUpdate },
|
|
71
|
+
idle: { onUpdate: topdownPlayerUpdate },
|
|
72
|
+
walk: { onUpdate: topdownPlayerUpdate },
|
|
73
|
+
// Coming back is what leaving death means, so it hangs off onExit: any
|
|
74
|
+
// other way out of this state (a project's own edge) revives too.
|
|
75
|
+
dead: {
|
|
76
|
+
// A state without its own onUpdate falls back to the role's default
|
|
77
|
+
// body update, so without this no-op the player kept walking for the
|
|
78
|
+
// whole death beat instead of the graph taking control away.
|
|
79
|
+
onUpdate() { },
|
|
80
|
+
onExit({ entity }) {
|
|
81
|
+
entity.get(Respawnable)?.respawn();
|
|
82
|
+
entity.get(Health)?.heal(Infinity);
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@waica/behaviors",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Waica built-in behaviors — the curated game-feel library",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -19,6 +19,6 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@waica/engine": "^0.
|
|
22
|
+
"@waica/engine": "^0.7.0"
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { AnimationContract } from './contract.js';
|
|
2
|
+
/**
|
|
3
|
+
* Directional animation contract: the archetype declares which facing
|
|
4
|
+
* directions exist, how clips are named per direction (`<state>-<dir>`),
|
|
5
|
+
* and how a missing direction degrades — including mirroring, so west can
|
|
6
|
+
* reuse east art flipped. Extends the base AnimationContract thesis to
|
|
7
|
+
* genres where characters face more than one way (top-down, isometric).
|
|
8
|
+
*/
|
|
9
|
+
export interface DirectionalFallback<Dir extends string = string> {
|
|
10
|
+
dir: Dir;
|
|
11
|
+
/** Mirror the resolved clip horizontally (e.g. west plays east flipped). */
|
|
12
|
+
flip?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface DirectionalAnimation<Dir extends string = string> {
|
|
15
|
+
/** Declared facing directions, e.g. ['n', 's', 'e', 'w'] — 8 for isometric. */
|
|
16
|
+
directions: readonly Dir[];
|
|
17
|
+
/** Directional degradation: a missing facing resolves to another, optionally mirrored. */
|
|
18
|
+
fallbacks?: Partial<Record<Dir, DirectionalFallback<Dir>>>;
|
|
19
|
+
/** State-level degradation chain applied when no directional clip resolves. */
|
|
20
|
+
contract: AnimationContract;
|
|
21
|
+
}
|
|
22
|
+
export interface ResolvedDirectionalClip {
|
|
23
|
+
clip: string | undefined;
|
|
24
|
+
flip: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Resolves state × facing to a playable clip: the exact `<state>-<dir>`
|
|
28
|
+
* clip, else the declared directional fallback chain (accumulating flips).
|
|
29
|
+
* On a dead end, walks the base AnimationContract's state fallback chain
|
|
30
|
+
* (cycle-safe) and, for each candidate state in turn, retries the
|
|
31
|
+
* directional chain against it before trying its bare name. An invalid
|
|
32
|
+
* facing, or a chain that dead-ends everywhere, resolves to nothing rather
|
|
33
|
+
* than guessing — the caller's name-based fallback path handles that.
|
|
34
|
+
*/
|
|
35
|
+
export declare function resolveDirectionalClip(animation: DirectionalAnimation, available: Iterable<string>, state: string, facing: string): ResolvedDirectionalClip;
|
|
36
|
+
/** Installs (or clears, with null) the active directional contract. */
|
|
37
|
+
export declare function installDirectionalAnimation(animation: DirectionalAnimation | null): void;
|
|
38
|
+
/** The active directional contract, if an archetype installed one. */
|
|
39
|
+
export declare function installedDirectionalAnimation(): DirectionalAnimation | null;
|
|
40
|
+
/**
|
|
41
|
+
* The explicit seam a driving component (a motor) opts into so StateMachine
|
|
42
|
+
* can resolve directional clips: it reports the entity's current facing as
|
|
43
|
+
* one of the contract's declared directions.
|
|
44
|
+
*/
|
|
45
|
+
export interface AnimationFacingProvider {
|
|
46
|
+
getAnimationFacing(): string;
|
|
47
|
+
}
|
|
48
|
+
export declare function isAnimationFacingProvider(value: unknown): value is AnimationFacingProvider;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Walks the exact `<state>-<dir>` clip, then the declared directional
|
|
3
|
+
* fallback chain (accumulating flips), cycle-safe. Undefined at a dead end —
|
|
4
|
+
* callers decide what to try next, instead of this reaching for anything else.
|
|
5
|
+
*/
|
|
6
|
+
function directionalChain(animation, available, state, facing) {
|
|
7
|
+
const seen = new Set();
|
|
8
|
+
let dir = facing;
|
|
9
|
+
let flip = false;
|
|
10
|
+
while (dir && !seen.has(dir)) {
|
|
11
|
+
const candidate = `${state}-${dir}`;
|
|
12
|
+
if (available.has(candidate))
|
|
13
|
+
return { clip: candidate, flip };
|
|
14
|
+
seen.add(dir);
|
|
15
|
+
const fallback = animation.fallbacks?.[dir];
|
|
16
|
+
if (!fallback)
|
|
17
|
+
break;
|
|
18
|
+
if (fallback.flip)
|
|
19
|
+
flip = !flip;
|
|
20
|
+
dir = fallback.dir;
|
|
21
|
+
}
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Resolves state × facing to a playable clip: the exact `<state>-<dir>`
|
|
26
|
+
* clip, else the declared directional fallback chain (accumulating flips).
|
|
27
|
+
* On a dead end, walks the base AnimationContract's state fallback chain
|
|
28
|
+
* (cycle-safe) and, for each candidate state in turn, retries the
|
|
29
|
+
* directional chain against it before trying its bare name. An invalid
|
|
30
|
+
* facing, or a chain that dead-ends everywhere, resolves to nothing rather
|
|
31
|
+
* than guessing — the caller's name-based fallback path handles that.
|
|
32
|
+
*/
|
|
33
|
+
export function resolveDirectionalClip(animation, available, state, facing) {
|
|
34
|
+
if (!animation.directions.includes(facing))
|
|
35
|
+
return { clip: undefined, flip: false };
|
|
36
|
+
const set = new Set(available);
|
|
37
|
+
const direct = directionalChain(animation, set, state, facing);
|
|
38
|
+
if (direct)
|
|
39
|
+
return direct;
|
|
40
|
+
const seenStates = new Set();
|
|
41
|
+
let candidate = state;
|
|
42
|
+
while (candidate && !seenStates.has(candidate)) {
|
|
43
|
+
seenStates.add(candidate);
|
|
44
|
+
if (candidate !== state) {
|
|
45
|
+
const viaDirection = directionalChain(animation, set, candidate, facing);
|
|
46
|
+
if (viaDirection)
|
|
47
|
+
return viaDirection;
|
|
48
|
+
}
|
|
49
|
+
if (set.has(candidate))
|
|
50
|
+
return { clip: candidate, flip: false };
|
|
51
|
+
candidate = animation.contract.fallbacks[candidate];
|
|
52
|
+
}
|
|
53
|
+
return { clip: undefined, flip: false };
|
|
54
|
+
}
|
|
55
|
+
let installed = null;
|
|
56
|
+
/** Installs (or clears, with null) the active directional contract. */
|
|
57
|
+
export function installDirectionalAnimation(animation) {
|
|
58
|
+
installed = animation;
|
|
59
|
+
}
|
|
60
|
+
/** The active directional contract, if an archetype installed one. */
|
|
61
|
+
export function installedDirectionalAnimation() {
|
|
62
|
+
return installed;
|
|
63
|
+
}
|
|
64
|
+
export function isAnimationFacingProvider(value) {
|
|
65
|
+
return (typeof value === 'object' &&
|
|
66
|
+
value !== null &&
|
|
67
|
+
typeof value.getAnimationFacing === 'function');
|
|
68
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DirectionalAnimation } from './animation/directional.js';
|
|
1
2
|
import type { InputBindings } from './input.js';
|
|
2
3
|
import type { PrefabJson, SceneEntityJson, SceneJson, SceneRegistry } from './scene.js';
|
|
3
4
|
import type { ArchetypeBundle } from './state/hooks.js';
|
|
@@ -30,6 +31,8 @@ export interface ArchetypeManifest {
|
|
|
30
31
|
bindings: Readonly<InputBindings>;
|
|
31
32
|
actionLabels: Readonly<Record<string, string>>;
|
|
32
33
|
bundle: ArchetypeBundle;
|
|
34
|
+
/** Directional animation contract, for genres where characters face around. */
|
|
35
|
+
animation?: DirectionalAnimation;
|
|
33
36
|
}
|
|
34
37
|
/** Browser manifest enriched with URLs produced by an asset-aware bundler. */
|
|
35
38
|
export interface BrowserArchetypeManifest extends ArchetypeManifest {
|