create-exo-app 0.1.0 → 0.19.1

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.
Files changed (57) hide show
  1. package/README.md +30 -29
  2. package/bin/create-exo-app.js +3 -0
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.js +2 -118
  5. package/dist/scaffold.d.ts +44 -0
  6. package/dist/scaffold.js +190 -0
  7. package/package.json +25 -8
  8. package/templates/audio-reactive/index.html +13 -3
  9. package/templates/audio-reactive/package.json +7 -3
  10. package/templates/audio-reactive/src/main.ts +4 -3
  11. package/templates/audio-reactive/src/scenes/AudioReactiveScene.ts +3 -3
  12. package/templates/game-starter/index.html +13 -3
  13. package/templates/game-starter/package.json +6 -3
  14. package/templates/game-starter/src/main.ts +5 -3
  15. package/templates/game-starter/src/objects/Player.ts +1 -1
  16. package/templates/game-starter/src/scenes/GameOverScene.ts +11 -17
  17. package/templates/game-starter/src/scenes/GameScene.ts +59 -26
  18. package/templates/minimal/index.html +13 -3
  19. package/templates/minimal/package.json +6 -3
  20. package/templates/minimal/src/main.ts +5 -4
  21. package/templates/minimal/src/scenes/MainScene.ts +3 -8
  22. package/templates/platformer/README.md +13 -0
  23. package/templates/platformer/index.html +25 -0
  24. package/templates/platformer/package.json +21 -0
  25. package/templates/platformer/public/assets/ART-LICENSE.txt +28 -0
  26. package/templates/platformer/public/assets/platformer-characters.json +1093 -0
  27. package/templates/platformer/public/assets/platformer-characters.png +0 -0
  28. package/templates/platformer/public/assets/platformer-tiles.json +7549 -0
  29. package/templates/platformer/public/assets/platformer-tiles.png +0 -0
  30. package/templates/platformer/src/main.ts +19 -0
  31. package/templates/platformer/src/objects/Player.ts +139 -0
  32. package/templates/platformer/src/scenes/PlatformerScene.ts +237 -0
  33. package/templates/platformer/tsconfig.json +12 -0
  34. package/templates/platformer/vite.config.ts +5 -0
  35. package/templates/top-down/README.md +27 -0
  36. package/templates/top-down/index.html +25 -0
  37. package/templates/top-down/package.json +24 -0
  38. package/templates/top-down/public/assets/ART-LICENSE.txt +21 -0
  39. package/templates/top-down/public/assets/characters.json +1093 -0
  40. package/templates/top-down/public/assets/characters.png +0 -0
  41. package/templates/top-down/public/assets/map-pack.png +0 -0
  42. package/templates/top-down/public/assets/town-square.tmj +689 -0
  43. package/templates/top-down/src/level.ts +59 -0
  44. package/templates/top-down/src/main.ts +29 -0
  45. package/templates/top-down/src/scenes/ProceduralMapScene.ts +74 -0
  46. package/templates/top-down/src/scenes/TiledMapScene.ts +33 -0
  47. package/templates/top-down/src/scenes/TopDownScene.ts +208 -0
  48. package/templates/top-down/tsconfig.json +12 -0
  49. package/templates/top-down/vite.config.ts +5 -0
  50. package/templates/ui-app/README.md +17 -0
  51. package/templates/ui-app/index.html +25 -0
  52. package/templates/ui-app/package.json +20 -0
  53. package/templates/ui-app/public/assets/.gitkeep +0 -0
  54. package/templates/ui-app/src/main.ts +18 -0
  55. package/templates/ui-app/src/scenes/SettingsScene.ts +136 -0
  56. package/templates/ui-app/tsconfig.json +12 -0
  57. package/templates/ui-app/vite.config.ts +5 -0
