minimojs 1.0.0-alpha.4 → 1.0.0-alpha.41

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 (71) hide show
  1. package/README.md +58 -20
  2. package/dist/internal/AnimationSystem.js +345 -0
  3. package/dist/internal/AssetSystem.d.ts +6 -0
  4. package/dist/internal/AssetSystem.js +281 -0
  5. package/dist/internal/BackgroundSystem.d.ts +1 -0
  6. package/dist/internal/BackgroundSystem.js +26 -0
  7. package/dist/internal/CanvasSystem.d.ts +1 -0
  8. package/dist/internal/CanvasSystem.js +51 -0
  9. package/dist/internal/DesignNamingCheck.d.ts +1 -0
  10. package/dist/internal/DesignNamingCheck.js +7 -0
  11. package/dist/internal/ExplosionSystem.d.ts +1 -0
  12. package/dist/internal/ExplosionSystem.js +540 -0
  13. package/dist/internal/InputSystem.d.ts +1 -0
  14. package/dist/internal/InputSystem.js +292 -0
  15. package/dist/internal/LoopSystem.d.ts +1 -0
  16. package/dist/internal/LoopSystem.js +61 -0
  17. package/dist/internal/PhysicsSystem.d.ts +1 -0
  18. package/dist/internal/PhysicsSystem.js +174 -0
  19. package/dist/internal/RenderSystem.d.ts +1 -0
  20. package/dist/internal/RenderSystem.js +1021 -0
  21. package/dist/internal/SoundSystem.d.ts +39 -0
  22. package/dist/internal/SoundSystem.js +292 -0
  23. package/dist/internal/SpriteSystem.d.ts +1 -0
  24. package/dist/internal/SpriteSystem.js +32 -0
  25. package/dist/internal/TextSystem.d.ts +1 -0
  26. package/dist/internal/TextSystem.js +16 -0
  27. package/dist/internal/TimerSystem.d.ts +1 -0
  28. package/dist/internal/TimerSystem.js +43 -0
  29. package/dist/internal/TrailSystem.d.ts +1 -0
  30. package/dist/internal/TrailSystem.js +116 -0
  31. package/dist/internal/TransitionSystem.d.ts +1 -0
  32. package/dist/internal/TransitionSystem.js +74 -0
  33. package/dist/internal/arcade-racer/ArcadeRacerCollisionSystem.d.ts +1 -0
  34. package/dist/internal/arcade-racer/ArcadeRacerCollisionSystem.js +198 -0
  35. package/dist/internal/arcade-racer/ArcadeRacerLaneSystem.d.ts +1 -0
  36. package/dist/internal/arcade-racer/ArcadeRacerLaneSystem.js +120 -0
  37. package/dist/internal/arcade-racer/ArcadeRacerRenderSystem.d.ts +1 -0
  38. package/dist/internal/arcade-racer/ArcadeRacerRenderSystem.js +599 -0
  39. package/dist/internal/arcade-racer/ArcadeRacerRoadSprite.d.ts +1 -0
  40. package/dist/internal/arcade-racer/ArcadeRacerRoadSprite.js +13 -0
  41. package/dist/internal/arcade-racer/ArcadeRacerTrackSystem.d.ts +1 -0
  42. package/dist/internal/arcade-racer/ArcadeRacerTrackSystem.js +447 -0
  43. package/dist/minimo-ambient.d.ts +299 -0
  44. package/dist/minimo-ambient.js +1445 -0
  45. package/dist/minimo-arcaderacer.d.ts +1431 -0
  46. package/dist/minimo-arcaderacer.js +2060 -0
  47. package/dist/minimo-cards.d.ts +359 -0
  48. package/dist/minimo-cards.js +819 -0
  49. package/dist/minimo-dice.d.ts +206 -0
  50. package/dist/minimo-dice.js +719 -0
  51. package/dist/minimo-fire.d.ts +282 -0
  52. package/dist/minimo-fire.js +930 -0
  53. package/dist/minimo-format.d.ts +632 -0
  54. package/dist/minimo-format.js +669 -0
  55. package/dist/minimo-leaderboard.d.ts +199 -0
  56. package/dist/minimo-leaderboard.js +566 -0
  57. package/dist/minimo-multiplayer.d.ts +387 -0
  58. package/dist/minimo-multiplayer.js +1323 -0
  59. package/dist/minimo.d.ts +1690 -233
  60. package/dist/minimo.js +2587 -892
  61. package/package.json +10 -3
  62. package/dist/animations.js +0 -30
  63. package/dist/audio.js +0 -17
  64. package/dist/game.js +0 -1105
  65. package/dist/input.js +0 -185
  66. package/dist/internal-types.js +0 -4
  67. package/dist/physics.js +0 -10
  68. package/dist/render.js +0 -75
  69. package/dist/sprite.js +0 -149
  70. package/dist/timers.js +0 -23
  71. /package/dist/{pointer-info.js → internal/AnimationSystem.d.ts} +0 -0
