Exemple #1
0
        /// <summary>
        /// The main Process method converts an intermediate format content pipeline
        /// NodeContent tree to a ModelContent object with embedded animation data.
        /// </summary>
        public override ModelContent Process(NodeContent input, ContentProcessorContext context)
        {
            contentPath = Environment.CurrentDirectory;

            using (XmlReader reader = XmlReader.Create(MaterialDataFilePath))
            {
                incomingMaterials = IntermediateSerializer.Deserialize <List <MaterialData> >(reader, null);
            }
            context.AddDependency(Path.Combine(Environment.CurrentDirectory, MaterialDataFilePath));

            // Chain to the base ModelProcessor class so it can convert the model data.
            ModelContent model = base.Process(input, context);

            // Put the material's flags into the ModelMeshPartContent's Tag property.
            foreach (ModelMeshContent mmc in model.Meshes)
            {
                foreach (ModelMeshPartContent mmpc in mmc.MeshParts)
                {
                    MaterialData mat       = incomingMaterials.Single(m => m.Name == mmpc.Material.Name);
                    MaterialInfo extraInfo = new MaterialInfo();
                    extraInfo.HandlingFlags = mat.HandlingFlags;
                    extraInfo.RenderState   = mat.RenderState;
                    mmpc.Tag = extraInfo;
                }
            }

            return(model);
        }
Exemple #2
0
        public void MathTypes()
        {
            object result;
            var    filePath = Paths.Xml("12_MathTypes.xml");

            using (var reader = XmlReader.Create(filePath))
                result = IntermediateSerializer.Deserialize <object>(reader, filePath);

            Assert.NotNull(result);
            Assert.IsAssignableFrom <MathTypes>(result);
            var mathTypes = (MathTypes)result;

            Assert.AreEqual(new Point(1, 2), mathTypes.Point);
            Assert.AreEqual(new Rectangle(1, 2, 3, 4), mathTypes.Rectangle);
            Assert.AreEqual(new Vector3(1, 2, 3), mathTypes.Vector3);
            Assert.AreEqual(new Vector4(1, 2, 3, 4), mathTypes.Vector4);
            Assert.AreEqual(new Quaternion(1, 2, 3, 4), mathTypes.Quaternion);
            Assert.AreEqual(new Plane(1, 2, 3, 4), mathTypes.Plane);
            Assert.AreEqual(new Matrix(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), mathTypes.Matrix);
            Assert.AreEqual(Color.CornflowerBlue, mathTypes.Color);
            Assert.NotNull(mathTypes.Vector2Array);
            Assert.AreEqual(2, mathTypes.Vector2Array.Length);
            Assert.AreEqual(Vector2.Zero, mathTypes.Vector2Array[0]);
            Assert.AreEqual(Vector2.One, mathTypes.Vector2Array[1]);
        }
        private T ReadAssetSourceFile <T>(string fileName, Action <IDisposable> recordDisposableObject)
        {
            GraphicsDevice device = ((IGraphicsDeviceService)ServiceProvider.GetService(typeof(IGraphicsDeviceService))).GraphicsDevice;

            //if (typeof(T) == typeof(Model))
            //{
            //    //
            //    //
            //    //return (T)(object)ModelInjector.X2Model.ModelFromFile(device, fileName);
            //}
            //else
            //else if (typeof(T) == typeof(Effect))
            //{
            //return (T)(object)ModelInjector.EffectCompiler.FromFile(device, fileName);
            //}
            if (typeof(T) == typeof(Texture2D))
            {
                object texture = null;
                using (Stream fs = File.OpenRead(fileName))
                {
                    texture = Texture2D.FromStream(device, fs);
                }
                return((T)texture);
            }
            else
            {
                using (XmlReader inXml = XmlReader.Create(fileName))
                {
                    return(IntermediateSerializer.Deserialize <T>(inXml, fileName));
                }
            }
            return(default(T));
        }
