コード例 #1
0
        public static void MakePalette(string[] astr)
        {
            // -makepal 16 templates.tc palsize fixpalsize backgroundpalsize fixed.pal out.pal

            // tile size

            Size sizTile = new Size(0, 0);

            sizTile.Width  = int.Parse(astr[1]);
            sizTile.Height = sizTile.Width;

            // Load template collection

            TemplateDoc tmpd = (TemplateDoc)DocManager.OpenDocument(astr[2]);

            // palette size

            int cPalEntries = int.Parse(astr[3]);

            // entries fixed

            int cPalEntriesFixed = int.Parse(astr[4]);

            // entries for background

            int cPalEntriesBackground = int.Parse(astr[5]);

            // fixed palette

            Palette palFixed = new Palette(astr[6]);

            // output palette

            string strFilePalOut = astr[7];

            // If this template collection already has a palette it has already been quantized; we don't
            // want that.

            if (tmpd.GetPalette() != null)
            {
                new Exception("Template collection has already been quantized!");
            }

            // Scale templates if needed

            if (sizTile.Width != tmpd.TileSize.Width || sizTile.Height != tmpd.TileSize.Height)
            {
                TemplateTools.ScaleTemplates(tmpd, sizTile);
            }

            // Quantize

            TemplateTools.QuantizeTemplates(tmpd, palFixed, cPalEntries, cPalEntriesFixed, cPalEntriesBackground);

            // Save the new palette out

            Palette palNew = tmpd.GetPalette();

            palNew.SaveJasc(strFilePalOut);
        }
コード例 #2
0
        public static void ImportText(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);
            }

            Console.WriteLine("Importing text from {0} files", alsFiles.Count);

            // Attempt to process these text files/level docs

            foreach (string strTextFile in alsFiles)
            {
                string strFile = "." + Path.DirectorySeparatorChar + Path.GetFileName(strTextFile).Replace(".txt", ".ld");
                Console.Write("Writing " + strTextFile + " to " + strFile + "...");
                LevelDoc lvld = (LevelDoc)DocManager.OpenDocument(strFile);
                if (lvld == null)
                {
                    throw new Exception("Could not load level doc " + strFile);
                }

                StreamReader stmr = new StreamReader(strTextFile);
                string       str  = stmr.ReadToEnd();
                stmr.Close();
                str = str.Replace("\r\n", "\n");

                int ichErrorPos;
                if (!lvld.SetLevelText(str, out ichErrorPos))
                {
                    Console.WriteLine(" error at char " + ichErrorPos);
                }
                else
                {
                    lvld.Save();
                    Console.WriteLine(" saved");
                }
                lvld.Dispose();
            }
        }
コード例 #3
0
        public static void Main(string[] astr)
        {
            new Globals();
            new DocManager();

            DocManager.AddTemplate(new LevelDocTemplate(null, null));
            DocManager.AddTemplate(new TemplateDocTemplate());

            switch (astr[0])
            {
            case "-mixmaps":
                OutputTools.ExportMixMaps(astr);
                break;

            case "-levels":
                OutputTools.ExportLevels(astr, 0);
                break;

            case "-images":
                OutputTools.ExportImages(astr);
                break;

            case "-makepal":
                OutputTools.MakePalette(astr);
                break;

            case "-special":
                char   sep  = Path.DirectorySeparatorChar;
                string root = sep + "ht" + sep + "data" + sep;
                OutputTools.MixMapImportSpecial(Theater.Desert, (TemplateDoc)DocManager.OpenDocument(root + "desert.tc"), root + "desert24.tc");
                OutputTools.MixMapImportSpecial(Theater.Temperate, (TemplateDoc)DocManager.OpenDocument(root + "temperate.tc"), root + "temperate24.tc");
                break;

            case "-exporttext":
                OutputTools.ExportText(astr);
                break;

            case "-importtext":
                OutputTools.ImportText(astr);
                break;

            case "-testimport":
                OutputTools.ImportExportPdbs(astr);
                break;
            }
        }
コード例 #4
0
        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");
            }
        }
