Explorar el Código

[phaser] Clean-up, TypeScript example README, non-null SpineGameObject fields.

Mario Zechner hace 2 años
padre
commit
2900605300

+ 4 - 0
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.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-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-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.atlas "$ROOT/spine-ts/spine-phaser/example/assets/"
 cp -f ../coin/export/coin-pma.png "$ROOT/spine-ts/spine-phaser/example/assets/"
 cp -f ../coin/export/coin-pma.png "$ROOT/spine-ts/spine-phaser/example/assets/"

+ 1 - 1
spine-ts/spine-phaser/example/depth-test.html

@@ -32,7 +32,7 @@
     let game = new Phaser.Game(config);
     let game = new Phaser.Game(config);
 
 
     function preload() {
     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.spineBinary("spineboy-data", "assets/spineboy-pro.skel");
         this.load.spineAtlas("spineboy-atlas", "assets/spineboy-pma.atlas");
         this.load.spineAtlas("spineboy-atlas", "assets/spineboy-pma.atlas");
     }
     }

+ 1 - 1
spine-ts/spine-phaser/example/extended-class-test.html

@@ -63,7 +63,7 @@
         }
         }
 
 
         preload() {
         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.spineBinary("spineboy-data", "assets/spineboy-pro.skel");
             this.load.spineAtlas("spineboy-atlas", "assets/spineboy-pma.atlas");
             this.load.spineAtlas("spineboy-atlas", "assets/spineboy-pma.atlas");
         }
         }

+ 6 - 0
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`

+ 1 - 1
spine-ts/spine-phaser/example/typescript/index.ts

@@ -1,5 +1,5 @@
 import {Scene} from "phaser"
 import {Scene} from "phaser"
-import {SpineGameObject, SpineGameObjectBoundsProvider, SpinePlugin} from "@esotericsoftware/spine-phaser"
+import {SpinePlugin} from "@esotericsoftware/spine-phaser"
 
 
 class SpineDemo extends Scene {
 class SpineDemo extends Scene {
     preload() {
     preload() {

+ 18 - 18
spine-ts/spine-phaser/example/typescript/package-lock.json

@@ -8,7 +8,7 @@
             "name": "name",
             "name": "name",
             "version": "1.0.0",
             "version": "1.0.0",
             "dependencies": {
             "dependencies": {
-                "@esotericsoftware/spine-phaser": "4.1.*",
+                "@esotericsoftware/spine-phaser": "../../",
                 "phaser": "3.60.0"
                 "phaser": "3.60.0"
             },
             },
             "devDependencies": {
             "devDependencies": {
@@ -370,34 +370,34 @@
             }
             }
         },
         },
         "node_modules/@esotericsoftware/spine-canvas": {
         "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": {
             "dependencies": {
-                "@esotericsoftware/spine-core": "^4.2.11"
+                "@esotericsoftware/spine-core": "4.1.29"
             }
             }
         },
         },
         "node_modules/@esotericsoftware/spine-core": {
         "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": {
         "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": {
             "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": {
         "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": {
             "dependencies": {
-                "@esotericsoftware/spine-core": "^4.2.11"
+                "@esotericsoftware/spine-core": "4.1.29"
             }
             }
         },
         },
         "node_modules/accepts": {
         "node_modules/accepts": {

+ 1 - 1
spine-ts/spine-phaser/example/typescript/package.json

@@ -8,7 +8,7 @@
         "dev": "npx concurrently \"npx live-server --no-browser\" \"npm run build -- --watch\""   
         "dev": "npx concurrently \"npx live-server --no-browser\" \"npm run build -- --watch\""   
     },
     },
     "dependencies": {
     "dependencies": {
-        "@esotericsoftware/spine-phaser": "4.1.*",
+        "@esotericsoftware/spine-phaser": "../../",
         "phaser": "3.60.0"
         "phaser": "3.60.0"
     },
     },
     "devDependencies": {
     "devDependencies": {

+ 9 - 18
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))))))) {
 export class SpineGameObject extends ComputedSizeMixin(DepthMixin(FlipMixin(ScrollFactorMixin(TransformMixin(VisibleMixin(AlphaMixin(BaseSpineGameObject))))))) {
 	blendMode = -1;
 	blendMode = -1;
-	skeleton: Skeleton | null = null;
-	animationStateData: AnimationStateData | null = null;
-	animationState: AnimationState | null = null;
+	skeleton: Skeleton;
+	animationStateData: AnimationStateData;
+	animationState: AnimationState;
 	private premultipliedAlpha = false;
 	private premultipliedAlpha = false;
 	private _displayOriginX = 0;
 	private _displayOriginX = 0;
 	private _displayOriginY = 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()) {
 	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);
 		super(scene, SPINE_GAME_OBJECT_TYPE);
 		this.setPosition(x, y);
 		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 () {
 	public get displayOriginX () {