@@ -0,0 +1,282 @@
1
+ import { DrawSprite, Game, Sprite } from "./minimo.js";
2
+ /**
3
+ * The kinds of fire {@link Fire.create} and {@link Fire.attach} make.
4
+ *
5
+ * - `"torch"`: a narrow, tall flame that glows. For torches, braziers, and
6
+ * lamps.
7
+ * - `"campfire"`: a wide flame with smoke and sparks that glows. For
8
+ * campfires, fireplaces, and burning debris.
9
+ * - `"burning"`: flames over a whole sprite, such as an enemy set alight or a
10
+ * burning house. The default of {@link Fire.attach}.
11
+ * - `"trail"`: a ball of fire that leaves flames and smoke behind it as it
12
+ * moves. For fireballs, flaming arrows, meteors, and exhausts.
13
+ */
14
+ export type FlameKind = "torch" | "campfire" | "burning" | "trail";
15
+ /** A named palette: orange fire, a blue gas flame, green poison, or purple magic. */
16
+ export type FirePaletteName = "fire" | "blue" | "green" | "purple";
17
+ /**
18
+ * The colors of a fire: a named palette, or three CSS colors for the core,
19
+ * the middle, and the edge of the flame, from hottest to coolest.
20
+ */
21
+ export type FirePalette = FirePaletteName | readonly [string, string, string];
22
+ /**
23
+ * How a fire is drawn: `"soft"`, glowing gradients that add up to light, or
24
+ * `"pixel"`, hard-edged squares in the palette's three colors, to match pixel
25
+ * art.
26
+ */
27
+ export type FireStyle = "soft" | "pixel";
28
+ /** The look of a fire. A {@link Fire} holds one for all its flames, and each flame can override any field. */
29
+ export interface FireLook {
30
+ /** Default `"fire"`. */
31
+ palette?: FirePalette;
32
+ /** Default `"soft"`. */
33
+ style?: FireStyle;
34
+ /** How much smoke rises, from `0` to `1`. Default: by kind. */
35
+ smoke?: number;
36
+ /** How many sparks fly, from `0` to `1`. Default: by kind. */
37
+ sparks?: number;
38
+ /** CSS color of the smoke. Default `"#4a4440"`. */
39
+ smokeColor?: string;
40
+ }
41
+ /** Settings of a {@link Fire}, and the look every flame starts from. */
42
+ export interface FireOptions extends FireLook {
43
+ /**
44
+ * The most particles alive at once, across every flame. Default `1200`,
45
+ * lowered on weak phones. A flame that would go over it emits fewer.
46
+ */
47
+ maxParticles?: number;
48
+ /**
49
+ * Fewer particles and a softer flicker. Default: the player's system
50
+ * `prefers-reduced-motion` setting.
51
+ */
52
+ reducedMotion?: boolean;
53
+ /** The first {@link Fire.wind}. Default `0`. */
54
+ wind?: number;
55
+ /**
56
+ * Seeds the module's own random source, so the same seed flickers the same
57
+ * way. Default: a different flicker every time. The module never calls
58
+ * `game.random()`, so drawing fire never changes a seeded game's sequence.
59
+ */
60
+ seed?: number;
61
+ }
62
+ /** Where a new flame burns, how big, and how it looks. */
63
+ export interface FlameOptions extends FireLook {
64
+ /** X position in world space, in pixels: the base of the flame. Default `0`. */
65
+ x?: number;
66
+ /** Y position in world space, in pixels: the base of the flame, where it burns from. Default `0`. */
67
+ y?: number;
68
+ /**
69
+ * About how wide the flame is, in pixels. Default `32`, or the sprite's
70
+ * width for a `"burning"` flame made by {@link Fire.attach}. Its collision
71
+ * body covers the flame's core; its drawing surface is larger, to hold its
72
+ * glow, smoke, and trail.
73
+ */
74
+ size?: number;
75
+ /** How strongly it burns, from `0` to `1`. Default `1`. */
76
+ intensity?: number;
77
+ /** Paint a soft, flickering glow around the flame. Default `true` for a torch and a campfire. */
78
+ light?: boolean;
79
+ /** The flame's sprite layer. Default `0`, or the sprite's layer for {@link Fire.attach}. */
80
+ layer?: number;
81
+ }
82
+ /** How {@link Fire.attach} keeps a flame on a sprite. */
83
+ export interface AttachOptions extends Omit<FlameOptions, "x" | "y"> {
84
+ /** Default `"burning"`. */
85
+ kind?: FlameKind;
86
+ /**
87
+ * Where the flame burns, from the sprite's position, in pixels. Default `0`;
88
+ * for a torch or a campfire, `offsetY` defaults to the sprite's top edge.
89
+ */
90
+ offsetX?: number;
91
+ offsetY?: number;
92
+ /** Put the flame out after this many milliseconds. Default: never. */
93
+ ms?: number;
94
+ }
95
+ /** How {@link Fire.burst} leaves fire where something was destroyed. */
96
+ export interface BurstOptions extends FireLook {
97
+ /** About how wide the fire is, in pixels. Default `48`. */
98
+ size?: number;
99
+ /** How long it burns before it is out, in milliseconds. Default `3000`. */
100
+ burnMs?: number;
101
+ /** Default `0`. */
102
+ layer?: number;
103
+ }
104
+ /** How {@link Fire.explosion} blows up. */
105
+ export interface ExplosionOptions extends FireLook {
106
+ /** About how wide the fireball grows, in pixels. Default `96`. */
107
+ size?: number;
108
+ /** Default `0`. */
109
+ layer?: number;
110
+ }
111
+ type InternalKind = FlameKind | "burst" | "explosion";
112
+ /**
113
+ * Fire for a game: torches, campfires, burning sprites, fireballs, fire where
114
+ * something was destroyed, and explosions. It makes each flame and advances
115
+ * all of them with one {@link Fire.update} call per frame.
116
+ *
117
+ * Every flame is a sprite, a {@link Flame}, so the game places it, layers it,
118
+ * hides it, and destroys it as any other. Its particles are painted into its
119
+ * own surface, so a fire costs one sprite however many particles it has.
120
+ *
121
+ * The module draws fire; the game decides what catches fire, what it hurts,
122
+ * and what puts it out.
123
+ *
124
+ * @example
125
+ * ```ts
126
+ * const fire = new Fire(game, { style: "pixel" });
127
+ * game.onUpdate = (dt) => fire.update(dt);
128
+ *
129
+ * const torch = fire.create("torch", { x: 120, y: 200, size: 28 });
130
+ * fire.burst(crate.x, crate.y, { size: 48, burnMs: 4000 }); // where the crate was
131
+ * fire.attach(fireball, { kind: "trail", palette: "blue" });
132
+ * torch.extinguish(600);
133
+ * ```
134
+ *
135
+ * ## In a design
136
+ *
137
+ * A design can place `torch`, `campfire`, `burning`, and `trail` flames, so
138
+ * the creator moves and resizes them in the design editor. Each is a
139
+ * `module` object of a version 3 design. It takes `x`, `y`, `alpha`,
140
+ * `visible`, `layer`, `ignoreScroll`, and the collision body's properties,
141
+ * never `scale` or `rotation`: its `size` option resizes it. Its `options`
142
+ * are `size`, `intensity`, `palette` (a palette's name), `style`, `smoke`,
143
+ * `sparks`, `smokeColor`, and `light`, each as in {@link FlameOptions}.
144
+ *
145
+ * ```json
146
+ * { "id": "3e7b1c9a-5d2f-4a8e-b0c6-9f1d2e4a7b35", "name": "left-torch", "type": "module", "module": "fire", "kind": "torch", "x": 120, "y": 200, "layer": 2, "options": { "size": 28, "palette": "blue" } }
147
+ * ```
148
+ *
149
+ * A placed flame looks as its options say and the module's defaults, never
150
+ * as the look given to `new Fire(game, …)`, so the game shows what the editor
151
+ * showed, and it is already burning when its screen opens. `burst` and
152
+ * `explosion` are moments, made in code. Create the fire in the scene's
153
+ * `onCreate()` before the design's objects, then find a flame by its name
154
+ * to change it while the game plays, and advance the fire every frame:
155
+ *
156
+ * ```ts
157
+ * onCreate() {
158
+ * this.fire = new Fire(game);
159
+ * const room = game.createObjectList(dungeon.objects);
160
+ * this.torch = room.findByName("left-torch"); // later: this.torch.extinguish()
161
+ * room.findByName("barrel-fire").follow(room.findByName("barrel"));
162
+ * }
163
+ * onUpdate(dt) {
164
+ * this.fire.update(dt);
165
+ * }
166
+ * ```
167
+ */
168
+ export declare class Fire {
169
+ /** The game the flames are added to. */
170
+ readonly game: Game;
171
+ /** The look every flame starts from. */
172
+ readonly look: FireLook;
173
+ /**
174
+ * Wind in pixels per second, positive to the right. Every flame, its smoke,
175
+ * and its sparks lean with it. A game with an `ambient` can copy
176
+ * `ambient.windX` here every frame.
177
+ */
178
+ wind: number;
179
+ /** Fewer particles and a softer flicker. Follows the player's system setting unless the game sets it. */
180
+ reducedMotion: boolean;
181
+ constructor(game: Game, options?: FireOptions);
182
+ /** The flames burning now, in the order they were made. */
183
+ get flames(): readonly Flame[];
184
+ /** How many particles are alive across every flame. */
185
+ get particleCount(): number;
186
+ /**
187
+ * Makes a flame, adds it to the game, and returns it. It burns until the
188
+ * game puts it out with {@link Flame.extinguish} or removes it.
189
+ * @param kind - `"torch"`, `"campfire"`, `"burning"`, or `"trail"`.
190
+ * @param options - Position, size, intensity, and any look over the fire's.
191
+ */
192
+ create(kind: FlameKind, options?: FlameOptions): Flame;
193
+ /**
194
+ * Makes a flame that follows `sprite` every frame and adds it to the game.
195
+ * Its particles stay where they were emitted, so a moving sprite leaves a
196
+ * trail behind it and a still one does not. The flame goes out by itself
197
+ * when the sprite is destroyed, or after `ms`.
198
+ * @param sprite - A sprite already added to the game.
199
+ * @param options - The kind, `"burning"` by default, where on the sprite, for how long, and the look.
200
+ */
201
+ attach(sprite: Sprite, options?: AttachOptions): Flame;
202
+ /**
203
+ * Leaves fire where something was destroyed: a burst of flame, then flames
204
+ * that die down into smoke and are gone after `burnMs`.
205
+ * @returns A promise that resolves when the fire is out and removed.
206
+ */
207
+ burst(x: number, y: number, options?: BurstOptions): Promise<void>;
208
+ /**
209
+ * Blows up at a point: a fireball with sparks and a cloud of smoke, which
210
+ * brightens the scene once and is gone in about a second and a half.
211
+ * @returns A promise that resolves when the explosion is over and removed.
212
+ */
213
+ explosion(x: number, y: number, options?: ExplosionOptions): Promise<void>;
214
+ /** Removes a flame at once, with no dying down. */
215
+ remove(flame: Flame): void;
216
+ /** Removes every flame at once. */
217
+ clear(): void;
218
+ /** Advances every flame. Call it once per frame from `onUpdate`. */
219
+ update(dt: number): void;
220
+ }
221
+ /**
222
+ * One fire: a `DrawSprite` whose position is the base of the flame. It has
223
+ * everything a sprite has, layer, visibility, `ignoreScroll` for fire on the
224
+ * HUD, and a collision body over the flame's core, and it carries the tag
225
+ * `fire`. Do not rotate or scale it: its particles are placed in the world.
226
+ *
227
+ * Make flames with {@link Fire.create}, {@link Fire.attach},
228
+ * {@link Fire.burst}, or {@link Fire.explosion}, which also advance them.
229
+ */
230
+ export declare class Flame extends DrawSprite {
231
+ /** The kind of fire. `"burst"` and `"explosion"` are the flames {@link Fire.burst} and {@link Fire.explosion} make. */
232
+ readonly kind: FlameKind | "burst" | "explosion";
233
+ /** About how wide the flame is, in pixels. */
234
+ readonly size: number;
235
+ /** The colors of this flame. */
236
+ palette: FirePalette;
237
+ /** How this flame is drawn. */
238
+ style: FireStyle;
239
+ /** How much smoke rises, from `0` to `1`. */
240
+ smoke: number;
241
+ /** How many sparks fly, from `0` to `1`. */
242
+ sparks: number;
243
+ /** CSS color of the smoke. */
244
+ smokeColor: string;
245
+ /** Paint a soft, flickering glow around the flame. */
246
+ light: boolean;
247
+ /** Called once when the flame is out and removed. */
248
+ onOut: (() => void) | null;
249
+ /**
250
+ * Use {@link Fire.create}, {@link Fire.attach}, {@link Fire.burst}, or
251
+ * {@link Fire.explosion} instead, which also add and advance the flame.
252
+ */
253
+ constructor(fire: Fire, kind: InternalKind, options?: FlameOptions);
254
+ /** How strongly it burns, from `0` to `1`. Setting it stops a change in progress. */
255
+ get intensity(): number;
256
+ set intensity(value: number);
257
+ /** `true` once the flame is going out for good: it emits nothing more and is removed when its last particle is gone. */
258
+ get out(): boolean;
259
+ /** The sprite this flame follows, or `null`. */
260
+ get target(): Sprite | null;
261
+ /**
262
+ * Makes the flame follow `sprite` every frame, keeping the offset it has
263
+ * from it now, as a flame placed over a sprite in a design keeps where the
264
+ * creator put it. It hides with the sprite and goes out when the sprite is
265
+ * destroyed. `null` stops following and leaves the flame where it is.
266
+ */
267
+ follow(sprite: Sprite | null): void;
268
+ /**
269
+ * Changes the intensity over `ms` milliseconds.
270
+ * @returns A promise that resolves when it gets there, or when another change replaces it.
271
+ */
272
+ to(intensity: number, ms: number): Promise<void>;
273
+ /**
274
+ * Puts the flame out: it dies down over `ms` milliseconds into a puff of
275
+ * smoke, and is removed from the game when the smoke is gone.
276
+ * @returns A promise that resolves when the flame is out and removed.
277
+ */
278
+ extinguish(ms?: number): Promise<void>;
279
+ protected getAnchorOffsetY(): number;
280
+ redraw(ctx: CanvasRenderingContext2D): void;
281
+ }
282
+ export {};