コード例 #5
0
        public static void ExportText(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);
            }

            Console.WriteLine("Exporting text from {0} files", alsFiles.Count);

            // Attempt to process these level docs

            foreach (string strFile in alsFiles)
            {
                Console.Write("Writing text of " + strFile + "...");
                LevelDoc lvld = (LevelDoc)DocManager.OpenDocument(strFile);
                if (lvld == null)
                {
                    throw new Exception("Could not load level doc " + strFile);
                }
                string strTextFile = "." + Path.DirectorySeparatorChar + Path.GetFileName(strFile).Replace(".ld", ".txt");
                string str         = lvld.GetLevelText();
                str = str.Replace("\n", "\r\n");
                StreamWriter stmw = new StreamWriter(strTextFile);
                stmw.Write(str);
                stmw.Close();
                lvld.Dispose();
                Console.WriteLine(" done");
            }
        }
コード例 #6
0
        private void toolBar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
        {
            switch (toolBar.Buttons.IndexOf(e.Button))
            {
            case 0:
                DocManager.NewDocument(typeof(TemplateDoc), null);
                break;

            case 1:
                DocManager.OpenDocument(typeof(TemplateDoc));
                break;

            case 2:
                if (m_tmpdActive != null)
                {
                    m_tmpdActive.Save();
                }
                break;

            case 3:
                AddTemplates();
                //Rectangle rc = toolBar.Buttons[toolBar.Buttons.IndexOf(e.Button)].Rectangle;
                //contextMenuToolbar.Show(toolBar, new Point(rc.X, rc.Y + rc.Height));
                break;

            case 4:
                // Separator
                break;

            case 5:
                if (m_tmpdActive == null)
                {
                    return;
                }
                m_tmpdActive.Close();
                break;
            }
        }
コード例 #7
0
        public static void ImportExpansionPdb(string strFile)
        {
            PdbPacker pdbp = new PdbPacker(strFile);

            ArrayList alsTileSets = new ArrayList();

            for (int i = 0; i < pdbp.Count; i++)
            {
                PdbPacker.File file = pdbp[i];
                if (!file.str.EndsWith(".lvl"))
                {
                    continue;
                }

                // Load up the pieces

                Ini     ini = Ini.LoadBinary(new MemoryStream(file.ab));
                string  strTileMapFilename = ini["General"]["TileMap"].Value;
                TileMap tmap = TileMap.Load(new MemoryStream(pdbp[strTileMapFilename].ab));


                // First, tell the active LevelDoc not to switch its templates based on the following
                // template load

                LevelDoc lvldActive = (LevelDoc)DocManager.GetActiveDocument(typeof(LevelDoc));
                if (lvldActive != null)
                {
                    lvldActive.SwitchTemplatesEnabled = false;
                }

                // If the TileSet for this level is not yet available, load it now

                TemplateDoc tmpd = (TemplateDoc)DocManager.OpenDocument(tmap.Filename.Replace(".tset", ".tc"));
                TileSet     tset = null;
                foreach (TileSet tsetT in alsTileSets)
                {
                    if (tsetT.FileName == tmap.Filename)
                    {
                        tset = tsetT;
                        break;
                    }
                }
                if (tset == null)
                {
                    tset = new TileSet(tmpd, tmap.Filename);
                    alsTileSets.Add(tset);
                }

                // Re-enable template switching

                if (lvldActive != null)
                {
                    lvldActive.SwitchTemplatesEnabled = true;
                }

                // Create a new level description, and deduce which templates are in it, with what visibility

                LevelDoc lvld = (LevelDoc)DocManager.NewDocument(typeof(LevelDoc), null);
                lvld.OutputFilename = file.str;
                ImportTileMap(tmap, tset, tmpd, lvld);

                // Walls are stored in the terrain map. Load them.
                string     strTrmapFilename = ini["General"]["TerrainMap"].Value;
                TerrainMap trmap            = TerrainMap.Load(new MemoryStream(pdbp[strTrmapFilename].ab));
                ImportWalls(trmap, lvld);

                // Load everything else
                lvld.LoadIni(ini);
            }
        }
コード例 #8
0
        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");
            }
        }