Exemple #4
0
        public static T Serialize <T>(T data)
        {
            var stringBuilder = new StringBuilder();

            XmlWriterSettings settings = new XmlWriterSettings {
                Indent = true
            };

            using (XmlWriter writer = XmlWriter.Create(stringBuilder, settings))
            {
                IntermediateSerializer.Serialize(writer, data, null);
            }

            var xml = stringBuilder.ToString();

            Trace.WriteLine("-----------------------------");
            Trace.WriteLine(xml);
            Trace.WriteLine("-----------------------------");


            using (XmlReader reader = XmlReader.Create(new StringReader(xml)))
            {
                return(IntermediateSerializer.Deserialize <T>(reader, null));
            }
        }
Exemple #5
0
        public override object Import(string filename, ContentImporterContext context)
        {
            context.Logger.LogMessage("Importing Xml asset", null);
            XmlReader reader = XmlReader.Create(filename);

            return(IntermediateSerializer.Deserialize <object>(reader, filename));
        }
Exemple #6
0
        public void PolymorphicTypes()
        {
            object result;
            var    filePath = Paths.Xml("13_PolymorphicTypes.xml");

            using (var reader = XmlReader.Create(filePath))
                result = IntermediateSerializer.Deserialize <object>(reader, filePath);

            Assert.NotNull(result);
            Assert.IsInstanceOf <PolymorphicTypes>(result);
            var polymorphicTypes = (PolymorphicTypes)result;

            Assert.AreEqual("World", polymorphicTypes.Hello);
            Assert.AreEqual(23, polymorphicTypes.Elf);

            Assert.NotNull(polymorphicTypes.TypedArray);
            Assert.AreEqual(3, polymorphicTypes.TypedArray.Length);
            Assert.IsAssignableFrom <PolymorphicA>(polymorphicTypes.TypedArray[0]);
            Assert.AreEqual(true, polymorphicTypes.TypedArray[0].Value);
            Assert.IsAssignableFrom <PolymorphicB>(polymorphicTypes.TypedArray[1]);
            Assert.AreEqual(true, polymorphicTypes.TypedArray[1].Value);
            Assert.IsAssignableFrom <PolymorphicC>(polymorphicTypes.TypedArray[2]);
            Assert.AreEqual(true, polymorphicTypes.TypedArray[2].Value);

            Assert.NotNull(polymorphicTypes.UntypedArray);
            Assert.AreEqual(3, polymorphicTypes.UntypedArray.Length);
            Assert.IsAssignableFrom <PolymorphicA>(polymorphicTypes.UntypedArray.GetValue(0));
            Assert.AreEqual(true, ((PolymorphicA)polymorphicTypes.UntypedArray.GetValue(0)).Value);
            Assert.IsAssignableFrom <PolymorphicB>(polymorphicTypes.UntypedArray.GetValue(1));
            Assert.AreEqual(true, ((PolymorphicB)polymorphicTypes.UntypedArray.GetValue(1)).Value);
            Assert.IsAssignableFrom <PolymorphicC>(polymorphicTypes.UntypedArray.GetValue(2));
            Assert.AreEqual(true, ((PolymorphicC)polymorphicTypes.UntypedArray.GetValue(2)).Value);
        }
Exemple #7
0
        /// <summary>
        /// Deserializes the specified ParticleEffect file.
        /// </summary>
        /// <param name="filename">The desired input file name.</param>
        /// <returns>A deserialized ParticleEffect instance.</returns>
        public ParticleEffect Deserialize(string filename)
        {
            // load the xml document...
            XDocument xmlDocument = XDocument.Load(filename);

            //try
            //{
            using (XmlReader reader = xmlDocument.CreateReader())
            {
                return(IntermediateSerializer.Deserialize <ParticleEffect>(reader, ".\\"));
            }
            //}
            //catch
            //{
            //    // hack: workaround for intermediate serializer not putting nodes in the right order...
            //    foreach (XElement emitterElement in xmlDocument.Descendants("Asset").Elements("Item"))
            //    {
            //        XElement releaseQuantityElement = emitterElement.Element("ReleaseQuantity");

            //        if ((releaseQuantityElement.PreviousNode as XElement).Name == "Name")
            //        {
            //            XElement termElement = emitterElement.Element("Term");

            //            termElement.AddAfterSelf(releaseQuantityElement);

            //            releaseQuantityElement.Remove();
            //        }
            //    }

            //    using (XmlReader reader = xmlDocument.CreateReader())
            //    {
            //        return IntermediateSerializer.Deserialize<ParticleEffect>(reader, ".\\");
            //    }
            //}
        }
