1681-engine 0.6.1 → 0.6.2

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 CHANGED
@@ -3,6 +3,13 @@
3
3
  All notable changes to this package are written here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
4
4
  and versions follow [Semantic Versioning](https://semver.org/); before 1.0 a minor version may break the API.
5
5
 
6
+ ## 0.6.2
7
+
8
+ ### Added
9
+
10
+ - `Stage.pixelDensity`: texels of the pixel-perfect grid to a world pixel (1 by default). A game drawing characters at
11
+ two art pixels to a world pixel sets 2, and the grid keeps their detail instead of sampling them back down.
12
+
6
13
  ## 0.6.1
7
14
 
8
15
  ### Added
@@ -1,7 +1,7 @@
1
- import { Matrix as n, Sprite as l, RenderTexture as a } from "pixi.js";
2
- import { gridPlacement as d } from "./gridPlacement.js";
1
+ import { Matrix as a, Sprite as l, RenderTexture as d } from "pixi.js";
2
+ import { gridPlacement as p } from "./gridPlacement.js";
3
3
  import { SharpText as x } from "./SharpText.js";
4
- class m {
4
+ class w {
5
5
  constructor(e, t) {
6
6
  this.app = e, this.world = t, this.text = new x(t);
7
7
  }
@@ -10,18 +10,18 @@ class m {
10
10
  texture = null;
11
11
  sprite = null;
12
12
  text;
13
- transform = new n();
13
+ transform = new a();
14
14
  on = !1;
15
15
  get enabled() {
16
16
  return this.on;
17
17
  }
18
18
  /** Once a frame, after the camera wrote the world's transform and before Pixi draws the screen. */
19
- render(e, t) {
19
+ render(e, t, i = 1) {
20
20
  if (t !== this.on && (t ? this.enable(e) : this.disable(e)), !t) return;
21
- const i = e.zoom || 1, s = this.world.position, r = d(s.x, s.y, i, this.app.renderer.resolution, e.width, e.height), o = this.fit(r.width, r.height);
22
- this.transform.set(1, 0, 0, 1, -r.tx, -r.ty), this.app.renderer.render({ container: this.world, target: o, clear: !0, clearColor: [0, 0, 0, 0], transform: this.transform });
23
- const h = this.sprite;
24
- h.scale.set(i), h.position.set(r.x, r.y), this.text.sync(s, i);
21
+ const r = e.zoom || 1, h = this.world.position, s = p(h.x, h.y, r, this.app.renderer.resolution, e.width, e.height), n = this.fit(s.width, s.height, Math.max(1, Math.round(i)));
22
+ this.transform.set(1, 0, 0, 1, -s.tx, -s.ty), this.app.renderer.render({ container: this.world, target: n, clear: !0, clearColor: [0, 0, 0, 0], transform: this.transform });
23
+ const o = this.sprite;
24
+ o.scale.set(r), o.position.set(s.x, s.y), this.text.sync(h, r);
25
25
  }
26
26
  destroy(e) {
27
27
  this.disable(e), this.text.destroy();
@@ -37,11 +37,15 @@ class m {
37
37
  const t = this.app.stage, i = Math.max(0, this.sprite ? t.children.indexOf(this.sprite) : 0);
38
38
  t.removeChild(this.text.layer), this.sprite?.destroy(), this.sprite = null, this.texture?.destroy(!0), this.texture = null, this.world.destroyed || t.addChildAt(this.world, i);
39
39
  }
40
- /** The texture at exactly this size, made again only when the screen or the zoom changed. */
41
- fit(e, t) {
42
- return this.texture && this.texture.width === e && this.texture.height === t ? this.texture : (this.texture?.destroy(!0), this.texture = a.create({ width: e, height: t, resolution: 1, scaleMode: "nearest", antialias: !1 }), this.sprite.texture = this.texture, this.texture);
40
+ /**
41
+ * The texture at exactly this size (world pixels) and density (texels to a world pixel), made again only when the
42
+ * screen, the zoom or the density changed.
43
+ */
44
+ fit(e, t, i) {
45
+ const r = this.texture;
46
+ return r && r.width === e && r.height === t && r.source.resolution === i ? r : (this.texture?.destroy(!0), this.texture = d.create({ width: e, height: t, resolution: i, scaleMode: "nearest", antialias: !1 }), this.sprite.texture = this.texture, this.texture);
43
47
  }
44
48
  }
45
49
  export {
46
- m as PixelGrid
50
+ w as PixelGrid
47
51
  };
@@ -1,13 +1,13 @@
1
1
  import { Container as s } from "pixi.js";
2
- import { Camera as a } from "./Camera.js";
3
- import { Clock as n } from "./Clock.js";
2
+ import { Camera as n } from "./Camera.js";
3
+ import { Clock as a } from "./Clock.js";
4
4
  import { ObjectFactory as o } from "./ObjectFactory.js";
5
5
  import { PixelGrid as d } from "./PixelGrid.js";
6
6
  import { Pointer as c } from "./Pointer.js";
7
7
  import { Tweener as m } from "./Tweener.js";
8
8
  class h {
9
9
  constructor(t, e) {
10
- this.app = t, this.textures = e, t.stage.addChild(this.world, this.screen), this.cameras = { main: new a(this.world, this.screen) }, this.input = { activePointer: new c(t.canvas) }, this.grid = new d(t, this.world), this.time.onError = (i) => this.caught("timers", i), this.syncSize();
10
+ this.app = t, this.textures = e, t.stage.addChild(this.world, this.screen), this.cameras = { main: new n(this.world, this.screen) }, this.input = { activePointer: new c(t.canvas) }, this.grid = new d(t, this.world), this.time.onError = (i) => this.caught("timers", i), this.syncSize();
11
11
  }
12
12
  app;
13
13
  textures;
@@ -17,7 +17,7 @@ class h {
17
17
  screen = new s();
18
18
  add = new o(this);
19
19
  tweens = new m();
20
- time = new n();
20
+ time = new a();
21
21
  cameras;
22
22
  input;
23
23
  /**
@@ -26,6 +26,12 @@ class h {
26
26
  * Off (the default), the world is drawn straight at the zoom. Takes effect on the next frame; may be switched any time.
27
27
  */
28
28
  pixelPerfect = !1;
29
+ /**
30
+ * Texels of the pixel-perfect grid to a world pixel (whole, 1 by default). A game whose characters are drawn finer
31
+ * than its world pixel (two art pixels to one) sets 2, so the grid keeps their detail; everything else still lands on
32
+ * that finer grid.
33
+ */
34
+ pixelDensity = 1;
29
35
  grid;
30
36
  /** Whether the grid drew last frame, so the frame it is switched off still takes it down. */
31
37
  gridLive = !1;
@@ -55,7 +61,7 @@ class h {
55
61
  */
56
62
  frame(t) {
57
63
  const e = performance.now();
58
- this.guard("resize", () => this.syncSize()), this.guard("update", () => this.update(e, t)), this.guard("tweens", () => this.tweens.update(t)), this.guard("timers", () => this.time.update(e)), this.guard("camera", () => this.cameras.main.apply(e)), (this.pixelPerfect || this.gridLive) && (this.gridLive = this.pixelPerfect, this.guard("pixel grid", () => this.grid.render(this.cameras.main, this.pixelPerfect)));
64
+ this.guard("resize", () => this.syncSize()), this.guard("update", () => this.update(e, t)), this.guard("tweens", () => this.tweens.update(t)), this.guard("timers", () => this.time.update(e)), this.guard("camera", () => this.cameras.main.apply(e)), (this.pixelPerfect || this.gridLive) && (this.gridLive = this.pixelPerfect, this.guard("pixel grid", () => this.grid.render(this.cameras.main, this.pixelPerfect, this.pixelDensity)));
59
65
  }
60
66
  /**
61
67
  * Keeps a piece of text made outside `add.text`/`add.label` (put on the world any way) at screen resolution while the
@@ -3,7 +3,7 @@ import type { Camera } from './Camera.js';
3
3
  import { SharpText } from './SharpText.js';
4
4
  /**
5
5
  * A pixel-perfect world (`Stage.pixelPerfect`): the world layer is taken off the stage and drawn each frame into a
6
- * texture of one texel per world pixel, whose origin sits on a whole world pixel, then shown at the camera's zoom and
6
+ * texture of one texel per world pixel (`Stage.pixelDensity` texels, when the art is finer), whose origin sits on a whole world pixel, then shown at the camera's zoom and
7
7
  * moved by the scroll's fraction, so the camera still glides one backing pixel at a time. Everything turned, scaled or
8
8
  * placed between pixels lands on the same grid as the rest of the art, so no pixel on screen is drawn at another size
9
9
  * ("mixels"); the world is also filled at 1/zoom² of the screen's pixels. Roots placed with `Camera.snapRoot` land on
@@ -20,11 +20,14 @@ export declare class PixelGrid {
20
20
  constructor(app: Application, world: Container);
21
21
  get enabled(): boolean;
22
22
  /** Once a frame, after the camera wrote the world's transform and before Pixi draws the screen. */
23
- render(cam: Camera, enabled: boolean): void;
23
+ render(cam: Camera, enabled: boolean, density?: number): void;
24
24
  destroy(cam: Camera): void;
25
25
  private enable;
26
26
  private disable;
27
- /** The texture at exactly this size, made again only when the screen or the zoom changed. */
27
+ /**
28
+ * The texture at exactly this size (world pixels) and density (texels to a world pixel), made again only when the
29
+ * screen, the zoom or the density changed.
30
+ */
28
31
  private fit;
29
32
  }
30
33
  //# sourceMappingURL=PixelGrid.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PixelGrid.d.ts","sourceRoot":"","sources":["../../../src/core/PixelGrid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiC,K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AI,EAAE,SAAS,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAgB;IAC1C,OAAO,CAAC,EAAE,CAAS;gBAGA,GAAG,EAAE,WAAW,EAChB,KAAK,EAAE,SAAS;IAKnC,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,mGAAmG;IACnG,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,SAAI,GAAG,IAAI;IAmBxD,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAK1B,OAAO,CAAC,MAAM;IAWd,OAAO,CAAC,OAAO;IAef;;;OAGG;IACH,OAAO,CAAC,GAAG;CAQZ"}
@@ -31,6 +31,12 @@ export declare abstract class Stage {
31
31
  * Off (the default), the world is drawn straight at the zoom. Takes effect on the next frame; may be switched any time.
32
32
  */
33
33
  pixelPerfect: boolean;
34
+ /**
35
+ * Texels of the pixel-perfect grid to a world pixel (whole, 1 by default). A game whose characters are drawn finer
36
+ * than its world pixel (two art pixels to one) sets 2, so the grid keeps their detail; everything else still lands on
37
+ * that finer grid.
38
+ */
39
+ pixelDensity: number;
34
40
  private readonly grid;
35
41
  /** Whether the grid drew last frame, so the frame it is switched off still takes it down. */
36
42
  private gridLive;
@@ -1 +1 @@
1
- {"version":3,"file":"Stage.d.ts","sourceRoot":"","sources":["../../../src/core/Stage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,C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,EAAE,CAAC,GAAG,CAAC;IAS/D,iIAAiI;IACjI,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,IAAI;IASlD,OAAO,IAAI,IAAI;IAUf,OAAO,CAAC,QAAQ;CAWjB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "1681-engine",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "A 2D game engine on PixiJS 8 for any art style: scenes and a fast ECS, a fixed-step loop, asset loading, Tiled maps, sprite animation, input actions, camera follow, audio and deterministic, server-replayable movement, plus Dither, an optional pixel-art module (pixel-perfect effects, dithered lighting).",
5
5
  "type": "module",
6
6
  "types": "./dist/types/index.d.ts",