public void TestBundleAnimationFetchByName() { Bundle bundle = new Bundle("TestBundle"); bundle.AddAnimation(AnimationGenerator.GenerateAnimation("TestAnimation1", 16, 16, 5, 0)); bundle.AddAnimation(AnimationGenerator.GenerateAnimation("TestAnimation2", 16, 16, 5, 0)); Animation firstAnimation = bundle.Animations[0]; Animation secondAnimation = bundle.Animations[0]; const string nonExistingName = "B4DF00D"; // Existing Assert.AreEqual(firstAnimation, bundle.GetAnimationByName(firstAnimation.Name), "Getting an animation by name should always return an animation matching a specified name on the bundle when it exists"); Assert.AreEqual(secondAnimation, bundle.GetAnimationByName(secondAnimation.Name), "Getting an animation by name should always return an animation matching a specified name on the bundle when it exists"); // Non-existing Assert.IsNull(bundle.GetAnimationByName(nonExistingName), "When trying to fetch an unexisting animation name, null should be returned"); }
public void TestBundleAnimationFetchById() { Bundle bundle = new Bundle("TestBundle"); bundle.AddAnimation(AnimationGenerator.GenerateAnimation("TestAnimation1", 16, 16, 5, 0)); bundle.AddAnimation(AnimationGenerator.GenerateAnimation("TestAnimation2", 16, 16, 5, 0)); Animation firstAnimation = bundle.Animations[0]; Animation secondAnimation = bundle.Animations[0]; const int nonExistingId = 10; // Existing Assert.AreEqual(firstAnimation, bundle.GetAnimationByID(firstAnimation.ID), "Getting an animation by ID should always return an animation matching a specified ID on the bundle when it exists"); Assert.AreEqual(secondAnimation, bundle.GetAnimationByID(secondAnimation.ID), "Getting an animation by ID should always return an animation matching a specified ID on the bundle when it exists"); // Non-existing Assert.IsNull(bundle.GetAnimationByID(nonExistingId), "When trying to fetch an unexisting animation ID, null should be returned"); }
public void TestBundleFrameIdGeneration() { Bundle bundle1 = BundleGenerator.GenerateTestBundle(0); Bundle bundle2 = new Bundle("TestBundle2"); // Remove animation from one bundle and add to another Animation anim = bundle1.Animations[0]; bundle1.RemoveAnimation(anim); bundle2.AddAnimation(anim); // Create a frame on the animation on bundle2 Frame newFrame = bundle2.Animations[0].CreateFrame(); // Test if the frame's ID matches the previos frame's ID + 1 Assert.AreEqual(newFrame.ID, bundle2.Animations[0][bundle2.Animations[0].FrameCount - 2].ID + 1, "When adding an animation to a bundle, the frame ID index should be bumped up to match the highest frame ID available + 1"); }
/// <summary> /// Loads a bundle from disk /// </summary> /// <param name="path">The path to load the bundle from</param> /// <returns>The bundle that was loaded from the given path</returns> public static Bundle LoadBundleFromDisk(string path) { FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read); BinaryReader reader = new BinaryReader(stream); // Signature Block if (reader.ReadByte() != 'P' || reader.ReadByte() != 'X' || reader.ReadByte() != 'L') { return(null); } // Bundle Header block int bundleVersion = reader.ReadInt32(); string bundleName = reader.ReadString(); string bundlePath = ""; // New pixelaria file format if (bundleVersion >= 9) { stream.Close(); return(LoadFileFromDisk(path).LoadedBundle); } //////// //// Legacy file formats //////// if (bundleVersion >= 3) { bundlePath = reader.ReadString(); } Bundle bundle = new Bundle(bundleName) { ExportPath = bundlePath }; // Animation block int animCount = reader.ReadInt32(); for (int i = 0; i < animCount; i++) { bundle.AddAnimation(LoadAnimationFromStream(stream, bundleVersion)); } // The next block (Animation Sheets) are only available on version 2 and higher if (bundleVersion == 1) { return(bundle); } // AnimationSheet block int sheetCount = reader.ReadInt32(); for (int i = 0; i < sheetCount; i++) { bundle.AddAnimationSheet(LoadAnimationSheetFromStream(stream, bundle, bundleVersion)); } stream.Close(); return(bundle); }