Readers, not streams.

This commit is contained in:
NathanSweet 2013-04-13 19:25:05 +02:00
parent 3b1cf6579c
commit 087b0cd874
2 changed files with 12 additions and 14 deletions

View File

@ -39,20 +39,20 @@ namespace Spine {
public Object Texture; public Object Texture;
public Atlas (String path, Object texture, int textureWidth, int textureHeight) { 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 { try {
initialize(input, texture, textureWidth, textureHeight); initialize(reader, texture, textureWidth, textureHeight);
} catch (Exception ex) { } catch (Exception ex) {
throw new Exception("Error reading atlas file: " + path, ex); throw new Exception("Error reading atlas file: " + path, ex);
} }
} }
} }
public Atlas (Stream input, Object texture, int textureWidth, int textureHeight) { public Atlas (TextReader reader, Object texture, int textureWidth, int textureHeight) {
initialize(input, texture, textureWidth, 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; TextureWidth = textureWidth;
TextureHeight = textureHeight; TextureHeight = textureHeight;
Texture = texture; Texture = texture;
@ -62,7 +62,6 @@ namespace Spine {
float invTexHeight = 1f / textureHeight; float invTexHeight = 1f / textureHeight;
String[] tuple = new String[4]; String[] tuple = new String[4];
StreamReader reader = new StreamReader(input);
// Skip to first page entry. // Skip to first page entry.
while (true) { while (true) {
String line = reader.ReadLine(); String line = reader.ReadLine();
@ -144,7 +143,7 @@ namespace Spine {
} }
} }
static String readValue (StreamReader reader) { static String readValue (TextReader reader) {
String line = reader.ReadLine(); String line = reader.ReadLine();
int colon = line.IndexOf(':'); int colon = line.IndexOf(':');
if (colon == -1) if (colon == -1)
@ -153,7 +152,7 @@ namespace Spine {
} }
/** Returns the number of tuple values read (2 or 4). */ /** 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(); String line = reader.ReadLine();
int colon = line.IndexOf(':'); int colon = line.IndexOf(':');
if (colon == -1) if (colon == -1)

View File

@ -52,20 +52,19 @@ namespace Spine {
} }
public SkeletonData ReadSkeletonData (String path) { public SkeletonData ReadSkeletonData (String path) {
using (Stream input = new FileStream(path, FileMode.Open, FileAccess.Read)) { using (StreamReader reader = new StreamReader(path)) {
SkeletonData skeletonData = ReadSkeletonData(input); SkeletonData skeletonData = ReadSkeletonData(reader);
skeletonData.Name = Path.GetFileNameWithoutExtension(path); skeletonData.Name = Path.GetFileNameWithoutExtension(path);
return skeletonData; return skeletonData;
} }
} }
public SkeletonData ReadSkeletonData (Stream input) { public SkeletonData ReadSkeletonData (TextReader reader) {
if (input == null) if (reader == null) throw new ArgumentNullException("reader cannot be null.");
throw new ArgumentNullException("json cannot be null.");
SkeletonData skeletonData = new SkeletonData(); 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. // Bones.
foreach (Dictionary<String, Object> boneMap in (List<Object>)root["bones"]) { foreach (Dictionary<String, Object> boneMap in (List<Object>)root["bones"]) {