Exemple #1
0
        public void TestPackEmptyAtlas()
        {
            TextureAtlas atlas = new TextureAtlas(AnimationSheetGenerator.GenerateDefaultAnimationExportSettings());

            DefaultTexturePacker packer = new DefaultTexturePacker();

            packer.Pack(atlas);

            Assert.AreEqual(new Rectangle(0, 0, 1, 1), atlas.AtlasRectangle, "Packing an empty texture atlas should result in an atlas with an empty area");
        }
Exemple #2
0
        public void TestSheetExportConsistency()
        {
            AnimationExportSettings[] permSettings = AnimationSheetGenerator.GetExportSettingsPermutations();

            foreach (var settings in permSettings)
            {
                TestSheetExportWithSettings(settings);
                TestTeardown();
            }
        }
        public void TestAnimationSheetFrameCount()
        {
            var r = new Random();

            for (int i = 0; i < 10; i++)
            {
                var animCount  = r.Next(1, 10);
                var frameCount = r.Next(1, 10);
                var sheet1     = AnimationSheetGenerator.GenerateAnimationSheet("TestSheet", animCount, 64, 64, frameCount, 0);

                Assert.AreEqual(sheet1.GetFrameCount(), animCount * frameCount, "GetFrameCount() must return the frame count of all the animations in a sprite sheet");
            }
        }
Exemple #4
0
        public void TestInsertAnimation()
        {
            TextureAtlas atlas = new TextureAtlas(AnimationSheetGenerator.GenerateDefaultAnimationExportSettings(), "TestAtlas");

            Animation anim = AnimationGenerator.GenerateAnimation("TestAnim1", 16, 16, 10);

            atlas.InsertFramesFromAnimation(anim);

            Assert.AreEqual(anim, atlas.GetAnimationsOnAtlas()[0], "After adding an animation to an atlas, the animation should be listed on the atlas' GetAnimationsOnAtlas()");
            Assert.AreEqual(anim.FrameCount, atlas.FrameCount, "When adding animations to an atlas, all valid frames on the animation should be counted in it");
            Assert.IsTrue(!anim.Frames.Where((t, i) => !ReferenceEquals(t, atlas.FrameList[i])).Any(),
                          "When adding animations to an atlas, all valid frames on the animation should be counted in it");
        }
Exemple #5
0
        public void TestInsertDuplicatedAnimation()
        {
            TextureAtlas atlas = new TextureAtlas(AnimationSheetGenerator.GenerateDefaultAnimationExportSettings(), "TestAtlas");

            Animation anim = AnimationGenerator.GenerateAnimation("TestAnim1", 16, 16, 10);

            atlas.InsertFramesFromAnimation(anim);
            atlas.InsertFramesFromAnimation(anim);

            Assert.AreEqual(anim, atlas.GetAnimationsOnAtlas()[0], "Adding the same animation to an atlas twice should have no effect on its animation count");
            Assert.AreEqual(anim.FrameCount, atlas.FrameCount, "Adding the same animation to an atlas twice should have no effect on its frame count");
            Assert.IsTrue(!anim.Frames.Where((t, i) => !ReferenceEquals(t, atlas.FrameList[i])).Any(),
                          "Adding the same animation to an atlas twice should have no effect in its frame set");
        }
Exemple #6
0
        public void TestPackEmptyFrames()
        {
            Animation anim = new Animation("TestAnim", 64, 64);

            // Fill the animation with a few empty frames
            anim.CreateFrame().ID = 1;
            anim.CreateFrame().ID = 2;

            TextureAtlas atlas = new TextureAtlas(AnimationSheetGenerator.GenerateDefaultAnimationExportSettings());

            atlas.InsertFramesFromAnimation(anim);

            DefaultTexturePacker packer = new DefaultTexturePacker();

            packer.Pack(atlas);

            Assert.AreEqual(new Rectangle(0, 0, 1, 1), atlas.AtlasRectangle, "Packing a texture atlas that contains empty frames should result in an atlas with a 1x1 area");
        }
