Esempio n. 1
0
            public void Test_LoadXML_OLD_palettes_valid()
            {
                // Valid old palette.
                XmlElement xnPalettes = m_xd.CreateElement("palettes");

                for (int id = 0; id < 16; id++)
                {
                    Test_LoadXML_OLD_palettes_AddSubpalette(xnPalettes, id, 16);
                }
                Assert.IsTrue(m_filer.LoadXML_OLD_palettes(xnPalettes.ChildNodes, m_doc.Palettes, Options.DefaultPaletteName));

                Assert.AreEqual(1, m_doc.Palettes.NumPalettes);
                Palette16 p = m_doc.Palettes.GetPalette(0) as Palette16;

                Assert.IsNotNull(p);

                // Verify the colors are the same ones from the XML:
                // Color 0 is the same as the subpalette id
                Assert.AreEqual(0, p.GetSubpalette(0).Encoding(0));
                Assert.AreEqual(4, p.GetSubpalette(4).Encoding(0));
                // Other colors are the same as the color index
                Assert.AreEqual(3, p.GetSubpalette(0).Encoding(3));
                Assert.AreEqual(7, p.GetSubpalette(6).Encoding(7));
                Assert.AreEqual(12, p.GetSubpalette(8).Encoding(12));
            }
Esempio n. 2
0
            public void Test_LoadXML_palette16_valid()
            {
                Palette16 p = m_doc.Palettes.AddPalette16("pal16", 0, "");

                Assert.IsNotNull(p);

                // Valid palette16.
                XmlElement xnPalette16 = m_xd.CreateElement("palette16");

                // Attributes on palette are not needed for test:
                //xnPalette16.SetAttribute("name", "pal16");
                //xnPalette16.SetAttribute("id", "0");
                //xnPalette16.SetAttribute("desc", "");
                for (int id = 0; id < 16; id++)
                {
                    Test_LoadXML_palette16_AddSubpalette(xnPalette16, id, 16);
                }

                Assert.IsTrue(p.LoadXML_palette16(xnPalette16));

                // Verify the colors are the same ones from the XML:
                // Each component of Color 0 is the same as the subpalette id
                Assert.AreEqual(0, p.GetSubpalette(0).Red(0));
                Assert.AreEqual(4, p.GetSubpalette(4).Green(0));
                // Components of other colors are the same as the color index
                Assert.AreEqual(3, p.GetSubpalette(0).Red(3));
                Assert.AreEqual(7, p.GetSubpalette(6).Green(7));
                Assert.AreEqual(12, p.GetSubpalette(8).Blue(12));
            }
Esempio n. 3
0
        private bool LoadXML_OLD_palettes(XmlNodeList xnl, Palettes palettes, string strName)
        {
            Palette16 palette     = palettes.AddPalette16(strName, 0, "");
            int       nSubpalette = 0;

            foreach (XmlNode xn in xnl)
            {
                if (xn.Name == "palette")
                {
                    int nSubpaletteId = XMLUtils.GetXMLIntegerAttribute(xn, "id");
                    if (nSubpalette > 16)
                    {
                        // Incorrect number of subpalettes - too many.
                        m_doc.ErrorString("Too many subpalettes specified for palette (expected 16)");
                        return(false);
                    }
                    if (nSubpaletteId != nSubpalette)
                    {
                        // Subpalettes out of order.
                        m_doc.ErrorString("Subpalette ids are out of order");
                        return(false);
                    }

                    int[] anPalette  = new int[16];
                    int   nCurrEntry = 0;

                    Regex rxPalette = new Regex(@"\s*0x([0-9A-Fa-f]{4})\s*,");
                    Match mxPalette = rxPalette.Match(xn.InnerText);
                    if (mxPalette.Success)
                    {
                        while (mxPalette.Success)
                        {
                            GroupCollection matchGroups = mxPalette.Groups;

                            if (nCurrEntry >= 16)
                            {
                                // Wrong number of colors in palette - too many.
                                m_doc.ErrorString("Too many colors specified for subpalette {0} (expected 16)", nSubpaletteId);
                                return(false);
                            }

                            anPalette[nCurrEntry] = Convert.ToInt32(matchGroups[1].Value, 16);
                            nCurrEntry++;
                            if (nCurrEntry == 16)
                            {
                                // After we've read 16 colors, update the subpalette.
                                if (!palette.ImportSubpalette(nSubpaletteId, anPalette))
                                {
                                    // Warning/Error message already displayed.
                                    return(false);
                                }

                                // Since we just loaded from a file, update the snapshot without creating an UndoAction
                                palette.GetSubpalette(nSubpaletteId).RecordSnapshot();
                            }

                            // Get the next match.
                            mxPalette = mxPalette.NextMatch();
                        }

                        if (nCurrEntry != 16)
                        {
                            // "Wrong number of colors in palette with ID='{0}'. Found {1}, expected 16."
                            m_doc.ErrorId("ErrorNumColorsInPalette", nSubpaletteId, nCurrEntry);
                            return(false);
                        }
                    }
                    nSubpalette++;
                }
            }

            if (nSubpalette != 16)
            {
                // Incorrect number of subpalettes - too few.
                m_doc.ErrorString("Too few subpalettes (expected 16)");
                return(false);
            }

            return(true);
        }