Exemple #8
0
        private void loadAnimationSetToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (loadAnimationSetDialog.ShowDialog() == DialogResult.OK)
            {
                undoHistory = new History();
                AnimationSet loadedAnimSet;

                using (XmlReader xmlRead = XmlReader.Create(loadAnimationSetDialog.FileName))
                {
                    loadedAnimSet = IntermediateSerializer.Deserialize <AnimationSet>(xmlRead, null);
                }

                if (animationBox.Enabled == false)
                {
                    EnableAnimationEditingControls();
                }
                InitiateAnimationList(newAnimation: false);
                foreach (KeyValuePair <string, Animation> currentEntry in loadedAnimSet.Anims)
                {
                    animations.Add(currentEntry.Value);
                }
                animationBox.SelectedIndex = 0;
                currentAnimation           = animations[animationBox.SelectedIndex];
                ReadAnimationInfo();
                UpdateAnimation();
            }
        }
Exemple #9
0
        /// <summary>
        /// Reads an object from the specified file in XNA format.
        /// Remember to cast it to its original type using (Type) cast.
        /// </summary>
        /// <param name="FilePath">Location of file to read from.</param>
        /// <returns></returns>
        public Object ReadFromXml(string FilePath)
        {
            XmlReaderSettings settings = new XmlReaderSettings();

            using (XmlReader reader = XmlReader.Create(FilePath))
            { return(IntermediateSerializer.Deserialize <Object>(reader, FilePath)); }
        }
Exemple #10
0
        private void CreateMaterial()
        {
            using (XmlReader reader = XmlReader.Create(MaterialDataFilePath))
            {
                mTerrainMaterial = IntermediateSerializer.Deserialize <List <MaterialData> >(reader, null);
            }

            MaterialData tmSingle = mTerrainMaterial.Single();

            EffectMaterialContent emc = new EffectMaterialContent();

            emc.Effect = new ExternalReference <EffectContent>(Path.Combine(Environment.CurrentDirectory,
                                                                            tmSingle.CustomEffect));
            emc.Name = tmSingle.Name;

            foreach (EffectParam ep in tmSingle.EffectParams)
            {
                if (ep.Category == EffectParamCategory.OpaqueData)
                {
                    emc.OpaqueData.Add(ep.Name, ep.Value);
                }
                else if (ep.Category == EffectParamCategory.Texture)
                {
                    emc.Textures.Add(ep.Name, new ExternalReference <TextureContent>((string)(ep.Value)));
                }
            }

            mOutputTC.Tag = tmSingle.HandlingFlags;

#if XBOX
            outputTC.MaterialContent = context.Convert <MaterialContent, MaterialContent>(emc, "MaterialProcessor");
#else
            mOutputTC.MaterialContent = mContext.Convert <MaterialContent, MaterialContent>(emc, "FxcMaterialProcessor");
#endif
        }
Exemple #11
0
        public void Collections()
        {
            object result;
            var    filePath = Paths.Xml("09_Collections.xml");

            using (var reader = XmlReader.Create(filePath))
                result = IntermediateSerializer.Deserialize <object>(reader, filePath);

            Assert.NotNull(result);
            Assert.IsAssignableFrom <Collections>(result);
            var collections = (Collections)result;

            Assert.NotNull(collections.StringArray);
            Assert.AreEqual(2, collections.StringArray.Length);
            Assert.AreEqual("Hello", collections.StringArray[0]);
            Assert.AreEqual("World", collections.StringArray[1]);

            Assert.NotNull(collections.StringList);
            Assert.AreEqual(4, collections.StringList.Count);
            Assert.AreEqual("This", collections.StringList[0]);
            Assert.AreEqual("is", collections.StringList[1]);
            Assert.AreEqual("a", collections.StringList[2]);
            Assert.AreEqual("test", collections.StringList[3]);

            Assert.NotNull(collections.IntArray);
            Assert.AreEqual(5, collections.IntArray.Length);
            Assert.AreEqual(1, collections.IntArray[0]);
            Assert.AreEqual(2, collections.IntArray[1]);
            Assert.AreEqual(3, collections.IntArray[2]);
            Assert.AreEqual(23, collections.IntArray[3]);
            Assert.AreEqual(42, collections.IntArray[4]);
        }
