public static void SetBundleData(int bundle_type, bool use_seed) { Random r = null; r = ((!use_seed) ? new Random() : new Random((int)Game1.uniqueIDForThisGame * 9)); switch (bundle_type) { // Normal default: { Game1.netWorldState.Value.SetBundleData(Game1.content.LoadBase <Dictionary <string, string> >("Data\\Bundles")); break; } // Remixed case 1: { Dictionary <string, string> bundle_data = new BundleGenerator().Generate("Data\\RandomBundles", r); Game1.netWorldState.Value.SetBundleData(bundle_data); break; } // Custom case 2: { string path = Path.Combine(Main.Helper.DirectoryPath, "Data\\RandomizedBundles.json"); Dictionary <string, string> bundle_data = new CustomBundleGenerator().Generate(path, r); Game1.netWorldState.Value.SetBundleData(bundle_data); break; } } }
public void TestFileLoaderSaver() { Bundle bundle = BundleGenerator.GenerateTestBundle(0); Stream stream = new MemoryStream(); PixelariaFile originalFile = new PixelariaFile(bundle, stream); PixelariaFileSaver.Save(originalFile); // Test if the memory stream is now filled Assert.IsTrue(stream.Length > 0, "After a call to PixelariaFileSaver.Save(), the pixelaria file's stream should not be empty"); // Bring the bundle back with a PixelariaFileLoader PixelariaFile newFile = new PixelariaFile(new Bundle(""), stream); stream.Position = 0; PixelariaFileLoader.Load(newFile); Assert.AreEqual(originalFile.LoadedBundle, newFile.LoadedBundle, "After persisting a file to a stream and loading it back up again, the bundles must be equal"); // Save the bundle a few more times to test resilience of the save/load process newFile.CurrentStream.Position = 0; PixelariaFileLoader.Load(newFile); newFile.CurrentStream.Position = 0; PixelariaFileSaver.Save(newFile); Assert.IsTrue( Utilities.ByteArrayCompare(((MemoryStream)newFile.CurrentStream).GetBuffer(), ((MemoryStream)originalFile.CurrentStream).GetBuffer()), "Two streams that represent the same Pixelaria File should be bitwise equal"); Assert.AreEqual(originalFile.LoadedBundle, newFile.LoadedBundle, "After persisting a file to a stream and loading it back up again, the bundles must be equal"); }
public void TestBundleEquality() { Bundle bundle1 = BundleGenerator.GenerateTestBundle(0); Bundle bundle2 = bundle1.Clone(); Assert.AreEqual(bundle1, bundle2, "After a Clone() operation, both Bundles must be equal"); // Modify the new bundle bundle2.RemoveAnimationFromAnimationSheet(bundle2.Animations[0], bundle2.AnimationSheets[0]); Assert.AreNotEqual(bundle1, bundle2, "Equal bundles after a Clone() operation must not be equal after a successful call to RemoveAnimationFromAnimationSheet()"); }
private void GameLoop_SaveCreated(object sender, SaveCreatedEventArgs e) { if (bundlesEnabled) { Dictionary <string, string> data = new BundleGenerator().Generate( "Data\\ExpertBundles", new Random((int)Game1.uniqueIDForThisGame * 9)); data = IridiumQualityItemsFix.FixIridiumQualityItems(data); Game1.netWorldState.Value.SetBundleData(data); } }
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"); }
public void TestPersistenceClass() { // Generate a dummy file name _testFilePath = Path.GetTempFileName(); Bundle originalBundle = BundleGenerator.GenerateTestBundle(0); // Test new file format saving and loading PixelariaSaverLoader.SaveBundleToDisk(originalBundle, _testFilePath); Bundle newBundle = PixelariaSaverLoader.LoadBundleFromDisk(_testFilePath); Assert.AreEqual(originalBundle, newBundle, "After persisting a new (>= v8) file to disk and loading it back up again, the bundles must be equal"); // Test old file format loading SaveBundle(originalBundle, _testFilePath); newBundle = PixelariaSaverLoader.LoadBundleFromDisk(_testFilePath); Assert.AreEqual(originalBundle, newBundle, "After loading a legacy (< v8) file to disk and loading it back up again, the bundles must be equal"); // Now load the bundle using the LoadFileFromDisk newBundle = PixelariaSaverLoader.LoadFileFromDisk(_testFilePath).LoadedBundle; Assert.AreEqual(originalBundle, newBundle, "After loading a legacy (< v8) file to disk and loading it back up again, the bundles must be equal"); }