public static void ExportImages(string[] astr) { // Get directory //string strDir = Path.GetFullPath(astr[1]); string strDir = "."; string strPrefix = astr[1]; // Expand filespecs ArrayList alsFiles = new ArrayList(); for (int n = 2; 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); } // Attempt to process these level docs foreach (string strFile in alsFiles) { Console.Write("Map of " + strFile + " -> "); LevelDoc lvld = (LevelDoc)DocManager.OpenDocument(strFile); if (lvld == null) { throw new Exception("Could not load level doc " + strFile); } string strPng = strDir + Path.DirectorySeparatorChar + strPrefix + Path.GetFileName(strFile).Replace(".ld", ".png"); Console.Write(strPng + "..."); TemplateDoc tmpd = lvld.GetTemplateDoc(); Bitmap bm = lvld.GetMapBitmap(tmpd.TileSize, tmpd, true); bm.Save(strPng, ImageFormat.Png); bm.Dispose(); lvld.Dispose(); Console.Write(" Done.\n"); } }
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 void ExportLevels(string[] astr, int nVersion) { // Get tile size Size sizTile = new Size(0, 0); sizTile.Width = int.Parse(astr[1]); sizTile.Height = sizTile.Width; // Get depth int nDepth = Int32.Parse(astr[2]); // Get background threshold double nAreaBackgroundThreshold = double.Parse(astr[3]); // Background luminance multiplier double nLuminanceMultBackground = double.Parse(astr[4]); // Background saturation multiplier double nSaturationMultBackground = double.Parse(astr[5]); // Foreground luminance multiplier double nLuminanceMultForeground = double.Parse(astr[6]); // Foreground saturation multiplier double nSaturationMultForeground = double.Parse(astr[7]); // Palette directory string strPalDir = astr[8]; // Get output directory string strDir = Path.GetFullPath(astr[9]); // Expand filespecs ArrayList alsFiles = new ArrayList(); for (int n = 9; 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); } // Attempt to process these level doc ArrayList alsTileSets = new ArrayList(); foreach (string strFile in alsFiles) { Console.Write("Loading " + strFile + "..."); LevelDoc lvld = (LevelDoc)DocManager.OpenDocument(strFile); if (lvld == null) { throw new Exception("Could not load level doc " + strFile); } Console.Write(" Done.\n"); // Size this template collection if necessary TemplateDoc tmpd = lvld.GetTemplateDoc(); if (sizTile.Width != tmpd.TileSize.Width || sizTile.Height != tmpd.TileSize.Height) { TemplateTools.ScaleTemplates(tmpd, sizTile); } // Get appropriate TileSet, or make one if this map // uses a new tile collection TileSet tset = null; foreach (TileSet tsetT in alsTileSets) { if (tsetT.TileCollectionFileName == Path.GetFileName(lvld.GetTemplateDoc().GetPath())) { tset = tsetT; break; } } // Create new tile set if none found if (tset == null) { string strTcPath = lvld.GetTemplateDoc().GetPath(); string strTcName = Path.GetFileNameWithoutExtension(strTcPath); string strTcDir = Path.GetDirectoryName(strTcPath); string strT3 = strTcDir + Path.DirectorySeparatorChar + strPalDir + Path.DirectorySeparatorChar + strTcName; tset = new TileSet(lvld.GetTemplateDoc(), Path.GetFileName(strTcPath), strT3, nDepth, sizTile); alsTileSets.Add(tset); } // Get and save a tile map for this level string strTmap = Path.GetFileName(lvld.GetPath().Replace(".ld", ".tmap")); string strFileTmap = strDir + Path.DirectorySeparatorChar + strTmap; Console.Write("Creating & writing " + strFileTmap + "..."); TileMap tmap = TileMap.CreateFromImage(tset, lvld.GetMapBitmap(tmpd.TileSize, tmpd, true), tmpd.TileSize); tmap.Save(strFileTmap); Console.Write(" Done.\n"); // Get and save terrain map for this level string strTrmap = Path.GetFileName(lvld.GetPath().Replace(".ld", ".trmap")); string strFileTrmap = strDir + Path.DirectorySeparatorChar + strTrmap; Console.Write("Creating & writing " + strFileTrmap + "..."); TerrainMap trmap = new TerrainMap(lvld.GetTerrainMap(tmpd.TileSize, tmpd, false)); trmap.Save(strFileTrmap); Console.Write(" Done.\n"); // Save .ini for this level doc string strFileIni = strDir + Path.DirectorySeparatorChar + Path.GetFileName(strFile).Replace(".ld", ".lvl"); Console.Write("Writing " + strFileIni + "..."); lvld.SaveIni(strFileIni, nVersion, strTmap, strTrmap, tset.PalBinFileName); Console.Write(" Done.\n"); lvld.Dispose(); } // Now write out tilesets foreach (TileSet tset in alsTileSets) { // Save tile set string strFileTset = strDir + Path.DirectorySeparatorChar + tset.FileName; Console.Write("Creating & writing " + strFileTset + ", " + tset.Count.ToString() + " tiles..."); tset.Save(strFileTset); tset.SaveMini(strFileTset, nAreaBackgroundThreshold, nLuminanceMultBackground, nSaturationMultBackground, nLuminanceMultForeground, nSaturationMultForeground); Console.Write(" Done.\n"); } }