minimojs 1.0.0-alpha.4 → 1.0.0-alpha.40
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 +58 -20
- package/dist/internal/AnimationSystem.js +345 -0
- package/dist/internal/AssetSystem.d.ts +6 -0
- package/dist/internal/AssetSystem.js +281 -0
- package/dist/internal/BackgroundSystem.d.ts +1 -0
- package/dist/internal/BackgroundSystem.js +26 -0
- package/dist/internal/CanvasSystem.d.ts +1 -0
- package/dist/internal/CanvasSystem.js +51 -0
- package/dist/internal/DesignNamingCheck.d.ts +1 -0
- package/dist/internal/DesignNamingCheck.js +7 -0
- package/dist/internal/ExplosionSystem.d.ts +1 -0
- package/dist/internal/ExplosionSystem.js +540 -0
- package/dist/internal/InputSystem.d.ts +1 -0
- package/dist/internal/InputSystem.js +292 -0
- package/dist/internal/LoopSystem.d.ts +1 -0
- package/dist/internal/LoopSystem.js +61 -0
- package/dist/internal/PhysicsSystem.d.ts +1 -0
- package/dist/internal/PhysicsSystem.js +174 -0
- package/dist/internal/RenderSystem.d.ts +1 -0
- package/dist/internal/RenderSystem.js +1021 -0
- package/dist/internal/SoundSystem.d.ts +39 -0
- package/dist/internal/SoundSystem.js +292 -0
- package/dist/internal/SpriteSystem.d.ts +1 -0
- package/dist/internal/SpriteSystem.js +32 -0
- package/dist/internal/TextSystem.d.ts +1 -0
- package/dist/internal/TextSystem.js +16 -0
- package/dist/internal/TimerSystem.d.ts +1 -0
- package/dist/internal/TimerSystem.js +43 -0
- package/dist/internal/TrailSystem.d.ts +1 -0
- package/dist/internal/TrailSystem.js +116 -0
- package/dist/internal/TransitionSystem.d.ts +1 -0
- package/dist/internal/TransitionSystem.js +74 -0
- package/dist/internal/arcade-racer/ArcadeRacerCollisionSystem.d.ts +1 -0
- package/dist/internal/arcade-racer/ArcadeRacerCollisionSystem.js +198 -0
- package/dist/internal/arcade-racer/ArcadeRacerLaneSystem.d.ts +1 -0
- package/dist/internal/arcade-racer/ArcadeRacerLaneSystem.js +120 -0
- package/dist/internal/arcade-racer/ArcadeRacerRenderSystem.d.ts +1 -0
- package/dist/internal/arcade-racer/ArcadeRacerRenderSystem.js +599 -0
- package/dist/internal/arcade-racer/ArcadeRacerRoadSprite.d.ts +1 -0
- package/dist/internal/arcade-racer/ArcadeRacerRoadSprite.js +13 -0
- package/dist/internal/arcade-racer/ArcadeRacerTrackSystem.d.ts +1 -0
- package/dist/internal/arcade-racer/ArcadeRacerTrackSystem.js +447 -0
- package/dist/minimo-ambient.d.ts +299 -0
- package/dist/minimo-ambient.js +1445 -0
- package/dist/minimo-arcaderacer.d.ts +1431 -0
- package/dist/minimo-arcaderacer.js +2060 -0
- package/dist/minimo-cards.d.ts +359 -0
- package/dist/minimo-cards.js +819 -0
- package/dist/minimo-dice.d.ts +206 -0
- package/dist/minimo-dice.js +719 -0
- package/dist/minimo-fire.d.ts +282 -0
- package/dist/minimo-fire.js +930 -0
- package/dist/minimo-format.d.ts +632 -0
- package/dist/minimo-format.js +669 -0
- package/dist/minimo-leaderboard.d.ts +199 -0
- package/dist/minimo-leaderboard.js +566 -0
- package/dist/minimo-multiplayer.d.ts +374 -0
- package/dist/minimo-multiplayer.js +1310 -0
- package/dist/minimo.d.ts +1690 -233
- package/dist/minimo.js +2587 -892
- package/package.json +10 -3
- package/dist/animations.js +0 -30
- package/dist/audio.js +0 -17
- package/dist/game.js +0 -1105
- package/dist/input.js +0 -185
- package/dist/internal-types.js +0 -4
- package/dist/physics.js +0 -10
- package/dist/render.js +0 -75
- package/dist/sprite.js +0 -149
- package/dist/timers.js +0 -23
- /package/dist/{pointer-info.js → internal/AnimationSystem.d.ts} +0 -0
|
@@ -0,0 +1,632 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module minimojs/format
|
|
3
|
+
*
|
|
4
|
+
* The file formats MinimoJS reads: asset files, `*.assets.json`, and design
|
|
5
|
+
* files, `*.design.json`.
|
|
6
|
+
*
|
|
7
|
+
* This module uses no DOM, so tools such as an editor or a validating server
|
|
8
|
+
* import the same code a game runs: `import { parseAssetFile, Design } from
|
|
9
|
+
* "minimojs/format"`. Games reach it through `minimo.js`, which re-exports it.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* An image declared in an asset file, loaded as
|
|
13
|
+
* `game.loadImage(key, src)` would load it.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```json
|
|
17
|
+
* { "key": "player", "type": "image", "src": "assets/player.png" }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export interface ImageAsset {
|
|
21
|
+
/**
|
|
22
|
+
* The key sprites and backgrounds use for this image, as in
|
|
23
|
+
* `new ImageSprite("player")`. Non-empty, with no leading or trailing
|
|
24
|
+
* spaces, and unique in the whole game: no other entry of any asset file,
|
|
25
|
+
* of any type, and no `loadImage` or `createTexture` call may use it.
|
|
26
|
+
*/
|
|
27
|
+
key: string;
|
|
28
|
+
/** Always `"image"`. */
|
|
29
|
+
type: "image";
|
|
30
|
+
/** The image's URL or path, as `game.loadImage(key, src)` takes it. Non-empty. */
|
|
31
|
+
src: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A sound declared in an asset file, loaded as
|
|
35
|
+
* `game.loadSound(key, src)` would load it, and played with
|
|
36
|
+
* `game.playSound(key)`.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```json
|
|
40
|
+
* { "key": "jump", "type": "sound", "src": "assets/jump.mp3" }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export interface SoundAsset {
|
|
44
|
+
/**
|
|
45
|
+
* The key `game.playSound` uses for this sound. Non-empty, with no leading
|
|
46
|
+
* or trailing spaces, and unique in the whole game, images included.
|
|
47
|
+
*/
|
|
48
|
+
key: string;
|
|
49
|
+
/** Always `"sound"`. */
|
|
50
|
+
type: "sound";
|
|
51
|
+
/** The audio file's URL or path, as `game.loadSound(key, src)` takes it. Non-empty. */
|
|
52
|
+
src: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* An entry whose `type` this engine does not support, such as one written for
|
|
56
|
+
* a newer engine. It is kept as written, so a tool that saves the file does
|
|
57
|
+
* not drop it, and `game.loadAssets` warns about it and skips it. Its key
|
|
58
|
+
* still counts toward the game's unique keys.
|
|
59
|
+
*/
|
|
60
|
+
export interface UnknownAsset {
|
|
61
|
+
/** The entry's key, unique in the whole game like every other. */
|
|
62
|
+
key: string;
|
|
63
|
+
/** A type this engine does not support. */
|
|
64
|
+
type: string;
|
|
65
|
+
/** The fields of that type, kept unchecked. */
|
|
66
|
+
[field: string]: unknown;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The content of an asset file, `*.assets.json`, which declares assets once,
|
|
70
|
+
* by key, for {@link parseAssetFile} and `game.loadAssets`.
|
|
71
|
+
*
|
|
72
|
+
* A game may have any number of asset files, such as `common.assets.json`
|
|
73
|
+
* and `level3.assets.json`.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```json
|
|
77
|
+
* {
|
|
78
|
+
* "format": "minimo-assets",
|
|
79
|
+
* "version": 1,
|
|
80
|
+
* "assets": [
|
|
81
|
+
* { "key": "player", "type": "image", "src": "assets/player.png" },
|
|
82
|
+
* { "key": "bat", "type": "image", "src": "assets/bat.png" },
|
|
83
|
+
* { "key": "jump", "type": "sound", "src": "assets/jump.mp3" }
|
|
84
|
+
* ]
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export interface AssetFile {
|
|
89
|
+
/** Always `"minimo-assets"`. */
|
|
90
|
+
format: "minimo-assets";
|
|
91
|
+
/** The version of the file's shape. Version `1` is the only one so far. */
|
|
92
|
+
version: 1;
|
|
93
|
+
/** The declared assets, in file order. */
|
|
94
|
+
assets: (ImageAsset | SoundAsset | UnknownAsset)[];
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Validates the content of an asset file and returns a copy of it.
|
|
98
|
+
*
|
|
99
|
+
* Parsing is strict. It throws an error naming what is wrong for:
|
|
100
|
+
* - a value that is not an asset file object, or an unknown field anywhere;
|
|
101
|
+
* - a `format` other than `"minimo-assets"`;
|
|
102
|
+
* - a `version` newer than this engine reads, or one that is not a positive integer;
|
|
103
|
+
* - an entry without a string `key` and `type`;
|
|
104
|
+
* - an empty key, or one with leading or trailing spaces;
|
|
105
|
+
* - a key repeated in the file, whatever the types of its entries;
|
|
106
|
+
* - an `image` or `sound` entry without a non-empty string `src`.
|
|
107
|
+
*
|
|
108
|
+
* An entry of a type this engine does not support is kept unchanged, without
|
|
109
|
+
* checking its other fields, so nothing is lost when a tool saves the file.
|
|
110
|
+
*
|
|
111
|
+
* @param json - The parsed JSON of a `*.assets.json` file.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* import common from "./common.assets.json" with { type: "json" };
|
|
116
|
+
* const file = parseAssetFile(common);
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export declare function parseAssetFile(json: unknown): AssetFile;
|
|
120
|
+
/**
|
|
121
|
+
* The type of a design object. Each built-in type maps to one runtime class:
|
|
122
|
+
* `image` to `ImageSprite`, `emoji` to `EmojiSprite`, `text` to `TextSprite`,
|
|
123
|
+
* and `background` to `BackgroundLayer`. A `module` object is built by the
|
|
124
|
+
* optional module it names, such as a `Flame` by the `fire` module.
|
|
125
|
+
*/
|
|
126
|
+
export type DesignObjectType = "image" | "emoji" | "text" | "background" | "module";
|
|
127
|
+
/**
|
|
128
|
+
* The properties every design object has, whatever its type.
|
|
129
|
+
*
|
|
130
|
+
* Every property of a design object is named as its runtime class names it,
|
|
131
|
+
* so the same names work in code and in files. A property the file omits
|
|
132
|
+
* keeps the runtime object's default.
|
|
133
|
+
*/
|
|
134
|
+
export interface DesignObjectBase {
|
|
135
|
+
/**
|
|
136
|
+
* Required. A UUID unique in the file, such as
|
|
137
|
+
* `"6f1c2a0e-3b7d-4c1e-9a52-0d8e4f6b1a27"`. Tools use it to select, undo,
|
|
138
|
+
* and compare objects, and it survives renames. It is the only property
|
|
139
|
+
* with no runtime counterpart.
|
|
140
|
+
*/
|
|
141
|
+
id: string;
|
|
142
|
+
/** Optional name, which may repeat. Becomes `Sprite.name`. */
|
|
143
|
+
name?: string;
|
|
144
|
+
/** Tags for grouping and for builders. Becomes `Sprite.tags`. Default: `[]`. */
|
|
145
|
+
tags?: string[];
|
|
146
|
+
/**
|
|
147
|
+
* The game's own values, such as a button's action or an enemy's speed.
|
|
148
|
+
* Always a JSON object, never a bare number or string. Becomes a copy in
|
|
149
|
+
* `Sprite.data`. Default: `{}`.
|
|
150
|
+
*/
|
|
151
|
+
data?: Record<string, unknown>;
|
|
152
|
+
}
|
|
153
|
+
/** The properties of every sprite type: `image`, `emoji`, and `text`. */
|
|
154
|
+
export interface DesignSpriteBase extends DesignObjectBase {
|
|
155
|
+
/** Horizontal center in world space, in pixels. Default: `0`. */
|
|
156
|
+
x?: number;
|
|
157
|
+
/** Vertical center in world space, in pixels. Positive is down. Default: `0`. */
|
|
158
|
+
y?: number;
|
|
159
|
+
/** Uniform visual scale. Default: `1`. */
|
|
160
|
+
scale?: number;
|
|
161
|
+
/** Rotation in degrees, clockwise. Default: `0`. */
|
|
162
|
+
rotation?: number;
|
|
163
|
+
/** Mirrors the sprite left to right. Default: `false`. */
|
|
164
|
+
flipX?: boolean;
|
|
165
|
+
/** Mirrors the sprite top to bottom. Default: `false`. */
|
|
166
|
+
flipY?: boolean;
|
|
167
|
+
/** Opacity, from `0` to `1`. Default: `1`. */
|
|
168
|
+
alpha?: number;
|
|
169
|
+
/** Whether the sprite is drawn. Default: `true`. */
|
|
170
|
+
visible?: boolean;
|
|
171
|
+
/** Render order; higher layers draw on top. Default: `0`. */
|
|
172
|
+
layer?: number;
|
|
173
|
+
/** CSS color, used by monochrome glyphs and by text. Default: `"#000000"`, and `"#ffffff"` for `text`. */
|
|
174
|
+
color?: string;
|
|
175
|
+
/** Draws the sprite in screen space, unaffected by scrolling. Default: `false`. */
|
|
176
|
+
ignoreScroll?: boolean;
|
|
177
|
+
/** Whether the engine leaves the sprite where it is, as a static obstacle. Default: `false`. */
|
|
178
|
+
isStatic?: boolean;
|
|
179
|
+
/** Horizontal velocity in pixels per second. Default: `0`. */
|
|
180
|
+
vx?: number;
|
|
181
|
+
/** Vertical velocity in pixels per second. Default: `0`. */
|
|
182
|
+
vy?: number;
|
|
183
|
+
/** Gravity multiplier. Default: `0`, immune to gravity. */
|
|
184
|
+
gravityScale?: number;
|
|
185
|
+
/** Width of the collision body in pixels, before scale; `null` uses the sprite's width. Default: `null`. */
|
|
186
|
+
bodyWidth?: number | null;
|
|
187
|
+
/** Height of the collision body in pixels, before scale; `null` uses the sprite's height. Default: `null`. */
|
|
188
|
+
bodyHeight?: number | null;
|
|
189
|
+
/** Horizontal offset of the body's center from the sprite's center, in pixels, before scale. Default: `0`. */
|
|
190
|
+
bodyOffsetX?: number;
|
|
191
|
+
/** Vertical offset of the body's center from the sprite's center, in pixels, before scale. Default: `0`. */
|
|
192
|
+
bodyOffsetY?: number;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* An `ImageSprite` in a design file.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```json
|
|
199
|
+
* { "id": "a93e51b4-6c0d-4f2a-8b17-3e5d9c2f0a61", "name": "play", "type": "image", "imageKey": "btn-play", "x": 360, "y": 700 }
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
export interface DesignImage extends DesignSpriteBase {
|
|
203
|
+
/** Always `"image"`. */
|
|
204
|
+
type: "image";
|
|
205
|
+
/** Required. The key of an image declared in one of the game's asset files. */
|
|
206
|
+
imageKey: string;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* An `EmojiSprite` in a design file.
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```json
|
|
213
|
+
* { "id": "0b9a7c3e-2d4f-4e61-a8c5-7f1e3d2b6a90", "type": "emoji", "sprite": "⭐", "size": 64, "x": 200, "y": 300 }
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
export interface DesignEmoji extends DesignSpriteBase {
|
|
217
|
+
/** Always `"emoji"`. */
|
|
218
|
+
type: "emoji";
|
|
219
|
+
/** Required. The emoji to draw. */
|
|
220
|
+
sprite: string;
|
|
221
|
+
/** Base size in pixels. Default: `32`. */
|
|
222
|
+
size?: number;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* A `TextSprite` in a design file.
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* ```json
|
|
229
|
+
* { "id": "5c2e8f1a-9b3d-4a7e-b6c0-1d4f8e2a7c35", "type": "text", "text": "GAME OVER", "fontSize": 64, "x": 360, "y": 400 }
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
export interface DesignText extends DesignSpriteBase {
|
|
233
|
+
/** Always `"text"`. */
|
|
234
|
+
type: "text";
|
|
235
|
+
/** Required. The text to draw. */
|
|
236
|
+
text: string;
|
|
237
|
+
/** Font size in pixels. Default: `16`. */
|
|
238
|
+
fontSize?: number;
|
|
239
|
+
/** CSS font family. Default: `"monospace"`. */
|
|
240
|
+
fontFamily?: string;
|
|
241
|
+
/** CSS font weight. Default: `"400"`. */
|
|
242
|
+
fontWeight?: string;
|
|
243
|
+
/** Line height as a multiple of the font size. Default: `1.2`. */
|
|
244
|
+
lineHeight?: number;
|
|
245
|
+
/** Which edge of the text `x` names. Default: `"center"`. */
|
|
246
|
+
anchorX?: "left" | "center" | "right";
|
|
247
|
+
/** Which edge of the text `y` names. Default: `"middle"`. */
|
|
248
|
+
anchorY?: "top" | "middle" | "bottom";
|
|
249
|
+
/** Alignment of the lines. Default: `"center"`. */
|
|
250
|
+
textAlign?: "left" | "right" | "center" | "start" | "end";
|
|
251
|
+
/** Width at which lines wrap, in pixels; `0` never wraps. Default: `0`. */
|
|
252
|
+
maxWidth?: number;
|
|
253
|
+
/** Fixed box width in pixels; `0` fits the text. Default: `0`. */
|
|
254
|
+
fixedWidth?: number;
|
|
255
|
+
/** Fixed box height in pixels; `0` fits the text. Default: `0`. */
|
|
256
|
+
fixedHeight?: number;
|
|
257
|
+
/** Horizontal padding inside the box, in pixels. Default: `2`. */
|
|
258
|
+
paddingX?: number;
|
|
259
|
+
/** Vertical padding inside the box, in pixels. Default: `2`. */
|
|
260
|
+
paddingY?: number;
|
|
261
|
+
/** CSS color of the box; `null` draws none. Default: `null`. */
|
|
262
|
+
backgroundColor?: string | null;
|
|
263
|
+
/** CSS color of the box's border; `null` draws none. Default: `null`. */
|
|
264
|
+
borderColor?: string | null;
|
|
265
|
+
/** Width of the box's border in pixels. Default: `0`. */
|
|
266
|
+
borderWidth?: number;
|
|
267
|
+
/** Corner radius of the box in pixels. Default: `0`. */
|
|
268
|
+
cornerRadius?: number;
|
|
269
|
+
/** CSS color of the text's outline; `null` draws none. Default: `null`. */
|
|
270
|
+
strokeColor?: string | null;
|
|
271
|
+
/** Width of the text's outline in pixels. Default: `0`. */
|
|
272
|
+
strokeWidth?: number;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* A `BackgroundLayer` in a design file. Unlike sprites, its `x` and `y` are
|
|
276
|
+
* the top-left corner in screen space.
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* ```json
|
|
280
|
+
* { "id": "6f1c2a0e-3b7d-4c1e-9a52-0d8e4f6b1a27", "type": "background", "imageKey": "sky" }
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
export interface DesignBackground extends DesignObjectBase {
|
|
284
|
+
/** Always `"background"`. */
|
|
285
|
+
type: "background";
|
|
286
|
+
/** Required. The key of an image declared in one of the game's asset files. */
|
|
287
|
+
imageKey: string;
|
|
288
|
+
/** Left edge in screen space, in pixels. Default: `0`. */
|
|
289
|
+
x?: number;
|
|
290
|
+
/** Top edge in screen space, in pixels. Default: `0`. */
|
|
291
|
+
y?: number;
|
|
292
|
+
/** Width in pixels; `0` uses the canvas width. Default: `0`. */
|
|
293
|
+
width?: number;
|
|
294
|
+
/** Height in pixels; `0` uses the canvas height. Default: `0`. */
|
|
295
|
+
height?: number;
|
|
296
|
+
/** Opacity, from `0` to `1`. Default: `1`. */
|
|
297
|
+
alpha?: number;
|
|
298
|
+
/** Whether the layer is drawn. Default: `true`. */
|
|
299
|
+
visible?: boolean;
|
|
300
|
+
/** Order among background layers; all of them draw behind sprites. Default: `0`. */
|
|
301
|
+
layer?: number;
|
|
302
|
+
/** How the image fits its rectangle. Default: `"cover"`. */
|
|
303
|
+
fit?: "none" | "stretch" | "contain" | "cover";
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* An object of an optional module in a design file, such as a torch of the
|
|
307
|
+
* `fire` module. It names its module and its kind, and the module builds it,
|
|
308
|
+
* so the scene creates the module, such as `new Fire(game)`, before creating
|
|
309
|
+
* the design's objects. A design holding one is version 3.
|
|
310
|
+
*
|
|
311
|
+
* Each module takes only some of the sprite properties and its own
|
|
312
|
+
* `options`, both listed in {@link designModules}; anything else about the
|
|
313
|
+
* object, such as what it does while the game plays, is set in code. The
|
|
314
|
+
* kinds a module places and its options are documented in that module's API.
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* ```json
|
|
318
|
+
* { "id": "3e7b1c9a-5d2f-4a8e-b0c6-9f1d2e4a7b35", "name": "left-torch", "type": "module", "module": "fire", "kind": "torch", "x": 120, "y": 200, "options": { "size": 28 } }
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
export interface DesignModule extends DesignSpriteBase {
|
|
322
|
+
/** Always `"module"`. */
|
|
323
|
+
type: "module";
|
|
324
|
+
/** Required. The module that builds the object, such as `"fire"`: a key of {@link designModules}. */
|
|
325
|
+
module: string;
|
|
326
|
+
/** Required. What the module builds, such as `"torch"`: one of its `kinds` in {@link designModules}. */
|
|
327
|
+
kind: string;
|
|
328
|
+
/** The module's own settings for the object, such as `{ "size": 28 }`. Default: `{}`. */
|
|
329
|
+
options?: Record<string, unknown>;
|
|
330
|
+
}
|
|
331
|
+
/** Any object of a design file. Its `type` says which. */
|
|
332
|
+
export type DesignObject = DesignImage | DesignEmoji | DesignText | DesignBackground | DesignModule;
|
|
333
|
+
/**
|
|
334
|
+
* The content of a design file, `*.design.json`, which a game reads through
|
|
335
|
+
* {@link Design} and creates with `game.createObject` and
|
|
336
|
+
* `game.createObjectList`. A design without pages is a {@link DesignFileV1},
|
|
337
|
+
* one flat list of objects; a design divided into pages is a
|
|
338
|
+
* {@link DesignFileV2}; a design holding objects of an optional module, with
|
|
339
|
+
* or without pages, is a {@link DesignFileV3}. All three are current: a
|
|
340
|
+
* design is written in the lowest version that holds it, so it also loads in
|
|
341
|
+
* an older MinimoJS whenever it can.
|
|
342
|
+
*/
|
|
343
|
+
export type DesignFile = DesignFileV1 | DesignFileV2 | DesignFileV3;
|
|
344
|
+
/**
|
|
345
|
+
* A design file without pages: one flat list of objects.
|
|
346
|
+
*
|
|
347
|
+
* @example
|
|
348
|
+
* ```json
|
|
349
|
+
* {
|
|
350
|
+
* "format": "minimo-design",
|
|
351
|
+
* "version": 1,
|
|
352
|
+
* "objects": [
|
|
353
|
+
* { "id": "6f1c2a0e-3b7d-4c1e-9a52-0d8e4f6b1a27", "type": "background", "imageKey": "sky" },
|
|
354
|
+
* { "id": "a93e51b4-6c0d-4f2a-8b17-3e5d9c2f0a61", "name": "play", "tags": ["button"], "type": "image", "imageKey": "btn-play", "x": 360, "y": 700, "data": { "action": "start" } }
|
|
355
|
+
* ]
|
|
356
|
+
* }
|
|
357
|
+
* ```
|
|
358
|
+
*/
|
|
359
|
+
export interface DesignFileV1 {
|
|
360
|
+
/** Always `"minimo-design"`. */
|
|
361
|
+
format: "minimo-design";
|
|
362
|
+
/** `1`: the design has no pages. */
|
|
363
|
+
version: 1;
|
|
364
|
+
/** The objects, in file order, which is the order they are created and drawn in. */
|
|
365
|
+
objects: DesignObject[];
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* A design file divided into pages. Pages only organize a design, such as
|
|
369
|
+
* one page per template, or a menu on one page and its button templates on
|
|
370
|
+
* another; they do not change how an object is created. Read one page's
|
|
371
|
+
* objects with {@link Design.findAllByPage}.
|
|
372
|
+
*
|
|
373
|
+
* @example
|
|
374
|
+
* ```json
|
|
375
|
+
* {
|
|
376
|
+
* "format": "minimo-design",
|
|
377
|
+
* "version": 2,
|
|
378
|
+
* "pages": [
|
|
379
|
+
* { "id": "0b1d5e7a-3c2f-4d8e-9a61-7f4b2c8e1d05", "name": "Hero", "objects": [
|
|
380
|
+
* { "id": "a93e51b4-6c0d-4f2a-8b17-3e5d9c2f0a61", "name": "hero", "type": "image", "imageKey": "hero" }
|
|
381
|
+
* ] },
|
|
382
|
+
* { "id": "7c4a2e9f-1b3d-4f6a-8c05-2e9d7b1f4a36", "name": "Enemies", "objects": [
|
|
383
|
+
* { "id": "c07d9e3f-1a2b-4c3d-8e4f-5a6b7c8d9e0f", "name": "bat", "tags": ["enemy"], "type": "image", "imageKey": "bat" }
|
|
384
|
+
* ] }
|
|
385
|
+
* ]
|
|
386
|
+
* }
|
|
387
|
+
* ```
|
|
388
|
+
*/
|
|
389
|
+
export interface DesignFileV2 {
|
|
390
|
+
/** Always `"minimo-design"`. */
|
|
391
|
+
format: "minimo-design";
|
|
392
|
+
/** `2`: the design is divided into pages. */
|
|
393
|
+
version: 2;
|
|
394
|
+
/** The pages, at least one, in file order. */
|
|
395
|
+
pages: DesignPage[];
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* A design file holding objects of an optional module, {@link DesignModule}.
|
|
399
|
+
* Like the earlier versions, it has either a flat list of `objects` or
|
|
400
|
+
* `pages`, never both; it is version 3 only because an engine older than
|
|
401
|
+
* module objects cannot read it.
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
404
|
+
* ```json
|
|
405
|
+
* {
|
|
406
|
+
* "format": "minimo-design",
|
|
407
|
+
* "version": 3,
|
|
408
|
+
* "objects": [
|
|
409
|
+
* { "id": "6f1c2a0e-3b7d-4c1e-9a52-0d8e4f6b1a27", "type": "background", "imageKey": "dungeon" },
|
|
410
|
+
* { "id": "3e7b1c9a-5d2f-4a8e-b0c6-9f1d2e4a7b35", "name": "left-torch", "type": "module", "module": "fire", "kind": "torch", "x": 120, "y": 200 }
|
|
411
|
+
* ]
|
|
412
|
+
* }
|
|
413
|
+
* ```
|
|
414
|
+
*/
|
|
415
|
+
export interface DesignFileV3 {
|
|
416
|
+
/** Always `"minimo-design"`. */
|
|
417
|
+
format: "minimo-design";
|
|
418
|
+
/** `3`: the design holds objects of an optional module. */
|
|
419
|
+
version: 3;
|
|
420
|
+
/** The objects of a design without pages, in file order. Present exactly when `pages` is not. */
|
|
421
|
+
objects?: DesignObject[];
|
|
422
|
+
/** The pages of a design divided into pages, in file order. Present exactly when `objects` is not. */
|
|
423
|
+
pages?: DesignPage[];
|
|
424
|
+
}
|
|
425
|
+
/** One page of a design file with pages: a named group of the design's objects. */
|
|
426
|
+
export interface DesignPage {
|
|
427
|
+
/**
|
|
428
|
+
* Required. A UUID unique among the file's pages. Tools use it to keep a
|
|
429
|
+
* page through a rename; code finds a page by its `name`.
|
|
430
|
+
*/
|
|
431
|
+
id: string;
|
|
432
|
+
/**
|
|
433
|
+
* Required. Unique in the file, not empty, and with no leading or trailing
|
|
434
|
+
* spaces, such as `"Enemies"`. Code finds a page by it.
|
|
435
|
+
*/
|
|
436
|
+
name: string;
|
|
437
|
+
/**
|
|
438
|
+
* The page's objects, in file order. An object's `id` is unique in the whole
|
|
439
|
+
* file, across pages.
|
|
440
|
+
*/
|
|
441
|
+
objects: DesignObject[];
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* How one property of a design object is written, for tools that read or edit
|
|
445
|
+
* designs without the TypeScript types, such as a property panel. See
|
|
446
|
+
* {@link designObjectProperties}.
|
|
447
|
+
*/
|
|
448
|
+
export interface DesignProperty {
|
|
449
|
+
/** The property's name, in the file and on the runtime object. */
|
|
450
|
+
readonly name: string;
|
|
451
|
+
/**
|
|
452
|
+
* The JSON type of its value. `"string-list"` is a list of strings, as
|
|
453
|
+
* `tags`; `"object"` is a JSON object, as `data`.
|
|
454
|
+
*/
|
|
455
|
+
readonly type: "number" | "string" | "boolean" | "string-list" | "object";
|
|
456
|
+
/** Whether `null` is accepted besides values of its type, as for `bodyWidth`. */
|
|
457
|
+
readonly nullable: boolean;
|
|
458
|
+
/** The only strings accepted, as for `fit`; `null` when any value of its type is. */
|
|
459
|
+
readonly values: readonly string[] | null;
|
|
460
|
+
/** Whether every object of its type must have it. A required property has no default. */
|
|
461
|
+
readonly required: boolean;
|
|
462
|
+
/**
|
|
463
|
+
* The runtime object's value when the file omits the property.
|
|
464
|
+
* `undefined` for a required property, for `name`, and for a module option
|
|
465
|
+
* whose default depends on the object's kind.
|
|
466
|
+
*/
|
|
467
|
+
readonly default: unknown;
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Every property each type of design object accepts besides `id` and `type`,
|
|
471
|
+
* with its JSON type, whether it is required, and its default.
|
|
472
|
+
*
|
|
473
|
+
* It is the runtime form of {@link DesignImage}, {@link DesignEmoji},
|
|
474
|
+
* {@link DesignText}, {@link DesignBackground}, and {@link DesignModule},
|
|
475
|
+
* which the compiler checks it against, for tools that cannot read TypeScript
|
|
476
|
+
* types, such as an editor's property panel. `new Design(json)` validates
|
|
477
|
+
* objects with it. A `module` object takes only the properties its module
|
|
478
|
+
* lists in {@link designModules}.
|
|
479
|
+
*
|
|
480
|
+
* @example
|
|
481
|
+
* ```ts
|
|
482
|
+
* for (const property of designObjectProperties.image) {
|
|
483
|
+
* console.log(property.name, property.type, property.default);
|
|
484
|
+
* }
|
|
485
|
+
* ```
|
|
486
|
+
*/
|
|
487
|
+
export declare const designObjectProperties: Readonly<Record<DesignObjectType, readonly DesignProperty[]>>;
|
|
488
|
+
/** One of a module's own options, as a {@link DesignModule}'s `options` holds it. */
|
|
489
|
+
export interface DesignModuleOption extends DesignProperty {
|
|
490
|
+
/** The smallest number accepted; `null` when there is no lower bound or the option is not a number. */
|
|
491
|
+
readonly min: number | null;
|
|
492
|
+
/** The largest number accepted; `null` when there is no upper bound or the option is not a number. */
|
|
493
|
+
readonly max: number | null;
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* What a design may hold of one optional module, for the engine that
|
|
497
|
+
* validates designs and for tools such as an editor. See {@link designModules}.
|
|
498
|
+
*/
|
|
499
|
+
export interface DesignModuleSchema {
|
|
500
|
+
/** The module's id, as a {@link DesignModule}'s `module` names it, such as `"fire"`. */
|
|
501
|
+
readonly module: string;
|
|
502
|
+
/** The module's file, next to `minimo.js`, such as `"minimo-fire.js"`. */
|
|
503
|
+
readonly file: string;
|
|
504
|
+
/**
|
|
505
|
+
* The class the module exports, which a scene creates with
|
|
506
|
+
* `new Class(game)` before creating the design's objects, and whose
|
|
507
|
+
* `update(dt)` advances them, such as `"Fire"`.
|
|
508
|
+
*/
|
|
509
|
+
readonly className: string;
|
|
510
|
+
/** The kinds a design can place, such as `"torch"`. The module makes any other kind in code only. */
|
|
511
|
+
readonly kinds: readonly string[];
|
|
512
|
+
/**
|
|
513
|
+
* The sprite properties of {@link DesignSpriteBase} a design may set on the
|
|
514
|
+
* module's objects, besides `name`, `tags`, and `data`, which every object takes.
|
|
515
|
+
*/
|
|
516
|
+
readonly properties: readonly string[];
|
|
517
|
+
/** The module's own options, which `options` may hold. */
|
|
518
|
+
readonly options: readonly DesignModuleOption[];
|
|
519
|
+
/**
|
|
520
|
+
* The number option that sets how big an object is, which an editor's
|
|
521
|
+
* scale handle changes, such as `"size"`; `null` when a design does not
|
|
522
|
+
* size the module's objects.
|
|
523
|
+
*/
|
|
524
|
+
readonly sizeOption: string | null;
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* The optional modules whose objects a design can hold, by id, with the kinds
|
|
528
|
+
* each places, the sprite properties and options it takes, and how a tool
|
|
529
|
+
* loads it. A design object of any other module, kind, property, or option is
|
|
530
|
+
* refused: what a design does not hold is set in code.
|
|
531
|
+
*
|
|
532
|
+
* A design holds how an object looks when its screen opens. What the game
|
|
533
|
+
* changes while it plays, such as a flame going out or a die's roll, is the
|
|
534
|
+
* module's API, used in code on the object the design created.
|
|
535
|
+
*
|
|
536
|
+
* @example
|
|
537
|
+
* ```ts
|
|
538
|
+
* for (const [id, schema] of Object.entries(designModules)) {
|
|
539
|
+
* console.log(id, schema.kinds, schema.options.map((option) => option.name));
|
|
540
|
+
* }
|
|
541
|
+
* ```
|
|
542
|
+
*/
|
|
543
|
+
export declare const designModules: Readonly<Record<string, DesignModuleSchema>>;
|
|
544
|
+
/**
|
|
545
|
+
* The data of a design file, `*.design.json`, validated: its objects, its
|
|
546
|
+
* pages, and searches on them. A `Design` needs no game and creates nothing; pass its
|
|
547
|
+
* objects, or the results of its searches, to `game.createObject` or
|
|
548
|
+
* `game.createObjectList`. Data alone also serves markers, such as spawn
|
|
549
|
+
* points, which code reads without creating anything.
|
|
550
|
+
*
|
|
551
|
+
* Obtain the file by JSON import. One `Design` can be created any number of
|
|
552
|
+
* times.
|
|
553
|
+
*
|
|
554
|
+
* @example
|
|
555
|
+
* ```ts
|
|
556
|
+
* import menuJson from "./menu.design.json" with { type: "json" };
|
|
557
|
+
*
|
|
558
|
+
* const menu = new Design(menuJson);
|
|
559
|
+
*
|
|
560
|
+
* class MenuScene {
|
|
561
|
+
* onCreate() {
|
|
562
|
+
* const ui = game.createObjectList(menu.objects);
|
|
563
|
+
* this.play = ui.findByName("play");
|
|
564
|
+
* }
|
|
565
|
+
* }
|
|
566
|
+
* ```
|
|
567
|
+
*
|
|
568
|
+
* A design divided into pages, such as a screen on one page and templates on
|
|
569
|
+
* another, is created one page at a time:
|
|
570
|
+
*
|
|
571
|
+
* ```ts
|
|
572
|
+
* const ui = game.createObjectList(menu.findAllByPage("Menu"));
|
|
573
|
+
* const bat = game.createObject(menu.findByPage("Bat"));
|
|
574
|
+
* ```
|
|
575
|
+
*/
|
|
576
|
+
export declare class Design {
|
|
577
|
+
/**
|
|
578
|
+
* Every object of the design, as object data, in file order: for a design
|
|
579
|
+
* with pages, every page's objects, page after page. Passing them to
|
|
580
|
+
* `game.createObjectList` creates every page at once.
|
|
581
|
+
*/
|
|
582
|
+
readonly objects: readonly DesignObject[];
|
|
583
|
+
/**
|
|
584
|
+
* The design's pages, in file order, each with its objects as object data.
|
|
585
|
+
* Empty for a design without pages, a version 1 file.
|
|
586
|
+
*/
|
|
587
|
+
readonly pages: readonly Readonly<DesignPage>[];
|
|
588
|
+
/**
|
|
589
|
+
* Validates a design file's content and keeps a copy of it.
|
|
590
|
+
*
|
|
591
|
+
* Parsing is strict. It throws an error naming what is wrong for a value
|
|
592
|
+
* that is not a design, an unknown field, a `format` other than
|
|
593
|
+
* `"minimo-design"`, a `version` newer than this engine reads, an object
|
|
594
|
+
* whose `type` is not one of the built-in types, an `id` that is not a UUID
|
|
595
|
+
* or is used twice, a value of the wrong type, a missing required property,
|
|
596
|
+
* a `data` that is not a JSON object, a page without a UUID `id` or with
|
|
597
|
+
* a missing, padded, or repeated `name`, and a `module` object in a design
|
|
598
|
+
* older than version 3 or with a module, kind, property, or option that
|
|
599
|
+
* {@link designModules} does not list.
|
|
600
|
+
*
|
|
601
|
+
* @param json - The content of a `*.design.json` file. See {@link DesignFile}.
|
|
602
|
+
*/
|
|
603
|
+
constructor(json: unknown);
|
|
604
|
+
/**
|
|
605
|
+
* Returns the first object of the page named `name`, in file order, such
|
|
606
|
+
* as a page holding one template. Throws an error naming the page when the
|
|
607
|
+
* design has no page with that name, or the page has no objects.
|
|
608
|
+
*/
|
|
609
|
+
findByPage(name: string): DesignObject;
|
|
610
|
+
/**
|
|
611
|
+
* Returns every object of the page named `name`, in file order; an empty
|
|
612
|
+
* list for an empty page. Throws an error naming the page when the design
|
|
613
|
+
* has no page with that name, because a page name that matches nothing is
|
|
614
|
+
* almost always a typo.
|
|
615
|
+
*/
|
|
616
|
+
findAllByPage(name: string): DesignObject[];
|
|
617
|
+
private pageNamed;
|
|
618
|
+
/**
|
|
619
|
+
* Returns the first object whose `name` is `name`, in file order.
|
|
620
|
+
* Throws an error naming `name` when there is none.
|
|
621
|
+
*/
|
|
622
|
+
findByName(name: string): DesignObject;
|
|
623
|
+
/** Returns every object whose `name` is `name`, in file order; an empty list when there is none. */
|
|
624
|
+
findAllByName(name: string): DesignObject[];
|
|
625
|
+
/**
|
|
626
|
+
* Returns the first object whose `tags` include `tag`, in file order.
|
|
627
|
+
* Throws an error naming `tag` when there is none.
|
|
628
|
+
*/
|
|
629
|
+
findByTag(tag: string): DesignObject;
|
|
630
|
+
/** Returns every object whose `tags` include `tag`, in file order; an empty list when there is none. */
|
|
631
|
+
findAllByTag(tag: string): DesignObject[];
|
|
632
|
+
}
|