[libgdx] Added SkeletonLoader#readSkeletonData(InputStream).

This commit is contained in:
Nathan Sweet 2021-03-13 19:07:48 +01:00
parent 365b242a46
commit b05422bf0d
3 changed files with 32 additions and 13 deletions

View File

@ -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));
}

View File

@ -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;
}
public SkeletonData readSkeletonData (InputStream input) {
if (input == null) throw new IllegalArgumentException("dataInput cannot be null.");
return readSkeletonData(new JsonReader().parse(input));
}
public SkeletonData readSkeletonData (JsonValue root) {
if (root == null) throw new IllegalArgumentException("root cannot be null.");
float scale = this.scale;
SkeletonData skeletonData = new SkeletonData();
skeletonData.name = file.nameWithoutExtension();
JsonValue root = parse(file);
// Skeleton.
SkeletonData skeletonData = new SkeletonData();
JsonValue skeletonMap = root.get("skeleton");
if (skeletonMap != null) {
skeletonData.hash = skeletonMap.getString("hash", null);

View File

@ -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);
}