minimojs 1.0.0-alpha.21 → 1.0.0-alpha.23
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/dist/minimo-ambient.d.ts +299 -0
- package/dist/minimo-ambient.js +1445 -0
- package/dist/minimo-cards.d.ts +355 -0
- package/dist/minimo-cards.js +809 -0
- package/package.json +1 -1
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { Game, Sprite } from "./minimo.js";
|
|
2
|
+
/**
|
|
3
|
+
* The weather and light of an {@link Ambient}.
|
|
4
|
+
*
|
|
5
|
+
* Every number runs from `0` to `1`, except {@link AmbientState.wind}, which
|
|
6
|
+
* runs from `-1` to `1`. Change it with {@link Ambient.set},
|
|
7
|
+
* {@link Ambient.to}, or {@link Ambient.preset}; read it from
|
|
8
|
+
* {@link Ambient.state}.
|
|
9
|
+
*/
|
|
10
|
+
export interface AmbientState {
|
|
11
|
+
/** Wind direction and strength: `1` is strong wind to the right, `-1` to the left. */
|
|
12
|
+
wind: number;
|
|
13
|
+
/** How irregularly the wind blows around {@link AmbientState.wind}. */
|
|
14
|
+
gusts: number;
|
|
15
|
+
/** Rain intensity. Rain splashes on the ambient's surfaces. */
|
|
16
|
+
rain: number;
|
|
17
|
+
/** Snow intensity. With {@link Ambient.snowSettles}, snow builds up on surfaces. */
|
|
18
|
+
snow: number;
|
|
19
|
+
/** Fog: drifting bands of mist and a haze over the scene. */
|
|
20
|
+
fog: number;
|
|
21
|
+
/** Lightning frequency. Flashes never exceed the safe rate, whatever the value. */
|
|
22
|
+
storm: number;
|
|
23
|
+
/** How dark the scene is: `1` is deep night. */
|
|
24
|
+
darkness: number;
|
|
25
|
+
/** How strongly {@link AmbientState.tintColor} colors the scene: `1` lays it at 50% over it. */
|
|
26
|
+
tint: number;
|
|
27
|
+
/** How many stars show in the sky. Clouds from rain, snow, and fog hide them. */
|
|
28
|
+
stars: number;
|
|
29
|
+
/** Hex color of the tint, such as `"#1b2a55"`. Interpolated in RGB by {@link Ambient.to}. */
|
|
30
|
+
tintColor: string;
|
|
31
|
+
}
|
|
32
|
+
/** The numeric fields of {@link AmbientState}. */
|
|
33
|
+
export type AmbientField = Exclude<keyof AmbientState, "tintColor">;
|
|
34
|
+
/** A partial state for {@link Ambient.set} and {@link Ambient.to}. */
|
|
35
|
+
export type AmbientChange = Partial<AmbientState>;
|
|
36
|
+
/**
|
|
37
|
+
* A named weather for {@link Ambient.preset}. Presets are geometric only, so
|
|
38
|
+
* every one works in any game without art.
|
|
39
|
+
*/
|
|
40
|
+
export type AmbientPreset = "clear" | "drizzle" | "rain" | "storm" | "snow" | "blizzard" | "mist" | "windy";
|
|
41
|
+
/** A horizontal line in world space that rain splashes on and snow settles on. */
|
|
42
|
+
export interface AmbientLine {
|
|
43
|
+
/** World X of the line's left end. */
|
|
44
|
+
left: number;
|
|
45
|
+
/** World X of the line's right end. */
|
|
46
|
+
right: number;
|
|
47
|
+
/** World Y of the line. */
|
|
48
|
+
y: number;
|
|
49
|
+
}
|
|
50
|
+
/** A rectangle in world space where no rain, snow, or falling drift is drawn. */
|
|
51
|
+
export interface AmbientRect {
|
|
52
|
+
left: number;
|
|
53
|
+
top: number;
|
|
54
|
+
right: number;
|
|
55
|
+
bottom: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Something rain splashes on and snow settles on. A sprite counts by the top
|
|
59
|
+
* edge of its collision body, and is followed if it moves.
|
|
60
|
+
*/
|
|
61
|
+
export type AmbientSurface = Sprite | AmbientLine;
|
|
62
|
+
/**
|
|
63
|
+
* A covered area, such as a cave, a roof, or an awning. A sprite counts by its
|
|
64
|
+
* collision body, and is followed if it moves.
|
|
65
|
+
*/
|
|
66
|
+
export type AmbientShelter = Sprite | AmbientRect;
|
|
67
|
+
/** Options for {@link Ambient}. Every field is optional. */
|
|
68
|
+
export interface AmbientOptions {
|
|
69
|
+
/** Sprite layer of the surface drawn behind the play field. Default `5`. */
|
|
70
|
+
backLayer?: number;
|
|
71
|
+
/**
|
|
72
|
+
* Sprite layer of the surface drawn in front of the play field: the nearest
|
|
73
|
+
* particles, splashes, settled snow, haze, darkness, and flashes. Put the
|
|
74
|
+
* HUD above it. Default `900`.
|
|
75
|
+
*/
|
|
76
|
+
frontLayer?: number;
|
|
77
|
+
/** Share of particles that are nearer than the play field and drawn in front of it. Default `0.25`. */
|
|
78
|
+
front?: number;
|
|
79
|
+
/** Seed for reproducible weather. Omit it for different weather on every load. */
|
|
80
|
+
seed?: number;
|
|
81
|
+
/** Hard cap on rain, snow, and drift particles together. Lowered on weak devices. Default `900`. */
|
|
82
|
+
maxParticles?: number;
|
|
83
|
+
/** Wind speed in pixels per second at `wind: 1`. Default `600`. */
|
|
84
|
+
windStrength?: number;
|
|
85
|
+
/** Initial {@link Ambient.surfaces}. */
|
|
86
|
+
surfaces?: AmbientSurface[];
|
|
87
|
+
/** Initial {@link Ambient.shelters}. */
|
|
88
|
+
shelters?: AmbientShelter[];
|
|
89
|
+
/** Initial {@link Ambient.snowSettles}. Default `false`. */
|
|
90
|
+
snowSettles?: boolean;
|
|
91
|
+
/** Deepest settled snow, in pixels. Default `16`. */
|
|
92
|
+
maxSnowDepth?: number;
|
|
93
|
+
/** Hex color of the fog. Default `"#dde5ee"`; a sand color makes a sandstorm. */
|
|
94
|
+
fogColor?: string;
|
|
95
|
+
/** Hex color of rain. Default `"#c8d6ea"`. */
|
|
96
|
+
rainColor?: string;
|
|
97
|
+
/** Hex color of snow, falling and settled. Default `"#ffffff"`. */
|
|
98
|
+
snowColor?: string;
|
|
99
|
+
/**
|
|
100
|
+
* Forces reduced motion on or off. By default it follows the player's
|
|
101
|
+
* `prefers-reduced-motion` setting: fewer particles and softer lightning.
|
|
102
|
+
*/
|
|
103
|
+
reducedMotion?: boolean;
|
|
104
|
+
/** Initial state. Fields left out start at `0`, and `tintColor` at `"#1b2a55"`. */
|
|
105
|
+
state?: AmbientChange;
|
|
106
|
+
}
|
|
107
|
+
/** A lightning strike, passed to {@link Ambient.onLightning}. */
|
|
108
|
+
export interface AmbientStrike {
|
|
109
|
+
/** `0` is overhead, `1` is far away. Use it to delay and soften the thunder. */
|
|
110
|
+
distance: number;
|
|
111
|
+
/** Screen X of the bolt, in pixels. */
|
|
112
|
+
x: number;
|
|
113
|
+
}
|
|
114
|
+
/** A glowing dot, the art of a drift that uses no image: fireflies, embers, dust. */
|
|
115
|
+
export interface AmbientDot {
|
|
116
|
+
/** Hex color of the dot, such as `"#fff6a0"`. */
|
|
117
|
+
color: string;
|
|
118
|
+
/** Radius of the solid core, in pixels. Default `2`. */
|
|
119
|
+
radius?: number;
|
|
120
|
+
/** Radius of the soft halo around the core, in pixels. Default `0`. */
|
|
121
|
+
glow?: number;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* How a drift moves.
|
|
125
|
+
*
|
|
126
|
+
* - `"fall"`: sways and tumbles downward, like leaves, petals, or ash. Rests a
|
|
127
|
+
* moment where it lands on a surface.
|
|
128
|
+
* - `"rise"`: floats upward, like embers or bubbles.
|
|
129
|
+
* - `"hover"`: wanders slowly in place, like fireflies or dust.
|
|
130
|
+
*/
|
|
131
|
+
export type AmbientDriftMotion = "fall" | "rise" | "hover";
|
|
132
|
+
/** Options for {@link Ambient.addDrift}. Give either `images` or `dot`. */
|
|
133
|
+
export interface AmbientDriftOptions {
|
|
134
|
+
/** How the drift moves. */
|
|
135
|
+
motion: AmbientDriftMotion;
|
|
136
|
+
/** Image keys the game loaded or created; each particle picks one. */
|
|
137
|
+
images?: string[];
|
|
138
|
+
/** A glowing dot, for drifts that need no image. */
|
|
139
|
+
dot?: AmbientDot;
|
|
140
|
+
/** Density from `0` to `1`, like the state fields. Default `0.5`. */
|
|
141
|
+
amount?: number;
|
|
142
|
+
/**
|
|
143
|
+
* Size of an image particle, as the pixel length of its longest side, or a
|
|
144
|
+
* `[min, max]` range. Nearer particles are drawn larger. Default `[16, 32]`.
|
|
145
|
+
* Ignored for dots, which use their own radius.
|
|
146
|
+
*/
|
|
147
|
+
size?: number | [number, number];
|
|
148
|
+
/** Speed multiplier. Default `1`. */
|
|
149
|
+
speed?: number;
|
|
150
|
+
/** How much images tumble and turn: `0` keeps them upright. Default `1` for `"fall"`, `0` otherwise. */
|
|
151
|
+
spin?: number;
|
|
152
|
+
/** Side-to-side swing. Default `1`. */
|
|
153
|
+
sway?: number;
|
|
154
|
+
/** How much the wind carries the drift, `0` for none, as underwater. Default `1` for `"fall"`, `0.5` otherwise. */
|
|
155
|
+
wind?: number;
|
|
156
|
+
/** Brightness flicker from `0` to `1`. Default `0`. */
|
|
157
|
+
twinkle?: number;
|
|
158
|
+
/**
|
|
159
|
+
* Draw the drift above the darkness, so it glows at night. Default `true`
|
|
160
|
+
* for a dot with a glow, `false` otherwise.
|
|
161
|
+
*/
|
|
162
|
+
lit?: boolean;
|
|
163
|
+
/** Fade out while rising instead of leaving through the top. Default `true` for dots, `false` for images. */
|
|
164
|
+
fade?: boolean;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* A stream of leaves, petals, embers, bubbles, fireflies, or dust, created by
|
|
168
|
+
* {@link Ambient.addDrift}. It shares the ambient's wind and parallax.
|
|
169
|
+
*/
|
|
170
|
+
export declare class AmbientDrift {
|
|
171
|
+
/** How the drift moves. */
|
|
172
|
+
get motion(): AmbientDriftMotion;
|
|
173
|
+
/** Density from `0` to `1`. Setting it stops a running {@link AmbientDrift.to}. */
|
|
174
|
+
get amount(): number;
|
|
175
|
+
set amount(value: number);
|
|
176
|
+
/**
|
|
177
|
+
* Changes the density over `durationMs` milliseconds. The promise resolves
|
|
178
|
+
* when the amount arrives, or when a later change takes over.
|
|
179
|
+
*/
|
|
180
|
+
to(amount: number, durationMs: number): Promise<void>;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Weather and atmosphere for a game: rain, snow, wind, fog, lightning,
|
|
184
|
+
* drifting leaves or fireflies, and the light of the hour.
|
|
185
|
+
*
|
|
186
|
+
* One shared state of intensities drives every effect, and every effect reads
|
|
187
|
+
* the same wind. All particles are painted into two canvas-sized surfaces, one
|
|
188
|
+
* behind the play field and one in front of it, so the module adds two sprites
|
|
189
|
+
* to the game whatever the weather.
|
|
190
|
+
*
|
|
191
|
+
* The ambient never moves a game sprite. The wind reaches the game only through
|
|
192
|
+
* {@link Ambient.windX}, which the game applies where it wants.
|
|
193
|
+
*
|
|
194
|
+
* Call {@link Ambient.update} once per frame. An ambient survives
|
|
195
|
+
* {@link Game.reset}: it puts its surfaces back on its next update and keeps
|
|
196
|
+
* its weather, so one ambient can serve every scene. Creating a new one in a
|
|
197
|
+
* scene's `onCreate` also works.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```ts
|
|
201
|
+
* const ambient = new Ambient(game, { surfaces: [ground], seed: 7 });
|
|
202
|
+
* ambient.preset("rain");
|
|
203
|
+
*
|
|
204
|
+
* // in onUpdate(dt)
|
|
205
|
+
* ambient.update(dt);
|
|
206
|
+
*
|
|
207
|
+
* // later: a storm rolls in over four seconds
|
|
208
|
+
* await ambient.to({ rain: 1, storm: 0.6, wind: 0.5 }, 4000);
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
export declare class Ambient {
|
|
212
|
+
/**
|
|
213
|
+
* Things rain splashes on and snow settles on: sprites, by the top of their
|
|
214
|
+
* collision body, or {@link AmbientLine}s in world space.
|
|
215
|
+
*/
|
|
216
|
+
surfaces: AmbientSurface[];
|
|
217
|
+
/**
|
|
218
|
+
* Covered areas where no rain, snow, or falling drift is drawn: sprites, by
|
|
219
|
+
* their collision body, or {@link AmbientRect}s in world space.
|
|
220
|
+
*/
|
|
221
|
+
shelters: AmbientShelter[];
|
|
222
|
+
/** When `true`, snow builds up on surfaces while it snows and melts when it stops. */
|
|
223
|
+
snowSettles: boolean;
|
|
224
|
+
/** Softer lightning and fewer particles. Follows the player's system setting unless the game sets it. */
|
|
225
|
+
reducedMotion: boolean;
|
|
226
|
+
/**
|
|
227
|
+
* Called on every lightning strike, for thunder, a camera shake, or a
|
|
228
|
+
* gameplay reaction.
|
|
229
|
+
*/
|
|
230
|
+
onLightning: ((strike: AmbientStrike) => void) | null;
|
|
231
|
+
/**
|
|
232
|
+
* Creates an ambient and adds its two surfaces to the game.
|
|
233
|
+
*
|
|
234
|
+
* @param game - The game to draw into.
|
|
235
|
+
* @param options - Layers, surfaces, shelters, seed, colors, and initial state.
|
|
236
|
+
*/
|
|
237
|
+
constructor(game: Game, options?: AmbientOptions);
|
|
238
|
+
/** The current state. Read-only: change it with {@link Ambient.set}, {@link Ambient.to}, or {@link Ambient.preset}. */
|
|
239
|
+
get state(): Readonly<AmbientState>;
|
|
240
|
+
/**
|
|
241
|
+
* The wind at this frame, gusts included, in pixels per second. Positive
|
|
242
|
+
* blows right. This is the only way the weather reaches the game's sprites:
|
|
243
|
+
*
|
|
244
|
+
* ```ts
|
|
245
|
+
* player.vx += ambient.windX * 0.3 * dt;
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
get windX(): number;
|
|
249
|
+
/** `true` while any {@link Ambient.to} or {@link Ambient.preset} transition is running. */
|
|
250
|
+
get isTransitioning(): boolean;
|
|
251
|
+
/** Changes state fields at once. Fields left out keep their value. */
|
|
252
|
+
set(change: AmbientChange): void;
|
|
253
|
+
/**
|
|
254
|
+
* Changes state fields over `durationMs` milliseconds with an ease in and
|
|
255
|
+
* out. Fields left out keep their value and any transition they are in.
|
|
256
|
+
*
|
|
257
|
+
* A field that is already moving starts from wherever it is, so a new call
|
|
258
|
+
* can interrupt an old one without a jump. The promise resolves when every
|
|
259
|
+
* field arrives, or when later calls have taken all of them over.
|
|
260
|
+
*/
|
|
261
|
+
to(change: AmbientChange, durationMs: number): Promise<void>;
|
|
262
|
+
/**
|
|
263
|
+
* Moves to a named weather. The preset's fields are set, and the other
|
|
264
|
+
* weather fields (`wind`, `gusts`, `rain`, `snow`, `fog`, `storm`) go to `0`.
|
|
265
|
+
* Light fields are left alone, because weather and time of day are
|
|
266
|
+
* independent.
|
|
267
|
+
*
|
|
268
|
+
* @param name - The preset.
|
|
269
|
+
* @param durationMs - Transition length in milliseconds. `0`, the default, changes at once.
|
|
270
|
+
*/
|
|
271
|
+
preset(name: AmbientPreset, durationMs?: number): Promise<void>;
|
|
272
|
+
/**
|
|
273
|
+
* Adds a stream of drifting things: leaves, petals, embers, bubbles,
|
|
274
|
+
* fireflies, or dust. Images must already be loaded or created.
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* ```ts
|
|
278
|
+
* const leaves = ambient.addDrift({ images: ["leaf-red", "leaf-gold"], motion: "fall", amount: 0.5 });
|
|
279
|
+
* const fireflies = ambient.addDrift({ dot: { color: "#fff6a0", glow: 8 }, motion: "hover", twinkle: 1 });
|
|
280
|
+
* ```
|
|
281
|
+
*/
|
|
282
|
+
addDrift(options: AmbientDriftOptions): AmbientDrift;
|
|
283
|
+
/** Removes a drift at once. Fade it out first with `drift.to(0, ms)` for a gentle exit. */
|
|
284
|
+
removeDrift(drift: AmbientDrift): void;
|
|
285
|
+
/** Removes all settled snow at once. */
|
|
286
|
+
clearSnow(): void;
|
|
287
|
+
/**
|
|
288
|
+
* Depth of settled snow in pixels on a surface at world X, `0` where there
|
|
289
|
+
* is none. Useful for footprints, or for slowing a player in deep snow.
|
|
290
|
+
*/
|
|
291
|
+
snowDepthAt(surface: AmbientSurface, worldX: number): number;
|
|
292
|
+
/**
|
|
293
|
+
* Advances the weather by `dt` seconds. Call it once per frame from the
|
|
294
|
+
* scene's `onUpdate`. Transition promises resolve from here.
|
|
295
|
+
*/
|
|
296
|
+
update(dt: number): void;
|
|
297
|
+
/** Removes both surfaces from the game and resolves every pending transition. The ambient does nothing afterwards. */
|
|
298
|
+
destroy(): void;
|
|
299
|
+
}
|