소스 검색

[haxe] AssetsTextureLoader is now StarlingTextureLoader, remove TextureAtlas.from, change SkeletonData.from to not use OpenFL Assets.

Mario Zechner 2 년 전
부모
커밋
eed1a3e30a

+ 5 - 3
spine-haxe/example/src/BasicExample.hx

@@ -27,20 +27,22 @@
  * SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *****************************************************************************/
 
+import openfl.utils.Assets;
 import spine.SkeletonData;
 import spine.animation.AnimationStateData;
 import spine.atlas.TextureAtlas;
 import spine.starling.SkeletonSprite;
+import spine.starling.StarlingTextureLoader;
 import starling.core.Starling;
 import starling.events.TouchEvent;
 import starling.events.TouchPhase;
 
 class BasicExample extends Scene {
-	var loadBinary = false;
+	var loadBinary = true;
 
 	public function load():Void {
-		var atlas = TextureAtlas.fromAssets("assets/raptor.atlas");
-		var skeletondata = SkeletonData.fromAssets("assets/raptor-pro" + (loadBinary ? ".skel" : ".json"), atlas);
+		var atlas = new TextureAtlas(Assets.getText("assets/raptor.atlas"), new StarlingTextureLoader("assets/raptor-pro.atlas"));
+		var skeletondata = SkeletonData.from(loadBinary ? Assets.getBytes("assets/raptor-pro.skel") : Assets.getText("assets/raptor-pro.json"), atlas);
 		var animationStateData = new AnimationStateData(skeletondata);
 		animationStateData.defaultMix = 0.25;
 

+ 4 - 2
spine-haxe/example/src/SequenceExample.hx

@@ -27,10 +27,12 @@
  * SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *****************************************************************************/
 
+import openfl.utils.Assets;
 import spine.SkeletonData;
 import spine.animation.AnimationStateData;
 import spine.atlas.TextureAtlas;
 import spine.starling.SkeletonSprite;
+import spine.starling.StarlingTextureLoader;
 import starling.core.Starling;
 import starling.events.TouchEvent;
 import starling.events.TouchPhase;
@@ -39,8 +41,8 @@ class SequenceExample extends Scene {
 	var loadBinary = false;
 
 	public function load():Void {
-		var atlas = TextureAtlas.fromAssets("assets/dragon.atlas");
-		var skeletondata = SkeletonData.fromAssets("assets/dragon-ess" + (loadBinary ? ".skel" : ".json"), atlas);
+		var atlas = new TextureAtlas(Assets.getText("assets/dragon.atlas"), new StarlingTextureLoader("assets/dragon.atlas"));
+		var skeletondata = SkeletonData.from(loadBinary ? Assets.getBytes("assets/dragon-ess.skel") : Assets.getText("assets/dragon-ess.json"), atlas);
 		var animationStateData = new AnimationStateData(skeletondata);
 		animationStateData.defaultMix = 0.25;
 

+ 7 - 8
spine-haxe/spine-haxe/spine/SkeletonData.hx

@@ -29,6 +29,7 @@
 
 package spine;
 
+import haxe.io.Bytes;
 import openfl.utils.Assets;
 import spine.animation.Animation;
 import spine.atlas.TextureAtlas;
@@ -57,19 +58,17 @@ class SkeletonData {
 	public var imagesPath:String;
 	public var audioPath:String;
 
-	public static function fromAssets(path:String, atlas:TextureAtlas, scale:Float = 1.0):SkeletonData {
-		if (StringTools.endsWith(path, ".skel")) {
-			var byteData = Assets.getBytes(path);
+	public static function from(data:Dynamic, atlas:TextureAtlas, scale:Float = 1.0):SkeletonData {
+		if (Std.isOfType(data, Bytes)) {
 			var loader = new SkeletonBinary(new AtlasAttachmentLoader(atlas));
 			loader.scale = scale;
-			return loader.readSkeletonData(byteData);
-		} else if (StringTools.endsWith(path, ".json")) {
-			var jsonData = Assets.getText(path);
+			return loader.readSkeletonData(cast(data, Bytes));
+		} else if (Std.isOfType(data, String)) {
 			var loader = new SkeletonJson(new AtlasAttachmentLoader(atlas));
 			loader.scale = scale;
-			return loader.readSkeletonData(jsonData);
+			return loader.readSkeletonData(cast(data, String));
 		} else {
-			throw new SpineException("Path of skeleton data file must end with .json or .skel");
+			throw new SpineException("Data must either be a String (.json) or Bytes (.skel) instance.");
 		}
 	}
 

+ 0 - 11
spine-haxe/spine-haxe/spine/atlas/TextureAtlas.hx

@@ -37,17 +37,6 @@ class TextureAtlas {
 	private var regions = new Array<TextureAtlasRegion>();
 	private var textureLoader:TextureLoader;
 
-	public static function fromAssets(path:String) {
-		var basePath = "";
-		var slashIndex = path.lastIndexOf("/");
-		if (slashIndex != -1) {
-			basePath = path.substring(0, slashIndex);
-		}
-
-		var textureLoader = new AssetsTextureLoader(basePath);
-		return new TextureAtlas(Assets.getText(path), textureLoader);
-	}
-
 	/** @param object A String or ByteArray. */
 	public function new(atlasText:String, textureLoader:TextureLoader) {
 		if (atlasText == null) {

+ 8 - 4
spine-haxe/spine-haxe/spine/atlas/AssetsTextureLoader.hx → spine-haxe/spine-haxe/spine/starling/StarlingTextureLoader.hx

@@ -27,18 +27,22 @@
  * SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *****************************************************************************/
 
-package spine.atlas;
+package spine.starling;
 
 import starling.textures.Texture;
 import spine.atlas.TextureAtlasRegion;
 import spine.atlas.TextureAtlasPage;
 import spine.atlas.TextureLoader;
 
-class AssetsTextureLoader implements TextureLoader {
+class StarlingTextureLoader implements TextureLoader {
 	private var basePath:String;
 
-	public function new(basePath:String) {
-		this.basePath = basePath;
+	public function new(atlasPath:String) {
+		basePath = "";
+		var slashIndex = atlasPath.lastIndexOf("/");
+		if (slashIndex != -1) {
+			basePath = atlasPath.substring(0, slashIndex);
+		}
 	}
 
 	public function loadPage(page:TextureAtlasPage, path:String) {