Beispiel #1
0
        /// <summary>
        /// The serialize.
        /// </summary>
        /// <param name="stream">
        /// The stream.
        /// </param>
        /// <param name="serializableLevel">
        /// The level entity collection.
        /// </param>
        public void Serialize(Stream stream, SerializableLevel serializableLevel)
        {
            IEnumerable <Type> entityTypes = from levelEntityTypeBinding in LevelScene.LevelEntityTypeBindings
                                             select levelEntityTypeBinding.LevelEntityType;
            var xmlSerializer = new XmlSerializer(typeof(SerializableLevel), entityTypes.ToArray());

            xmlSerializer.Serialize(stream, serializableLevel);
        }
Beispiel #2
0
        /// <summary>
        /// The create serializable collection.
        /// </summary>
        /// <param name="level">
        /// The level.
        /// </param>
        /// <returns>
        /// </returns>
        private SerializableLevel CreateSerializableLevel(Level level)
        {
            var serializableLevel = new SerializableLevel
            {
                Author = level.Author, Script = level.Script, StartPosition = level.StartPosition
            };

            foreach (LevelEntity levelEntity in
                     level.Components.Select(sceneComponent => this.ConvertToEntity(sceneComponent)))
            {
                serializableLevel.LevelEntityCollection.Add(levelEntity);
            }

            return(serializableLevel);
        }
Beispiel #3
0
        /// <summary>
        /// The convert to level.
        /// </summary>
        /// <param name="serializableLevel">
        /// The level entity collection.
        /// </param>
        /// <param name="scene">
        /// The scene.
        /// </param>
        /// <returns>
        /// </returns>
        public Level ConvertToLevel(SerializableLevel serializableLevel, Scene scene)
        {
            var level = new Level(false)
            {
                Author        = serializableLevel.Author,
                Script        = serializableLevel.Script,
                StartPosition = serializableLevel.StartPosition
            };

            foreach (SceneComponent sceneComponent in
                     serializableLevel.LevelEntityCollection.Select(
                         levelEntity => this.ConvertToSceneComponent(levelEntity, scene)))
            {
                level.Components.Add(sceneComponent);
            }

            return(level);
        }
Beispiel #4
0
        /// <summary>
        /// The deserialize.
        /// </summary>
        /// <param name="stream">
        /// The stream.
        /// </param>
        /// <param name="scene">
        /// The scene.
        /// </param>
        /// <returns>
        /// </returns>
        public Level Deserialize(Stream stream, Scene scene)
        {
            SerializableLevel levelEntityCollection = this.Deserialize(stream);

            return(this.ConvertToLevel(levelEntityCollection, scene));
        }
Beispiel #5
0
        /// <summary>
        /// The serialize.
        /// </summary>
        /// <param name="stream">
        /// The stream.
        /// </param>
        /// <param name="level">
        /// The level.
        /// </param>
        public void Serialize(Stream stream, Level level)
        {
            SerializableLevel serializableLevel = this.CreateSerializableLevel(level);

            this.Serialize(stream, serializableLevel);
        }