kiwiengine 0.5.12 → 0.5.13
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/lib/renderer/renderer.js +14 -0
- package/lib/renderer/renderer.js.map +1 -1
- package/lib/types/renderer/renderer.d.ts +2 -0
- package/lib/types/renderer/renderer.d.ts.map +1 -1
- package/lib/types/renderer/ticker.test.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/renderer/renderer.ts +11 -0
package/lib/renderer/renderer.js
CHANGED
|
@@ -13,6 +13,8 @@ export class Renderer extends RenderableNode {
|
|
|
13
13
|
#ticker = new Ticker((dt) => this.#render(dt));
|
|
14
14
|
camera = new Camera();
|
|
15
15
|
fpsDisplay;
|
|
16
|
+
#fixedWidth;
|
|
17
|
+
#fixedHeight;
|
|
16
18
|
#logicalWidth;
|
|
17
19
|
#logicalHeight;
|
|
18
20
|
#backgroundColor;
|
|
@@ -39,6 +41,10 @@ export class Renderer extends RenderableNode {
|
|
|
39
41
|
this.camera.on('positionChanged', () => this.#updatePosition());
|
|
40
42
|
this.camera.on('scaleChanged', () => this.#updatePosition());
|
|
41
43
|
if (options) {
|
|
44
|
+
if (options.fixedWidth !== undefined)
|
|
45
|
+
this.#fixedWidth = options.fixedWidth;
|
|
46
|
+
if (options.fixedHeight !== undefined)
|
|
47
|
+
this.#fixedHeight = options.fixedHeight;
|
|
42
48
|
if (options.logicalWidth !== undefined)
|
|
43
49
|
this.#logicalWidth = options.logicalWidth;
|
|
44
50
|
if (options.logicalHeight !== undefined)
|
|
@@ -65,6 +71,10 @@ export class Renderer extends RenderableNode {
|
|
|
65
71
|
eventMode: 'none',
|
|
66
72
|
resolution: window.devicePixelRatio,
|
|
67
73
|
};
|
|
74
|
+
if (this.#fixedWidth)
|
|
75
|
+
options.width = this.#fixedWidth;
|
|
76
|
+
if (this.#fixedHeight)
|
|
77
|
+
options.height = this.#fixedHeight;
|
|
68
78
|
if (this.#logicalWidth)
|
|
69
79
|
options.width = this.#logicalWidth;
|
|
70
80
|
if (this.#logicalHeight)
|
|
@@ -89,6 +99,10 @@ export class Renderer extends RenderableNode {
|
|
|
89
99
|
this._pixiContainer.position.set(this.centerX - this.camera.x * S, this.centerY - this.camera.y * S);
|
|
90
100
|
}
|
|
91
101
|
#updateSize(containerWidth, containerHeight) {
|
|
102
|
+
if (this.#fixedWidth)
|
|
103
|
+
containerWidth = this.#fixedWidth;
|
|
104
|
+
if (this.#fixedHeight)
|
|
105
|
+
containerHeight = this.#fixedHeight;
|
|
92
106
|
const canvasWidth = this.#logicalWidth ?? containerWidth;
|
|
93
107
|
const canvasHeight = this.#logicalHeight ?? containerHeight;
|
|
94
108
|
this.canvasWidth = canvasWidth;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../../src/renderer/renderer.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,kBAAkB,EAAe,SAAS,IAAI,aAAa,EAA4B,MAAM,SAAS,CAAA;AAClI,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAUjC,MAAM,OAAO,QAAS,SAAQ,cAE5B;IAuBmB;IAtBnB,iBAAiB,CAA0B;IAC3C,OAAO,GAAG,IAAI,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAA;IAC9C,MAAM,GAAG,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QAC5B,IAAI,CAAC,yBAAyB,EAAE,CAAA;QAChC,IAAI,CAAC,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;QAC/C,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,CAAA;QAEzB,IAAI,CAAC,YAAY,GAAG,KAAK,CAAA;IAC3B,CAAC;IAED,WAAW,CAAC,IAA6C,EAAE,SAAiB;QAC1E,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;QACrC,IAAI,CAAC,KAAK;YAAE,MAAM,IAAI,KAAK,CAAC,SAAS,SAAS,kBAAkB,CAAC,CAAA;QACjE,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;IACpD,CAAC;IAEQ,MAAM;QACb,IAAI,CAAC,iBAAiB,CAAC,MAAM,EAAE,CAAA;QAC/B,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAA;QACrB,IAAI,CAAC,aAAa,EAAE,OAAO,EAAE,CAAA;QAC7B,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,CAAA;QACzB,KAAK,CAAC,MAAM,EAAE,CAAA;IAChB,CAAC;IAED,aAAa,CAAC,OAAe,EAAE,OAAe;QAC5C,MAAM,CAAC,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,WAAW,GAAG,CAAC,CAAA;QACjF,MAAM,CAAC,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,YAAY,GAAG,CAAC,CAAA;QACjF,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAA;IACjB,CAAC;CACF","sourcesContent":["import { EventMap } from '@webtaku/event-emitter'\nimport { AutoDetectOptions, autoDetectRenderer, ColorSource, Container as PixiContainer, Renderer as PixiRenderer } from 'pixi.js'\nimport { debugMode } from '../debug'\nimport { setStyle } from '../dom/dom-utils'\nimport { RenderableNode } from '../node/core/renderable'\nimport { Camera } from './camera'\nimport { RendererContainerManager } from './container-manager'\nimport { FpsDisplay } from './fps-display'\nimport { Layer } from './layer'\nimport { Ticker } from './ticker'\n\nexport type RendererOptions = {\n logicalWidth?: number\n logicalHeight?: number\n backgroundColor?: ColorSource\n backgroundAlpha?: number\n layers?: { name: string; drawOrder: number }[]\n}\n\nexport class Renderer extends RenderableNode<PixiContainer, {\n resize: (width: number, height: number) => void\n}> {\n #containerManager: RendererContainerManager\n #ticker = new Ticker((dt) => this.#render(dt))\n camera = new Camera()\n fpsDisplay?: FpsDisplay\n\n #logicalWidth?: number\n #logicalHeight?: number\n #backgroundColor?: ColorSource\n #backgroundAlpha?: number\n\n #pixiRenderer?: PixiRenderer\n #layers: { [name: string]: Layer } = {}\n _isSizeDirty = false\n\n canvasWidth = 0\n canvasHeight = 0\n canvasLeft = 0\n canvasTop = 0\n viewportScale = 1\n centerX = 0\n centerY = 0\n\n constructor(public container: HTMLElement, options?: RendererOptions) {\n super(new PixiContainer({ sortableChildren: true }))\n this.renderer = this\n\n this.worldTransform.x.v = 0\n this.worldTransform.y.v = 0\n this.worldTransform.resetDirty()\n\n this.#containerManager = new RendererContainerManager(container)\n this.#containerManager.on('resize', (width, height) => this.#updateSize(width, height))\n\n this.camera.on('positionChanged', () => this.#updatePosition())\n this.camera.on('scaleChanged', () => this.#updatePosition())\n\n if (options) {\n if (options.logicalWidth !== undefined) this.#logicalWidth = options.logicalWidth\n if (options.logicalHeight !== undefined) this.#logicalHeight = options.logicalHeight\n if (options.backgroundColor !== undefined) this.#backgroundColor = options.backgroundColor\n if (options.backgroundAlpha !== undefined) this.#backgroundAlpha = options.backgroundAlpha\n\n if (options.layers) {\n for (const layerOption of options.layers) {\n const layer = new Layer(layerOption.drawOrder)\n this._pixiContainer.addChild(layer._pixiContainer)\n this.#layers[layerOption.name] = layer\n }\n }\n }\n\n if (debugMode) {\n this.fpsDisplay = new FpsDisplay(container)\n }\n\n this.init()\n }\n\n private async init() {\n const options: Partial<AutoDetectOptions> = {\n eventMode: 'none',\n resolution: window.devicePixelRatio,\n }\n\n if (this.#logicalWidth) options.width = this.#logicalWidth\n if (this.#logicalHeight) options.height = this.#logicalHeight\n if (this.#backgroundColor) options.backgroundColor = this.#backgroundColor\n if (this.#backgroundAlpha) options.backgroundAlpha = this.#backgroundAlpha\n\n const pr = await autoDetectRenderer(options)\n\n setStyle(pr.canvas, {\n position: 'absolute',\n touchAction: 'auto',\n })\n this.container.appendChild(pr.canvas)\n\n this.#pixiRenderer = pr\n\n const cr = this.container.getBoundingClientRect()\n this.#updateSize(cr.width, cr.height)\n }\n\n #updatePosition() {\n const S = this.camera.scale\n this._pixiContainer.scale = S\n this._pixiContainer.position.set(\n this.centerX - this.camera.x * S,\n this.centerY - this.camera.y * S\n )\n }\n\n #updateSize(containerWidth: number, containerHeight: number) {\n const canvasWidth = this.#logicalWidth ?? containerWidth\n const canvasHeight = this.#logicalHeight ?? containerHeight\n this.canvasWidth = canvasWidth\n this.canvasHeight = canvasHeight\n\n this.centerX = canvasWidth / 2\n this.centerY = canvasHeight / 2\n this.#updatePosition()\n\n const S = Math.min(containerWidth / canvasWidth, containerHeight / canvasHeight)\n this.viewportScale = S\n\n const displayWidth = canvasWidth * S\n const displayHeight = canvasHeight * S\n\n const canvasLeft = (containerWidth - displayWidth) / 2\n const canvasTop = (containerHeight - displayHeight) / 2\n this.canvasLeft = canvasLeft\n this.canvasTop = canvasTop\n\n if (this.#pixiRenderer) {\n this.#pixiRenderer.resize(canvasWidth, canvasHeight)\n\n setStyle(this.#pixiRenderer.canvas, {\n width: `${displayWidth}px`,\n height: `${displayHeight}px`,\n left: `${canvasLeft}px`,\n top: `${canvasTop}px`,\n })\n\n this.emit('resize', canvasWidth, canvasHeight)\n }\n\n this._isSizeDirty = true\n }\n\n #render(dt: number) {\n this.update(dt) // 로직 업데이트\n this._updateWorldTransform()\n this._resetWorldTransformDirty()\n this.#pixiRenderer?.render(this._pixiContainer)\n this.fpsDisplay?.update()\n\n this._isSizeDirty = false\n }\n\n _addToLayer(node: RenderableNode<PixiContainer, EventMap>, layerName: string) {\n const layer = this.#layers[layerName]\n if (!layer) throw new Error(`Layer ${layerName} does not exist.`)\n layer._pixiContainer.addChild(node._pixiContainer)\n }\n\n override remove() {\n this.#containerManager.remove()\n this.#ticker.remove()\n this.#pixiRenderer?.destroy()\n this.fpsDisplay?.remove()\n super.remove()\n }\n\n screenToWorld(screenX: number, screenY: number) {\n const x = (screenX - this.canvasLeft) / this.viewportScale - this.canvasWidth / 2\n const y = (screenY - this.canvasTop) / this.viewportScale - this.canvasHeight / 2\n return { x, y }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../../src/renderer/renderer.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,kBAAkB,EAAe,SAAS,IAAI,aAAa,EAA4B,MAAM,SAAS,CAAA;AAClI,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAYjC,MAAM,OAAO,QAAS,SAAQ,cAE5B;IAyBmB;IAxBnB,iBAAiB,CAA0B;IAC3C,OAAO,GAAG,IAAI,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAA;IAC9C,MAAM,GAAG,IAAI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M,EAAE,CAAA;QACzB,KAAK,CAAC,MAAM,EAAE,CAAA;IAChB,CAAC;IAED,aAAa,CAAC,OAAe,EAAE,OAAe;QAC5C,MAAM,CAAC,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,WAAW,GAAG,CAAC,CAAA;QACjF,MAAM,CAAC,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,YAAY,GAAG,CAAC,CAAA;QACjF,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAA;IACjB,CAAC;CACF","sourcesContent":["import { EventMap } from '@webtaku/event-emitter'\nimport { AutoDetectOptions, autoDetectRenderer, ColorSource, Container as PixiContainer, Renderer as PixiRenderer } from 'pixi.js'\nimport { debugMode } from '../debug'\nimport { setStyle } from '../dom/dom-utils'\nimport { RenderableNode } from '../node/core/renderable'\nimport { Camera } from './camera'\nimport { RendererContainerManager } from './container-manager'\nimport { FpsDisplay } from './fps-display'\nimport { Layer } from './layer'\nimport { Ticker } from './ticker'\n\nexport type RendererOptions = {\n fixedWidth?: number\n fixedHeight?: number\n logicalWidth?: number\n logicalHeight?: number\n backgroundColor?: ColorSource\n backgroundAlpha?: number\n layers?: { name: string; drawOrder: number }[]\n}\n\nexport class Renderer extends RenderableNode<PixiContainer, {\n resize: (width: number, height: number) => void\n}> {\n #containerManager: RendererContainerManager\n #ticker = new Ticker((dt) => this.#render(dt))\n camera = new Camera()\n fpsDisplay?: FpsDisplay\n\n #fixedWidth?: number\n #fixedHeight?: number\n #logicalWidth?: number\n #logicalHeight?: number\n #backgroundColor?: ColorSource\n #backgroundAlpha?: number\n\n #pixiRenderer?: PixiRenderer\n #layers: { [name: string]: Layer } = {}\n _isSizeDirty = false\n\n canvasWidth = 0\n canvasHeight = 0\n canvasLeft = 0\n canvasTop = 0\n viewportScale = 1\n centerX = 0\n centerY = 0\n\n constructor(public container: HTMLElement, options?: RendererOptions) {\n super(new PixiContainer({ sortableChildren: true }))\n this.renderer = this\n\n this.worldTransform.x.v = 0\n this.worldTransform.y.v = 0\n this.worldTransform.resetDirty()\n\n this.#containerManager = new RendererContainerManager(container)\n this.#containerManager.on('resize', (width, height) => this.#updateSize(width, height))\n\n this.camera.on('positionChanged', () => this.#updatePosition())\n this.camera.on('scaleChanged', () => this.#updatePosition())\n\n if (options) {\n if (options.fixedWidth !== undefined) this.#fixedWidth = options.fixedWidth\n if (options.fixedHeight !== undefined) this.#fixedHeight = options.fixedHeight\n if (options.logicalWidth !== undefined) this.#logicalWidth = options.logicalWidth\n if (options.logicalHeight !== undefined) this.#logicalHeight = options.logicalHeight\n if (options.backgroundColor !== undefined) this.#backgroundColor = options.backgroundColor\n if (options.backgroundAlpha !== undefined) this.#backgroundAlpha = options.backgroundAlpha\n\n if (options.layers) {\n for (const layerOption of options.layers) {\n const layer = new Layer(layerOption.drawOrder)\n this._pixiContainer.addChild(layer._pixiContainer)\n this.#layers[layerOption.name] = layer\n }\n }\n }\n\n if (debugMode) {\n this.fpsDisplay = new FpsDisplay(container)\n }\n\n this.init()\n }\n\n private async init() {\n const options: Partial<AutoDetectOptions> = {\n eventMode: 'none',\n resolution: window.devicePixelRatio,\n }\n\n if (this.#fixedWidth) options.width = this.#fixedWidth\n if (this.#fixedHeight) options.height = this.#fixedHeight\n if (this.#logicalWidth) options.width = this.#logicalWidth\n if (this.#logicalHeight) options.height = this.#logicalHeight\n if (this.#backgroundColor) options.backgroundColor = this.#backgroundColor\n if (this.#backgroundAlpha) options.backgroundAlpha = this.#backgroundAlpha\n\n const pr = await autoDetectRenderer(options)\n\n setStyle(pr.canvas, {\n position: 'absolute',\n touchAction: 'auto',\n })\n this.container.appendChild(pr.canvas)\n\n this.#pixiRenderer = pr\n\n const cr = this.container.getBoundingClientRect()\n this.#updateSize(cr.width, cr.height)\n }\n\n #updatePosition() {\n const S = this.camera.scale\n this._pixiContainer.scale = S\n this._pixiContainer.position.set(\n this.centerX - this.camera.x * S,\n this.centerY - this.camera.y * S\n )\n }\n\n #updateSize(containerWidth: number, containerHeight: number) {\n if (this.#fixedWidth) containerWidth = this.#fixedWidth\n if (this.#fixedHeight) containerHeight = this.#fixedHeight\n\n const canvasWidth = this.#logicalWidth ?? containerWidth\n const canvasHeight = this.#logicalHeight ?? containerHeight\n this.canvasWidth = canvasWidth\n this.canvasHeight = canvasHeight\n\n this.centerX = canvasWidth / 2\n this.centerY = canvasHeight / 2\n this.#updatePosition()\n\n const S = Math.min(containerWidth / canvasWidth, containerHeight / canvasHeight)\n this.viewportScale = S\n\n const displayWidth = canvasWidth * S\n const displayHeight = canvasHeight * S\n\n const canvasLeft = (containerWidth - displayWidth) / 2\n const canvasTop = (containerHeight - displayHeight) / 2\n this.canvasLeft = canvasLeft\n this.canvasTop = canvasTop\n\n if (this.#pixiRenderer) {\n this.#pixiRenderer.resize(canvasWidth, canvasHeight)\n\n setStyle(this.#pixiRenderer.canvas, {\n width: `${displayWidth}px`,\n height: `${displayHeight}px`,\n left: `${canvasLeft}px`,\n top: `${canvasTop}px`,\n })\n\n this.emit('resize', canvasWidth, canvasHeight)\n }\n\n this._isSizeDirty = true\n }\n\n #render(dt: number) {\n this.update(dt) // 로직 업데이트\n this._updateWorldTransform()\n this._resetWorldTransformDirty()\n this.#pixiRenderer?.render(this._pixiContainer)\n this.fpsDisplay?.update()\n\n this._isSizeDirty = false\n }\n\n _addToLayer(node: RenderableNode<PixiContainer, EventMap>, layerName: string) {\n const layer = this.#layers[layerName]\n if (!layer) throw new Error(`Layer ${layerName} does not exist.`)\n layer._pixiContainer.addChild(node._pixiContainer)\n }\n\n override remove() {\n this.#containerManager.remove()\n this.#ticker.remove()\n this.#pixiRenderer?.destroy()\n this.fpsDisplay?.remove()\n super.remove()\n }\n\n screenToWorld(screenX: number, screenY: number) {\n const x = (screenX - this.canvasLeft) / this.viewportScale - this.canvasWidth / 2\n const y = (screenY - this.canvasTop) / this.viewportScale - this.canvasHeight / 2\n return { x, y }\n }\n}\n"]}
|
|
@@ -4,6 +4,8 @@ import { RenderableNode } from '../node/core/renderable';
|
|
|
4
4
|
import { Camera } from './camera';
|
|
5
5
|
import { FpsDisplay } from './fps-display';
|
|
6
6
|
export type RendererOptions = {
|
|
7
|
+
fixedWidth?: number;
|
|
8
|
+
fixedHeight?: number;
|
|
7
9
|
logicalWidth?: number;
|
|
8
10
|
logicalHeight?: number;
|
|
9
11
|
backgroundColor?: ColorSource;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../../../src/renderer/renderer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAA;AACjD,OAAO,EAAyC,WAAW,EAAE,SAAS,IAAI,aAAa,EAA4B,MAAM,SAAS,CAAA;AAGlI,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAI1C,MAAM,MAAM,eAAe,GAAG;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,eAAe,CAAC,EAAE,WAAW,CAAA;IAC7B,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAC/C,CAAA;AAED,qBAAa,QAAS,SAAQ,cAAc,CAAC,aAAa,EAAE;IAC1D,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;CAChD,CAAC;;
|
|
1
|
+
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../../../src/renderer/renderer.ts"],"names":[],"mappings":"A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E,OAAO,EAAE,MAAM;;;;CAK/C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ticker.test.d.ts","sourceRoot":"","sources":["../../../src/renderer/ticker.test.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAE9B;;;;;;;;;;;;GAYG;AAEH,0EAA0E;AAG1E,KAAK,OAAO,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;AAGrC,QAAA,IAAI,KAAK,QAAI,CAAA;AAGb,QAAA,MAAM,YAAY,sBAA6B,CAAA;AAC/C,QAAA,IAAI,SAAS,QAAI,CAAA;AAEjB,QAAA,MAAM,sBAAsB,YAc3B,CAAA;AAED,QAAA,MAAM,YAAY,YAIjB,CAAA;AAED;;;;GAIG;AACH,QAAA,MAAM,IAAI,
|
|
1
|
+
{"version":3,"file":"ticker.test.d.ts","sourceRoot":"","sources":["../../../src/renderer/ticker.test.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAE9B;;;;;;;;;;;;GAYG;AAEH,0EAA0E;AAG1E,KAAK,OAAO,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;AAGrC,QAAA,IAAI,KAAK,QAAI,CAAA;AAGb,QAAA,MAAM,YAAY,sBAA6B,CAAA;AAC/C,QAAA,IAAI,SAAS,QAAI,CAAA;AAEjB,QAAA,MAAM,sBAAsB,YAc3B,CAAA;AAED,QAAA,MAAM,YAAY,YAIjB,CAAA;AAED;;;;GAIG;AACH,QAAA,MAAM,IAAI,cAAe,MAAM,SAK9B,CAAA;AAED,uCAAuC;AACvC,QAAA,MAAM,OAAO,YAAa,MAAM,0BAK/B,CAAA;AAED;;;GAGG;AACH,QAAA,MAAM,mBAAmB,UAAiB,OAAO,0BAIJ,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,KAAK;IAAE,MAAM,IAAI,IAAI,CAAA;CAAE,CACvF,CAAA;AAED,8CAA8C;AAC9C,QAAA,MAAM,KAAK,WAAY,IAAI,CAAC,IAAI,gBAAgB,MAAM,KAA2C,MAAM,CAAA;AACvG,QAAA,MAAM,OAAO,WAAY,IAAI,CAAC,IAAI,KAEE,MACnC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kiwiengine",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.13",
|
|
4
4
|
"types": "./lib/types/index.d.ts",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@esotericsoftware/spine-pixi-v8": "^4.2.
|
|
7
|
+
"@esotericsoftware/spine-pixi-v8": "^4.2.95",
|
|
8
8
|
"@webtaku/event-emitter": "^0.0.2",
|
|
9
9
|
"matter-js": "^0.20.0",
|
|
10
|
-
"pixi.js": "^8.
|
|
10
|
+
"pixi.js": "^8.14.0",
|
|
11
11
|
"stats.js": "^0.17.0"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@types/jest": "^30.0.0",
|
|
15
|
-
"@types/matter-js": "^0.
|
|
15
|
+
"@types/matter-js": "^0.20.2",
|
|
16
16
|
"@types/stats.js": "^0.17.4",
|
|
17
|
-
"jest": "^30.0
|
|
18
|
-
"jest-environment-jsdom": "^30.0
|
|
19
|
-
"ts-jest": "^29.4.
|
|
17
|
+
"jest": "^30.2.0",
|
|
18
|
+
"jest-environment-jsdom": "^30.2.0",
|
|
19
|
+
"ts-jest": "^29.4.5",
|
|
20
20
|
"ts-node": "^10.9.2",
|
|
21
|
-
"typescript": "^5.
|
|
21
|
+
"typescript": "^5.9.3"
|
|
22
22
|
},
|
|
23
23
|
"packageManager": "yarn@1.22.22"
|
|
24
24
|
}
|
package/src/renderer/renderer.ts
CHANGED
|
@@ -10,6 +10,8 @@ import { Layer } from './layer'
|
|
|
10
10
|
import { Ticker } from './ticker'
|
|
11
11
|
|
|
12
12
|
export type RendererOptions = {
|
|
13
|
+
fixedWidth?: number
|
|
14
|
+
fixedHeight?: number
|
|
13
15
|
logicalWidth?: number
|
|
14
16
|
logicalHeight?: number
|
|
15
17
|
backgroundColor?: ColorSource
|
|
@@ -25,6 +27,8 @@ export class Renderer extends RenderableNode<PixiContainer, {
|
|
|
25
27
|
camera = new Camera()
|
|
26
28
|
fpsDisplay?: FpsDisplay
|
|
27
29
|
|
|
30
|
+
#fixedWidth?: number
|
|
31
|
+
#fixedHeight?: number
|
|
28
32
|
#logicalWidth?: number
|
|
29
33
|
#logicalHeight?: number
|
|
30
34
|
#backgroundColor?: ColorSource
|
|
@@ -57,6 +61,8 @@ export class Renderer extends RenderableNode<PixiContainer, {
|
|
|
57
61
|
this.camera.on('scaleChanged', () => this.#updatePosition())
|
|
58
62
|
|
|
59
63
|
if (options) {
|
|
64
|
+
if (options.fixedWidth !== undefined) this.#fixedWidth = options.fixedWidth
|
|
65
|
+
if (options.fixedHeight !== undefined) this.#fixedHeight = options.fixedHeight
|
|
60
66
|
if (options.logicalWidth !== undefined) this.#logicalWidth = options.logicalWidth
|
|
61
67
|
if (options.logicalHeight !== undefined) this.#logicalHeight = options.logicalHeight
|
|
62
68
|
if (options.backgroundColor !== undefined) this.#backgroundColor = options.backgroundColor
|
|
@@ -84,6 +90,8 @@ export class Renderer extends RenderableNode<PixiContainer, {
|
|
|
84
90
|
resolution: window.devicePixelRatio,
|
|
85
91
|
}
|
|
86
92
|
|
|
93
|
+
if (this.#fixedWidth) options.width = this.#fixedWidth
|
|
94
|
+
if (this.#fixedHeight) options.height = this.#fixedHeight
|
|
87
95
|
if (this.#logicalWidth) options.width = this.#logicalWidth
|
|
88
96
|
if (this.#logicalHeight) options.height = this.#logicalHeight
|
|
89
97
|
if (this.#backgroundColor) options.backgroundColor = this.#backgroundColor
|
|
@@ -113,6 +121,9 @@ export class Renderer extends RenderableNode<PixiContainer, {
|
|
|
113
121
|
}
|
|
114
122
|
|
|
115
123
|
#updateSize(containerWidth: number, containerHeight: number) {
|
|
124
|
+
if (this.#fixedWidth) containerWidth = this.#fixedWidth
|
|
125
|
+
if (this.#fixedHeight) containerHeight = this.#fixedHeight
|
|
126
|
+
|
|
116
127
|
const canvasWidth = this.#logicalWidth ?? containerWidth
|
|
117
128
|
const canvasHeight = this.#logicalHeight ?? containerHeight
|
|
118
129
|
this.canvasWidth = canvasWidth
|