Exemple #12
0
        private void updateAnimationSpritesFromSpriteMapToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var loadedSpriteMap = LoadSpriteMapFromFile();

            using (XmlReader xmlRead = XmlReader.Create(loadSpriteMapDialog.FileName))
            {
                loadedSpriteMap = IntermediateSerializer.Deserialize <Dictionary <string, Sprite> >(xmlRead, null);
            }

            int updateCounter = 0;

            foreach (Animation anim in animations)
            {
                foreach (Frame frame in anim.Frames)
                {
                    if (frame.Sprites != null)
                    {
                        for (int index = 0; index < frame.Sprites.Count; index++)
                        {
                            var sprite = frame.Sprites[index];
                            if (loadedSpriteMap.ContainsKey(sprite.Name))
                            {
                                frame.Sprites[index] = loadedSpriteMap[sprite.Name];
                                updateCounter++;
                            }
                        }
                    }
                }
            }

            MessageBox.Show("Updated " + updateCounter + " sprites!");
        }
Exemple #13
0
 /// <summary>
 /// Desserializa um XmlContent em um objeto.
 /// </summary>
 /// <typeparam name="T">O tipo do parâmetro</typeparam>
 /// <param name="path">O caminho do arquivo xml.</param>
 public static T Deserialize <T>(string path)
 {
     using (XmlReader reader = XmlReader.Create(path))
     {
         T obj = IntermediateSerializer.Deserialize <T>(reader, null);
         return(obj);
     }
 }
Exemple #14
0
        /// <summary>
        /// Deserializes a particle effect from the specified file path.
        /// </summary>
        /// <param name="filePath">The path to the desired input file.</param>
        /// <returns>A new instance of a particle effect.</returns>
        public ParticleEffect Deserialize(string filePath)
        {
            XDocument xmlDocument = XDocument.Load(filePath);

            using (XmlReader reader = xmlDocument.CreateReader())
            {
                return(IntermediateSerializer.Deserialize <ParticleEffect>(reader, ".\\"));
            }
        }
        public override FontDescription Import(string filename, ContentImporterContext context)
        {
            FontDescription description = null;

            using (XmlReader reader = XmlReader.Create(filename))
            {
                description = IntermediateSerializer.Deserialize <FontDescription>(reader, filename);
            }
            description.Identity = new ContentIdentity(new FileInfo(filename).FullName, "FontDescriptionImporter");
            return(description);
        }
        /// <summary>
        /// Called by the framework when importing a .spritefont file to be used as a game asset.
        /// This is the method called by the framework when an asset is to be
        /// imported into an object that can be recognized by the Content Pipeline.
        /// </summary>
        /// <param name="filename">Name of a game asset file.</param>
        /// <param name="context">Contains information for importing a game asset, such as a logger interface.</param>
        /// <returns>Resulting game asset.</returns>
        public override FontDescription Import(string filename, ContentImporterContext context)
        {
            FontDescription fontDescription = null;

            using (var input = XmlReader.Create(filename))
                fontDescription = IntermediateSerializer.Deserialize <FontDescription>(input, filename);

            fontDescription.Identity = new ContentIdentity(
                new FileInfo(filename).FullName, nameof(FontDescriptionImporter));

            return(fontDescription);
        }
