@datamoc/mw_games 0.7.8 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +178 -0
- package/README.md +21 -0
- package/dist/assets/index.d.ts +1 -1
- package/dist/assets/index.d.ts.map +1 -1
- package/dist/assets/index.js +1 -1
- package/dist/assets/index.js.map +1 -1
- package/dist/assets/loader.d.ts.map +1 -1
- package/dist/assets/loader.js +10 -1
- package/dist/assets/loader.js.map +1 -1
- package/dist/assets/paths.d.ts +23 -0
- package/dist/assets/paths.d.ts.map +1 -1
- package/dist/assets/paths.js +29 -0
- package/dist/assets/paths.js.map +1 -1
- package/dist/core/Math.d.ts +14 -0
- package/dist/core/Math.d.ts.map +1 -0
- package/dist/core/Math.js +16 -0
- package/dist/core/Math.js.map +1 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -0
- package/dist/core/index.js.map +1 -1
- package/dist/mw_games.global.js +102 -102
- package/dist/mwl/catalog.d.ts +18 -2
- package/dist/mwl/catalog.d.ts.map +1 -1
- package/dist/mwl/catalog.js +0 -0
- package/dist/mwl/catalog.js.map +1 -1
- package/dist/mwl/content.d.ts +4 -0
- package/dist/mwl/content.d.ts.map +1 -1
- package/dist/mwl/content.js +2 -0
- package/dist/mwl/content.js.map +1 -1
- package/dist/mwl/grammar.d.ts.map +1 -1
- package/dist/mwl/grammar.js +37 -0
- package/dist/mwl/grammar.js.map +1 -1
- package/dist/mwl/hooks.d.ts +42 -1
- package/dist/mwl/hooks.d.ts.map +1 -1
- package/dist/mwl/hooks.js +41 -0
- package/dist/mwl/hooks.js.map +1 -1
- package/dist/mwl/index.d.ts +4 -4
- package/dist/mwl/index.d.ts.map +1 -1
- package/dist/mwl/index.js +2 -2
- package/dist/mwl/index.js.map +1 -1
- package/dist/mwl/runtime.d.ts +9 -0
- package/dist/mwl/runtime.d.ts.map +1 -1
- package/dist/mwl/runtime.js +70 -9
- package/dist/mwl/runtime.js.map +1 -1
- package/dist/mwl/schema.d.ts +33 -1
- package/dist/mwl/schema.d.ts.map +1 -1
- package/dist/mwl/schema.js +70 -10
- package/dist/mwl/schema.js.map +1 -1
- package/dist/roguelike/Targeting.d.ts +35 -0
- package/dist/roguelike/Targeting.d.ts.map +1 -1
- package/dist/roguelike/Targeting.js +72 -0
- package/dist/roguelike/Targeting.js.map +1 -1
- package/dist/roguelike/index.d.ts +2 -0
- package/dist/roguelike/index.d.ts.map +1 -1
- package/dist/roguelike/index.js +1 -0
- package/dist/roguelike/index.js.map +1 -1
- package/dist/rpg/Collision.d.ts.map +1 -1
- package/dist/rpg/Collision.js +1 -3
- package/dist/rpg/Collision.js.map +1 -1
- package/dist/two-d/pixi-interop.d.ts +28 -10
- package/dist/two-d/pixi-interop.d.ts.map +1 -1
- package/dist/two-d/pixi-interop.js +36 -10
- package/dist/two-d/pixi-interop.js.map +1 -1
- package/dist/two-d/render/Camera.d.ts +11 -0
- package/dist/two-d/render/Camera.d.ts.map +1 -1
- package/dist/two-d/render/Camera.js +14 -3
- package/dist/two-d/render/Camera.js.map +1 -1
- package/dist/two-d/render/ImageModifiers.d.ts +40 -0
- package/dist/two-d/render/ImageModifiers.d.ts.map +1 -1
- package/dist/two-d/render/ImageModifiers.js +47 -0
- package/dist/two-d/render/ImageModifiers.js.map +1 -1
- package/dist/two-d/render/PaletteRemap.d.ts.map +1 -1
- package/dist/two-d/render/PaletteRemap.js +12 -1
- package/dist/two-d/render/PaletteRemap.js.map +1 -1
- package/dist/two-d/render/Particles.d.ts +30 -9
- package/dist/two-d/render/Particles.d.ts.map +1 -1
- package/dist/two-d/render/Particles.js +42 -7
- package/dist/two-d/render/Particles.js.map +1 -1
- package/dist/two-d/render/Projectile.d.ts +16 -0
- package/dist/two-d/render/Projectile.d.ts.map +1 -1
- package/dist/two-d/render/Projectile.js +14 -0
- package/dist/two-d/render/Projectile.js.map +1 -1
- package/dist/two-d/render/ScreenEffects.d.ts +42 -4
- package/dist/two-d/render/ScreenEffects.d.ts.map +1 -1
- package/dist/two-d/render/ScreenEffects.js +64 -9
- package/dist/two-d/render/ScreenEffects.js.map +1 -1
- package/dist/two-d/render/Shape2D.d.ts +22 -2
- package/dist/two-d/render/Shape2D.d.ts.map +1 -1
- package/dist/two-d/render/Shape2D.js +31 -2
- package/dist/two-d/render/Shape2D.js.map +1 -1
- package/dist/two-d/render/SpriteSheet.d.ts +19 -3
- package/dist/two-d/render/SpriteSheet.d.ts.map +1 -1
- package/dist/two-d/render/SpriteSheet.js +26 -5
- package/dist/two-d/render/SpriteSheet.js.map +1 -1
- package/dist/two-d/render/StatusVisuals.d.ts +41 -23
- package/dist/two-d/render/StatusVisuals.d.ts.map +1 -1
- package/dist/two-d/render/StatusVisuals.js +65 -26
- package/dist/two-d/render/StatusVisuals.js.map +1 -1
- package/dist/two-d/render/index.d.ts +2 -2
- package/dist/two-d/render/index.d.ts.map +1 -1
- package/dist/two-d/render/index.js +2 -2
- package/dist/two-d/render/index.js.map +1 -1
- package/dist/two-d/ui/ListView.d.ts +9 -0
- package/dist/two-d/ui/ListView.d.ts.map +1 -1
- package/dist/two-d/ui/ListView.js +16 -6
- package/dist/two-d/ui/ListView.js.map +1 -1
- package/dist/two-d/ui/MarkupText.d.ts +14 -1
- package/dist/two-d/ui/MarkupText.d.ts.map +1 -1
- package/dist/two-d/ui/MarkupText.js +45 -11
- package/dist/two-d/ui/MarkupText.js.map +1 -1
- package/dist/two-d/ui/MessageBox.d.ts +10 -1
- package/dist/two-d/ui/MessageBox.d.ts.map +1 -1
- package/dist/two-d/ui/MessageBox.js +4 -1
- package/dist/two-d/ui/MessageBox.js.map +1 -1
- package/dist/two-d/ui/RichLabel.d.ts +7 -1
- package/dist/two-d/ui/RichLabel.d.ts.map +1 -1
- package/dist/two-d/ui/RichLabel.js +20 -9
- package/dist/two-d/ui/RichLabel.js.map +1 -1
- package/dist/two-d/ui/Window.d.ts +37 -1
- package/dist/two-d/ui/Window.d.ts.map +1 -1
- package/dist/two-d/ui/Window.js +55 -2
- package/dist/two-d/ui/Window.js.map +1 -1
- package/dist/two-d/ui/WindowStack.d.ts +24 -2
- package/dist/two-d/ui/WindowStack.d.ts.map +1 -1
- package/dist/two-d/ui/WindowStack.js +22 -1
- package/dist/two-d/ui/WindowStack.js.map +1 -1
- package/dist/two-d/ui/markup.d.ts +9 -1
- package/dist/two-d/ui/markup.d.ts.map +1 -1
- package/dist/two-d/ui/markup.js +20 -3
- package/dist/two-d/ui/markup.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +5 -1
- package/tools/classic-html.d.mts +6 -0
- package/tools/classic-html.mjs +61 -0
- package/tools/mwl.mjs +12 -0
|
@@ -4,6 +4,27 @@ import { reducedMotion } from '../../core/Motion.js';
|
|
|
4
4
|
function pick(range) {
|
|
5
5
|
return typeof range === 'number' ? range : Random.float(range[0], range[1]);
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* A colour from a range, mixed channel by channel: interpolating the packed value instead
|
|
9
|
+
* would carry from one channel into the next and walk through colours that are not between
|
|
10
|
+
* the two. One seeded draw drives all three channels, so a particle's colour is a point on
|
|
11
|
+
* the line between them rather than three unrelated picks.
|
|
12
|
+
*/
|
|
13
|
+
function pickTint(range) {
|
|
14
|
+
if (typeof range === 'number')
|
|
15
|
+
return range;
|
|
16
|
+
const t = Random.float();
|
|
17
|
+
const channel = (shift) => {
|
|
18
|
+
const from = (range[0] >> shift) & 0xff;
|
|
19
|
+
const to = (range[1] >> shift) & 0xff;
|
|
20
|
+
return Math.round(from + (to - from) * t) << shift;
|
|
21
|
+
};
|
|
22
|
+
return channel(16) | channel(8) | channel(0);
|
|
23
|
+
}
|
|
24
|
+
/** a pair of endpoints as a curve, so the update path only ever calls a function */
|
|
25
|
+
function curveOf(range) {
|
|
26
|
+
return typeof range === 'function' ? range : (t) => range[0] + (range[1] - range[0]) * t;
|
|
27
|
+
}
|
|
7
28
|
/**
|
|
8
29
|
* A pooled particle emitter: sparks off a sword hit, dust under a footstep, rain over a map.
|
|
9
30
|
*
|
|
@@ -58,9 +79,11 @@ export class ParticleEmitter extends Container {
|
|
|
58
79
|
this.angleRange = options.angle ?? [0, Math.PI * 2];
|
|
59
80
|
this.gravityX = options.gravity?.x ?? 0;
|
|
60
81
|
this.gravityY = options.gravity?.y ?? 0;
|
|
61
|
-
this.
|
|
62
|
-
this.
|
|
82
|
+
this.scaleOf = curveOf(options.scale ?? [1, 1]);
|
|
83
|
+
this.alphaOf = curveOf(options.alpha ?? [1, 0]);
|
|
84
|
+
this.flicker = Math.min(1, Math.max(0, options.flicker ?? 0));
|
|
63
85
|
this.spin = options.spin ?? 0;
|
|
86
|
+
this.tintRange = options.tint ?? 0xffffff;
|
|
64
87
|
this.frames = options.frames;
|
|
65
88
|
this.spawnArea = options.spawn ?? null;
|
|
66
89
|
for (let i = 0; i < max; i++) {
|
|
@@ -75,6 +98,7 @@ export class ParticleEmitter extends Container {
|
|
|
75
98
|
spin: 0,
|
|
76
99
|
scale: 1,
|
|
77
100
|
alpha: 1,
|
|
101
|
+
tint: 0xffffff,
|
|
78
102
|
frame: 0,
|
|
79
103
|
active: false,
|
|
80
104
|
});
|
|
@@ -83,7 +107,8 @@ export class ParticleEmitter extends Container {
|
|
|
83
107
|
const sprite = new Sprite(base);
|
|
84
108
|
sprite.anchor.set(0.5);
|
|
85
109
|
sprite.visible = false;
|
|
86
|
-
|
|
110
|
+
//one colour for the emitter is set once here; a range is per particle, in `draw`
|
|
111
|
+
if (typeof options.tint === 'number')
|
|
87
112
|
sprite.tint = options.tint;
|
|
88
113
|
this.sprites.push(sprite);
|
|
89
114
|
this.addChild(sprite);
|
|
@@ -155,8 +180,9 @@ export class ParticleEmitter extends Container {
|
|
|
155
180
|
particle.life = Math.max(1e-6, pick(this.life));
|
|
156
181
|
particle.rotation = 0;
|
|
157
182
|
particle.spin = pick(this.spin) * motion;
|
|
158
|
-
particle.scale = this.
|
|
159
|
-
particle.alpha = this.
|
|
183
|
+
particle.scale = this.scaleOf(0);
|
|
184
|
+
particle.alpha = this.alphaOf(0);
|
|
185
|
+
particle.tint = pickTint(this.tintRange);
|
|
160
186
|
particle.frame = 0;
|
|
161
187
|
particle.active = true;
|
|
162
188
|
return true;
|
|
@@ -217,8 +243,12 @@ export class ParticleEmitter extends Container {
|
|
|
217
243
|
particle.y += particle.vy * dt;
|
|
218
244
|
particle.rotation += particle.spin * dt;
|
|
219
245
|
const t = particle.age / particle.life;
|
|
220
|
-
particle.scale = this.
|
|
221
|
-
particle.alpha = this.
|
|
246
|
+
particle.scale = this.scaleOf(t);
|
|
247
|
+
particle.alpha = this.alphaOf(t);
|
|
248
|
+
//a flicker is motion that goes nowhere, so reduced motion drops it along with the
|
|
249
|
+
//travel and the spin; the curve underneath still plays
|
|
250
|
+
if (this.flicker > 0 && !frozen)
|
|
251
|
+
particle.scale *= 1 - this.flicker * Random.float();
|
|
222
252
|
//a frame sequence plays across the particle's own life, so `t` picks the frame the
|
|
223
253
|
//same way it interpolates scale and alpha; the last frame holds until it dies rather
|
|
224
254
|
//than falling off the end of the array
|
|
@@ -232,6 +262,9 @@ export class ParticleEmitter extends Container {
|
|
|
232
262
|
draw() {
|
|
233
263
|
if (this.sprites.length === 0)
|
|
234
264
|
return;
|
|
265
|
+
//asked once per frame rather than per particle: a plain tint was set at construction,
|
|
266
|
+
//while a range belongs to the particle and has to be assigned as it is drawn
|
|
267
|
+
const tintPerParticle = typeof this.tintRange !== 'number';
|
|
235
268
|
for (let i = 0; i < this.pool.length; i++) {
|
|
236
269
|
const particle = this.pool[i];
|
|
237
270
|
const sprite = this.sprites[i];
|
|
@@ -245,6 +278,8 @@ export class ParticleEmitter extends Container {
|
|
|
245
278
|
sprite.rotation = particle.rotation;
|
|
246
279
|
sprite.alpha = particle.alpha;
|
|
247
280
|
sprite.scale.set(particle.scale);
|
|
281
|
+
if (tintPerParticle)
|
|
282
|
+
sprite.tint = particle.tint;
|
|
248
283
|
//a frame sequence swaps the sprite's texture; a single-texture emitter leaves it
|
|
249
284
|
if (this.frames)
|
|
250
285
|
sprite.texture = this.frames[particle.frame] ?? sprite.texture;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Particles.js","sourceRoot":"","sources":["../../../src/two-d/render/Particles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"Particles.js","sourceRoot":"","sources":["../../../src/two-d/render/Particles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,MAAM,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAmIrD,SAAS,IAAI,CAAC,KAAoB;IACjC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7E,CAAC;AAED;;;;;GAKG;AACH,SAAS,QAAQ,CAAC,KAAoB;IACrC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5C,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC;IACzB,MAAM,OAAO,GAAG,CAAC,KAAa,EAAU,EAAE;QACzC,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC;QACxC,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,GAAG,IAAI,C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jC,IAAI,eAAe;gBAAE,MAAM,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC;YACjD,iFAAiF;YACjF,IAAI,IAAI,CAAC,MAAM;gBAAE,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC;QACjF,CAAC;IACF,CAAC;IAED,2EAA2E;IAC3E,KAAK;QACJ,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,IAAI;YAAE,QAAQ,CAAC,MAAM,GAAG,KAAK,CAAC;QAC1D,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;QACd,IAAI,CAAC,IAAI,EAAE,CAAC;IACb,CAAC;CACD"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Animation, AnimationFrame } from './AnimatedSprite.ts';
|
|
1
2
|
export interface ProjectilePoint {
|
|
2
3
|
x: number;
|
|
3
4
|
y: number;
|
|
@@ -7,6 +8,12 @@ export interface ProjectileOptions {
|
|
|
7
8
|
speed?: number;
|
|
8
9
|
/** seconds to cross the whole flight; overrides `speed` when both are given */
|
|
9
10
|
duration?: number;
|
|
11
|
+
/**
|
|
12
|
+
* Flight frames for the missile art. The projectile advances this with its own elapsed
|
|
13
|
+
* time, so a caller reads `frame`/`frameOffset` here instead of keeping a second
|
|
14
|
+
* animation and an elapsed clock in step with the tween.
|
|
15
|
+
*/
|
|
16
|
+
animation?: Animation;
|
|
10
17
|
}
|
|
11
18
|
/**
|
|
12
19
|
* Tweens a sprite's position in a straight line, world units to world units.
|
|
@@ -39,12 +46,21 @@ export declare class Projectile {
|
|
|
39
46
|
private toX;
|
|
40
47
|
private toY;
|
|
41
48
|
private duration;
|
|
49
|
+
private readonly animation?;
|
|
42
50
|
private elapsed;
|
|
43
51
|
private arrived;
|
|
44
52
|
constructor(sprite: ProjectilePoint, from: ProjectilePoint, to: ProjectilePoint, options?: ProjectileOptions);
|
|
45
53
|
get done(): boolean;
|
|
46
54
|
/** 0 at launch, 1 on arrival */
|
|
47
55
|
get progress(): number;
|
|
56
|
+
/** the frame the optional flight animation is on right now, or undefined without one */
|
|
57
|
+
get frame(): AnimationFrame | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Pixels that frame is drawn away from the sprite's own position. This class only reports
|
|
60
|
+
* it; the caller adds it where it already positions the sprite, the same rule
|
|
61
|
+
* `AnimatedSprite.frameOffset` follows.
|
|
62
|
+
*/
|
|
63
|
+
get frameOffset(): ProjectilePoint;
|
|
48
64
|
/** @returns true the instant it arrives, so a caller can trigger impact exactly once */
|
|
49
65
|
update(dt: number): boolean;
|
|
50
66
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Projectile.d.ts","sourceRoot":"","sources":["../../../src/two-d/render/Projectile.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC/B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACV;AAED,MAAM,WAAW,iBAAiB;IACjC,6DAA6D;IAC7D,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"Projectile.d.ts","sourceRoot":"","sources":["../../../src/two-d/render/Projectile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErE,MAAM,WAAW,eAAe;IAC/B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACV;AAED,MAAM,WAAW,iBAAiB;IACjC,6DAA6D;IAC7D,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;;OAIG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,UAAU;IACtB,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAY;IACvC,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,OAAO,CAAS;IAExB,YAAY,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,eAAe,EAAE,EAAE,EAAE,eAAe,EAAE,OAAO,GAAE,iBAAsB,EAe/G;IAED,IAAI,IAAI,IAAI,OAAO,CAElB;IAED,gCAAgC;IAChC,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,wFAAwF;IACxF,IAAI,KAAK,IAAI,cAAc,GAAG,SAAS,CAEtC;IAED;;;;OAIG;IACH,IAAI,WAAW,IAAI,eAAe,CAGjC;IAED,wFAAwF;IACxF,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAa1B;CACD"}
|
|
@@ -31,6 +31,7 @@ export class Projectile {
|
|
|
31
31
|
this.fromY = from.y;
|
|
32
32
|
this.toX = to.x;
|
|
33
33
|
this.toY = to.y;
|
|
34
|
+
this.animation = options.animation;
|
|
34
35
|
const distance = Math.hypot(to.x - from.x, to.y - from.y);
|
|
35
36
|
this.duration = options.duration ?? distance / (options.speed ?? 400);
|
|
36
37
|
//a zero-length flight (fired at your own feet) still resolves in one update
|
|
@@ -46,6 +47,19 @@ export class Projectile {
|
|
|
46
47
|
get progress() {
|
|
47
48
|
return Math.min(1, this.elapsed / this.duration);
|
|
48
49
|
}
|
|
50
|
+
/** the frame the optional flight animation is on right now, or undefined without one */
|
|
51
|
+
get frame() {
|
|
52
|
+
return this.animation?.frameAt(this.elapsed);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Pixels that frame is drawn away from the sprite's own position. This class only reports
|
|
56
|
+
* it; the caller adds it where it already positions the sprite, the same rule
|
|
57
|
+
* `AnimatedSprite.frameOffset` follows.
|
|
58
|
+
*/
|
|
59
|
+
get frameOffset() {
|
|
60
|
+
const frame = this.frame;
|
|
61
|
+
return { x: frame?.offsetX ?? 0, y: frame?.offsetY ?? 0 };
|
|
62
|
+
}
|
|
49
63
|
/** @returns true the instant it arrives, so a caller can trigger impact exactly once */
|
|
50
64
|
update(dt) {
|
|
51
65
|
if (this.arrived)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Projectile.js","sourceRoot":"","sources":["../../../src/two-d/render/Projectile.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Projectile.js","sourceRoot":"","sources":["../../../src/two-d/render/Projectile.ts"],"names":[],"mappings":"AAsBA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,OAAO,UAAU;IAWtB,YAAY,MAAuB,EAAE,IAAqB,EAAE,EAAmB,EAAE,OAAO,GAAsB,EAAE;QAHxG,YAAO,GAAG,CAAC,CAAC;QACZ,YAAO,GAAG,KAAK,CAAC;QAGvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC;QACpB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC;QACpB,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC;QAChB,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC;QAChB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QAEnC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAC1D,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,QAAQ,GAAG,CAA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AAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAEzD,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACZ,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;YACpB,OAAO,IAAI,CAAC;QACb,CAAC;QACD,OAAO,KAAK,CAAC;IACd,CAAC;CACD"}
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
import { Container } from 'pixi.js';
|
|
2
2
|
/** what the overlay is currently doing; `'idle'` covers both fully clear and a held tint */
|
|
3
|
-
export type ScreenEffectPhase = 'idle' | 'fadeOut' | 'fadeIn' | 'flash';
|
|
3
|
+
export type ScreenEffectPhase = 'idle' | 'fadeOut' | 'fadeIn' | 'flash' | 'hold';
|
|
4
4
|
export interface ScreenEffectsOptions {
|
|
5
5
|
width?: number;
|
|
6
6
|
height?: number;
|
|
7
7
|
/** the colour used when a call does not name one; defaults to black */
|
|
8
8
|
color?: number;
|
|
9
9
|
}
|
|
10
|
+
/** one step of a `sequence`; `hold` keeps the overlay exactly as the previous step left it */
|
|
11
|
+
export interface ScreenEffectStep {
|
|
12
|
+
kind: 'fadeOut' | 'fadeIn' | 'flash' | 'hold';
|
|
13
|
+
duration: number;
|
|
14
|
+
/** omit on `hold` to keep whatever tint the previous step left */
|
|
15
|
+
color?: number;
|
|
16
|
+
/** `flash` only; see `flash`'s own doc comment */
|
|
17
|
+
peak?: number;
|
|
18
|
+
}
|
|
10
19
|
/**
|
|
11
20
|
* A full-screen colour wash over everything else: fade out to black between floors, flash
|
|
12
21
|
* white on a critical hit, hold a red tint while poisoned.
|
|
@@ -35,6 +44,20 @@ export interface ScreenEffectsOptions {
|
|
|
35
44
|
*
|
|
36
45
|
* effects.setTint(0x336633, 0.3); // held green cast while poisoned
|
|
37
46
|
* ```
|
|
47
|
+
*
|
|
48
|
+
* `sequence` chains steps end to end, driven by the same `update(dt)` - `isBusy` stays true
|
|
49
|
+
* and `update` keeps returning false across every step boundary, only returning true once the
|
|
50
|
+
* whole sequence finishes, so a caller still needs no `await` for the genre-standard
|
|
51
|
+
* hold-then-fade-back transition `fadeOut`/`fadeIn`/`flash` alone cannot express:
|
|
52
|
+
*
|
|
53
|
+
* ```ts
|
|
54
|
+
* effects.sequence([
|
|
55
|
+
* { kind: 'fadeOut', duration: 0.3 },
|
|
56
|
+
* { kind: 'hold', duration: 0.5 }, // the new area loads while the screen is covered
|
|
57
|
+
* { kind: 'fadeIn', duration: 0.3 },
|
|
58
|
+
* ]);
|
|
59
|
+
* while (!effects.update(1 / 60)) continue; // drives every step, one frame at a time
|
|
60
|
+
* ```
|
|
38
61
|
*/
|
|
39
62
|
export declare class ScreenEffects extends Container {
|
|
40
63
|
private readonly overlay;
|
|
@@ -47,6 +70,8 @@ export declare class ScreenEffects extends Container {
|
|
|
47
70
|
/** alpha the current phase starts from and drives towards */
|
|
48
71
|
private fromAlpha;
|
|
49
72
|
private toAlpha;
|
|
73
|
+
/** steps still to run once the current one finishes, for `sequence` */
|
|
74
|
+
private queue;
|
|
50
75
|
constructor(options?: ScreenEffectsOptions);
|
|
51
76
|
/** call from a scene's own `resize`, so the wash keeps covering the whole canvas */
|
|
52
77
|
setViewport(width: number, height: number): void;
|
|
@@ -72,15 +97,28 @@ export declare class ScreenEffects extends Container {
|
|
|
72
97
|
* stuck at full white waiting for a second phase that no longer runs.
|
|
73
98
|
*/
|
|
74
99
|
flash(duration: number, color?: number, peak?: number): void;
|
|
100
|
+
/**
|
|
101
|
+
* Runs `steps` end to end - fade, hold, flash, in any order and count - driven by the
|
|
102
|
+
* same `update(dt)` as a single call: `isBusy` stays true and `update` keeps returning
|
|
103
|
+
* false at every step boundary, only returning true once the last step finishes. See this
|
|
104
|
+
* class's own doc comment for the hold-then-fade-back example this exists for. Replaces
|
|
105
|
+
* anything currently running or queued, the same as any other call here.
|
|
106
|
+
*/
|
|
107
|
+
sequence(steps: readonly ScreenEffectStep[]): void;
|
|
75
108
|
/**
|
|
76
109
|
* Holds a colour at a fixed opacity until changed - a poisoned green cast, an underwater
|
|
77
|
-
* blue. Cancels any running fade or
|
|
110
|
+
* blue. Cancels any running fade, flash or sequence, since those drive the same one overlay.
|
|
78
111
|
*/
|
|
79
112
|
setTint(color: number, alpha: number): void;
|
|
80
|
-
/** clears the overlay outright, running effect and held tint alike */
|
|
113
|
+
/** clears the overlay outright, running effect, sequence and held tint alike */
|
|
81
114
|
clear(): void;
|
|
115
|
+
/** @returns true if this step completed instantly (a non-positive duration) and the next one, if any, already started */
|
|
116
|
+
private beginStep;
|
|
117
|
+
/** starts the next queued step, or goes idle when the queue is empty; @returns true once idle */
|
|
118
|
+
private advance;
|
|
119
|
+
/** @returns true if `phase` is idle once this call returns (an instant cut may cascade through several queued steps) */
|
|
82
120
|
private begin;
|
|
83
|
-
/** @returns true on the single frame the running effect completes */
|
|
121
|
+
/** @returns true on the single frame the running effect (or the whole `sequence`) completes */
|
|
84
122
|
update(dt: number): boolean;
|
|
85
123
|
}
|
|
86
124
|
//# sourceMappingURL=ScreenEffects.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScreenEffects.d.ts","sourceRoot":"","sources":["../../../src/two-d/render/ScreenEffects.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAY,MAAM,SAAS,CAAC;AAI9C,4FAA4F;AAC5F,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"ScreenEffects.d.ts","sourceRoot":"","sources":["../../../src/two-d/render/ScreenEffects.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAY,MAAM,SAAS,CAAC;AAI9C,4FAA4F;AAC5F,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;AAEjF,MAAM,WAAW,oBAAoB;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MA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7C;IAED;;;;;;OAMG;IACH,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,SAAI,GAAG,IAAI,CAEtD;IAED;;;;;;OAMG;IACH,QAAQ,CAAC,KAAK,EAAE,SAAS,gBAAgB,EAAE,GAAG,IAAI,CAOjD;IAED;;;OAGG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAM1C;IAED,gFAAgF;IAChF,KAAK,IAAI,IAAI,CAMZ;IAED,yHAAyH;IACzH,OAAO,CAAC,SAAS;IAqBjB,iGAAiG;IACjG,OAAO,CAAC,OAAO;IAOf,wHAAwH;IACxH,OAAO,CAAC,KAAK;IAqBb,+FAA+F;IAC/F,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CA2B1B;CACD"}
|
|
@@ -29,6 +29,20 @@ import { reducedMotion } from '../../core/Motion.js';
|
|
|
29
29
|
*
|
|
30
30
|
* effects.setTint(0x336633, 0.3); // held green cast while poisoned
|
|
31
31
|
* ```
|
|
32
|
+
*
|
|
33
|
+
* `sequence` chains steps end to end, driven by the same `update(dt)` - `isBusy` stays true
|
|
34
|
+
* and `update` keeps returning false across every step boundary, only returning true once the
|
|
35
|
+
* whole sequence finishes, so a caller still needs no `await` for the genre-standard
|
|
36
|
+
* hold-then-fade-back transition `fadeOut`/`fadeIn`/`flash` alone cannot express:
|
|
37
|
+
*
|
|
38
|
+
* ```ts
|
|
39
|
+
* effects.sequence([
|
|
40
|
+
* { kind: 'fadeOut', duration: 0.3 },
|
|
41
|
+
* { kind: 'hold', duration: 0.5 }, // the new area loads while the screen is covered
|
|
42
|
+
* { kind: 'fadeIn', duration: 0.3 },
|
|
43
|
+
* ]);
|
|
44
|
+
* while (!effects.update(1 / 60)) continue; // drives every step, one frame at a time
|
|
45
|
+
* ```
|
|
32
46
|
*/
|
|
33
47
|
export class ScreenEffects extends Container {
|
|
34
48
|
constructor(options = {}) {
|
|
@@ -40,6 +54,8 @@ export class ScreenEffects extends Container {
|
|
|
40
54
|
/** alpha the current phase starts from and drives towards */
|
|
41
55
|
this.fromAlpha = 0;
|
|
42
56
|
this.toAlpha = 0;
|
|
57
|
+
/** steps still to run once the current one finishes, for `sequence` */
|
|
58
|
+
this.queue = [];
|
|
43
59
|
this.defaultColor = options.color ?? 0x000000;
|
|
44
60
|
this.viewWidth = options.width ?? 0;
|
|
45
61
|
this.viewHeight = options.height ?? 0;
|
|
@@ -91,23 +107,64 @@ export class ScreenEffects extends Container {
|
|
|
91
107
|
flash(duration, color, peak = 1) {
|
|
92
108
|
this.begin('flash', duration, 0, peak, color);
|
|
93
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Runs `steps` end to end - fade, hold, flash, in any order and count - driven by the
|
|
112
|
+
* same `update(dt)` as a single call: `isBusy` stays true and `update` keeps returning
|
|
113
|
+
* false at every step boundary, only returning true once the last step finishes. See this
|
|
114
|
+
* class's own doc comment for the hold-then-fade-back example this exists for. Replaces
|
|
115
|
+
* anything currently running or queued, the same as any other call here.
|
|
116
|
+
*/
|
|
117
|
+
sequence(steps) {
|
|
118
|
+
this.queue = steps.slice(1);
|
|
119
|
+
if (steps.length === 0) {
|
|
120
|
+
this.phase = 'idle';
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
this.beginStep(steps[0]);
|
|
124
|
+
}
|
|
94
125
|
/**
|
|
95
126
|
* Holds a colour at a fixed opacity until changed - a poisoned green cast, an underwater
|
|
96
|
-
* blue. Cancels any running fade or
|
|
127
|
+
* blue. Cancels any running fade, flash or sequence, since those drive the same one overlay.
|
|
97
128
|
*/
|
|
98
129
|
setTint(color, alpha) {
|
|
130
|
+
this.queue = [];
|
|
99
131
|
this.phase = 'idle';
|
|
100
132
|
this.elapsed = 0;
|
|
101
133
|
this.overlay.tint = color;
|
|
102
134
|
this.overlay.alpha = Math.max(0, Math.min(1, alpha));
|
|
103
135
|
}
|
|
104
|
-
/** clears the overlay outright, running effect and held tint alike */
|
|
136
|
+
/** clears the overlay outright, running effect, sequence and held tint alike */
|
|
105
137
|
clear() {
|
|
138
|
+
this.queue = [];
|
|
106
139
|
this.phase = 'idle';
|
|
107
140
|
this.elapsed = 0;
|
|
108
141
|
this.overlay.alpha = 0;
|
|
109
142
|
this.overlay.tint = this.defaultColor;
|
|
110
143
|
}
|
|
144
|
+
/** @returns true if this step completed instantly (a non-positive duration) and the next one, if any, already started */
|
|
145
|
+
beginStep(step) {
|
|
146
|
+
switch (step.kind) {
|
|
147
|
+
case 'fadeOut':
|
|
148
|
+
return this.begin('fadeOut', step.duration, this.overlay.alpha, 1, step.color);
|
|
149
|
+
case 'fadeIn':
|
|
150
|
+
return this.begin('fadeIn', step.duration, this.overlay.alpha, 0, step.color);
|
|
151
|
+
case 'flash':
|
|
152
|
+
return this.begin('flash', step.duration, 0, step.peak ?? 1, step.color);
|
|
153
|
+
case 'hold':
|
|
154
|
+
//no explicit colour keeps whatever tint the previous step left, rather than
|
|
155
|
+
//begin()'s usual fall back to the default colour
|
|
156
|
+
return this.begin('hold', step.duration, this.overlay.alpha, this.overlay.alpha, step.color ?? this.overlay.tint);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/** starts the next queued step, or goes idle when the queue is empty; @returns true once idle */
|
|
160
|
+
advance() {
|
|
161
|
+
const next = this.queue.shift();
|
|
162
|
+
if (next)
|
|
163
|
+
return this.beginStep(next);
|
|
164
|
+
this.phase = 'idle';
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
/** @returns true if `phase` is idle once this call returns (an instant cut may cascade through several queued steps) */
|
|
111
168
|
begin(phase, duration, from, to, color) {
|
|
112
169
|
//reduced motion turns a fade or flash into the instant cut a non-positive duration is
|
|
113
170
|
if (reducedMotion())
|
|
@@ -120,13 +177,13 @@ export class ScreenEffects extends Container {
|
|
|
120
177
|
//a non-positive duration is an instant cut, applied now rather than a frame later
|
|
121
178
|
if (!(duration > 0)) {
|
|
122
179
|
this.overlay.alpha = phase === 'flash' ? 0 : to;
|
|
123
|
-
this.
|
|
124
|
-
return;
|
|
180
|
+
return this.advance();
|
|
125
181
|
}
|
|
126
182
|
this.phase = phase;
|
|
127
183
|
this.overlay.alpha = phase === 'flash' ? 0 : from;
|
|
184
|
+
return false;
|
|
128
185
|
}
|
|
129
|
-
/** @returns true on the single frame the running effect completes */
|
|
186
|
+
/** @returns true on the single frame the running effect (or the whole `sequence`) completes */
|
|
130
187
|
update(dt) {
|
|
131
188
|
if (this.phase === 'idle')
|
|
132
189
|
return false;
|
|
@@ -134,8 +191,7 @@ export class ScreenEffects extends Container {
|
|
|
134
191
|
//trigger, so finish it at once rather than letting the running one play out
|
|
135
192
|
if (reducedMotion()) {
|
|
136
193
|
this.overlay.alpha = this.phase === 'flash' ? 0 : this.toAlpha;
|
|
137
|
-
this.
|
|
138
|
-
return true;
|
|
194
|
+
return this.advance();
|
|
139
195
|
}
|
|
140
196
|
this.elapsed += dt;
|
|
141
197
|
const t = Math.min(1, this.elapsed / this.duration);
|
|
@@ -150,8 +206,7 @@ export class ScreenEffects extends Container {
|
|
|
150
206
|
}
|
|
151
207
|
if (t >= 1) {
|
|
152
208
|
this.overlay.alpha = this.phase === 'flash' ? 0 : this.toAlpha;
|
|
153
|
-
this.
|
|
154
|
-
return true;
|
|
209
|
+
return this.advance();
|
|
155
210
|
}
|
|
156
211
|
return false;
|
|
157
212
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScreenEffects.js","sourceRoot":"","sources":["../../../src/two-d/render/ScreenEffects.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"ScreenEffects.js","sourceRoot":"","sources":["../../../src/two-d/render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AAC;aAAM,CAAC;YACP,MAAM,KAAK,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;YACtC,IAAI,CAAC,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,GAAG,CAAC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC;QAC/E,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACZ,IAAI,CAAC,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC;YAC/D,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;QACvB,CAAC;QACD,OAAO,KAAK,CAAC;IACd,CAAC;CACD"}
|
|
@@ -2,8 +2,10 @@ import { Container, Graphics, Text, TilingSprite, FillGradient, Sprite } from 'p
|
|
|
2
2
|
/**
|
|
3
3
|
* A plain grouping container under an MWG-owned name, for the common "just group some
|
|
4
4
|
* children" need `Scene2D.stage` itself covers for the whole scene - a sub-layer inside it
|
|
5
|
-
* (a HUD strip, a creature layer, a popup stack) still needs its own constructible class
|
|
6
|
-
*
|
|
5
|
+
* (a HUD strip, a creature layer, a popup stack) still needs its own constructible class.
|
|
6
|
+
* `Container2D` (`Types2D.ts`) is itself a value re-export of the same underlying class, so
|
|
7
|
+
* `new Container2D()` also works; `Node2D` exists as the name this module and its own doc
|
|
8
|
+
* comments actually use, so a game reads one name rather than two for the same thing.
|
|
7
9
|
*
|
|
8
10
|
* A bare re-export under this name, deliberately: Pixi's own `Container` already does
|
|
9
11
|
* everything this needs, so the point is not to add behaviour but to give a game a name it
|
|
@@ -21,6 +23,24 @@ import { Container, Graphics, Text, TilingSprite, FillGradient, Sprite } from 'p
|
|
|
21
23
|
*/
|
|
22
24
|
export declare class Node2D extends Container {
|
|
23
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates one labeled `Node2D` per name, attached to `parent` in the order given, and returns
|
|
28
|
+
* them keyed by name. A game with a dozen conventionally-ordered layers (terrain, units, effects,
|
|
29
|
+
* UI, ...) otherwise hand-wires each one and adds them in the right order everywhere; this is that
|
|
30
|
+
* boilerplate once. The names and their order stay the caller's own convention - nothing here
|
|
31
|
+
* decides what a layer is called or which should draw on top.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { Node2D, createLayers, Sprite2D } from '@datamoc/mw_games/two-d/render';
|
|
36
|
+
*
|
|
37
|
+
* const stage = new Node2D();
|
|
38
|
+
* const layers = createLayers(stage, ['terrain', 'units', 'effects', 'ui']);
|
|
39
|
+
* layers.units.addChild(new Sprite2D());
|
|
40
|
+
* console.log(layers.effects.label); // 'effects'
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function createLayers(parent: Container, names: readonly string[]): Record<string, Node2D>;
|
|
24
44
|
/**
|
|
25
45
|
* Vector drawing - rectangles, circles, polygons, lines - under an MWG-owned name.
|
|
26
46
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Shape2D.d.ts","sourceRoot":"","sources":["../../../src/two-d/render/Shape2D.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAExF
|
|
1
|
+
{"version":3,"file":"Shape2D.d.ts","sourceRoot":"","sources":["../../../src/two-d/render/Shape2D.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAExF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,MAAO,SAAQ,SAAS;CAAG;AAExC;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAShG;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,OAAQ,SAAQ,QAAQ;CAAG;AAExC;;;;;;;;;;;;;GAaG;AACH,qBAAa,MAAO,SAAQ,IAAI;CAAG;AAEnC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,QAAS,SAAQ,MAAM;CAAG;AAEvC;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,WAAY,SAAQ,YAAY;CAAG;AAEhD;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,QAAQ,qBAAe,CAAC"}
|
|
@@ -2,8 +2,10 @@ import { Container, Graphics, Text, TilingSprite, FillGradient, Sprite } from 'p
|
|
|
2
2
|
/**
|
|
3
3
|
* A plain grouping container under an MWG-owned name, for the common "just group some
|
|
4
4
|
* children" need `Scene2D.stage` itself covers for the whole scene - a sub-layer inside it
|
|
5
|
-
* (a HUD strip, a creature layer, a popup stack) still needs its own constructible class
|
|
6
|
-
*
|
|
5
|
+
* (a HUD strip, a creature layer, a popup stack) still needs its own constructible class.
|
|
6
|
+
* `Container2D` (`Types2D.ts`) is itself a value re-export of the same underlying class, so
|
|
7
|
+
* `new Container2D()` also works; `Node2D` exists as the name this module and its own doc
|
|
8
|
+
* comments actually use, so a game reads one name rather than two for the same thing.
|
|
7
9
|
*
|
|
8
10
|
* A bare re-export under this name, deliberately: Pixi's own `Container` already does
|
|
9
11
|
* everything this needs, so the point is not to add behaviour but to give a game a name it
|
|
@@ -21,6 +23,33 @@ import { Container, Graphics, Text, TilingSprite, FillGradient, Sprite } from 'p
|
|
|
21
23
|
*/
|
|
22
24
|
export class Node2D extends Container {
|
|
23
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates one labeled `Node2D` per name, attached to `parent` in the order given, and returns
|
|
28
|
+
* them keyed by name. A game with a dozen conventionally-ordered layers (terrain, units, effects,
|
|
29
|
+
* UI, ...) otherwise hand-wires each one and adds them in the right order everywhere; this is that
|
|
30
|
+
* boilerplate once. The names and their order stay the caller's own convention - nothing here
|
|
31
|
+
* decides what a layer is called or which should draw on top.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { Node2D, createLayers, Sprite2D } from '@datamoc/mw_games/two-d/render';
|
|
36
|
+
*
|
|
37
|
+
* const stage = new Node2D();
|
|
38
|
+
* const layers = createLayers(stage, ['terrain', 'units', 'effects', 'ui']);
|
|
39
|
+
* layers.units.addChild(new Sprite2D());
|
|
40
|
+
* console.log(layers.effects.label); // 'effects'
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export function createLayers(parent, names) {
|
|
44
|
+
const layers = {};
|
|
45
|
+
for (const name of names) {
|
|
46
|
+
const layer = new Node2D();
|
|
47
|
+
layer.label = name;
|
|
48
|
+
parent.addChild(layer);
|
|
49
|
+
layers[name] = layer;
|
|
50
|
+
}
|
|
51
|
+
return layers;
|
|
52
|
+
}
|
|
24
53
|
/**
|
|
25
54
|
* Vector drawing - rectangles, circles, polygons, lines - under an MWG-owned name.
|
|
26
55
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Shape2D.js","sourceRoot":"","sources":["../../../src/two-d/render/Shape2D.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAExF
|
|
1
|
+
{"version":3,"file":"Shape2D.js","sourceRoot":"","sources":["../../../src/two-d/render/Shape2D.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAExF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,MAAO,SAAQ,SAAS;CAAG;AAExC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,YAAY,CAAC,MAAiB,EAAE,KAAwB;IACvE,MAAM,MAAM,GAA2B,EAAE,CAAC;IAC1C,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,MAAM,KAAK,GAAG,IAAI,MAAM,EAAE,CAAC;QAC3B,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC;QACnB,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACvB,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;IACtB,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,OAAQ,SAAQ,QAAQ;CAAG;AAExC;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,MAAO,SAAQ,IAAI;CAAG;AAEnC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,QAAS,SAAQ,MAAM;CAAG;AAEvC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,WAAY,SAAQ,YAAY;CAAG;AAEhD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,YAAY,CAAC"}
|
|
@@ -6,6 +6,10 @@ import { type TextureRegion, type Texture2D } from './Types2D.ts';
|
|
|
6
6
|
* case and `name` labels the frames that matter. Frames are cut once and cached: asking
|
|
7
7
|
* for the same index twice returns the same Texture, so sprites sharing a frame also share
|
|
8
8
|
* a texture and stay in one batch.
|
|
9
|
+
*
|
|
10
|
+
* The rest are not grids at all: a hand-packed icon atlas, a strip of bar segments, a
|
|
11
|
+
* nine-patch's corners. Those declare their own rectangles with `rect`, and the sheet is
|
|
12
|
+
* built with no frame size, which leaves it with no grid and only the frames declared.
|
|
9
13
|
*/
|
|
10
14
|
export declare class SpriteSheet {
|
|
11
15
|
readonly texture: Texture2D;
|
|
@@ -17,12 +21,13 @@ export declare class SpriteSheet {
|
|
|
17
21
|
private names;
|
|
18
22
|
private constructor();
|
|
19
23
|
/**
|
|
20
|
-
* Cuts a loaded texture into a grid, numbered left to right then top to bottom
|
|
24
|
+
* Cuts a loaded texture into a grid, numbered left to right then top to bottom, or, with
|
|
25
|
+
* no frame size, leaves the sheet with no grid for `rect` to fill in.
|
|
21
26
|
*
|
|
22
27
|
* @param path the asset path the texture was loaded with
|
|
23
28
|
*/
|
|
24
|
-
static grid(path: string, frameWidth
|
|
25
|
-
static fromTexture(texture: Texture2D, frameWidth
|
|
29
|
+
static grid(path: string, frameWidth?: number, frameHeight?: number): SpriteSheet;
|
|
30
|
+
static fromTexture(texture: Texture2D, frameWidth?: number, frameHeight?: number): SpriteSheet;
|
|
26
31
|
get count(): number;
|
|
27
32
|
/** gives a frame a name, so game code reads `sheet.get('door')` rather than `sheet.get(6)` */
|
|
28
33
|
name(name: string, index: number): this;
|
|
@@ -30,6 +35,17 @@ export declare class SpriteSheet {
|
|
|
30
35
|
nameAll(names: Readonly<Record<string, number>>): this;
|
|
31
36
|
indexOf(name: string): number;
|
|
32
37
|
get(frame: number | string): Texture2D;
|
|
38
|
+
/**
|
|
39
|
+
* Cuts an arbitrary rectangle out of the texture, for a sheet that is not a grid: one
|
|
40
|
+
* hand-packed icon, two banner frames, the corners of a nine-patch.
|
|
41
|
+
*
|
|
42
|
+
* The rectangle is cached under `index` exactly like a grid frame, so `get`, `region`,
|
|
43
|
+
* `name` and `pick` all treat it as a frame and asking for it twice returns the same
|
|
44
|
+
* `Texture` rather than cutting a second one. Declaring a rect for an index the grid
|
|
45
|
+
* also covers replaces that frame, which is what a tightened sub-rect of a cell is:
|
|
46
|
+
* an item whose art is smaller than its 16 by 16 cell keeps its index and its name.
|
|
47
|
+
*/
|
|
48
|
+
rect(index: number, x: number, y: number, width: number, height: number): this;
|
|
33
49
|
/** the texture and frame rectangle together, as plain MWG types rather than `pixi.js`'s
|
|
34
50
|
* `Texture`/`Rectangle` - for a game that needs the geometry, not just the cut texture */
|
|
35
51
|
region(frame: number | string): TextureRegion;
|