Exemplo n.º 1
0
        public Mother3EfcRenderer(Mother3Reader reader, Mother3Efc efc, SizedOffsetTable sar)
        {
            reader.ThrowIfNull(nameof(reader));
            efc.ThrowIfNull(nameof(efc));
            sar.ThrowIfNull(nameof(sar));

            Reader = reader;
            Efc    = efc;
            Sar    = sar;
        }
        public void DumpBattleAnimations()
        {
            var baseDirectory = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, @"..\..\..\..\.."));

            var frameAnimationDirectory          = new DirectoryInfo(Path.Combine(baseDirectory.FullName, "frame-animations"));
            var frameAnimationSequencesDirectory = new DirectoryInfo(Path.Combine(baseDirectory.FullName, "frame-animation-sequences"));
            var spriteSequencesDirectory         = new DirectoryInfo(Path.Combine(baseDirectory.FullName, "sprite-sequences"));

            if (!frameAnimationDirectory.Exists)
            {
                frameAnimationDirectory.Create();
            }

            if (!frameAnimationSequencesDirectory.Exists)
            {
                frameAnimationSequencesDirectory.Create();
            }

            if (!spriteSequencesDirectory.Exists)
            {
                spriteSequencesDirectory.Create();
            }

            var reader = new Mother3Reader(new GbaReader(new BinaryReader(m3)));

            var efc         = reader.ReadEfc(0x1E4015C);
            var sar         = reader.ReadSar(0x1E45C1C);
            var efcRenderer = new Mother3EfcRenderer(reader, efc, sar);

            // Frame animation sequences
            for (int sequenceIndex = 0; sequenceIndex < efc.FrameAnimationSequences.Length; sequenceIndex++)
            {
                foreach (var step in efcRenderer.RenderFrameAnimationSequence(sequenceIndex))
                {
                    var sequenceDirectory = new DirectoryInfo(Path.Combine(frameAnimationSequencesDirectory.FullName, sequenceIndex.ToString("D3")));
                    if (!sequenceDirectory.Exists)
                    {
                        sequenceDirectory.Create();
                    }

                    string fileName = Path.Combine(sequenceDirectory.FullName, $"{step.SequenceIndex:D3}.png");
                    RenderImage(fileName, step.Render);
                }
            }

            // Sprite sequences
            for (int sequenceIndex = 0; sequenceIndex < efc.SpriteSequenceHeaders.Length; sequenceIndex++)
            {
                var sequenceDirectory = new DirectoryInfo(Path.Combine(spriteSequencesDirectory.FullName, sequenceIndex.ToString("D3")));
                if (!sequenceDirectory.Exists)
                {
                    sequenceDirectory.Create();
                }

                int animationIndex = 0;
                foreach (var animation in efcRenderer.RenderSpriteSequence(sequenceIndex))
                {
                    var animationDirectory = new DirectoryInfo(Path.Combine(sequenceDirectory.FullName, animationIndex.ToString("D3")));
                    if (!animationDirectory.Exists)
                    {
                        animationDirectory.Create();
                    }

                    foreach (var animationStep in animation)
                    {
                        string fileName = Path.Combine(animationDirectory.FullName, $"{animationStep.SequenceIndex:D3}.png");
                        RenderImage(fileName, animationStep.Render);
                    }

                    animationIndex++;
                }
            }

            // Frame animations
            for (int sequenceIndex = 0; sequenceIndex < efc.FrameAnimations.Length; sequenceIndex++)
            {
                var sequenceDirectory = new DirectoryInfo(Path.Combine(frameAnimationDirectory.FullName, sequenceIndex.ToString("D3")));
                if (!sequenceDirectory.Exists)
                {
                    sequenceDirectory.Create();
                }

                foreach (var step in efcRenderer.RenderFrameAnimation(sequenceIndex))
                {
                    string fileName = Path.Combine(sequenceDirectory.FullName, $"{step.SequenceIndex:D3}.png");
                    RenderImage(fileName, step.Render);
                }
            }
        }