create-exo-app 0.19.0 → 0.20.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 +10 -8
- package/dist/scaffold.js +21 -19
- package/package.json +1 -1
- package/templates/audio-reactive/package.json +1 -2
- package/templates/audio-reactive/src/scenes/AudioReactiveScene.ts +5 -2
- package/templates/game-starter/src/scenes/GameOverScene.ts +5 -1
- package/templates/platformer/README.md +11 -1
- package/templates/platformer/package.json +1 -2
- package/templates/platformer/src/objects/Player.ts +22 -11
- package/templates/platformer/src/scenes/PlatformerScene.ts +53 -54
- package/templates/top-down/README.md +27 -10
- package/templates/top-down/package.json +1 -4
- package/templates/top-down/public/assets/town-square.tmj +110 -49
- package/templates/top-down/src/actor.ts +159 -0
- package/templates/top-down/src/level.ts +29 -31
- package/templates/top-down/src/main.ts +6 -5
- package/templates/top-down/src/scenes/ProceduralMapScene.ts +70 -45
- package/templates/top-down/src/scenes/TiledMapScene.ts +8 -20
- package/templates/top-down/src/scenes/TopDownScene.ts +304 -130
- package/templates/ui-app/README.md +2 -0
- package/templates/ui-app/src/scenes/SettingsScene.ts +6 -1
|
@@ -1,208 +1,382 @@
|
|
|
1
|
-
import type { RenderingContext, Seconds, SpritesheetData } from '@codexo/exojs';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import type { PointLike, RenderingContext, Seconds, SpritesheetData } from '@codexo/exojs';
|
|
2
|
+
import {
|
|
3
|
+
ActionMap,
|
|
4
|
+
BehaviorComponent,
|
|
5
|
+
ButtonAction,
|
|
6
|
+
Color,
|
|
7
|
+
Container,
|
|
8
|
+
Graphics,
|
|
9
|
+
Keyboard,
|
|
10
|
+
Label,
|
|
11
|
+
Rectangle,
|
|
12
|
+
Scene,
|
|
13
|
+
SceneState,
|
|
14
|
+
Spritesheet,
|
|
15
|
+
SystemOrder,
|
|
16
|
+
Texture,
|
|
17
|
+
VectorAction,
|
|
18
|
+
View,
|
|
19
|
+
} from '@codexo/exojs';
|
|
20
|
+
import { type NavigationStatus, TileNavigationSpace } from '@codexo/exojs/pathfinding';
|
|
21
|
+
import { BoxShape, PhysicsWorld } from '@codexo/exojs/physics';
|
|
22
|
+
import { type ResolvedTile, type TileLayer, type TileMap, TileMapNode } from '@codexo/exojs/tilemap';
|
|
23
|
+
import { TileColliderStreamer } from '@codexo/exojs/tilemap-physics';
|
|
24
|
+
|
|
25
|
+
import { type Actor, type ActorOptions, spawnActor } from '../actor';
|
|
26
|
+
|
|
27
|
+
/** The player's collision radius: room to turn in a one-tile corridor. */
|
|
28
|
+
export const PLAYER_RADIUS = 22;
|
|
29
|
+
const PLAYER_SPEED = 260;
|
|
30
|
+
/** How far from a door's centre the player can reach it, in pixels. */
|
|
31
|
+
const DOOR_REACH = 100;
|
|
32
|
+
|
|
33
|
+
const PLAYER_STATUS_TEXT: Partial<Record<NavigationStatus, string>> = {
|
|
34
|
+
navigating: 'Walking...',
|
|
35
|
+
arrived: 'Arrived.',
|
|
36
|
+
unreachable: 'There is no way there.',
|
|
37
|
+
blocked: 'Something is in the way.',
|
|
38
|
+
};
|
|
11
39
|
|
|
12
40
|
const PATH_COLOR = new Color(90, 200, 255);
|
|
13
41
|
const GOAL_COLOR = new Color(255, 170, 80);
|
|
14
42
|
|
|
43
|
+
/** A tile whose definition carries a collision shape blocks walking. */
|
|
44
|
+
const isSolid = (tile: ResolvedTile | null): boolean => tile?.tileset.getTileDefinition(tile.localTileId)?.collision !== undefined;
|
|
45
|
+
|
|
46
|
+
const isDoor = (tile: ResolvedTile | null): boolean => tile?.tileset.getTileDefinition(tile.localTileId)?.properties?.['door'] === true;
|
|
47
|
+
|
|
48
|
+
/** A door cell of the `Walls` layer, open or closed. */
|
|
49
|
+
export interface Door {
|
|
50
|
+
readonly column: number;
|
|
51
|
+
readonly row: number;
|
|
52
|
+
/** The closed door, as the map authored it. */
|
|
53
|
+
readonly closedTile: ResolvedTile;
|
|
54
|
+
readonly open: boolean;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface DoorState extends Door {
|
|
58
|
+
open: boolean;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Moves the player while a direction is held, taking over from click-to-move.
|
|
63
|
+
*
|
|
64
|
+
* A navigation agent expects to be its movement's only source of commands.
|
|
65
|
+
* This component stops navigation before it commands the movement itself, and
|
|
66
|
+
* it has to be added after the navigation agent, so that in the step where the
|
|
67
|
+
* route still steered, its own command is the later one and wins.
|
|
68
|
+
*/
|
|
69
|
+
class DirectControl extends BehaviorComponent {
|
|
70
|
+
public constructor(
|
|
71
|
+
private readonly _actor: Actor,
|
|
72
|
+
private readonly _direction: VectorAction,
|
|
73
|
+
) {
|
|
74
|
+
super();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public override fixedUpdate(): void {
|
|
78
|
+
const direction = this._direction.value;
|
|
79
|
+
|
|
80
|
+
if (direction.x === 0 && direction.y === 0) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (this._actor.agent.status !== 'idle') {
|
|
85
|
+
this._actor.agent.stop();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
this._actor.movement.move(direction);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
15
92
|
/**
|
|
16
|
-
* Everything a top-down scene needs except
|
|
17
|
-
*
|
|
18
|
-
* camera.
|
|
93
|
+
* Everything a top-down scene needs except where its map comes from: a physics
|
|
94
|
+
* world, wall colliders and a navigation grid derived from the map, a player
|
|
95
|
+
* that walks by click or by keys, a door, and a camera.
|
|
96
|
+
*
|
|
97
|
+
* `ProceduralMapScene` builds the `TileMap` in code; `TiledMapScene` loads it
|
|
98
|
+
* from `town-square.tmj`. Everything below reads only that map:
|
|
19
99
|
*
|
|
20
|
-
* The map is the
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
100
|
+
* - The map's `Walls` layer is the single source of truth for what blocks. A
|
|
101
|
+
* tile whose tileset definition carries a collision shape is solid - the
|
|
102
|
+
* `TileColliderStreamer` turns those shapes into static bodies, and the
|
|
103
|
+
* `TileNavigationSpace` routes around the same cells.
|
|
104
|
+
* - A `Walls` tile with a `door` property is a door. Opening it removes the
|
|
105
|
+
* tile, closing it puts the tile back; both consumers see the edit through
|
|
106
|
+
* the layer's revision.
|
|
107
|
+
* - The spawn point is the `spawn` object of the map's `Markers` layer.
|
|
24
108
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
109
|
+
* Collision and navigation update at different points, so the scene names
|
|
110
|
+
* them: the collider bridge syncs before every frame's fixed steps and again
|
|
111
|
+
* straight after a door edit, so no step runs against stale walls; the
|
|
112
|
+
* navigation space resamples when an agent next reads it. A walking agent
|
|
113
|
+
* notices the edit and replans within its repath interval; until then the
|
|
114
|
+
* synced collider is what stops it at a door that just closed.
|
|
29
115
|
*/
|
|
30
116
|
export abstract class TopDownScene extends Scene {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
117
|
+
/** The ActionMap the scene reads: held directions move the player, a door press toggles the nearest door. */
|
|
118
|
+
public readonly controls = new ActionMap({
|
|
119
|
+
move: new VectorAction([
|
|
120
|
+
{ up: Keyboard.W, down: Keyboard.S, left: Keyboard.A, right: Keyboard.D },
|
|
121
|
+
{ up: Keyboard.Up, down: Keyboard.Down, left: Keyboard.Left, right: Keyboard.Right },
|
|
122
|
+
]),
|
|
123
|
+
door: new ButtonAction([Keyboard.E]),
|
|
124
|
+
cancel: new ButtonAction([Keyboard.Escape]),
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
private _map!: TileMap;
|
|
128
|
+
private _walls!: TileLayer;
|
|
129
|
+
private _world!: PhysicsWorld;
|
|
130
|
+
private _colliders!: TileColliderStreamer;
|
|
131
|
+
private _navigation!: TileNavigationSpace<ResolvedTile>;
|
|
132
|
+
private _player!: Actor;
|
|
39
133
|
private _camera!: View;
|
|
40
134
|
private _status!: Label;
|
|
41
|
-
private _waypoints: readonly Vector[] = [];
|
|
42
|
-
private _waypoint = 0;
|
|
43
135
|
private _characterData!: SpritesheetData;
|
|
136
|
+
private readonly _charactersTexture = new Texture('characters.png');
|
|
137
|
+
private _doorProbe!: BoxShape;
|
|
138
|
+
private readonly _doors: DoorState[] = [];
|
|
139
|
+
private readonly _scenery = new Container();
|
|
140
|
+
private readonly _overlay = new Graphics();
|
|
141
|
+
|
|
142
|
+
/** Loads the map this scene plays on. Called from `load()`, after the actor art. */
|
|
143
|
+
protected abstract loadMap(): Promise<TileMap>;
|
|
144
|
+
|
|
145
|
+
public get map(): TileMap {
|
|
146
|
+
return this._map;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
public get world(): PhysicsWorld {
|
|
150
|
+
return this._world;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
public get colliders(): TileColliderStreamer {
|
|
154
|
+
return this._colliders;
|
|
155
|
+
}
|
|
44
156
|
|
|
45
|
-
|
|
46
|
-
|
|
157
|
+
public get navigation(): TileNavigationSpace<ResolvedTile> {
|
|
158
|
+
return this._navigation;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
public get player(): Actor {
|
|
162
|
+
return this._player;
|
|
163
|
+
}
|
|
47
164
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return Promise.resolve();
|
|
165
|
+
public get doors(): readonly Door[] {
|
|
166
|
+
return this._doors;
|
|
51
167
|
}
|
|
52
168
|
|
|
53
169
|
public override async load(): Promise<void> {
|
|
54
|
-
this._characterData = (await this.loader.load(
|
|
170
|
+
this._characterData = (await this.loader.load({ type: 'json', source: 'characters.json' })) as SpritesheetData;
|
|
55
171
|
|
|
56
|
-
await this.
|
|
57
|
-
await this.loadMap();
|
|
172
|
+
await this.assets.load(this._charactersTexture);
|
|
173
|
+
this._map = await this.loadMap();
|
|
58
174
|
}
|
|
59
175
|
|
|
60
176
|
public override init(): void {
|
|
61
|
-
|
|
177
|
+
const map = this._map;
|
|
178
|
+
const walls = map.getTileLayer('Walls');
|
|
179
|
+
const spawn = map.getObjectLayer('Markers')?.query({ name: 'spawn' })[0];
|
|
62
180
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const spawnPoint = tileCenter(spawn.column, spawn.row);
|
|
67
|
-
const characters = new Spritesheet(this.loader.get('characters.png'), this._characterData);
|
|
181
|
+
if (walls === undefined || spawn === undefined) {
|
|
182
|
+
throw new Error('TopDownScene: the map needs a "Walls" tile layer and a "spawn" object in a "Markers" layer.');
|
|
183
|
+
}
|
|
68
184
|
|
|
69
|
-
this.
|
|
70
|
-
|
|
71
|
-
this.
|
|
185
|
+
this._walls = walls;
|
|
186
|
+
// The host clock steps the world, so the world has to step at the host's rate.
|
|
187
|
+
this._world = new PhysicsWorld({ gravity: { x: 0, y: 0 }, fixedDelta: this.app.fixedTimeStep });
|
|
188
|
+
this.systems.add(this._world, { order: SystemOrder.Physics });
|
|
72
189
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
fixedRotation: true,
|
|
78
|
-
});
|
|
190
|
+
// Registered after the world, so it is destroyed first and removes its bodies from a live world.
|
|
191
|
+
this._colliders = new TileColliderStreamer(this._world, walls);
|
|
192
|
+
this._colliders.sync();
|
|
193
|
+
this.systems.add({ preFrame: () => this._colliders.sync(), destroy: () => this._colliders.destroy() });
|
|
79
194
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
this.
|
|
195
|
+
this._navigation = new TileNavigationSpace(walls, { cost: tile => (isSolid(tile) ? 0 : 1) });
|
|
196
|
+
this._doorProbe = new BoxShape(walls.tileWidth, walls.tileHeight);
|
|
197
|
+
this._findDoors();
|
|
83
198
|
|
|
84
|
-
this._scenery.addChild(
|
|
199
|
+
this._scenery.addChild(new TileMapNode(map), this._overlay);
|
|
85
200
|
this.addChild(this._scenery);
|
|
86
201
|
|
|
87
|
-
this.
|
|
88
|
-
this.
|
|
89
|
-
this.
|
|
202
|
+
this._player = this.spawnActor({ position: spawn, radius: PLAYER_RADIUS, speed: PLAYER_SPEED });
|
|
203
|
+
this._player.node.addComponent(new DirectControl(this._player, this.controls.move));
|
|
204
|
+
this._player.agent.onStatusChange.add(this._onPlayerStatus);
|
|
205
|
+
this._dressPlayer();
|
|
90
206
|
|
|
91
|
-
this.
|
|
207
|
+
this._camera = new View(spawn.x, spawn.y, this.app.width, this.app.height);
|
|
208
|
+
this._camera.follow(this._player.node, { lerp: 0.12 });
|
|
209
|
+
this._camera.setBounds(new Rectangle(0, 0, map.pixelWidth ?? 0, map.pixelHeight ?? 0));
|
|
210
|
+
|
|
211
|
+
this._status = new Label('Click a floor tile to walk there, or use WASD. E opens and closes doors.', { fontSize: 18 });
|
|
92
212
|
this._status.anchorIn(this.ui, 'top-left', 24, 20);
|
|
93
213
|
this.ui.addChild(this._status);
|
|
94
214
|
|
|
95
|
-
this.
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
this._planPath(world.x, world.y);
|
|
102
|
-
});
|
|
215
|
+
this.inputs.attach(this.controls);
|
|
216
|
+
// A global signal: removed with the scene, and ignored while the scene is
|
|
217
|
+
// paused or suspended so a click never queues a walk for later.
|
|
218
|
+
this.app.input.onPointerTap.add(this._onTap);
|
|
219
|
+
this.track({ destroy: () => this.app.input.onPointerTap.remove(this._onTap) });
|
|
220
|
+
}
|
|
103
221
|
|
|
104
|
-
|
|
222
|
+
/** Adds an {@link Actor} to the level, colliding with its walls and routing around them. */
|
|
223
|
+
public spawnActor(options: ActorOptions): Actor {
|
|
224
|
+
return spawnActor(this._scenery, this._world, this._navigation, options);
|
|
105
225
|
}
|
|
106
226
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
227
|
+
/**
|
|
228
|
+
* Opens or closes `door`. Refuses, returning `false`, to close a door on any
|
|
229
|
+
* body of the world that reaches into the doorway.
|
|
230
|
+
*/
|
|
231
|
+
public setDoor(door: Door, open: boolean): boolean {
|
|
232
|
+
const state = this._doors.find(candidate => candidate === door);
|
|
113
233
|
|
|
114
|
-
|
|
234
|
+
if (state === undefined) {
|
|
235
|
+
throw new Error('TopDownScene.setDoor(): not a door of this scene.');
|
|
115
236
|
}
|
|
116
237
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const distance = Math.hypot(dx, dy);
|
|
238
|
+
if (state.open === open) {
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
121
241
|
|
|
122
|
-
if (
|
|
123
|
-
|
|
242
|
+
if (!open && this._isOccupied(door)) {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
124
245
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
246
|
+
if (open) {
|
|
247
|
+
this._walls.clearTileAt(door.column, door.row);
|
|
248
|
+
} else {
|
|
249
|
+
this._walls.setTileAt(door.column, door.row, door.closedTile);
|
|
250
|
+
}
|
|
129
251
|
|
|
130
|
-
|
|
252
|
+
state.open = open;
|
|
253
|
+
// The edit lands mid-frame; without this the remaining fixed steps of the
|
|
254
|
+
// frame would still collide with the door as it was.
|
|
255
|
+
this._colliders.sync();
|
|
256
|
+
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
public override fixedUpdate(): void {
|
|
261
|
+
if (this.controls.cancel.tick.pressed) {
|
|
262
|
+
this._player.agent.stop();
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (this.controls.door.tick.pressed) {
|
|
266
|
+
const door = this._nearestDoor();
|
|
267
|
+
|
|
268
|
+
if (door !== null) {
|
|
269
|
+
this._status.text = this.setDoor(door, !door.open) ? `Door ${door.open ? 'opened' : 'closed'}.` : 'Something is in the way.';
|
|
270
|
+
}
|
|
131
271
|
}
|
|
272
|
+
}
|
|
132
273
|
|
|
133
|
-
|
|
134
|
-
this.
|
|
274
|
+
public override update(_delta: Seconds): void {
|
|
275
|
+
this._drawPath();
|
|
135
276
|
}
|
|
136
277
|
|
|
137
278
|
public override draw(context: RenderingContext): void {
|
|
138
279
|
context.render(this._scenery, { view: this._camera });
|
|
139
280
|
}
|
|
140
281
|
|
|
141
|
-
private
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
282
|
+
private readonly _onTap = (pointer: PointLike): void => {
|
|
283
|
+
if (this.state !== SceneState.Active || this.paused) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// Pointer coordinates are in screen space; the world is drawn through a
|
|
288
|
+
// camera, so they have to come back through it first.
|
|
289
|
+
const target = this._camera.screenToWorld(pointer.x, pointer.y);
|
|
290
|
+
|
|
291
|
+
this._player.moveTo(target);
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
private readonly _onPlayerStatus = (status: NavigationStatus): void => {
|
|
295
|
+
const text = PLAYER_STATUS_TEXT[status];
|
|
145
296
|
|
|
146
|
-
|
|
147
|
-
|
|
297
|
+
if (text !== undefined) {
|
|
298
|
+
this._status.text = text;
|
|
299
|
+
}
|
|
300
|
+
};
|
|
148
301
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
} else if (!solid && start !== -1) {
|
|
152
|
-
const length = column - start;
|
|
302
|
+
private _findDoors(): void {
|
|
303
|
+
const walls = this._walls;
|
|
153
304
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
position: { x: (start + length / 2) * TILE, y: (row + 0.5) * TILE },
|
|
158
|
-
colliders: [{ shape: new BoxShape(length * TILE, TILE) }],
|
|
159
|
-
}),
|
|
160
|
-
);
|
|
305
|
+
for (let row = 0; row < (walls.height ?? 0); row++) {
|
|
306
|
+
for (let column = 0; column < (walls.width ?? 0); column++) {
|
|
307
|
+
const tile = walls.getTileAt(column, row);
|
|
161
308
|
|
|
162
|
-
|
|
309
|
+
if (tile !== null && isDoor(tile)) {
|
|
310
|
+
this._doors.push({ column, row, closedTile: tile, open: false });
|
|
163
311
|
}
|
|
164
312
|
}
|
|
165
313
|
}
|
|
166
314
|
}
|
|
167
315
|
|
|
168
|
-
private
|
|
169
|
-
const
|
|
316
|
+
private _nearestDoor(): DoorState | null {
|
|
317
|
+
const { body } = this._player;
|
|
318
|
+
let nearest: DoorState | null = null;
|
|
319
|
+
let nearestDistance = DOOR_REACH;
|
|
170
320
|
|
|
171
|
-
|
|
172
|
-
this.
|
|
173
|
-
this.
|
|
321
|
+
for (const door of this._doors) {
|
|
322
|
+
const center = this._walls.tileToPixel(door.column, door.row);
|
|
323
|
+
const distance = Math.hypot(center.x + this._walls.tileWidth / 2 - body.x, center.y + this._walls.tileHeight / 2 - body.y);
|
|
174
324
|
|
|
175
|
-
|
|
325
|
+
if (distance <= nearestDistance) {
|
|
326
|
+
nearest = door;
|
|
327
|
+
nearestDistance = distance;
|
|
328
|
+
}
|
|
176
329
|
}
|
|
177
330
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
this._waypoints = result.points.slice(1);
|
|
181
|
-
this._waypoint = 0;
|
|
182
|
-
this._status.text = `${this._waypoints.length} waypoints, cost ${result.cost.toFixed(1)}.`;
|
|
331
|
+
return nearest;
|
|
332
|
+
}
|
|
183
333
|
|
|
184
|
-
|
|
334
|
+
private _isOccupied(door: Door): boolean {
|
|
335
|
+
const { tileWidth, tileHeight } = this._walls;
|
|
336
|
+
const corner = this._walls.tileToPixel(door.column, door.row);
|
|
337
|
+
const center = { x: corner.x + tileWidth / 2, y: corner.y + tileHeight / 2 };
|
|
338
|
+
|
|
339
|
+
// The walls beside the doorway touch it along its edges; only a body that
|
|
340
|
+
// can move is in the way.
|
|
341
|
+
return this._world.overlapShape(this._doorProbe, center).some(collider => collider.body.type !== 'static');
|
|
185
342
|
}
|
|
186
343
|
|
|
187
|
-
private
|
|
188
|
-
this.
|
|
189
|
-
|
|
190
|
-
|
|
344
|
+
private _dressPlayer(): void {
|
|
345
|
+
const characters = new Spritesheet(this._charactersTexture, this._characterData);
|
|
346
|
+
const sprite = characters.getFrameSprite('character_green_front').setAnchor(0.5);
|
|
347
|
+
|
|
348
|
+
sprite.width = PLAYER_RADIUS * 2;
|
|
349
|
+
sprite.height = PLAYER_RADIUS * 2.6;
|
|
350
|
+
this._player.node.addChild(sprite);
|
|
191
351
|
}
|
|
192
352
|
|
|
193
353
|
private _drawPath(): void {
|
|
354
|
+
const { agent, body, offset } = this._player;
|
|
355
|
+
const points = agent.path?.points ?? [];
|
|
356
|
+
|
|
194
357
|
this._overlay.clear();
|
|
358
|
+
|
|
359
|
+
if (agent.status !== 'navigating' || points.length <= agent.waypointIndex) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
|
|
195
363
|
this._overlay.lineWidth = 4;
|
|
196
364
|
this._overlay.lineColor = PATH_COLOR;
|
|
197
365
|
|
|
198
|
-
let
|
|
366
|
+
let previousX = body.x;
|
|
367
|
+
let previousY = body.y;
|
|
368
|
+
|
|
369
|
+
// Route points are in navigation space; see Actor.offset.
|
|
370
|
+
for (let index = agent.waypointIndex; index < points.length; index++) {
|
|
371
|
+
const x = points[index]!.x + offset;
|
|
372
|
+
const y = points[index]!.y + offset;
|
|
199
373
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
374
|
+
this._overlay.drawLine(previousX, previousY, x, y);
|
|
375
|
+
previousX = x;
|
|
376
|
+
previousY = y;
|
|
203
377
|
}
|
|
204
378
|
|
|
205
379
|
this._overlay.fillColor = GOAL_COLOR;
|
|
206
|
-
this._overlay.drawCircle(
|
|
380
|
+
this._overlay.drawCircle(previousX, previousY, 8);
|
|
207
381
|
}
|
|
208
382
|
}
|
|
@@ -12,6 +12,8 @@ Nothing reads a value back out of a widget. Each control writes into a draft obj
|
|
|
12
12
|
|
|
13
13
|
That separation is what lets you add a control without touching anything that consumes the settings, and it is what makes `Revert` a two-line method instead of a walk over every widget on screen.
|
|
14
14
|
|
|
15
|
+
For a smaller form with Button, TextInput, shared validation, keyboard focus and explicit gamepad Confirm, see the [name-form recipe](https://exoridus.github.io/ExoJS/en/guide/runtime/ui-and-widgets/#a-name-form-with-one-submit-rule). The [font recipe](https://exoridus.github.io/ExoJS/en/guide/rendering/text/#system-web-and-bitmap-fonts-in-one-scene) compares system, web and bitmap fonts with their supported effects.
|
|
16
|
+
|
|
15
17
|
## Theming
|
|
16
18
|
|
|
17
19
|
Every widget resolves its colours from the inherited `UITheme` and its own interaction state. `createUITheme` and `defaultUITheme` are exported from core: patch the roles you care about and pass the result down, rather than styling widgets one at a time.
|
|
@@ -127,7 +127,12 @@ export class SettingsScene extends Scene {
|
|
|
127
127
|
private _refreshSummary(): void {
|
|
128
128
|
const { playerName, volume, difficulty, fullscreen } = this._applied;
|
|
129
129
|
|
|
130
|
-
this._summary.text = [
|
|
130
|
+
this._summary.text = [
|
|
131
|
+
`Name: ${playerName}`,
|
|
132
|
+
this._volumeText(volume),
|
|
133
|
+
`Difficulty: ${difficulty}`,
|
|
134
|
+
`Fullscreen: ${fullscreen ? 'on' : 'off'}`,
|
|
135
|
+
].join('\n');
|
|
131
136
|
}
|
|
132
137
|
|
|
133
138
|
private _volumeText(value: number): string {
|