mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 07:14:55 +08:00
Readers, not streams.
This commit is contained in:
parent
3b1cf6579c
commit
087b0cd874
@ -39,20 +39,20 @@ namespace Spine {
|
||||
public Object Texture;
|
||||
|
||||
public Atlas (String path, Object texture, int textureWidth, int textureHeight) {
|
||||
using (Stream input = new FileStream(path, FileMode.Open, FileAccess.Read)) {
|
||||
using (StreamReader reader = new StreamReader(path)) {
|
||||
try {
|
||||
initialize(input, texture, textureWidth, textureHeight);
|
||||
initialize(reader, texture, textureWidth, textureHeight);
|
||||
} catch (Exception ex) {
|
||||
throw new Exception("Error reading atlas file: " + path, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Atlas (Stream input, Object texture, int textureWidth, int textureHeight) {
|
||||
initialize(input, texture, textureWidth, textureHeight);
|
||||
public Atlas (TextReader reader, Object texture, int textureWidth, int textureHeight) {
|
||||
initialize(reader, texture, textureWidth, textureHeight);
|
||||
}
|
||||
|
||||
private void initialize (Stream input, Object texture, int textureWidth, int textureHeight) {
|
||||
private void initialize (TextReader reader, Object texture, int textureWidth, int textureHeight) {
|
||||
TextureWidth = textureWidth;
|
||||
TextureHeight = textureHeight;
|
||||
Texture = texture;
|
||||
@ -62,7 +62,6 @@ namespace Spine {
|
||||
float invTexHeight = 1f / textureHeight;
|
||||
String[] tuple = new String[4];
|
||||
|
||||
StreamReader reader = new StreamReader(input);
|
||||
// Skip to first page entry.
|
||||
while (true) {
|
||||
String line = reader.ReadLine();
|
||||
@ -144,7 +143,7 @@ namespace Spine {
|
||||
}
|
||||
}
|
||||
|
||||
static String readValue (StreamReader reader) {
|
||||
static String readValue (TextReader reader) {
|
||||
String line = reader.ReadLine();
|
||||
int colon = line.IndexOf(':');
|
||||
if (colon == -1)
|
||||
@ -153,7 +152,7 @@ namespace Spine {
|
||||
}
|
||||
|
||||
/** Returns the number of tuple values read (2 or 4). */
|
||||
static int readTuple (StreamReader reader, String[] tuple) {
|
||||
static int readTuple (TextReader reader, String[] tuple) {
|
||||
String line = reader.ReadLine();
|
||||
int colon = line.IndexOf(':');
|
||||
if (colon == -1)
|
||||
|
||||
@ -52,20 +52,19 @@ namespace Spine {
|
||||
}
|
||||
|
||||
public SkeletonData ReadSkeletonData (String path) {
|
||||
using (Stream input = new FileStream(path, FileMode.Open, FileAccess.Read)) {
|
||||
SkeletonData skeletonData = ReadSkeletonData(input);
|
||||
using (StreamReader reader = new StreamReader(path)) {
|
||||
SkeletonData skeletonData = ReadSkeletonData(reader);
|
||||
skeletonData.Name = Path.GetFileNameWithoutExtension(path);
|
||||
return skeletonData;
|
||||
}
|
||||
}
|
||||
|
||||
public SkeletonData ReadSkeletonData (Stream input) {
|
||||
if (input == null)
|
||||
throw new ArgumentNullException("json cannot be null.");
|
||||
public SkeletonData ReadSkeletonData (TextReader reader) {
|
||||
if (reader == null) throw new ArgumentNullException("reader cannot be null.");
|
||||
|
||||
SkeletonData skeletonData = new SkeletonData();
|
||||
|
||||
var root = Json.Deserialize(new StreamReader(input)) as Dictionary<String, Object>;
|
||||
var root = Json.Deserialize(reader) as Dictionary<String, Object>;
|
||||
|
||||
// Bones.
|
||||
foreach (Dictionary<String, Object> boneMap in (List<Object>)root["bones"]) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user