Exemple #1
0
        public static MixMap LoadMap(Stream stm, MixTemplate[] amixt)
        {
            MixReader mixr = new MixReader("general.mix");
            MixMap    map  = new MixMap(stm, amixt);

            mixr.Dispose();
            return(map);
        }
Exemple #2
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);
        }
 public static MixMap LoadMap(Stream stm, MixTemplate[] amixt)
 {
     MixReader mixr = new MixReader("general.mix");
     MixMap map = new MixMap(stm, amixt);
     mixr.Dispose();
     return map;
 }