// The minimal case has a simple build content and thus a known state.
        public void TestMinimalBuildCorrect()
        {
            var reader = new ScmlReader(Minimal.Scml, Minimal.Sprites);

            reader.Read();

            var buildData = reader.BuildData;

            Assert.AreEqual(1, buildData.SymbolCount);
            Assert.AreEqual(1, buildData.FrameCount);
            Assert.AreEqual(1696137821, buildData.Symbols[0].Hash);
            var frames = buildData.Symbols[0].Frames;

            Assert.AreEqual(1, frames.Count);
            Assert.AreEqual(1, frames[0].Duration);
            Assert.AreEqual(0, frames[0].BuildImageIndex);
            Assert.AreEqual(100, frames[0].PivotX);
            Assert.AreEqual(100, frames[0].PivotY);

            var hashtable = reader.BuildHashes;

            Assert.AreEqual(1, hashtable.Count);
            Assert.AreEqual(1696137821, hashtable.Keys.First());
            Assert.AreEqual("square", hashtable.Values.First().Value);
        }
Beispiel #2
0
        private static void Convert(string inputFormat, string outputFormat, List <string> files, ConversionOptions opt)
        {
            SetVerbosity(opt);

            if (files.Count == 0)
            {
                Logger.Fatal("Please specify files to convert.");
                Environment.Exit((int)ExitCodes.IncorrectArguments);
            }

            Logger.Info("Reading...");
            Reader reader = null;

            switch (inputFormat)
            {
            case "scml":
                var scml       = files.Find(path => path.EndsWith(".scml"));
                var scmlreader = new ScmlReader(scml)
                {
                    AllowMissingSprites      = !opt.Strict,
                    AllowInFramePivots       = !opt.Strict,
                    InterpolateMissingFrames = opt.Interp,
                    Debone = opt.Debone
                };
                scmlreader.Read();
                reader = scmlreader;
                break;

            case "kanim":
                var png   = "";
                var build = "";
                var anim  = "";
                if (opt is GenericOptions && ((GenericOptions)opt).Ordered)
                {
                    png   = files[0];
                    build = files[1];
                    anim  = files[2];
                }
                else
                {
                    png   = files.Find(path => path.EndsWith(".png"));
                    build = files.Find(path => path.EndsWith("build.bytes"));
                    anim  = files.Find(path => path.EndsWith("anim.bytes"));
                }

                var fileNames = new[] { png, build, anim };

                var nullCount = fileNames.Count(o => o == null);
                if (nullCount > 0)
                {
                    Logger.Fatal($"The following file{(nullCount > 1 ? "s were" : "was")} not specified:");
                    for (var i = 0; i < 3; ++i)
                    {
                        if (fileNames[i] == null)
                        {
                            switch (i)
                            {
                            case 0:
                                Logger.Fatal("    png");
                                break;

                            case 1:
                                Logger.Fatal("    build");
                                break;

                            case 2:
                                Logger.Fatal("    anim");
                                break;
                            }
                        }
                    }

                    Environment.Exit((int)ExitCodes.IncorrectArguments);
                }
                reader = new KanimReader(
                    new FileStream(build, FileMode.Open),
                    new FileStream(anim, FileMode.Open),
                    new FileStream(png, FileMode.Open));
                reader.Read();
                break;

            default:
                Logger.Fatal($"The specified input format \"{inputFormat}\" is not recognized.");
                Environment.Exit((int)ExitCodes.IncorrectArguments);
                break;
            }

            Logger.Info($"Successfully read from format {inputFormat}.");
            Logger.Info("Writing...");

            switch (outputFormat)
            {
            case "scml":
                var scmlWriter = new ScmlWriter(reader)
                {
                    FillMissingSprites    = !opt.Strict,
                    AllowDuplicateSprites = !opt.Strict
                };
                scmlWriter.SaveToDir(Path.Join(opt.OutputPath));
                break;

            case "kanim":
                var kanimWriter = new KanimWriter(reader);
                kanimWriter.SaveToDir(opt.OutputPath);
                break;

            default:
                Logger.Fatal($"The specified output format \"{outputFormat}\" is not recognized.");
                Environment.Exit((int)ExitCodes.IncorrectArguments);
                break;
            }

            Logger.Info($"Successfully wrote to format {outputFormat}");
        }