Exemple #1
0
        static int Main(string[] astrArgs)
        {
            string    strOutputDir = null;
            ArrayList alFiles      = new ArrayList();
            bool      fForce       = false;

            if (astrArgs.Length < 1)
            {
                Console.WriteLine("amx2zamx usage:\namx2zamx <file.amx ...> [-o output dir]");
                return(-1);
            }

            for (int i = 0; i < astrArgs.Length; i++)
            {
                string str = astrArgs[i];

                if (str == "-o")
                {
                    strOutputDir = astrArgs[++i];
                    continue;
                }
                else if (str == "-f")
                {
                    fForce = true;
                    continue;
                }

                string strRoot = Path.GetPathRoot(str);
                if (strRoot == "")
                {
                    strRoot = ".";
                }
                string   strFile   = Path.GetFileName(str);
                string[] astrFiles = Directory.GetFiles(strRoot, strFile);
                if (astrFiles.Length == 0)
                {
                    Console.WriteLine("Warning: nothing matches {0}", str);
                    continue;
                }

                alFiles.AddRange(astrFiles);
            }

            foreach (string strFile in alFiles)
            {
                if (Path.GetExtension(strFile).ToLower() != ".amx")
                {
                    Console.WriteLine("Warning: ignoring {0}", strFile);
                    continue;
                }

                AnimDoc doc = AnimDoc.Load(strFile);

                string strOutFile = Path.GetFileName(strFile);
                strOutFile = Path.ChangeExtension(strOutFile, ".zamx");
                if (strOutputDir != null)
                {
                    strOutFile = Path.Combine(strOutputDir, strOutFile);
                }

                if (File.Exists(strOutFile) && !fForce)
                {
                    Console.WriteLine("Warning: {0} already exists, skipping", strOutFile);
                    continue;
                }

                Console.WriteLine("writing {0}", strOutFile);
                doc.Save(strOutFile);
            }

            return(0);
        }
Exemple #2
0
        static int Main(string[] astrArgs)
        {
            if (astrArgs.Length < 3 || astrArgs.Length > 10)
            {
                Console.WriteLine("Usage:\nacrunch [-scale N] [-save] [-noscaleicon] [-noshrinkwrap] [-highlight <cxTile>] [-stats] <palette.pal> <input.amx> <outdir>\n");
                return(-1);
            }

            double nScale         = 1.0;
            bool   fSave          = false;
            bool   fNoShrinkWrap  = false;
            bool   fDumpStats     = false;
            bool   fScaleIcon     = true;
            bool   fMakeHighlight = true;
            int    cxTile         = 0;

            int iarg = 0;

            while (astrArgs[iarg][0] == '-')
            {
                switch (astrArgs[iarg])
                {
                case "-scale":
                    nScale = double.Parse(astrArgs[++iarg]);
                    break;

                case "-noscaleicon":
                    fScaleIcon = false;
                    break;

                case "-save":
                    fSave = true;
                    break;

                case "-noshrinkwrap":
                    fNoShrinkWrap = true;
                    break;

                case "-stats":
                    fDumpStats = true;
                    break;

                case "-highlight":
                    fMakeHighlight = true;
                    cxTile         = Int32.Parse(astrArgs[++iarg]);
                    break;
                }

                iarg++;
            }

            // Read in the palette

            string  strFilePal = astrArgs[iarg++];
            Palette pal        = new Palette(strFilePal);

            if (pal == null)
            {
                Console.WriteLine("Error: unable to read the palette file {0}\n", strFilePal);
                return(-1);
            }

            // Read in the animation file (.amx)

            string  strFileAmx = astrArgs[iarg++];
            AnimDoc doc        = AnimDoc.Load(strFileAmx);

            if (doc == null)
            {
                Console.WriteLine("Error: unable to read animation file {0}\n", strFileAmx);
                return(-1);
            }

            // Get directory

            string strDir = astrArgs[iarg++];

            // Reduce the Bitmaps down to the tightest rectangular boundary around the
            // non-transparent pixels.

            if (!fNoShrinkWrap)
            {
                ShrinkWrap(doc);
            }

            // Make highlight if asked. This uses existing images, so do this
            // before scaling.

            Strip stpHighlight = null;

            if (fMakeHighlight)
            {
                stpHighlight = MakeHighlightStrip(doc, cxTile, pal);
            }

            // Scale if asked

            if (nScale != 1.0)
            {
                Scale(doc, nScale, pal, fScaleIcon);
            }

            // Add in highlight strip

            if (stpHighlight != null)
            {
                doc.StripSet.Add(stpHighlight);
                foreach (Frame fr in stpHighlight)
                {
                    foreach (BitmapPlacer plc in fr.BitmapPlacers)
                    {
                        doc.XBitmapSet.Add(plc.XBitmap);
                    }
                }
            }

            // If dump stats, we're *only* dumping stats

            if (fDumpStats)
            {
                DumpStats(doc);
                return(0);
            }

            // Write the runtime animation file (.anir) and crunched bitmaps

            if (fSave)
            {
                doc.Save(strDir + Path.DirectorySeparatorChar + Path.GetFileName(strFileAmx));
            }
            else
            {
                doc.WriteAnir(pal, strDir, Path.GetFileNameWithoutExtension(strFileAmx));
            }
            return(0);
        }