Exemple #17
0
        private void LoadLevel()
        {
            int levelID = GameSettings.Instance.CurrentLevel;

            if (this._level != null)
            {
                this._level.Content.Unload();
            }

            this._level = new Level();
            this._world = new World(Vector2.Zero);
            //Camera.Instance.SetUpIs(UpIs.Up);
            EventManager.Instance.Load(this);
            SpriteManager.Instance.Clear();
            HUD.Instance.RefreshHUD();

            AudioManager.Instance.StopAllSounds(AudioStopOptions.AsAuthored);
            this.PlayRandomAmbience();

            try
            {
                using (XmlReader reader = XmlReader.Create(Defines.Level(levelID)))
                {
                    this._level = IntermediateSerializer.Deserialize <Level>(reader, null);
                }
            }
            catch (FileNotFoundException e)
            {
                MessageBox.Show("Something went wrong when trying to load level: '" + levelID + "'\nThe level wasn't found.");
                ErrorReport.GenerateReport("The level " + levelID + " could not be found.\n" + e.ToString(), null);
                ScreenManager.Game.Exit();
            }

            try
            {
                this._level.Load(this);
            }
            catch (ContentLoadException e)
            {
                string error = e.InnerException.ToString();

                MessageBox.Show("Something went wrong loading level " + levelID + ".\n" + error);
                ErrorReport.GenerateReport(error, null);
            }

            //  Now the level has been set up, if we have development
            //  mode on, turn on the display.
            if (GameSettings.Instance.DevelopmentMode)
            {
                DevDisplay.Load(this.ScreenManager, World);
            }
        }
Exemple #18
0
        public void GetterOnlyPolymorphicArrayProperties()
        {
            var filePath = Paths.Xml("23_GetterOnlyPolymorphicArrayProperties.xml");

            using (var reader = XmlReader.Create(filePath))
            {
                // This should throw an InvalidContentException as the
                // xml tries to deserialize into an IList property
                // but the property value is actually an Array.
                Assert.Throws <InvalidOperationException>(() =>
                                                          IntermediateSerializer.Deserialize <GetterOnlyPolymorphicArrayProperties>(reader, filePath));
            }
        }
Exemple #19
0
        public static T Deserialize <T>(string filename)
        {
            T data;

            using (FileStream stream = new FileStream(filename, FileMode.Open))
            {
                using (XmlReader reader = XmlReader.Create(stream))
                {
                    data = IntermediateSerializer.Deserialize <T>(reader, null);
                }
            }
            return(data);
        }
Exemple #20
0
        public void ExcludingPublicMembers()
        {
            var filePath = Paths.Xml("04_ExcludingPublicMembers.xml");

            using (var reader = XmlReader.Create(filePath))
            {
                // This should throw an InvalidContentException as the
                // xml tries to set the <elf> element which has a
                // [ContentSerializerIgnore] attribute.
                Assert.Throws <InvalidContentException>(() =>
                                                        IntermediateSerializer.Deserialize <object>(reader, filePath));
            }
        }
Exemple #21
0
        public static T Load <T>(string path)
        {
            T data;

            using (FileStream stream = new FileStream(path, System.IO.FileMode.Open))
            {
                using (XmlReader reader = XmlReader.Create(stream))
                {
                    data = IntermediateSerializer.Deserialize <T>(reader, null);
                }
            }
            return(data);
        }
Exemple #22
0
        /// <summary>
        /// Load a Curve from given filename.
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="name"></param>
        /// <param name="color"></param>
        /// <param name="commandHistory"></param>
        /// <returns></returns>
        public static EditCurve LoadFromFile(string filename, string name,
                                             System.Drawing.Color color, CommandHistory commandHistory)
        {
            EditCurve editCurve = null;

            using (XmlReader xr = XmlReader.Create(filename))
            {
                Curve curve = IntermediateSerializer.Deserialize <Curve>(xr,
                                                                         Path.GetDirectoryName(filename));
                editCurve = new EditCurve(name, color, curve, commandHistory);
            }

            return(editCurve);
        }
Exemple #23
0
        private static T Deserialize <T>(string file, Action <T> doAsserts)
        {
            object result;
            var    filePath = Paths.Xml(file);

            using (var reader = XmlReader.Create(filePath))
                result = IntermediateSerializer.Deserialize <object>(reader, filePath);

            Assert.NotNull(result);
            Assert.IsAssignableFrom <T>(result);

            doAsserts((T)result);

            return((T)result);
        }
