From 2900605300ade54f7e6309b2f900aed730d5b9f1 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Fri, 21 Apr 2023 13:52:35 +0200 Subject: [PATCH] [phaser] Clean-up, TypeScript example README, non-null SpineGameObject fields. --- examples/export/runtimes.sh | 4 +++ spine-ts/spine-phaser/example/depth-test.html | 2 +- .../example/extended-class-test.html | 2 +- .../spine-phaser/example/typescript/README.md | 6 ++++ .../spine-phaser/example/typescript/index.ts | 2 +- .../example/typescript/package-lock.json | 36 +++++++++---------- .../example/typescript/package.json | 2 +- spine-ts/spine-phaser/src/SpineGameObject.ts | 27 +++++--------- 8 files changed, 41 insertions(+), 40 deletions(-) create mode 100644 spine-ts/spine-phaser/example/typescript/README.md diff --git a/examples/export/runtimes.sh b/examples/export/runtimes.sh index 9c99c9caa..5727f9316 100755 --- a/examples/export/runtimes.sh +++ b/examples/export/runtimes.sh @@ -350,6 +350,10 @@ cp -f ../spineboy/export/spineboy-pro.skel "$ROOT/spine-ts/spine-phaser/example/ cp -f ../spineboy/export/spineboy-pma.atlas "$ROOT/spine-ts/spine-phaser/example/assets/" cp -f ../spineboy/export/spineboy-pma.png "$ROOT/spine-ts/spine-phaser/example/assets/" +cp -f ../spineboy/export/spineboy-pro.skel "$ROOT/spine-ts/spine-phaser/example/typescript/assets/" +cp -f ../spineboy/export/spineboy-pma.atlas "$ROOT/spine-ts/spine-phaser/example/typescript/assets/" +cp -f ../spineboy/export/spineboy-pma.png "$ROOT/spine-ts/spine-phaser/example/typescript/assets/" + cp -f ../coin/export/coin-pro.skel "$ROOT/spine-ts/spine-phaser/example/assets/" cp -f ../coin/export/coin-pma.atlas "$ROOT/spine-ts/spine-phaser/example/assets/" cp -f ../coin/export/coin-pma.png "$ROOT/spine-ts/spine-phaser/example/assets/" diff --git a/spine-ts/spine-phaser/example/depth-test.html b/spine-ts/spine-phaser/example/depth-test.html index 26def5e1b..910db939b 100644 --- a/spine-ts/spine-phaser/example/depth-test.html +++ b/spine-ts/spine-phaser/example/depth-test.html @@ -32,7 +32,7 @@ let game = new Phaser.Game(config); function preload() { - this.load.image('logo', 'assets/phaser.png'); + this.load.image('logo', 'phaser.png'); this.load.spineBinary("spineboy-data", "assets/spineboy-pro.skel"); this.load.spineAtlas("spineboy-atlas", "assets/spineboy-pma.atlas"); } diff --git a/spine-ts/spine-phaser/example/extended-class-test.html b/spine-ts/spine-phaser/example/extended-class-test.html index 9eec599bb..239d2bb42 100644 --- a/spine-ts/spine-phaser/example/extended-class-test.html +++ b/spine-ts/spine-phaser/example/extended-class-test.html @@ -63,7 +63,7 @@ } preload() { - this.load.image('logo', 'assets/phaser.png'); + this.load.image('logo', 'phaser.png'); this.load.spineBinary("spineboy-data", "assets/spineboy-pro.skel"); this.load.spineAtlas("spineboy-atlas", "assets/spineboy-pma.atlas"); } diff --git a/spine-ts/spine-phaser/example/typescript/README.md b/spine-ts/spine-phaser/example/typescript/README.md new file mode 100644 index 000000000..78a50614b --- /dev/null +++ b/spine-ts/spine-phaser/example/typescript/README.md @@ -0,0 +1,6 @@ +# spine-phaser TypeScript +Minimal example project using Phaser, spine-phaser, and TypeScript via NPM and [esbuild](https://esbuild.github.io/). + +1. Install dependencies: `npm install` +2. Build bundle: `npm run build` +3. Development (run server and recompile in watch mode): `npm run dev` \ No newline at end of file diff --git a/spine-ts/spine-phaser/example/typescript/index.ts b/spine-ts/spine-phaser/example/typescript/index.ts index c6c8b492e..1e4c6a671 100644 --- a/spine-ts/spine-phaser/example/typescript/index.ts +++ b/spine-ts/spine-phaser/example/typescript/index.ts @@ -1,5 +1,5 @@ import {Scene} from "phaser" -import {SpineGameObject, SpineGameObjectBoundsProvider, SpinePlugin} from "@esotericsoftware/spine-phaser" +import {SpinePlugin} from "@esotericsoftware/spine-phaser" class SpineDemo extends Scene { preload() { diff --git a/spine-ts/spine-phaser/example/typescript/package-lock.json b/spine-ts/spine-phaser/example/typescript/package-lock.json index 15399dabe..a93a9323a 100644 --- a/spine-ts/spine-phaser/example/typescript/package-lock.json +++ b/spine-ts/spine-phaser/example/typescript/package-lock.json @@ -8,7 +8,7 @@ "name": "name", "version": "1.0.0", "dependencies": { - "@esotericsoftware/spine-phaser": "4.1.*", + "@esotericsoftware/spine-phaser": "../../", "phaser": "3.60.0" }, "devDependencies": { @@ -370,34 +370,34 @@ } }, "node_modules/@esotericsoftware/spine-canvas": { - "version": "4.2.11", - "resolved": "https://registry.npmjs.org/@esotericsoftware/spine-canvas/-/spine-canvas-4.2.11.tgz", - "integrity": "sha512-NEYBSPxAvVaJO2Jtcr/FCYzq6uZprX2BuohA3isq2xn/BckXfZQXLlLT/1+34kK3+gc5XQsMA2YfrHYw35QAMQ==", + "version": "4.1.29", + "resolved": "https://registry.npmjs.org/@esotericsoftware/spine-canvas/-/spine-canvas-4.1.29.tgz", + "integrity": "sha512-X5wbvIPeYRQGvRa30gc2/FNbw6K0IQCn4ByjIB23pEutmXeJJyuRPON0Kn3951Ir5BPUohZoZMYHd2uxyLXTGA==", "dependencies": { - "@esotericsoftware/spine-core": "^4.2.11" + "@esotericsoftware/spine-core": "4.1.29" } }, "node_modules/@esotericsoftware/spine-core": { - "version": "4.2.11", - "resolved": "https://registry.npmjs.org/@esotericsoftware/spine-core/-/spine-core-4.2.11.tgz", - "integrity": "sha512-yyieou3t6XNYNqbWDdGEkVBg2JAAjLrtrNxGIkweNaH38O4p5Z4pPw2r7BKhCkUEW6+TITYkbNslsGGPU3HMAw==" + "version": "4.1.29", + "resolved": "https://registry.npmjs.org/@esotericsoftware/spine-core/-/spine-core-4.1.29.tgz", + "integrity": "sha512-Lzgt30MioPRWaco8fyaoVqBOfWO/jsGtRNl+6I1h3sWu9AhpV+/sXYcplSqma3KzWvALh2Q/WFOr5bUSReqINw==" }, "node_modules/@esotericsoftware/spine-phaser": { - "version": "4.1.28", - "resolved": "https://registry.npmjs.org/@esotericsoftware/spine-phaser/-/spine-phaser-4.1.28.tgz", - "integrity": "sha512-vlDBFeBNLEjxWS4uo24AH4HZeEMfYIDzpsyV8cvnLI5F3E9l+GfHOtdc2to9m1CYOilawZA4zl4oOOCLPgbmWA==", + "version": "4.1.29", + "resolved": "https://registry.npmjs.org/@esotericsoftware/spine-phaser/-/spine-phaser-4.1.29.tgz", + "integrity": "sha512-6vStoBJxnBii9Mk+adX7nygicCwboK49EcIVH+O9C128mH1jc16pb9OeQAT6xeLpFOnE6k+Nre2EXYdQ+eXXYw==", "dependencies": { - "@esotericsoftware/spine-canvas": "^4.1.28", - "@esotericsoftware/spine-core": "^4.1.28", - "@esotericsoftware/spine-webgl": "^4.1.28" + "@esotericsoftware/spine-canvas": "4.1.29", + "@esotericsoftware/spine-core": "4.1.29", + "@esotericsoftware/spine-webgl": "4.1.29" } }, "node_modules/@esotericsoftware/spine-webgl": { - "version": "4.2.11", - "resolved": "https://registry.npmjs.org/@esotericsoftware/spine-webgl/-/spine-webgl-4.2.11.tgz", - "integrity": "sha512-DCk+Qp4QxzA3PCYpxtVxt1cChnDhs9AjvbzVtHkHE7nKyRnoYjH7JDghuyVvOEI8YJZS29vDD0rD7i22ne9QXg==", + "version": "4.1.29", + "resolved": "https://registry.npmjs.org/@esotericsoftware/spine-webgl/-/spine-webgl-4.1.29.tgz", + "integrity": "sha512-sucAXTO0Hp5BR4DqkQTkA+gKI62AtCoSmz1Ld9akowG/x1+XYLVJ9GEbYLsUEUyoZOAP7aWa/HzGDSi/sHRs0w==", "dependencies": { - "@esotericsoftware/spine-core": "^4.2.11" + "@esotericsoftware/spine-core": "4.1.29" } }, "node_modules/accepts": { diff --git a/spine-ts/spine-phaser/example/typescript/package.json b/spine-ts/spine-phaser/example/typescript/package.json index d935d262c..bb74043e1 100644 --- a/spine-ts/spine-phaser/example/typescript/package.json +++ b/spine-ts/spine-phaser/example/typescript/package.json @@ -8,7 +8,7 @@ "dev": "npx concurrently \"npx live-server --no-browser\" \"npm run build -- --watch\"" }, "dependencies": { - "@esotericsoftware/spine-phaser": "4.1.*", + "@esotericsoftware/spine-phaser": "../../", "phaser": "3.60.0" }, "devDependencies": { diff --git a/spine-ts/spine-phaser/src/SpineGameObject.ts b/spine-ts/spine-phaser/src/SpineGameObject.ts index 32c60949e..a63e8ae28 100644 --- a/spine-ts/spine-phaser/src/SpineGameObject.ts +++ b/spine-ts/spine-phaser/src/SpineGameObject.ts @@ -77,9 +77,9 @@ export class SkinsAndAnimationBoundsProvider implements SpineGameObjectBoundsPro export class SpineGameObject extends ComputedSizeMixin(DepthMixin(FlipMixin(ScrollFactorMixin(TransformMixin(VisibleMixin(AlphaMixin(BaseSpineGameObject))))))) { blendMode = -1; - skeleton: Skeleton | null = null; - animationStateData: AnimationStateData | null = null; - animationState: AnimationState | null = null; + skeleton: Skeleton; + animationStateData: AnimationStateData; + animationState: AnimationState; private premultipliedAlpha = false; private _displayOriginX = 0; private _displayOriginY = 0; @@ -89,21 +89,12 @@ export class SpineGameObject extends ComputedSizeMixin(DepthMixin(FlipMixin(Scro constructor (scene: Phaser.Scene, private plugin: SpinePlugin, x: number, y: number, dataKey: string, atlasKey: string, public boundsProvider: SpineGameObjectBoundsProvider = new SetupPoseBoundsProvider()) { super(scene, SPINE_GAME_OBJECT_TYPE); this.setPosition(x, y); - this.setSkeleton(dataKey, atlasKey); - } - - setSkeleton (dataKey: string, atlasKey: string) { - if (dataKey && atlasKey) { - this.premultipliedAlpha = this.plugin.isAtlasPremultiplied(atlasKey); - this.skeleton = this.plugin.createSkeleton(dataKey, atlasKey); - this.animationStateData = new AnimationStateData(this.skeleton.data); - this.animationState = new AnimationState(this.animationStateData); - this.updateSize(); - } else { - this.skeleton = null; - this.animationStateData = null; - this.animationState = null; - } + + this.premultipliedAlpha = this.plugin.isAtlasPremultiplied(atlasKey); + this.skeleton = this.plugin.createSkeleton(dataKey, atlasKey); + this.animationStateData = new AnimationStateData(this.skeleton.data); + this.animationState = new AnimationState(this.animationStateData); + this.updateSize(); } public get displayOriginX () {