From d14f65d779ac0a2fc7d54b9ba88cb48c71e1de2b Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Sat, 12 May 2012 18:49:22 -0500 Subject: [PATCH] Adding support to load a Gleed2D level from a stream --- axios/Axios_settings.cs | 1 + axios/Engine/Gleed2D/Level.cs | 26 +++++++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/axios/Axios_settings.cs b/axios/Axios_settings.cs index fc86aa6..a7de535 100644 --- a/axios/Axios_settings.cs +++ b/axios/Axios_settings.cs @@ -73,6 +73,7 @@ * - Splitting the code for Gleed2D into seperate files * - Adding a cache for loading in textures for Gleed2D * - Adding GetStream(FileMode) to get the stream of a file + * - Adding support to load a Gleed2D level from a stream * */ diff --git a/axios/Engine/Gleed2D/Level.cs b/axios/Engine/Gleed2D/Level.cs index 2da0626..b6f27a3 100644 --- a/axios/Engine/Gleed2D/Level.cs +++ b/axios/Engine/Gleed2D/Level.cs @@ -38,15 +38,12 @@ namespace Axios.Engine.Gleed2D /// public SerializableDictionary CustomProperties; - private Dictionary _texturecache; - public Level() { Visible = true; Layers = new List(); CustomProperties = new SerializableDictionary(); - _texturecache = new Dictionary(); } public Level(World world) @@ -55,11 +52,11 @@ namespace Axios.Engine.Gleed2D Layers = new List(); CustomProperties = new SerializableDictionary(); _world = world; - _texturecache = new Dictionary(); } - public static Level FromFile(string filename, ContentManager cm, World world, ref Dictionary cache) + public static Level FromFile(string filename, ContentManager cm, World world) { + Dictionary cache = new Dictionary(); FileStream stream = System.IO.File.Open(filename, FileMode.Open); XmlSerializer serializer = new XmlSerializer(typeof(Level)); Level level = (Level)serializer.Deserialize(stream); @@ -77,6 +74,25 @@ namespace Axios.Engine.Gleed2D return level; } + public static Level FromStream(FileStream stream, ContentManager cm, World world) + { + Dictionary cache = new Dictionary(); + 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) { foreach (Layer layer in Layers)