@@ -0,0 +1,29 @@
1
+ import { Application, Color, FixedResolutionCanvasSizing } from '@codexo/exojs';
2
+ import { tiledExtension } from '@codexo/exojs-tiled';
3
+
4
+ import { ProceduralMapScene } from './scenes/ProceduralMapScene';
5
+ import { TiledMapScene } from './scenes/TiledMapScene';
6
+
7
+ const app = new Application({
8
+ scenes: { ProceduralMapScene, TiledMapScene },
9
+ canvas: {
10
+ width: 1280,
11
+ height: 720,
12
+ mount: 'body',
13
+ sizing: new FixedResolutionCanvasSizing(),
14
+ },
15
+ // Every path a scene loads is resolved against this, so the sources name
16
+ // assets rather than URLs. Vite serves `public/` at the site root.
17
+ loader: { basePath: 'assets/' },
18
+ // `tiledExtension` registers the `tileMap` and `tiledSource` asset types.
19
+ // It depends on the tilemap extension and pulls it in, so registering this
20
+ // one alone is enough for both scenes.
21
+ extensions: [tiledExtension],
22
+ clearColor: new Color(19, 26, 23),
23
+ });
24
+
25
+ // Two scenes, one level. `ProceduralMapScene` builds the map in code and
26
+ // `TiledMapScene` loads it from `town-square.tmj`; both share everything else
27
+ // through `TopDownScene`. Start whichever suits the project and delete the
28
+ // other - or switch at runtime with `app.scenes.change(TiledMapScene)`.
29
+ await app.start(ProceduralMapScene);
@@ -0,0 +1,74 @@
1
+ import { Asset, Container, TextureRegion } from '@codexo/exojs';
2
+ import { TILE_TRANSFORM_IDENTITY, TileLayer, TileMap, TileSet } from '@codexo/exojs-tilemap';
3
+
4
+ import { COLUMNS, isWall, ROWS, TILE } from '../level';
5
+ import { TopDownScene } from './TopDownScene';
6
+
7
+ /** Local tile ids in `map-pack.png`. `town-square.tmj` uses the same two. */
8
+ const FLOOR_TILE = 0;
9
+ const WALL_TILE = 5;
10
+
11
+ /**
12
+ * The level built in code: a `TileSet` over the atlas, one `TileLayer` filled
13
+ * from `level.ts`, and a `TileMap` around it. No map file is involved.
14
+ *
15
+ * This is the right shape when the level is generated - procedural dungeons,
16
+ * puzzle boards, anything whose layout is decided at runtime. When a designer
17
+ * edits the level instead, see `TiledMapScene`.
18
+ */
19
+ export class ProceduralMapScene extends TopDownScene {
20
+ protected override async loadMap(): Promise<void> {
21
+ // Awaited rather than handed over as a `loader.get()` handle: `TileSet`
22
+ // needs a region with real dimensions, which an unhydrated handle has not
23
+ // got yet.
24
+ await this.loader.load(Asset.type('texture', 'map-pack.png'));
25
+ }
26
+
27
+ protected override buildMap(): Container {
28
+ const texture = this.loader.get('map-pack.png');
29
+ const tileset = new TileSet({
30
+ name: 'map-pack',
31
+ texture: new TextureRegion(texture, { x: 0, y: 0, width: texture.width, height: texture.height }),
32
+ tileWidth: TILE,
33
+ tileHeight: TILE,
34
+ tileCount: 204,
35
+ columns: 17,
36
+ });
37
+
38
+ const ground = new TileLayer({
39
+ id: 1,
40
+ name: 'ground',
41
+ width: COLUMNS,
42
+ height: ROWS,
43
+ tileWidth: TILE,
44
+ tileHeight: TILE,
45
+ tilesets: [tileset],
46
+ });
47
+
48
+ for (let row = 0; row < ROWS; row++) {
49
+ for (let column = 0; column < COLUMNS; column++) {
50
+ ground.setTileAt(column, row, {
51
+ tileset,
52
+ localTileId: isWall(column, row) ? WALL_TILE : FLOOR_TILE,
53
+ transform: TILE_TRANSFORM_IDENTITY,
54
+ });
55
+ }
56
+ }
57
+
58
+ const map = new TileMap({
59
+ name: 'town-square',
60
+ width: COLUMNS,
61
+ height: ROWS,
62
+ tileWidth: TILE,
63
+ tileHeight: TILE,
64
+ tilesets: [tileset],
65
+ layers: [ground],
66
+ });
67
+
68
+ const container = new Container();
69
+
70
+ container.addChild(map.createView({ bands: { ground: ['ground'] } }).band('ground'));
71
+
72
+ return container;
73
+ }
74
+ }
@@ -0,0 +1,33 @@
1
+ import { Asset, Container } from '@codexo/exojs';
2
+ import { TileMapNode } from '@codexo/exojs-tiled';
3
+ import type { TileMap } from '@codexo/exojs-tilemap';
4
+
5
+ import { TopDownScene } from './TopDownScene';
6
+
7
+ /**
8
+ * The same level, loaded from `public/assets/town-square.tmj` instead of built
9
+ * in code.
10
+ *
11
+ * `Asset.type('tileMap', url)` is the common-case binding: it parses the Tiled
12
+ * source and converts it to the runtime `TileMap` that `TileMapNode` renders.
13
+ * The tileset image is resolved relative to the map file, so both live in
14
+ * `public/assets/`.
15
+ *
16
+ * `tiledExtension` has to be registered on the Application for this asset type
17
+ * to exist - see `main.ts`.
18
+ */
19
+ export class TiledMapScene extends TopDownScene {
20
+ private _map!: TileMap;
21
+
22
+ protected override async loadMap(): Promise<void> {
23
+ this._map = await this.loader.load(Asset.type('tileMap', 'town-square.tmj'));
24
+ }
25
+
26
+ protected override buildMap(): Container {
27
+ const container = new Container();
28
+
29
+ container.addChild(new TileMapNode(this._map));
30
+
31
+ return container;
32
+ }
33
+ }
@@ -0,0 +1,208 @@
1
+ import type { RenderingContext, Seconds, SpritesheetData } from '@codexo/exojs';
2
+ import { Asset, Color, Container, Graphics, Keyboard, Label, Rectangle, Scene, Sprite, Spritesheet, SystemOrder, Vector, View } from '@codexo/exojs';
3
+ import { GridSpace, Pathfinder } from '@codexo/exojs-pathfinding';
4
+ import { BoxShape, PhysicsBody, PhysicsWorld } from '@codexo/exojs-physics';
5
+
6
+ import { cellCost, COLUMNS, findMarker, isWall, ROWS, TILE, tileCenter } from '../level';
7
+
8
+ const ACTOR_SPEED = 260;
9
+ /** How close to a waypoint counts as having reached it, in pixels. */
10
+ const ARRIVE_RADIUS = 6;
11
+
12
+ const PATH_COLOR = new Color(90, 200, 255);
13
+ const GOAL_COLOR = new Color(255, 170, 80);
14
+
15
+ /**
16
+ * Everything a top-down scene needs except the map itself: a physics world for
17
+ * the walls and the actor, a navigation grid, click-to-move pathfinding, and a
18
+ * camera.
19
+ *
20
+ * The map is the only difference between the two scenes in this template, so it
21
+ * is the only thing left abstract. `ProceduralMapScene` builds a `TileMap` in
22
+ * code; `TiledMapScene` loads the same level from `town-square.tmj`. Both hand
23
+ * back a node to render, and neither touches anything below.
24
+ *
25
+ * Note what does NOT vary: the navigation grid and the wall colliders are built
26
+ * from `level.ts` in both cases. Pathfinding and physics never read the tilemap
27
+ * - a grid of costs and a set of bodies are the whole input, which is why
28
+ * swapping the map format changes nothing here.
29
+ */
30
+ export abstract class TopDownScene extends Scene {
31
+ protected readonly world = new PhysicsWorld({ gravity: { x: 0, y: 0 } });
32
+
33
+ private readonly _pathfinder = new Pathfinder();
34
+ private readonly _grid = GridSpace.from(COLUMNS, ROWS, cellCost, { cellSize: TILE });
35
+ private readonly _scenery = new Container();
36
+ private readonly _overlay = new Graphics();
37
+ private _actor!: Sprite;
38
+ private _body!: PhysicsBody;
39
+ private _camera!: View;
40
+ private _status!: Label;
41
+ private _waypoints: readonly Vector[] = [];
42
+ private _waypoint = 0;
43
+ private _characterData!: SpritesheetData;
44
+
45
+ /** The node that draws the map. Called once, after the scene's assets have loaded. */
46
+ protected abstract buildMap(): Container;
47
+
48
+ /** Assets the concrete scene needs on top of the actor spritesheet. */
49
+ protected async loadMap(): Promise<void> {
50
+ return Promise.resolve();
51
+ }
52
+
53
+ public override async load(): Promise<void> {
54
+ this._characterData = (await this.loader.load(Asset.type('json', 'characters.json'))) as SpritesheetData;
55
+
56
+ await this.loader.load(Asset.type('texture', 'characters.png'));
57
+ await this.loadMap();
58
+ }
59
+
60
+ public override init(): void {
61
+ this.systems.add(this.world, { order: SystemOrder.Physics });
62
+
63
+ this._buildWalls();
64
+
65
+ const spawn = findMarker('S');
66
+ const spawnPoint = tileCenter(spawn.column, spawn.row);
67
+ const characters = new Spritesheet(this.loader.get('characters.png'), this._characterData);
68
+
69
+ this._actor = characters.getFrameSprite('character_green_front').setAnchor(0.5);
70
+ this._actor.width = TILE * 0.7;
71
+ this._actor.height = TILE * 0.9;
72
+
73
+ this._body = this.world.attach(this._actor, {
74
+ type: 'dynamic',
75
+ position: spawnPoint,
76
+ shape: new BoxShape(TILE * 0.5, TILE * 0.5),
77
+ fixedRotation: true,
78
+ });
79
+
80
+ // The actor is driven by velocity, not by momentum: damping stops it the
81
+ // moment the path runs out instead of letting it drift into a wall.
82
+ this._body.linearDamping = 12;
83
+
84
+ this._scenery.addChild(this.buildMap(), this._overlay, this._actor);
85
+ this.addChild(this._scenery);
86
+
87
+ this._camera = new View(spawnPoint.x, spawnPoint.y, this.app.width, this.app.height);
88
+ this._camera.follow(this._actor, { lerp: 0.12 });
89
+ this._camera.setBounds(new Rectangle(0, 0, COLUMNS * TILE, ROWS * TILE));
90
+
91
+ this._status = new Label('Click a floor tile to walk there.', { fontSize: 18 });
92
+ this._status.anchorIn(this.ui, 'top-left', 24, 20);
93
+ this.ui.addChild(this._status);
94
+
95
+ this.app.input.onPointerTap.add(pointer => {
96
+ // Pointer coordinates are in screen space; the world is drawn through a
97
+ // camera, so they have to come back through it before they mean anything
98
+ // to the grid.
99
+ const world = this._camera.screenToWorld(pointer.x, pointer.y);
100
+
101
+ this._planPath(world.x, world.y);
102
+ });
103
+
104
+ this.inputs.onTrigger(Keyboard.Escape, () => this._clearPath());
105
+ }
106
+
107
+ // The world integrates on its own fixed step, so steering is all this hook
108
+ // has to do and the frame delta never enters the calculation.
109
+ public override update(_delta: Seconds): void {
110
+ if (this._waypoint >= this._waypoints.length) {
111
+ this._body.linearVelocityX = 0;
112
+ this._body.linearVelocityY = 0;
113
+
114
+ return;
115
+ }
116
+
117
+ const target = this._waypoints[this._waypoint]!;
118
+ const dx = target.x - this._body.x;
119
+ const dy = target.y - this._body.y;
120
+ const distance = Math.hypot(dx, dy);
121
+
122
+ if (distance < ARRIVE_RADIUS) {
123
+ this._waypoint++;
124
+
125
+ if (this._waypoint >= this._waypoints.length) {
126
+ this._status.text = 'Arrived. Click somewhere else.';
127
+ this._clearPath();
128
+ }
129
+
130
+ return;
131
+ }
132
+
133
+ this._body.linearVelocityX = (dx / distance) * ACTOR_SPEED;
134
+ this._body.linearVelocityY = (dy / distance) * ACTOR_SPEED;
135
+ }
136
+
137
+ public override draw(context: RenderingContext): void {
138
+ context.render(this._scenery, { view: this._camera });
139
+ }
140
+
141
+ private _buildWalls(): void {
142
+ // Merged per row, so a straight wall is one body rather than one per tile.
143
+ for (let row = 0; row < ROWS; row++) {
144
+ let start = -1;
145
+
146
+ for (let column = 0; column <= COLUMNS; column++) {
147
+ const solid = column < COLUMNS && isWall(column, row);
148
+
149
+ if (solid && start === -1) {
150
+ start = column;
151
+ } else if (!solid && start !== -1) {
152
+ const length = column - start;
153
+
154
+ this.world.add(
155
+ new PhysicsBody({
156
+ type: 'static',
157
+ position: { x: (start + length / 2) * TILE, y: (row + 0.5) * TILE },
158
+ colliders: [{ shape: new BoxShape(length * TILE, TILE) }],
159
+ }),
160
+ );
161
+
162
+ start = -1;
163
+ }
164
+ }
165
+ }
166
+ }
167
+
168
+ private _planPath(x: number, y: number): void {
169
+ const result = this._pathfinder.findPathBetween(this._grid, this._body.x, this._body.y, x, y, { smooth: true });
170
+
171
+ if (result.status !== 'found') {
172
+ this._status.text = `No route there (${result.status}).`;
173
+ this._clearPath();
174
+
175
+ return;
176
+ }
177
+
178
+ // The first point is the cell the actor already stands in; walking to it
179
+ // first would make it step backwards before setting off.
180
+ this._waypoints = result.points.slice(1);
181
+ this._waypoint = 0;
182
+ this._status.text = `${this._waypoints.length} waypoints, cost ${result.cost.toFixed(1)}.`;
183
+
184
+ this._drawPath();
185
+ }
186
+
187
+ private _clearPath(): void {
188
+ this._waypoints = [];
189
+ this._waypoint = 0;
190
+ this._overlay.clear();
191
+ }
192
+
193
+ private _drawPath(): void {
194
+ this._overlay.clear();
195
+ this._overlay.lineWidth = 4;
196
+ this._overlay.lineColor = PATH_COLOR;
197
+
198
+ let previous = { x: this._body.x, y: this._body.y };
199
+
200
+ for (const point of this._waypoints) {
201
+ this._overlay.drawLine(previous.x, previous.y, point.x, point.y);
202
+ previous = point;
203
+ }
204
+
205
+ this._overlay.fillColor = GOAL_COLOR;
206
+ this._overlay.drawCircle(previous.x, previous.y, 8);
207
+ }
208
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
7
+ "strict": true,
8
+ "skipLibCheck": true,
9
+ "noEmit": true
10
+ },
11
+ "include": ["src"]
12
+ }
@@ -0,0 +1,5 @@
1
+ import { defineConfig } from 'vite';
2
+
3
+ export default defineConfig({
4
+ base: './',
5
+ });
@@ -0,0 +1,17 @@
1
+ # UI app template
2
+
3
+ A settings screen built from the UI widgets in `@codexo/exojs`. No extension packages and no assets — the widget set, the theme and the text rendering are all in core.
4
+
5
+ ## Where things are
6
+
7
+ `src/scenes/SettingsScene.ts` is the whole app. Widgets live on `scene.ui`, a screen-fixed layer the engine renders above the world without being asked to, and anchor to the screen edges rather than to absolute positions, so the layout survives a resize.
8
+
9
+ ## The pattern worth copying
10
+
11
+ Nothing reads a value back out of a widget. Each control writes into a draft object on change, `Apply` copies the draft into the applied state, and the summary panel renders from the applied state alone.
12
+
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
+
15
+ ## Theming
16
+
17
+ 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.
@@ -0,0 +1,25 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>ExoJS UI App</title>
7
+ <style>
8
+ * {
9
+ margin: 0;
10
+ padding: 0;
11
+ box-sizing: border-box;
12
+ }
13
+ body {
14
+ background: #0b0e14;
15
+ display: flex;
16
+ justify-content: center;
17
+ align-items: center;
18
+ min-height: 100vh;
19
+ }
20
+ </style>
21
+ </head>
22
+ <body>
23
+ <script type="module" src="/src/main.ts"></script>
24
+ </body>
25
+ </html>
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "exo-ui-app",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "engines": {
6
+ "node": ">=24"
7
+ },
8
+ "scripts": {
9
+ "dev": "vite",
10
+ "build": "tsc && vite build",
11
+ "preview": "vite preview"
12
+ },
13
+ "dependencies": {
14
+ "@codexo/exojs": "lockstep"
15
+ },
16
+ "devDependencies": {
17
+ "typescript": "^7.0.2",
18
+ "vite": "^8.3.1"
19
+ }
20
+ }
File without changes
@@ -0,0 +1,18 @@
1
+ import { Application, Color, FixedResolutionCanvasSizing } from '@codexo/exojs';
2
+
3
+ import { SettingsScene } from './scenes/SettingsScene';
4
+
5
+ const app = new Application({
6
+ scenes: { SettingsScene },
7
+ canvas: {
8
+ width: 1280,
9
+ height: 720,
10
+ mount: 'body',
11
+ // Keeps the design resolution above and scales the canvas to its box, so
12
+ // widget positions stay in the coordinates they were authored in.
13
+ sizing: new FixedResolutionCanvasSizing(),
14
+ },
15
+ clearColor: new Color(11, 14, 20),
16
+ });
17
+
18
+ await app.start(SettingsScene);
@@ -0,0 +1,136 @@
1
+ import { Button, Checkbox, Color, Dropdown, Label, Panel, Scene, Slider, Stack, TextInput } from '@codexo/exojs';
2
+
3
+ type Difficulty = 'casual' | 'normal' | 'brutal';
4
+
5
+ interface Settings {
6
+ playerName: string;
7
+ volume: number;
8
+ difficulty: Difficulty;
9
+ fullscreen: boolean;
10
+ }
11
+
12
+ /**
13
+ * A settings screen built from the UI widgets in core.
14
+ *
15
+ * Widgets live on `scene.ui`, a screen-fixed layer the engine renders above the
16
+ * world without being asked to - `draw` below only renders `this.root`. They
17
+ * anchor to the screen edges rather than to absolute positions, so the layout
18
+ * survives a resize.
19
+ *
20
+ * The pattern worth copying is the split between the widgets and the state they
21
+ * edit: nothing reads a value back out of a widget. Each control writes into
22
+ * `_draft` on change, `Apply` copies the draft into `_applied`, and the summary
23
+ * panel renders from `_applied` alone.
24
+ */
25
+ export class SettingsScene extends Scene {
26
+ private readonly _draft: Settings = { playerName: 'Player One', volume: 0.7, difficulty: 'normal', fullscreen: false };
27
+ private _applied: Settings = { ...this._draft };
28
+ private _summary!: Label;
29
+ private _status!: Label;
30
+
31
+ public override init(): void {
32
+ this.ui.addChild(this._buildForm());
33
+ this.ui.addChild(this._buildSummary());
34
+
35
+ this._refreshSummary();
36
+ }
37
+
38
+ private _buildForm(): Panel {
39
+ const name = new TextInput({ width: 300, placeholder: 'Your name', value: this._draft.playerName, maxLength: 24 });
40
+ name.onChange.add(value => {
41
+ this._draft.playerName = value;
42
+ });
43
+
44
+ const volume = new Slider({ width: 300, min: 0, max: 1, value: this._draft.volume, step: 0.05 });
45
+ const volumeLabel = new Label(this._volumeText(this._draft.volume), { fontSize: 16 });
46
+ volume.onChange.add(value => {
47
+ this._draft.volume = value;
48
+ volumeLabel.text = this._volumeText(value);
49
+ });
50
+
51
+ const difficulty = new Dropdown<Difficulty>({
52
+ width: 300,
53
+ items: [
54
+ { label: 'Casual', value: 'casual' },
55
+ { label: 'Normal', value: 'normal' },
56
+ { label: 'Brutal', value: 'brutal' },
57
+ ],
58
+ selectedIndex: 1,
59
+ });
60
+ difficulty.onChange.add(value => {
61
+ this._draft.difficulty = value;
62
+ });
63
+
64
+ const fullscreen = new Checkbox({ label: 'Start in fullscreen', checked: this._draft.fullscreen });
65
+ fullscreen.onChange.add(checked => {
66
+ this._draft.fullscreen = checked;
67
+ });
68
+
69
+ const apply = new Button({ label: 'Apply', color: new Color(54, 120, 220), width: 140, height: 42 });
70
+ apply.onClick.add(() => {
71
+ this._applied = { ...this._draft };
72
+ this._refreshSummary();
73
+ this._status.text = 'Applied.';
74
+ });
75
+
76
+ const revert = new Button({ label: 'Revert', color: new Color(90, 96, 110), width: 140, height: 42 });
77
+ revert.onClick.add(() => {
78
+ Object.assign(this._draft, this._applied);
79
+ name.value = this._applied.playerName;
80
+ volume.value = this._applied.volume;
81
+ volumeLabel.text = this._volumeText(this._applied.volume);
82
+ fullscreen.checked = this._applied.fullscreen;
83
+ this._status.text = 'Reverted to the applied settings.';
84
+ });
85
+
86
+ const actions = new Stack({ direction: 'row', spacing: 12 });
87
+ actions.addItem(apply);
88
+ actions.addItem(revert);
89
+
90
+ this._status = new Label('Change something, then Apply.', { fontSize: 15 });
91
+
92
+ const form = new Stack({ direction: 'column', spacing: 14, padding: 24 });
93
+ form.addItem(new Label('Settings', { fontSize: 30 }));
94
+ form.addItem(new Label('Player name', { fontSize: 16 }));
95
+ form.addItem(name);
96
+ form.addItem(volumeLabel);
97
+ form.addItem(volume);
98
+ form.addItem(new Label('Difficulty', { fontSize: 16 }));
99
+ form.addItem(difficulty);
100
+ form.addItem(fullscreen);
101
+ form.addItem(actions);
102
+ form.addItem(this._status);
103
+
104
+ const panel = new Panel({ borderColor: new Color(255, 255, 255, 0.16), borderWidth: 1, cornerRadius: 12 });
105
+ panel.setSize(form.uiWidth, form.uiHeight);
106
+ panel.addChild(form);
107
+ panel.anchorIn(this.ui, 'top-left', 48, 48);
108
+
109
+ return panel;
110
+ }
111
+
112
+ private _buildSummary(): Panel {
113
+ this._summary = new Label('', { fontSize: 18 });
114
+
115
+ const stack = new Stack({ direction: 'column', spacing: 12, padding: 24 });
116
+ stack.addItem(new Label('In effect', { fontSize: 22 }));
117
+ stack.addItem(this._summary);
118
+
119
+ const panel = new Panel({ borderColor: new Color(255, 255, 255, 0.16), borderWidth: 1, cornerRadius: 12 });
120
+ panel.setSize(360, 200);
121
+ panel.addChild(stack);
122
+ panel.anchorIn(this.ui, 'top-right', -48, 48);
123
+
124
+ return panel;
125
+ }
126
+
127
+ private _refreshSummary(): void {
128
+ const { playerName, volume, difficulty, fullscreen } = this._applied;
129
+
130
+ this._summary.text = [`Name: ${playerName}`, this._volumeText(volume), `Difficulty: ${difficulty}`, `Fullscreen: ${fullscreen ? 'on' : 'off'}`].join('\n');
131
+ }
132
+
133
+ private _volumeText(value: number): string {
134
+ return `Volume: ${Math.round(value * 100)}%`;
135
+ }
136
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
7
+ "strict": true,
8
+ "skipLibCheck": true,
9
+ "noEmit": true
10
+ },
11
+ "include": ["src"]
12
+ }
@@ -0,0 +1,5 @@
1
+ import { defineConfig } from 'vite';
2
+
3
+ export default defineConfig({
4
+ base: './',
5
+ });