@datamoc/mw_games 0.13.0 → 0.14.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 +92 -0
- package/README.md +5 -1
- package/dist/board/Classics.d.ts.map +1 -1
- package/dist/board/Classics.js +3 -2
- package/dist/board/Classics.js.map +1 -1
- package/dist/board/FogOfWar.d.ts.map +1 -1
- package/dist/board/FogOfWar.js +5 -2
- package/dist/board/FogOfWar.js.map +1 -1
- package/dist/board/HexSkirmish.d.ts.map +1 -1
- package/dist/board/HexSkirmish.js +2 -1
- package/dist/board/HexSkirmish.js.map +1 -1
- package/dist/core/Grid.d.ts +64 -0
- package/dist/core/Grid.d.ts.map +1 -0
- package/dist/core/Grid.js +76 -0
- package/dist/core/Grid.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 +107 -107
- package/dist/roguelike/Level.d.ts.map +1 -1
- package/dist/roguelike/Level.js +5 -4
- package/dist/roguelike/Level.js.map +1 -1
- package/dist/two-d/Game.d.ts +24 -0
- package/dist/two-d/Game.d.ts.map +1 -1
- package/dist/two-d/Game.js +42 -1
- package/dist/two-d/Game.js.map +1 -1
- package/dist/two-d/ResolutionFit.d.ts +28 -0
- package/dist/two-d/ResolutionFit.d.ts.map +1 -0
- package/dist/two-d/ResolutionFit.js +39 -0
- package/dist/two-d/ResolutionFit.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -1
- package/tools/classic-html.mjs +1 -1
- package/tools/compress-dist.d.mts +18 -0
- package/tools/compress-dist.mjs +5 -0
- package/tools/single-file.d.mts +16 -0
- package/tools/single-file.mjs +8 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Level.d.ts","sourceRoot":"","sources":["../../src/roguelike/Level.ts"],"names":[],"mappings":"
|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AAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAEtC;IAED,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAEzC;IAED,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAIvC;IAED,mEAAmE;IACnE,aAAa,IAAI,MAAM,EAAE,CAMxB;IAED,MAAM,IAAI;QACT,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,UAAU,CAAC;QAClB,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,KAAK,EAAE,IAAI,EAAE,CAAC;QACd,YAAY,CAAC,EAAE,MAAM,CAAC;KACtB,CASA;IAED;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CACd,KAAK,EAAE,WAAW,EAAE,EACpB,IAAI,EAAE;QACL,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,UAAU,CAAC;QAClB,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,KAAK,EAAE,IAAI,EAAE,CAAC;QACd,YAAY,CAAC,EAAE,MAAM,CAAC;KACtB,GACC,KAAK,CAKP;CACD;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAK/D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,SAAI,GAAG,OAAO,CAOlE"}
|
package/dist/roguelike/Level.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { hexNeighbors } from '../core/Hex.js';
|
|
2
|
+
import { cellIndex, cellInside, cellX, cellY } from '../core/Grid.js';
|
|
2
3
|
//one frozen table per topology, shared by every caller: these sit inside the hottest loops
|
|
3
4
|
//here (a flood fill calls `neighbors` per cell), so a fresh array per call was pure GC churn
|
|
4
5
|
const OFFSET_4 = [
|
|
@@ -76,16 +77,16 @@ export class Level {
|
|
|
76
77
|
return this.width * this.height;
|
|
77
78
|
}
|
|
78
79
|
index(x, y) {
|
|
79
|
-
return
|
|
80
|
+
return cellIndex(this.width, x, y);
|
|
80
81
|
}
|
|
81
82
|
xOf(cell) {
|
|
82
|
-
return
|
|
83
|
+
return cellX(this.width, cell);
|
|
83
84
|
}
|
|
84
85
|
yOf(cell) {
|
|
85
|
-
return
|
|
86
|
+
return cellY(this.width, cell);
|
|
86
87
|
}
|
|
87
88
|
inside(x, y) {
|
|
88
|
-
return
|
|
89
|
+
return cellInside(this.width, this.height, x, y);
|
|
89
90
|
}
|
|
90
91
|
/**
|
|
91
92
|
* The cells adjacent to `(x, y)` - six of them on a hex `Level`, four or eight on a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Level.js","sourceRoot":"","sources":["../../src/roguelike/Level.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"Level.js","sourceRoot":"","sources":["../../src/roguelike/Level.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AActE,2FAA2F;AAC3F,6FAA6F;AAC7F,MAAM,QAAQ,GAA6C;IAC1D,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,EAAE,CAAC,CAAC;IACN,CAAC,CAAC,EAAE,CAAC,CAAC;IACN,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;CACP,CAAC;AAEF,MAAM,QAAQ,GAA6C;IAC1D,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,EAAE,CAAC,C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AG,IAAI,EAAE,CAAC,CAAC,CAAC;QACtD,OAAO,KAAK,CAAC;IACd,CAAC;CACD;AAED,MAAM,UAAU,UAAU,CAAC,IAAU;IACpC,OAAO;QACN,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC3C,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;KAC3C,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,YAAY,CAAC,CAAO,EAAE,CAAO,EAAE,MAAM,GAAG,CAAC;IACxD,OAAO,CAAC,CACP,CAAC,CAAC,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC,IAAI;QACzB,CAAC,CAAC,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC,IAAI;QACzB,CAAC,CAAC,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,GAAG;QACzB,CAAC,CAAC,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,GAAG,CACzB,CAAC;AACH,CAAC"}
|
package/dist/two-d/Game.d.ts
CHANGED
|
@@ -53,6 +53,13 @@ export interface GameOptions {
|
|
|
53
53
|
* The application: owns the renderer, the loop, and the current scene.
|
|
54
54
|
*
|
|
55
55
|
* Construct it, `await start(FirstScene)`, and the rest is scenes.
|
|
56
|
+
*
|
|
57
|
+
* The canvas is drawn at the display's `devicePixelRatio`, up to what the device can actually
|
|
58
|
+
* make: a backing store of `viewport * devicePixelRatio` pixels is refused past the GPU's
|
|
59
|
+
* `MAX_TEXTURE_SIZE` (WebGL clamps it rather than failing, with nothing reported), so the
|
|
60
|
+
* resolution is reduced to the largest whole number that fits and a warning says so. A game
|
|
61
|
+
* therefore keeps rendering on a device with a small limit, softer than the display asked for
|
|
62
|
+
* rather than wrong; nothing changes on a device that can afford what it asked for.
|
|
56
63
|
*/
|
|
57
64
|
export declare class Game {
|
|
58
65
|
private static instance;
|
|
@@ -132,6 +139,23 @@ export declare class Game {
|
|
|
132
139
|
* Neither is read by the framework. Nothing depends on them existing.
|
|
133
140
|
*/
|
|
134
141
|
private expose;
|
|
142
|
+
/**
|
|
143
|
+
* Resizes the renderer to a resolution this device can actually afford.
|
|
144
|
+
*
|
|
145
|
+
* A full-window canvas at device resolution can ask for a backing store larger than the
|
|
146
|
+
* GPU's `MAX_TEXTURE_SIZE`, and WebGL clamps that silently instead of failing: the canvas
|
|
147
|
+
* keeps its size, the scene keeps being rendered into a surface that is not the one asked
|
|
148
|
+
* for, and nothing anywhere says so. A 1080-wide phone at `devicePixelRatio` 2.625 asks for
|
|
149
|
+
* 2121x4709 against the 4096 limit one emulator reported, and got a 2121x4096 drawing
|
|
150
|
+
* buffer; see `fitResolution` for the arithmetic and for what that investigation did and
|
|
151
|
+
* did not establish about the black screen that process showed.
|
|
152
|
+
*
|
|
153
|
+
* Called after `init`, whenever the renderer is resized (a rotation changes which one fits),
|
|
154
|
+
* and when `devicePixelRatio` itself changes. It returns immediately when the device can
|
|
155
|
+
* afford what was asked for, which is every ordinary case, so nothing about a normal
|
|
156
|
+
* startup changes.
|
|
157
|
+
*/
|
|
158
|
+
private fitResolutionToDevice;
|
|
135
159
|
private frame;
|
|
136
160
|
private switchNow;
|
|
137
161
|
/** a new scene alone: everything else is destroyed, the clocks restart */
|
package/dist/two-d/Game.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Game.d.ts","sourceRoot":"","sources":["../../src/two-d/Game.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAiB,MAAM,SAAS,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EAAE,MAAM,EAAE,MAAM,mBA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E,WAAgB,EAwBpC;IAED,6EAA6E;IAC7E,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,wEAAwE;IACxE,MAAM,KAAK,OAAO,IAAI,IAAI,CAGzB;IAEK,KAAK,CAAC,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CA+DrD;IAED;;;;;OAKG;IACH,WAAW,CAAC,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,IAAI,CAE3C;IAED;;;;;;OAMG;IACH,SAAS,CAAC,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,IAAI,CAEzC;IAED;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI,CAE/B;IAED,yDAAyD;IACzD,IAAI,YAAY,IAAI,OAAO,GAAG,IAAI,CAEjC;IAED;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,SAAI,GAAG,IAAI,CAGzC;IAED;;;;;;;;OAQG;IACH,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAGrB;IAED;;;;;;;;;;OAUG;IACH,OAAO,CAAC,MAAM;IAMd;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,qBAAqB;IAc7B,OAAO,CAAC,KAAK;IA8Bb,OAAO,CAAC,SAAS;IAIjB,0EAA0E;IAC1E,OAAO,CAAC,WAAW;IAanB,+EAA+E;IAC/E,OAAO,CAAC,SAAS;IAYjB,kEAAkE;IAClE,OAAO,CAAC,QAAQ;IAMhB,OAAO,IAAI,IAAI,CAOd;CACD"}
|
package/dist/two-d/Game.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { Application, TextureSource } from 'pixi.js';
|
|
2
2
|
import { SceneStack } from '../core/SceneStack.js';
|
|
3
3
|
import { Signal } from '../core/Signal.js';
|
|
4
|
+
import { Logger } from '../core/Log.js';
|
|
5
|
+
import { fitResolution } from './ResolutionFit.js';
|
|
4
6
|
import * as Input from '../core/Input.js';
|
|
5
7
|
const PIXEL_ART_CLASS = 'mwg-pixel-art';
|
|
8
|
+
const log = new Logger('renderer');
|
|
6
9
|
/**
|
|
7
10
|
* A class beats an inline `canvas.style.imageRendering` because Pixi's own `autoDensity`/
|
|
8
11
|
* `resizeTo` rewrite the canvas's `style` attribute wholesale (see `start()`); this rule
|
|
@@ -42,6 +45,13 @@ function watchDevicePixelRatio(onChange) {
|
|
|
42
45
|
* The application: owns the renderer, the loop, and the current scene.
|
|
43
46
|
*
|
|
44
47
|
* Construct it, `await start(FirstScene)`, and the rest is scenes.
|
|
48
|
+
*
|
|
49
|
+
* The canvas is drawn at the display's `devicePixelRatio`, up to what the device can actually
|
|
50
|
+
* make: a backing store of `viewport * devicePixelRatio` pixels is refused past the GPU's
|
|
51
|
+
* `MAX_TEXTURE_SIZE` (WebGL clamps it rather than failing, with nothing reported), so the
|
|
52
|
+
* resolution is reduced to the largest whole number that fits and a warning says so. A game
|
|
53
|
+
* therefore keeps rendering on a device with a small limit, softer than the display asked for
|
|
54
|
+
* rather than wrong; nothing changes on a device that can afford what it asked for.
|
|
45
55
|
*/
|
|
46
56
|
export class Game {
|
|
47
57
|
static { this.instance = null; }
|
|
@@ -134,7 +144,11 @@ export class Game {
|
|
|
134
144
|
//them the backing size would push everything they centre off the screen.
|
|
135
145
|
this.app.renderer.on('resize', () => {
|
|
136
146
|
this.stack.resize(this.width, this.height);
|
|
147
|
+
//a rotation or a window resize changes how much of a backing store this device
|
|
148
|
+
//can afford, so re-fit rather than keeping whatever was chosen at startup
|
|
149
|
+
this.fitResolutionToDevice();
|
|
137
150
|
});
|
|
151
|
+
this.fitResolutionToDevice();
|
|
138
152
|
//the resolution passed to app.init() above is a one-time snapshot of
|
|
139
153
|
//devicePixelRatio; a later browser zoom (or dragging the window to a display with a
|
|
140
154
|
//different scale factor) changes that ratio without Pixi noticing on its own. Left
|
|
@@ -143,7 +157,7 @@ export class Game {
|
|
|
143
157
|
//non-integer ratio duplicates pixel columns inconsistently - the seams a pixel-art
|
|
144
158
|
//tilemap shows between tiles that were perfectly adjacent in the buffer itself.
|
|
145
159
|
this.stopWatchingDpr = watchDevicePixelRatio(() => {
|
|
146
|
-
this.
|
|
160
|
+
this.fitResolutionToDevice();
|
|
147
161
|
});
|
|
148
162
|
this.expose();
|
|
149
163
|
this.switchNow(first);
|
|
@@ -221,6 +235,33 @@ export class Game {
|
|
|
221
235
|
target.__PIXI_APP__ = this.app;
|
|
222
236
|
target.__MWG__ = this;
|
|
223
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* Resizes the renderer to a resolution this device can actually afford.
|
|
240
|
+
*
|
|
241
|
+
* A full-window canvas at device resolution can ask for a backing store larger than the
|
|
242
|
+
* GPU's `MAX_TEXTURE_SIZE`, and WebGL clamps that silently instead of failing: the canvas
|
|
243
|
+
* keeps its size, the scene keeps being rendered into a surface that is not the one asked
|
|
244
|
+
* for, and nothing anywhere says so. A 1080-wide phone at `devicePixelRatio` 2.625 asks for
|
|
245
|
+
* 2121x4709 against the 4096 limit one emulator reported, and got a 2121x4096 drawing
|
|
246
|
+
* buffer; see `fitResolution` for the arithmetic and for what that investigation did and
|
|
247
|
+
* did not establish about the black screen that process showed.
|
|
248
|
+
*
|
|
249
|
+
* Called after `init`, whenever the renderer is resized (a rotation changes which one fits),
|
|
250
|
+
* and when `devicePixelRatio` itself changes. It returns immediately when the device can
|
|
251
|
+
* afford what was asked for, which is every ordinary case, so nothing about a normal
|
|
252
|
+
* startup changes.
|
|
253
|
+
*/
|
|
254
|
+
fitResolutionToDevice() {
|
|
255
|
+
const gl = this.app.renderer.gl;
|
|
256
|
+
const limit = gl ? gl.getParameter(gl.MAX_TEXTURE_SIZE) : Number.POSITIVE_INFINITY;
|
|
257
|
+
const wanted = window.devicePixelRatio || 1;
|
|
258
|
+
const fitted = fitResolution(this.width, this.height, wanted, limit);
|
|
259
|
+
if (fitted === this.app.renderer.resolution)
|
|
260
|
+
return;
|
|
261
|
+
log.warn(`this device cannot render a ${this.width}x${this.height} canvas at ${wanted}x ` +
|
|
262
|
+
`(its limit is ${limit}); using ${fitted}x instead, which is softer than the display`);
|
|
263
|
+
this.app.renderer.resize(this.width, this.height, fitted);
|
|
264
|
+
}
|
|
224
265
|
frame(deltaSeconds) {
|
|
225
266
|
//queued scene changes run first, in order, so a frame never updates a
|
|
226
267
|
//scene that was already asked to leave
|
package/dist/two-d/Game.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Game.js","sourceRoot":"","sources":["../../src/two-d/Game.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGrD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAC;AAE1C,MAAM,eAAe,GAAG,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"Game.js","sourceRoot":"","sources":["../../src/two-d/Game.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGrD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAC;AAE1C,MAAM,eAAe,GAAG,eAAe,CAAC;AAExC,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,UAAU,CAAC,CAAC;AAQnC;;;;;GAKG;AACH,SAAS,wBAAwB;IAChC,IAAI,QAAQ,CAAC,cAAc,CAAC,eAAe,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,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACvB,IAAI,GAAG;YAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAChD,CAAC;IAED,OAAO;QACN,KAAK,CAAC,MAAM,EAAE,CAAC;QACf,IAAI,CAAC,eAAe,EAAE,EAAE,CAAC;QACzB,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QACrB,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;QACzB,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;QAC3C,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI;YAAE,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IAClD,CAAC;CACD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A renderer's backing store is `width * resolution` by `height * resolution` pixels, and a
|
|
3
|
+
* device's GPU has a `MAX_TEXTURE_SIZE` it will not go past. `Game` used to ask for the
|
|
4
|
+
* display's full `devicePixelRatio` whatever the canvas size, which on a large enough canvas is
|
|
5
|
+
* a request the device cannot honour: WebGL answers that by clamping the drawing buffer rather
|
|
6
|
+
* than failing, so the game carries on rendering into a surface that is not the one it asked
|
|
7
|
+
* for, with nothing reported anywhere.
|
|
8
|
+
*
|
|
9
|
+
* Measured, not assumed: a full-window canvas of 816x1812 css pixels at `devicePixelRatio`
|
|
10
|
+
* 2.625 asks for 2121x4709, and a device reporting a 4096 limit produced a drawing buffer
|
|
11
|
+
* clamped to 2121x4096. That same process painted an entirely black screen, but that is *not*
|
|
12
|
+
* attributed here: the failure did not reproduce (the emulator reported 8192 on every later
|
|
13
|
+
* start) and a deliberately clamped 1050x10500 request rendered correctly on the next process,
|
|
14
|
+
* so the black screen's cause was never established. What stands on its own is the clamped
|
|
15
|
+
* request, which is a size the game never asked for and cannot see.
|
|
16
|
+
*
|
|
17
|
+
* So the request is kept inside what the device says it can make. Whole numbers, because whole
|
|
18
|
+
* device pixels are the point: a fractional ratio duplicates pixel columns unevenly, the same
|
|
19
|
+
* reason `Game` watches `devicePixelRatio` in the first place.
|
|
20
|
+
*
|
|
21
|
+
* @param width logical width in css pixels (`renderer.screen.width`)
|
|
22
|
+
* @param height logical height in css pixels
|
|
23
|
+
* @param devicePixelRatio what the display asks for; never exceeded
|
|
24
|
+
* @param maxTextureSize the GPU's own limit, or any non-finite/non-positive value for "no cap"
|
|
25
|
+
* @returns the resolution to resize with, never above `devicePixelRatio`, never below 1
|
|
26
|
+
*/
|
|
27
|
+
export declare function fitResolution(width: number, height: number, devicePixelRatio: number, maxTextureSize: number): number;
|
|
28
|
+
//# sourceMappingURL=ResolutionFit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResolutionFit.d.ts","sourceRoot":"","sources":["../../src/two-d/ResolutionFit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CASrH"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A renderer's backing store is `width * resolution` by `height * resolution` pixels, and a
|
|
3
|
+
* device's GPU has a `MAX_TEXTURE_SIZE` it will not go past. `Game` used to ask for the
|
|
4
|
+
* display's full `devicePixelRatio` whatever the canvas size, which on a large enough canvas is
|
|
5
|
+
* a request the device cannot honour: WebGL answers that by clamping the drawing buffer rather
|
|
6
|
+
* than failing, so the game carries on rendering into a surface that is not the one it asked
|
|
7
|
+
* for, with nothing reported anywhere.
|
|
8
|
+
*
|
|
9
|
+
* Measured, not assumed: a full-window canvas of 816x1812 css pixels at `devicePixelRatio`
|
|
10
|
+
* 2.625 asks for 2121x4709, and a device reporting a 4096 limit produced a drawing buffer
|
|
11
|
+
* clamped to 2121x4096. That same process painted an entirely black screen, but that is *not*
|
|
12
|
+
* attributed here: the failure did not reproduce (the emulator reported 8192 on every later
|
|
13
|
+
* start) and a deliberately clamped 1050x10500 request rendered correctly on the next process,
|
|
14
|
+
* so the black screen's cause was never established. What stands on its own is the clamped
|
|
15
|
+
* request, which is a size the game never asked for and cannot see.
|
|
16
|
+
*
|
|
17
|
+
* So the request is kept inside what the device says it can make. Whole numbers, because whole
|
|
18
|
+
* device pixels are the point: a fractional ratio duplicates pixel columns unevenly, the same
|
|
19
|
+
* reason `Game` watches `devicePixelRatio` in the first place.
|
|
20
|
+
*
|
|
21
|
+
* @param width logical width in css pixels (`renderer.screen.width`)
|
|
22
|
+
* @param height logical height in css pixels
|
|
23
|
+
* @param devicePixelRatio what the display asks for; never exceeded
|
|
24
|
+
* @param maxTextureSize the GPU's own limit, or any non-finite/non-positive value for "no cap"
|
|
25
|
+
* @returns the resolution to resize with, never above `devicePixelRatio`, never below 1
|
|
26
|
+
*/
|
|
27
|
+
export function fitResolution(width, height, devicePixelRatio, maxTextureSize) {
|
|
28
|
+
const longest = Math.max(width, height);
|
|
29
|
+
if (!Number.isFinite(maxTextureSize) || maxTextureSize <= 0)
|
|
30
|
+
return devicePixelRatio;
|
|
31
|
+
if (!Number.isFinite(longest) || longest <= 0)
|
|
32
|
+
return devicePixelRatio;
|
|
33
|
+
if (longest * devicePixelRatio <= maxTextureSize)
|
|
34
|
+
return devicePixelRatio;
|
|
35
|
+
//a canvas longer than the limit even at 1x is left at 1x: nothing smaller can be offered,
|
|
36
|
+
//and scaling the scene down instead would move every coordinate a game depends on
|
|
37
|
+
return Math.max(1, Math.floor(maxTextureSize / longest));
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=ResolutionFit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResolutionFit.js","sourceRoot":"","sources":["../../src/two-d/ResolutionFit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa,EAAE,MAAc,EAAE,gBAAwB,EAAE,cAAsB;IAC5G,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACxC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,cAAc,IAAI,CAAC;QAAE,OAAO,gBAAgB,CAAC;IACrF,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,IAAI,CAAC;QAAE,OAAO,gBAAgB,CAAC;IACvE,IAAI,OAAO,GAAG,gBAAgB,IAAI,cAAc;QAAE,OAAO,gBAAgB,CAAC;IAE1E,0FAA0F;IAC1F,kFAAkF;IAClF,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,cAAc,GAAG,OAAO,CAAC,CAAC,CAAC;AAC1D,CAAC"}
|
package/dist/version.d.ts
CHANGED
|
@@ -9,5 +9,5 @@
|
|
|
9
9
|
* this from `package.json` automatically, chosen because this project's own build already
|
|
10
10
|
* has no step before `tsc`/`vite` that this would need to run ahead of.
|
|
11
11
|
*/
|
|
12
|
-
export declare const version = "0.
|
|
12
|
+
export declare const version = "0.14.0";
|
|
13
13
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.js
CHANGED
|
@@ -9,5 +9,5 @@
|
|
|
9
9
|
* this from `package.json` automatically, chosen because this project's own build already
|
|
10
10
|
* has no step before `tsc`/`vite` that this would need to run ahead of.
|
|
11
11
|
*/
|
|
12
|
-
export const version = '0.
|
|
12
|
+
export const version = '0.14.0';
|
|
13
13
|
//# sourceMappingURL=version.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datamoc/mw_games",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "A local-file game framework: renderer-free game logic, drawn through PixiJS in 2D or Babylon.js in 3D, with mobile and desktop packaging.",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -134,8 +134,11 @@
|
|
|
134
134
|
"types": "./dist/ai/lua.d.ts",
|
|
135
135
|
"import": "./dist/ai/lua.js"
|
|
136
136
|
},
|
|
137
|
+
"./tools/classic-html": "./tools/classic-html.mjs",
|
|
137
138
|
"./tools/compile-resources": "./tools/compile-resources.mjs",
|
|
138
139
|
"./tools/compress-dist": "./tools/compress-dist.mjs",
|
|
140
|
+
"./tools/extract-html": "./tools/extract-html.mjs",
|
|
141
|
+
"./tools/single-file": "./tools/single-file.mjs",
|
|
139
142
|
"./tools/webp-convert": "./tools/webp-convert.mjs",
|
|
140
143
|
"./two-d": {
|
|
141
144
|
"types": "./dist/two-d/index.d.ts",
|
package/tools/classic-html.mjs
CHANGED
|
@@ -23,7 +23,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
23
23
|
* @example
|
|
24
24
|
* ```js
|
|
25
25
|
* import { readFile, writeFile } from 'node:fs/promises';
|
|
26
|
-
* import { toClassicScript } from '@datamoc/mw_games/tools/classic-html
|
|
26
|
+
* import { toClassicScript } from '@datamoc/mw_games/tools/classic-html';
|
|
27
27
|
*
|
|
28
28
|
* const html = await readFile('dist/index.html', 'utf8');
|
|
29
29
|
* const result = toClassicScript(html);
|
|
@@ -1,9 +1,19 @@
|
|
|
1
|
+
/** Options for {@link compressDist}. */
|
|
1
2
|
export interface CompressOptions {
|
|
3
|
+
/** Write `.gz` siblings (default true). */
|
|
2
4
|
gzip?: boolean;
|
|
5
|
+
/** Write `.br` siblings (default true). */
|
|
3
6
|
brotli?: boolean;
|
|
7
|
+
/** Also write `.xz` siblings where smaller (default false, needs the system `xz`). */
|
|
4
8
|
xz?: boolean;
|
|
5
9
|
}
|
|
6
10
|
|
|
11
|
+
/**
|
|
12
|
+
* One considered file, with the sizes of the siblings actually written for it: `file` is
|
|
13
|
+
* relative to `dir`, and a size is 0 when that sibling was not asked for, was not smaller
|
|
14
|
+
* than the original, or (for `.xz`) needs a system binary that is not there. Files under the
|
|
15
|
+
* size floor, and extensions that are already compressed or not text, never produce a row.
|
|
16
|
+
*/
|
|
7
17
|
export interface CompressRow {
|
|
8
18
|
file: string;
|
|
9
19
|
raw: number;
|
|
@@ -12,5 +22,13 @@ export interface CompressRow {
|
|
|
12
22
|
xz: number;
|
|
13
23
|
}
|
|
14
24
|
|
|
25
|
+
/** True when the system `xz` binary (LZMA2) is available for the opt-in archive pass. */
|
|
15
26
|
export function hasXz(): boolean;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Writes compressed siblings for the large files in `dir`, *into that same folder*: the
|
|
30
|
+
* originals are left untouched, and each `<file>` gains `<file>.gz`, `<file>.br` and, when
|
|
31
|
+
* opted into, `<file>.xz`, beside it. There is no separate output directory, so pass a
|
|
32
|
+
* directory you own or a copy of the build output, not one you are about to publish.
|
|
33
|
+
*/
|
|
16
34
|
export function compressDist(dir: string, options?: CompressOptions): Promise<CompressRow[]>;
|
package/tools/compress-dist.mjs
CHANGED
|
@@ -58,6 +58,11 @@ function compressXz(data) {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
|
+
* Writes sibling files *into the folder it is given*: each `<file>.gz`/`.br`/`.xz` appears
|
|
62
|
+
* beside its original inside `dir`, which is rewritten in place, with no separate output
|
|
63
|
+
* directory. The originals themselves are never modified, so a caller whose `dist` is also
|
|
64
|
+
* what it publishes should still hand this a copy.
|
|
65
|
+
*
|
|
61
66
|
* @param dir folder to compress, normally an example's `dist`
|
|
62
67
|
* @param options.gzip write `.gz` siblings (default true)
|
|
63
68
|
* @param options.brotli write `.br` siblings (default true)
|
package/tools/single-file.d.mts
CHANGED
|
@@ -1,16 +1,32 @@
|
|
|
1
|
+
/** Options for {@link buildSingleFile}. */
|
|
1
2
|
export interface SingleFileOptions {
|
|
3
|
+
/** Path to the folder `emit-page.mjs` already wrote. */
|
|
2
4
|
dist: string;
|
|
5
|
+
/** Compress each inlined script before embedding it (default false). */
|
|
3
6
|
compress?: boolean;
|
|
7
|
+
/** Algorithm used when `compress` is set (default 'gzip'). */
|
|
4
8
|
algorithm?: 'gzip' | 'brotli';
|
|
9
|
+
/** gzip level 1-9, or brotli quality 0-11 (default 9 for gzip, 11 for brotli). */
|
|
5
10
|
level?: number;
|
|
11
|
+
/** Show a splash screen while the embedded scripts decode (default true). */
|
|
6
12
|
splash?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Output file *name*, written inside `dist` (default `standalone.html`). A name, not a
|
|
15
|
+
* path: one containing a separator is refused with a thrown error rather than joined
|
|
16
|
+
* onto `dist`. Additive, so `dist/index.html` is left as it was.
|
|
17
|
+
*/
|
|
7
18
|
output?: string;
|
|
8
19
|
}
|
|
9
20
|
|
|
21
|
+
/** What {@link buildSingleFile} wrote. */
|
|
10
22
|
export interface SingleFileResult {
|
|
23
|
+
/** Path of the written file: `dist` joined with `output`. */
|
|
11
24
|
path: string;
|
|
25
|
+
/** How many `<script src>` payloads were inlined. */
|
|
12
26
|
scripts: number;
|
|
27
|
+
/** Total size of that script code before compression. */
|
|
13
28
|
rawBytes: number;
|
|
29
|
+
/** Total length of the base64 payloads actually embedded, so after compression. */
|
|
14
30
|
embeddedBytes: number;
|
|
15
31
|
}
|
|
16
32
|
|
package/tools/single-file.mjs
CHANGED
|
@@ -51,7 +51,8 @@ import { fileURLToPath } from 'node:url';
|
|
|
51
51
|
* set (default 9 for gzip, 11 for brotli)
|
|
52
52
|
* @param {boolean} [options.splash] show a splash screen while scripts decode (default true)
|
|
53
53
|
* @param {string} [options.output] output file name, written inside `dist` (default
|
|
54
|
-
* `standalone.html`) -
|
|
54
|
+
* `standalone.html`) - a name, not a path: one containing a separator is refused rather than
|
|
55
|
+
* joined onto `dist`. Additive, so the existing multi-file `index.html` is untouched
|
|
55
56
|
* @returns {Promise<{path: string, scripts: number, rawBytes: number, embeddedBytes: number}>}
|
|
56
57
|
*/
|
|
57
58
|
export async function buildSingleFile({
|
|
@@ -66,6 +67,12 @@ export async function buildSingleFile({
|
|
|
66
67
|
if (algorithm !== 'gzip' && algorithm !== 'brotli') {
|
|
67
68
|
throw new Error(`buildSingleFile: algorithm must be 'gzip' or 'brotli', got ${JSON.stringify(algorithm)}`);
|
|
68
69
|
}
|
|
70
|
+
if (/[\\/]/.test(output)) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
'buildSingleFile: `output` is a file name written inside `dist`, not a path, so it cannot ' +
|
|
73
|
+
`contain a separator - got ${JSON.stringify(output)}`,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
69
76
|
|
|
70
77
|
const htmlPath = join(dist, 'index.html');
|
|
71
78
|
const html = await readFile(htmlPath, 'utf8');
|