public static void Load() { if (Directory.Exists(OldConfigFolderPath)) { if (File.Exists(OldConfigPath)) { GoldensMisc.Log("Found config file in old folder! Moving config..."); File.Move(OldConfigPath, ConfigPath); } if (File.Exists(OldConfigVersionPath)) { File.Delete(OldConfigVersionPath); } if (Directory.GetFiles(OldConfigFolderPath).Length == 0 && Directory.GetDirectories(OldConfigFolderPath).Length == 0) { Directory.Delete(OldConfigFolderPath); } else { GoldensMisc.Log("Old config folder still cotains some files/directories. They will not get deleted."); } } SetDefaults(); if (!ReadConfig()) { GoldensMisc.Log("Failed to read config file!"); } SaveConfig(); }
static void AddFurniture(GenerationProgress progress, string name, int type, int rarity, int minY, int maxY, params int[] wallIDs) { try { if (progress != null) { progress.Message = "Adding " + name; } else { Main.NewText("Adding " + name); } int generated = 0; float toGenerate = Main.maxTilesX / rarity; // var watch = Stopwatch.StartNew(); for (int i = 0; i < toGenerate; i++) { progress.Set(i / toGenerate); bool success = false; int attempts = 0; while (!success) { // if(watch.Elapsed.Seconds >= 10) // { // GoldensMisc.Log("SUCC FOR TOO LONG IMMA NUT"); // GoldensMisc.Log("Generated {0}/{1} {2}", generated, toGenerate, name); // watch.Stop(); // return; // } int x = WorldGen.genRand.Next(1, Main.maxTilesX); int y = WorldGen.genRand.Next(minY, maxY); foreach (int wallID in wallIDs) { if (Main.tile[x, y].wall == wallID) { // GoldensMisc.Log("READY FOR THE SUCC {0} {1}", num, attempts); while (!Main.tile[x, y].active()) { y++; } y--; WorldGen.PlaceObject(x, y, (ushort)type, true); if (Main.tile[x, y].type == (ushort)type) { generated++; success = true; // GoldensMisc.Log("SUCCESS"); } else { attempts++; if (attempts >= 1000) { // GoldensMisc.Log("OH NO"); success = true; } } } } } } if (progress != null) { GoldensMisc.Log("Generated {0}/{1} {2}", generated, toGenerate, name); } else { Main.NewText(String.Format("Generated {0}/{1} {2}", generated, toGenerate, name)); } } //Vanilla Terraria does this, so I guess this is OK...? catch (Exception e) { ErrorLogger.Log(e.ToString()); } }
static void AddFurniture(GenerationProgress progress, string name, int type, int rarity, int minY, int maxY, params int[] wallIDs) { try { if (progress != null) { progress.Message = name; } else { Main.NewText(name); } int generated = 0; int toGenerate = Main.maxTilesX / rarity; for (int i = 0; i < toGenerate; i++) { if (progress != null) { progress.Set(i / toGenerate); } bool success = false; int attempts = 0; while (!success) { int x = WorldGen.genRand.Next(1, Main.maxTilesX); int y = WorldGen.genRand.Next(minY, maxY); foreach (int wallID in wallIDs) { if (Main.tile[x, y].wall == wallID) { while (!Main.tile[x, y].active()) { y++; } y--; WorldGen.PlaceObject(x, y, (ushort)type, true); if (Main.tile[x, y].type == (ushort)type) { generated++; success = true; } else { attempts++; if (attempts >= 1000) { success = true; } } } } } } if (progress != null) { GoldensMisc.Log(name + ' ' + Language.GetTextValue("Mods.GoldensMisc.WorldGen.FurnitureGeneratorResults"), generated, toGenerate); } else { Main.NewText(Language.GetTextValue("Mods.GoldensMisc.WorldGen.FurnitureGeneratorResults", generated, toGenerate)); } } //Vanilla Terraria does this, so I guess this is OK...? catch (Exception e) { GoldensMisc.Error("Error during worldgen", e); } }