コード例 #1
0
        public static void ExportMixMaps(string[] astr)
        {
            // Expand filespecs
            ArrayList alsFiles = new ArrayList();

            for (int n = 1; n < astr.Length; n++)
            {
                string strFileT = Path.GetFileName(astr[n]);
                string strDirT  = Path.GetDirectoryName(astr[n]);
                if (strDirT == "")
                {
                    strDirT = ".";
                }
                string[] astrFiles = Directory.GetFiles(strDirT, strFileT);
                alsFiles.AddRange(astrFiles);
            }

            foreach (string strFile in alsFiles)
            {
                LevelDoc lvld = (LevelDoc)DocManager.NewDocument(typeof(LevelDoc), null);
                Console.Write("Exporting " + strFile + " as ");
                string strFileExport = MixSuck.ImportExportMixMap(strFile, lvld);
                if (strFileExport == null)
                {
                    Console.Write("Error exporting!\n");
                }
                else
                {
                    Console.Write(strFileExport + "\n");
                }
                lvld.Dispose();
            }
        }
コード例 #2
0
        public static void MixMapImportSpecial(Theater theater, TemplateDoc tmpdCopyTerrain, string strFileSave)
        {
            TemplateDoc tmpd24 = (TemplateDoc)DocManager.NewDocument(typeof(TemplateDoc), new Object[] { new Size(24, 24) });

            MixTemplate[] amixt = MixSuck.LoadTemplates(theater);
            MixSuck.ImportTemplates(amixt, tmpd24);

            Template[] atmpl24 = tmpd24.GetTemplates();
            Template[] atmpl16 = tmpdCopyTerrain.GetTemplates();

            for (int n = 0; n < atmpl24.Length; n++)
            {
                Template tmpl24 = atmpl24[n];
                Template tmpl16 = atmpl16[n];
                tmpl24.TerrainMap = tmpl16.TerrainMap;
            }

            tmpd24.SetBackgroundTemplate(atmpl24[0]);
            tmpd24.SaveAs(strFileSave);
        }
コード例 #3
0
        public static string ImportExportMixMap(string strFile, LevelDoc lvld)
        {
            // Load ini
            Ini ini = new Ini(strFile);

            // Get name of level
            String strName = strFile;

            Ini.Section secBasic = ini["Basic"];
            if (secBasic != null)
            {
                Ini.Property propName = secBasic["Name"];
                if (propName != null)
                {
                    strName = propName.Value;
                }
                else
                {
                    Ini.Property propBrief = secBasic["Brief"];
                    if (propBrief != null)
                    {
                        strName = propBrief.Value;
                    }
                }
            }

            // Get theater
            Ini.Section secMap = ini["MAP"];
            if (secMap == null)
            {
                MessageBox.Show("Could not load " + strFile);
                return(null);
            }
            Theater theater;

            switch (secMap["Theater"].Value)
            {
            case "DESERT":
                theater = Theater.Desert;
                break;

            case "TEMPERATE":
                theater = Theater.Temperate;
                break;

            case "WINTER":
                theater = Theater.Winter;
                break;

            default:
                MessageBox.Show("Could not load " + strFile);
                return(null);
            }

            // Get bounds & invert
            int       xLeft    = Int32.Parse(secMap["X"].Value);
            int       yTop     = Int32.Parse(secMap["Y"].Value);
            int       cxWidth  = Int32.Parse(secMap["Width"].Value);
            int       cyHeight = Int32.Parse(secMap["Height"].Value);
            Rectangle rcBounds = new Rectangle(64 - (xLeft + cxWidth), yTop, cxWidth, cyHeight);

            // We're ready to go
            lvld.Title = strName;
            //fixme
            //lvld.TileCollectionFileName = theater.ToString() + ".tc";
            lvld.Bounds = rcBounds;

            // Load up
            MixTemplate[] amixt = MixSuck.LoadTemplates(theater);
            MixSuck.ImportTemplates(amixt, lvld.GetTemplateDoc());
            Stream stm = (Stream) new FileStream(strFile.ToLower().Replace(".ini", ".bin"), FileMode.Open, FileAccess.Read, FileShare.Read);
            MixMap map = MixSuck.LoadMap(stm, amixt);

            stm.Close();
            map.ImportMap(lvld);
            //fixme
            //lvld.SetBackgroundTemplate(lvld.GetTemplateDoc()FindTemplate(0));

            // Save

            string strFileLvld = strName + "_" + Path.GetFileName(strFile).Replace(".ini", ".ld");

            lvld.SaveAs(strFileLvld);

            // Also save a scaled image for reference
            TemplateDoc tmpd = lvld.GetTemplateDoc();
            Bitmap      bm   = lvld.GetMapBitmap(tmpd.TileSize, tmpd, true);
            int         cx;
            int         cy;

            if (bm.Width > bm.Height)
            {
                cx = 128;
                cy = bm.Height * 128 / bm.Width;
            }
            else
            {
                cx = bm.Width * 128 / bm.Height;
                cy = 128;
            }
            bm = (Bitmap)bm.GetThumbnailImage(cx, cy, null, IntPtr.Zero);
            bm.Save(strFileLvld.Replace(".ld", ".png"), ImageFormat.Png);
            bm.Dispose();

            // Save a full 24x24 original map image for reference
            map.SaveMapBitmap("cc_" + strFileLvld.Replace(".ld", ".png"));

            return(strFileLvld);
        }