Esempio n. 1
0
        public bool LoadXML_spriteset16(XmlNode xnode)
        {
            int nTileId = 0;

            foreach (XmlNode xn in xnode.ChildNodes)
            {
                if (xn.Name == "sprite16")
                {
                    string strName       = XMLUtils.GetXMLAttribute(xn, "name");
                    int    id            = XMLUtils.GetXMLIntegerAttribute(xn, "id");
                    string strDesc       = XMLUtils.GetXMLAttribute(xn, "desc");
                    string strSize       = XMLUtils.GetXMLAttribute(xn, "size");
                    int    nSubpaletteId = XMLUtils.GetXMLIntegerAttribute(xn, "subpalette_id");

                    string[] aSize   = strSize.Split('x');
                    int      nWidth  = XMLUtils.ParseInteger(aSize[0]);
                    int      nHeight = XMLUtils.ParseInteger(aSize[1]);

                    Sprite s = AddSprite(nWidth, nHeight, strName, NextSpriteId++, strDesc, nSubpaletteId, null);
                    if (!s.LoadXML_sprite16(xn, nTileId))
                    {
                        return(false);
                    }

                    nTileId += s.NumTiles;
                }
            }
            return(true);
        }
Esempio n. 2
0
        public void Test_LoadXML_sprite16_2x4()
        {
            Palette p = m_doc.Palettes.AddPalette16(Options.DefaultPaletteName, 0, "");

            Assert.IsNotNull(p);

            Spriteset ss = m_doc.Spritesets.AddSpriteset(Options.DefaultSpritesetName, 0, "", p);

            Assert.IsNotNull(ss);

            Sprite s = ss.AddSprite(2, 4, "sample", 0, "", 0, null);

            Assert.IsNotNull(s);

            XmlElement xnSprite = m_xd.CreateElement("sprite16");

            for (int i = 0; i < 8; i++)
            {
                Test_LoadXML_sprite16_AddTile(xnSprite, i, 8, 8);
            }
            Assert.IsTrue(s.LoadXML_sprite16(xnSprite, 0));

            // Verify the data is the same as the XML
            // Pixel 0 is the same as the tileid
            Assert.AreEqual(0, s.GetTile(0).GetPixel(0, 0));
            Assert.AreEqual(3, s.GetTile(3).GetPixel(0, 0));
            Assert.AreEqual(7, s.GetTile(7).GetPixel(0, 0));
            // Other pixels = x+y
            Assert.AreEqual(9, s.GetTile(0).GetPixel(4, 5));
            Assert.AreEqual(3, s.GetTile(4).GetPixel(0, 3));
            Assert.AreEqual(14, s.GetTile(7).GetPixel(7, 7));
        }
Esempio n. 3
0
        public void Test_LoadXML_sprite16_1x1()
        {
            Palette p = m_doc.Palettes.AddPalette16(Options.DefaultPaletteName, 0, "");

            Assert.IsNotNull(p);
            Spriteset ss = m_doc.Spritesets.AddSpriteset(Options.DefaultSpritesetName, 0, "", p);

            Assert.IsNotNull(ss);
            Sprite s = ss.AddSprite(1, 1, "sample", 0, "", 0, null);

            Assert.IsNotNull(s);

            XmlElement xnSprite = m_xd.CreateElement("sprite16");

            // Note: <sprite16> attributes not needed for test.
            Test_LoadXML_sprite16_AddTile(xnSprite, 0, 8, 8);
            Assert.IsTrue(s.LoadXML_sprite16(xnSprite, 0));

            // Verify the data is the same as the XML
            // Pixel 0 is the same as the tileid
            Assert.AreEqual(0, s.GetTile(0).GetPixel(0, 0));
            // Other pixels = x+y
            Assert.AreEqual(9, s.GetTile(0).GetPixel(4, 5));
            Assert.AreEqual(14, s.GetTile(0).GetPixel(7, 7));
        }
Esempio n. 4
0
        public void Test_LoadXML_sprite16_1x1_9columns()
        {
            Palette p = m_doc.Palettes.AddPalette16(Options.DefaultPaletteName, 0, "");

            Assert.IsNotNull(p);

            Spriteset ss = m_doc.Spritesets.AddSpriteset(Options.DefaultSpritesetName, 0, "", p);

            Assert.IsNotNull(ss);

            Sprite s = ss.AddSprite(1, 1, "sample", 0, "", 0, null);

            Assert.IsNotNull(s);

            XmlElement xnSprite = m_xd.CreateElement("sprite16");

            Test_LoadXML_sprite16_AddTile(xnSprite, 0, 9, 8);
            Assert.IsFalse(s.LoadXML_sprite16(xnSprite, 0));
        }
Esempio n. 5
0
        public void Test_LoadXML_sprite16_2x2_3tiles()
        {
            Palette p = m_doc.Palettes.AddPalette16(Options.DefaultPaletteName, 0, "");

            Assert.IsNotNull(p);

            Spriteset ss = m_doc.Spritesets.AddSpriteset(Options.DefaultSpritesetName, 0, "", p);

            Assert.IsNotNull(ss);

            Sprite s = ss.AddSprite(2, 2, "sample", 0, "", 0, null);

            Assert.IsNotNull(s);

            XmlElement xnSprite = m_xd.CreateElement("sprite16");

            for (int i = 0; i < 3; i++)
            {
                Test_LoadXML_sprite16_AddTile(xnSprite, i, 8, 8);
            }
            Assert.IsFalse(s.LoadXML_sprite16(xnSprite, 0));
        }