Exemple #24
0
        public void NullReferences()
        {
            object result;
            var    filePath = Paths.Xml("06_NullReferences.xml");

            using (var reader = XmlReader.Create(filePath))
                result = IntermediateSerializer.Deserialize <object>(reader, filePath);

            Assert.NotNull(result);
            Assert.IsAssignableFrom <NullReferences>(result);

            var nullref = (NullReferences)result;

            Assert.AreEqual(null, nullref.hello);
        }
Exemple #25
0
        /// <summary>
        /// Loads the contents of the mapfile to the model.
        /// </summary>
        /// <param name="fileName"></param>
        public void Load(String fileName)
        {
            _bodies.Clear();
            _powerUps.Clear();

            float x = _game.Window.ClientBounds.Width / 2;
            float y = _game.Window.ClientBounds.Height / 2;

            _player = new EntityPlayer(new Vector2(x, y));

            XmlReaderSettings settings = new XmlReaderSettings();

            using (XmlReader reader = XmlReader.Create("Content/maps/" + fileName, settings))
                _map = IntermediateSerializer.Deserialize <Map>(reader, null);
        }
Exemple #26
0
        public void IncludingPrivateMembers()
        {
            object result;
            var    filePath = Paths.Xml("03_IncludingPrivateMembers.xml");

            using (var reader = XmlReader.Create(filePath))
                result = IntermediateSerializer.Deserialize <object>(reader, filePath);

            Assert.NotNull(result);
            Assert.IsAssignableFrom <IncludingPrivateMembers>(result);

            var including = (IncludingPrivateMembers)result;

            Assert.AreEqual(23, including.GetElfValue());
        }
Exemple #27
0
        private void LoadButton_Click(object sender, EventArgs e)
        {
            Stream         myStream       = null;
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = "c:\\";
            openFileDialog.Filter           = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
            openFileDialog.FilterIndex      = 2;
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            mFormation           = null;
                            mCurrentSpline       = null;
                            mNextCurrentSpline   = null;
                            mPrevCurrentSpline   = null;
                            mCurrentParentSpline = null;
                            mPointNumber         = -1;

                            mAnimate       = false;
                            mCurrentEngine = null;
                            XmlReader reader = XmlReader.Create(myStream);
                            mFormation = IntermediateSerializer.Deserialize <Formation>(reader, null);

                            RefreshAll();

                            foreach (BezierSpline spline in mFormation.Splines)
                            {
                                spline.Update();
                            }

                            reader.Close();
                            myStream.Close();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
Exemple #28
0
        public void RenamingXmlElements()
        {
            object result;
            var    filePath = Paths.Xml("05_RenamingXmlElements.xml");

            using (var reader = XmlReader.Create(filePath))
                result = IntermediateSerializer.Deserialize <object>(reader, filePath);

            Assert.NotNull(result);
            Assert.IsAssignableFrom <RenamingXmlElements>(result);

            var renaming = (RenamingXmlElements)result;

            Assert.AreEqual("world", renaming.hello);
            Assert.AreEqual(23, renaming.elf);
        }
Exemple #29
0
        public void Inheritance()
        {
            object result;
            var    filePath = Paths.Xml("02_Inheritance.xml");

            using (var reader = XmlReader.Create(filePath))
                result = IntermediateSerializer.Deserialize <object>(reader, filePath);

            Assert.NotNull(result);
            Assert.IsAssignableFrom <Inheritance>(result);

            var inheritance = (Inheritance)result;

            Assert.AreEqual(23, inheritance.elf);
            Assert.AreEqual("world", inheritance.hello);
        }
Exemple #30
0
        public void ExternalReferences()
        {
            object result;
            var    filePath = Paths.Xml("17_ExternalReferences.xml");

            using (var reader = XmlReader.Create(filePath))
                result = IntermediateSerializer.Deserialize <object>(reader, filePath);

            Assert.NotNull(result);
            Assert.IsAssignableFrom <ExternalReferences>(result);
            var externalReferences = (ExternalReferences)result;

            Assert.NotNull(externalReferences.Texture);
            Assert.IsTrue(externalReferences.Texture.Filename.EndsWith(@"\Xml\grass.tga"));
            Assert.NotNull(externalReferences.Shader);
            Assert.IsTrue(externalReferences.Shader.Filename.EndsWith(@"\Xml\foliage.fx"));
        }