public static SeedCollection GetMostCurrentSeeds(StaticString shipName, int level) { if (Collections == null) { return(null); } SeedCollection best = null; DateTime now = DateTime.Now; DateTime currentBest = DateTime.MinValue; foreach (SeedCollection collection in Collections) { if (collection.GetSeedForShipLevel(shipName, level) == null) { continue; } if (collection.ReadFrom.Length <= 0) { // This collection hasn't been written/read from, so it is the most up to date. return(collection); } if (File.Exists(collection.ReadFrom)) { DateTime current = File.GetLastWriteTime(collection.ReadFrom); if ((now - current) < (now - currentBest)) { best = collection; currentBest = current; } } } return(best); }
public static SeedCollection CreateAndRead(string path) { SeedCollection c = Create(); c.ReadSeeds(path); return(c); }
private static IEnumerator DungeonGenerator2_GenerateDungeonCoroutine(On.DungeonGenerator2.orig_GenerateDungeonCoroutine orig, DungeonGenerator2 self, int level, StaticString shipName) { // Preferably, sort all SeedCollections in Collections by most current file SeedCollection collection = GetMostCurrentSeeds(shipName, level); if (collection != null) { if (collection.Enabled) { if (collection.EnqueNotification) { SingletonManager.Get <Dungeon>(false).EnqueueNotification("Using Seeds: " + collection.GetSeedForShipLevel(shipName, level)); } collection.SetSeedForShipLevel(shipName, level); } if (collection.AddNewSeeds) { if (collection.GetSeedsForShip(shipName) == null) { collection.Add(shipName); } collection.Add(shipName, level, new SeedData()); if (collection.EnqueNotification) { SingletonManager.Get <Dungeon>(false).EnqueueNotification("Added Seeds: " + collection.GetSeedForShipLevel(shipName, level)); } } } yield return(orig(self, level, shipName)); }
private static string ShipConfig_GetLocalizedDescription(On.ShipConfig.orig_GetLocalizedDescription orig, ShipConfig self) { SeedCollection collection = GetMostCurrentSeeds(self.Name, 1); if (collection != null && collection.Enabled) { return(orig(self) + "\n\n" + SeedColor + "Seeds: " + collection.GetSeedForShipLevel(self.Name, 1).DungeonSeed + "," + collection.GetSeedForShipLevel(self.Name, 1).RandomGeneratorSeed + SeedColor); } return(orig(self)); }
public static void Remove(SeedCollection coll) { Collections.Remove(coll); }