Exemple #7
0
        public void TestBundleAnimationSheetFetchById()
        {
            Bundle bundle = new Bundle("TestBundle");

            bundle.AddAnimationSheet(AnimationSheetGenerator.GenerateAnimationSheet("TestSheet1", 5, 16, 16, 5, 0));
            bundle.AddAnimationSheet(AnimationSheetGenerator.GenerateAnimationSheet("TestSheet2", 5, 16, 16, 5, 0));

            AnimationSheet firstSheet    = bundle.AnimationSheets[0];
            AnimationSheet secondSheet   = bundle.AnimationSheets[0];
            const int      nonExistingId = 10;

            // Existing
            Assert.AreEqual(firstSheet, bundle.GetAnimationSheetByID(firstSheet.ID),
                            "Getting an animation sheet by ID should always return an animation sheet matching a specified ID on the bundle when it exists");
            Assert.AreEqual(secondSheet, bundle.GetAnimationSheetByID(secondSheet.ID),
                            "Getting an animation sheet by ID should always return an animation sheet matching a specified ID on the bundle when it exists");

            // Non-existing
            Assert.IsNull(bundle.GetAnimationSheetByID(nonExistingId),
                          "When trying to fetch an unexisting animation sheet ID, null should be returned");
        }
Exemple #8
0
        public void TestBundleAnimationSheetFetchByName()
        {
            Bundle bundle = new Bundle("TestBundle");

            bundle.AddAnimationSheet(AnimationSheetGenerator.GenerateAnimationSheet("TestSheet1", 5, 16, 16, 5, 0));
            bundle.AddAnimationSheet(AnimationSheetGenerator.GenerateAnimationSheet("TestSheet2", 5, 16, 16, 5, 0));

            AnimationSheet firstSheet      = bundle.AnimationSheets[0];
            AnimationSheet secondSheet     = bundle.AnimationSheets[0];
            const string   nonExistingName = "B4DF00D";

            // Existing
            Assert.AreEqual(firstSheet, bundle.GetAnimationSheetByName(firstSheet.Name),
                            "Getting an animation sheet by name should always return an animation sheet matching a specified name on the bundle when it exists");
            Assert.AreEqual(secondSheet, bundle.GetAnimationSheetByName(secondSheet.Name),
                            "Getting an animation sheet by name should always return an animation sheet matching a specified name on the bundle when it exists");

            // Non-existing
            Assert.IsNull(bundle.GetAnimationSheetByName(nonExistingName),
                          "When trying to fetch an unexisting animation sheet name, null should be returned");
        }
        public void TestAnimationSheetClone()
        {
            var sheet1 = AnimationSheetGenerator.GenerateAnimationSheet("TestSheet", 2, 64, 64, 10, 0);
            var sheet2 = sheet1.Clone();

            Assert.AreEqual(sheet1, sheet2, "Animation sheets copied with the Clone() method must be equal");

            // Modify one of the sheet's properties
            var frame = sheet2.Animations[0].Frames[0] as Frame;

            frame?.SetFrameBitmap(FrameGenerator.GenerateDifferentFrom(sheet1.Animations[0].Frames[0].GetComposedBitmap()));

            Assert.AreNotEqual(sheet1, sheet2, "After modification of a cloned animation sheet's animation's frame, it must no longer be considered equal to the original");

            // Modify one of the sheet's properties
            frame = sheet2.Animations[0].Frames[0] as Frame;
            frame?.SetFrameBitmap(FrameGenerator.GenerateDifferentFrom(sheet1.Animations[0].Frames[0].GetComposedBitmap()));

            sheet2.ExportSettings = new AnimationExportSettings {
                ExportJson = !sheet1.ExportSettings.ExportJson
            };

            Assert.AreNotEqual(sheet1, sheet2, "After modification of a cloned animation sheet's export settings, it must no longer be considered equal to the original");
        }