clean up some stream using code (using blocks, dispose calls, etc)
This commit is contained in:
parent
bd55d43ab3
commit
25c08c807a
|
@ -10,12 +10,14 @@ namespace Blarg.GameFramework.Graphics.Atlas.Json
|
||||||
{
|
{
|
||||||
public static TextureAtlas Load(string file)
|
public static TextureAtlas Load(string file)
|
||||||
{
|
{
|
||||||
var stream = Framework.FileSystem.Open(file);
|
using (var stream = Framework.FileSystem.Open(file))
|
||||||
string path = null;
|
{
|
||||||
if (file.Contains("/"))
|
string path = null;
|
||||||
path = file.Substring(0, file.LastIndexOf('/') + 1);
|
if (file.Contains("/"))
|
||||||
|
path = file.Substring(0, file.LastIndexOf('/') + 1);
|
||||||
return Load(stream, path);
|
|
||||||
|
return Load(stream, path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TextureAtlas Load(Stream file, string texturePath = null)
|
public static TextureAtlas Load(Stream file, string texturePath = null)
|
||||||
|
@ -25,6 +27,7 @@ namespace Blarg.GameFramework.Graphics.Atlas.Json
|
||||||
|
|
||||||
var reader = new StreamReader(file);
|
var reader = new StreamReader(file);
|
||||||
var definition = JsonConvert.DeserializeObject<JsonTextureAtlasDefinition>(reader.ReadToEnd());
|
var definition = JsonConvert.DeserializeObject<JsonTextureAtlasDefinition>(reader.ReadToEnd());
|
||||||
|
reader.Dispose();
|
||||||
|
|
||||||
if (definition.Texture == null)
|
if (definition.Texture == null)
|
||||||
throw new ConfigFileException("No texture file specified.");
|
throw new ConfigFileException("No texture file specified.");
|
||||||
|
|
|
@ -32,6 +32,7 @@ namespace Blarg.GameFramework.TileMap.Json
|
||||||
|
|
||||||
var reader = new StreamReader(file);
|
var reader = new StreamReader(file);
|
||||||
var map = JsonConvert.DeserializeObject<JsonTileMap>(reader.ReadToEnd());
|
var map = JsonConvert.DeserializeObject<JsonTileMap>(reader.ReadToEnd());
|
||||||
|
reader.Dispose();
|
||||||
|
|
||||||
if (map.Chunks == null || map.Chunks.Count == 0)
|
if (map.Chunks == null || map.Chunks.Count == 0)
|
||||||
throw new ConfigFileException("Invalid map: no chunks.");
|
throw new ConfigFileException("Invalid map: no chunks.");
|
||||||
|
|
|
@ -11,12 +11,14 @@ namespace Blarg.GameFramework.TileMap.Meshes.Json
|
||||||
{
|
{
|
||||||
public static TileMeshCollection Load(string file, TextureAtlas atlas)
|
public static TileMeshCollection Load(string file, TextureAtlas atlas)
|
||||||
{
|
{
|
||||||
var stream = Framework.FileSystem.Open(file);
|
using (var stream = Framework.FileSystem.Open(file))
|
||||||
string path = null;
|
{
|
||||||
if (file.Contains("/"))
|
string path = null;
|
||||||
path = file.Substring(0, file.LastIndexOf('/') + 1);
|
if (file.Contains("/"))
|
||||||
|
path = file.Substring(0, file.LastIndexOf('/') + 1);
|
||||||
return Load(stream, atlas, path);
|
|
||||||
|
return Load(stream, atlas, path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TileMeshCollection Load(Stream file, TextureAtlas atlas, string filePath = null)
|
public static TileMeshCollection Load(Stream file, TextureAtlas atlas, string filePath = null)
|
||||||
|
@ -28,6 +30,7 @@ namespace Blarg.GameFramework.TileMap.Meshes.Json
|
||||||
|
|
||||||
var reader = new StreamReader(file);
|
var reader = new StreamReader(file);
|
||||||
var definition = JsonConvert.DeserializeObject<JsonTileMeshCollection>(reader.ReadToEnd());
|
var definition = JsonConvert.DeserializeObject<JsonTileMeshCollection>(reader.ReadToEnd());
|
||||||
|
reader.Dispose();
|
||||||
|
|
||||||
var collection = new TileMeshCollection(atlas);
|
var collection = new TileMeshCollection(atlas);
|
||||||
|
|
||||||
|
|
Reference in a new issue