Ver Fonte

[libgdx] Added SkeletonLoader#readSkeletonData(InputStream).

Nathan Sweet há 4 anos atrás
pai
commit
b05422bf0d

+ 13 - 3
spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java

@@ -31,6 +31,7 @@ package com.esotericsoftware.spine;
 
 import java.io.EOFException;
 import java.io.IOException;
+import java.io.InputStream;
 
 import com.badlogic.gdx.files.FileHandle;
 import com.badlogic.gdx.graphics.Color;
@@ -128,13 +129,18 @@ public class SkeletonBinary extends SkeletonLoader {
 
 	public SkeletonData readSkeletonData (FileHandle file) {
 		if (file == null) throw new IllegalArgumentException("file cannot be null.");
+		SkeletonData skeletonData = readSkeletonData(file.read());
+		skeletonData.name = file.nameWithoutExtension();
+		return skeletonData;
+	}
+
+	public SkeletonData readSkeletonData (InputStream dataInput) {
+		if (dataInput == null) throw new IllegalArgumentException("dataInput cannot be null.");
 
 		float scale = this.scale;
 
+		SkeletonInput input = new SkeletonInput(dataInput);
 		SkeletonData skeletonData = new SkeletonData();
-		skeletonData.name = file.nameWithoutExtension();
-
-		SkeletonInput input = new SkeletonInput(file);
 		try {
 			long hash = input.readLong();
 			skeletonData.hash = hash == 0 ? null : Long.toString(hash);
@@ -1054,6 +1060,10 @@ public class SkeletonBinary extends SkeletonLoader {
 		private char[] chars = new char[32];
 		String[] strings;
 
+		public SkeletonInput (InputStream input) {
+			super(input);
+		}
+
 		public SkeletonInput (FileHandle file) {
 			super(file.read(512));
 		}

+ 14 - 9
spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java

@@ -31,6 +31,8 @@ package com.esotericsoftware.spine;
 
 import static com.esotericsoftware.spine.utils.SpineUtils.*;
 
+import java.io.InputStream;
+
 import com.badlogic.gdx.files.FileHandle;
 import com.badlogic.gdx.graphics.Color;
 import com.badlogic.gdx.graphics.g2d.TextureAtlas;
@@ -100,22 +102,25 @@ public class SkeletonJson extends SkeletonLoader {
 		super(atlas);
 	}
 
-	protected JsonValue parse (FileHandle file) {
-		if (file == null) throw new IllegalArgumentException("file cannot be null.");
-		return new JsonReader().parse(file);
-	}
-
 	public SkeletonData readSkeletonData (FileHandle file) {
 		if (file == null) throw new IllegalArgumentException("file cannot be null.");
+		SkeletonData skeletonData = readSkeletonData(new JsonReader().parse(file));
+		skeletonData.name = file.nameWithoutExtension();
+		return skeletonData;
+	}
 
-		float scale = this.scale;
+	public SkeletonData readSkeletonData (InputStream input) {
+		if (input == null) throw new IllegalArgumentException("dataInput cannot be null.");
+		return readSkeletonData(new JsonReader().parse(input));
+	}
 
-		SkeletonData skeletonData = new SkeletonData();
-		skeletonData.name = file.nameWithoutExtension();
+	public SkeletonData readSkeletonData (JsonValue root) {
+		if (root == null) throw new IllegalArgumentException("root cannot be null.");
 
-		JsonValue root = parse(file);
+		float scale = this.scale;
 
 		// Skeleton.
+		SkeletonData skeletonData = new SkeletonData();
 		JsonValue skeletonMap = root.get("skeleton");
 		if (skeletonMap != null) {
 			skeletonData.hash = skeletonMap.getString("hash", null);

+ 4 - 0
spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonLoader.java

@@ -1,6 +1,8 @@
 
 package com.esotericsoftware.spine;
 
+import java.io.InputStream;
+
 import com.badlogic.gdx.files.FileHandle;
 import com.badlogic.gdx.graphics.g2d.TextureAtlas;
 import com.badlogic.gdx.utils.Array;
@@ -46,4 +48,6 @@ abstract public class SkeletonLoader {
 	}
 
 	abstract public SkeletonData readSkeletonData (FileHandle file);
+
+	abstract public SkeletonData readSkeletonData (InputStream input);
 }