public static void KillDynamic() { TileList.RemoveAll(tile => tile.IsLoaded); GuidLookup.RemoveAll(pair => pair.Value.IsLoaded); NameLookup.RemoveAll(pair => pair.Value.IsLoaded); PathLookup.RemoveAll(pair => pair.Value.IsLoaded); }
public void LoadModShapes() { Parallel.ForEach(Directory.GetFiles(PathLookup.Transform(Path.Combine(this.ModFolderPath, "Objects", "Database", "ShapeSets"))), shapeListFilePath => { if (IsValidShapeListPath(shapeListFilePath)) { try { var partListData = JsonConvert.DeserializeObject <PartListData>(File.ReadAllText(shapeListFilePath)); PartLoader.LoadShapes(partListData, this); if (partListData.PartList != null) { foreach (var part in partListData.PartList) { this.partUuids.Add(part.Uuid); } } if (partListData.BlockList != null) { foreach (var block in partListData.BlockList) { this.partUuids.Add(block.Uuid); } } } catch (Exception e) { Debug.LogException(new Exception($"\nAn error occurred when trying to load mod data", e)); } } }); }
public static uint ToID(string str) { if (string.IsNullOrEmpty(str)) { return(0); } if (PathLookup.TryGetValue(str, out uint num)) { return(num); } return(0); }
private PathResolver() { FindAppdataPath(); FindPaths(); ValidateAndCorrectPaths(); scrapDataPath = Path.Combine(scrapMechanicPath, "Data"); scrapSurvivalPath = Path.Combine(scrapMechanicPath, "Survival"); scrapChallengePath = Path.Combine(scrapMechanicPath, "ChallengeData"); CollectWorkshopModPaths(); string upgradeFilePath = PathLookup.Transform(Resolve(GameController.Instance.upgradeResourcesPath)); upgradeResolver = new UpgradeResolver(upgradeFilePath); }
public static void AddTileSet(TileSet tileset) { TileList.Add(tileset); // Add the tileset to the Guid lookup GuidLookup.AddOrOverwrite(tileset.Guid, tileset); // Add the tileset to the Name lookup NameLookup.AddOrOverwrite(tileset.Name, tileset); // Add the tileset to the Path lookup if (tileset.MyPath.Length > 0) { PathLookup.AddOrOverwrite(tileset.MyPath, tileset); } }
public static void LoadLanguageFiles(string languageFolderPath) { try { // Debug.Log($"Loading Language files {DateTime.Now:O}"); too much logging languageFolderPath = Path.Combine(languageFolderPath, "English"); languageFolderPath = PathLookup.Transform(languageFolderPath); if (!Directory.Exists(languageFolderPath)) { return; } foreach (string languageFile in Directory.GetFiles(languageFolderPath)) { if (Path.GetExtension(languageFile).ToLower() != ".json" || !languageFile.ToLower().Contains("inventory")) { continue; } string text = File.ReadAllText(languageFile); LanguageData languageData = JsonConvert.DeserializeObject <LanguageData>(text); if (languageData == null) { continue; } foreach (var languageKV in languageData) { string key = languageKV.Key; var translation = languageKV.Value; translations.TryAdd(key, translation); Shape shape = loadedShapes.FirstOrDefault(shapeKV => shapeKV.Key == key).Value; if (shape != null) { shape.translation = translation; } } } } catch (Exception e) { Debug.LogException(new Exception($"\nCould not load translation data in {languageFolderPath}", e)); } }
static TileSet GetOrMakeTileset(string path) { TileSet tileset; if (PathLookup.ContainsKey(path)) { tileset = PathLookup[path]; tileset.MakeNew(); } else { tileset = new TileSet(); // Add the tileset to Freeplay CustomLevel_GUI.FreeplayTilesets.Add(tileset); } return(tileset); }
public static void Load(string path) { BackgroundTemplate template; if (PathLookup.ContainsKey(path)) { template = PathLookup[path]; } else { template = new BackgroundTemplate(); var name = Tools.GetFileName(path); template.Name = name; template.File = path; AddTemplate(template); } template.MadeOfCode = false; template.MadeOfText = true; }
public void LoadVanilla(string basePath) { string shapeSetFilePath = PathLookup.Transform(Path.Combine(basePath, "Objects/Database/shapesets.json")); var shapeSets = JsonConvert.DeserializeObject <ShapeSetListData>(File.ReadAllText(shapeSetFilePath)); Parallel.ForEach(shapeSets.ShapeSetList, partListPath => { var partListFilePath = PathResolver.ResolvePath(partListPath); try { var partListData = JsonConvert.DeserializeObject <PartListData>(File.ReadAllText(partListFilePath)); LoadShapes(partListData); } catch (Exception e) { Debug.LogException(new Exception($"\nCould not load vanilla partlist/blocklist", e)); } }); LoadLanguageFiles(Path.Combine(basePath, "Gui/Language")); }
public static bool IsValidModPath(string modPath) => File.Exists(Path.Combine(modPath, "description.json")) && Directory.Exists(PathLookup.Transform(Path.Combine(modPath, "Objects", "Database", "ShapeSets")));
public static void AddTemplate(BackgroundTemplate template) { NameLookup.AddOrOverwrite(template.Name, template); PathLookup.AddOrOverwrite(template.File, template); }
public static string ResolvePath(string path, string parentPath = null) { path = Instance.Resolve(path, parentPath); return(PathLookup.Transform(path)); }