Adding support to load a Gleed2D level from a stream
This commit is contained in:
parent
e74c663c02
commit
d14f65d779
@ -73,6 +73,7 @@
|
|||||||
* - Splitting the code for Gleed2D into seperate files
|
* - Splitting the code for Gleed2D into seperate files
|
||||||
* - Adding a cache for loading in textures for Gleed2D
|
* - Adding a cache for loading in textures for Gleed2D
|
||||||
* - Adding GetStream(FileMode) to get the stream of a file
|
* - Adding GetStream(FileMode) to get the stream of a file
|
||||||
|
* - Adding support to load a Gleed2D level from a stream
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -38,15 +38,12 @@ namespace Axios.Engine.Gleed2D
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public SerializableDictionary CustomProperties;
|
public SerializableDictionary CustomProperties;
|
||||||
|
|
||||||
private Dictionary<string, Texture2D> _texturecache;
|
|
||||||
|
|
||||||
|
|
||||||
public Level()
|
public Level()
|
||||||
{
|
{
|
||||||
Visible = true;
|
Visible = true;
|
||||||
Layers = new List<Layer>();
|
Layers = new List<Layer>();
|
||||||
CustomProperties = new SerializableDictionary();
|
CustomProperties = new SerializableDictionary();
|
||||||
_texturecache = new Dictionary<string, Texture2D>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Level(World world)
|
public Level(World world)
|
||||||
@ -55,11 +52,11 @@ namespace Axios.Engine.Gleed2D
|
|||||||
Layers = new List<Layer>();
|
Layers = new List<Layer>();
|
||||||
CustomProperties = new SerializableDictionary();
|
CustomProperties = new SerializableDictionary();
|
||||||
_world = world;
|
_world = world;
|
||||||
_texturecache = new Dictionary<string, Texture2D>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Level FromFile(string filename, ContentManager cm, World world, ref Dictionary<string, Texture2D> cache)
|
public static Level FromFile(string filename, ContentManager cm, World world)
|
||||||
{
|
{
|
||||||
|
Dictionary<string, Texture2D> cache = new Dictionary<string, Texture2D>();
|
||||||
FileStream stream = System.IO.File.Open(filename, FileMode.Open);
|
FileStream stream = System.IO.File.Open(filename, FileMode.Open);
|
||||||
XmlSerializer serializer = new XmlSerializer(typeof(Level));
|
XmlSerializer serializer = new XmlSerializer(typeof(Level));
|
||||||
Level level = (Level)serializer.Deserialize(stream);
|
Level level = (Level)serializer.Deserialize(stream);
|
||||||
@ -77,6 +74,25 @@ namespace Axios.Engine.Gleed2D
|
|||||||
return level;
|
return level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Level FromStream(FileStream stream, ContentManager cm, World world)
|
||||||
|
{
|
||||||
|
Dictionary<string, Texture2D> cache = new Dictionary<string, Texture2D>();
|
||||||
|
XmlSerializer serializer = new XmlSerializer(typeof(Level));
|
||||||
|
Level level = (Level)serializer.Deserialize(stream);
|
||||||
|
stream.Close();
|
||||||
|
|
||||||
|
foreach (Layer layer in level.Layers)
|
||||||
|
{
|
||||||
|
foreach (Item item in layer.Items)
|
||||||
|
{
|
||||||
|
item.CustomProperties.RestoreItemAssociations(level);
|
||||||
|
item.load(cm, world, ref cache);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
public Item getItemByName(string name)
|
public Item getItemByName(string name)
|
||||||
{
|
{
|
||||||
foreach (Layer layer in Layers)
|
foreach (Layer layer in Layers)
|
||||||
|
Loading…
Reference in New Issue
Block a user