public ContentPackDataInfo(string directory, string fileName, ContentPackData content) { this.FullPath = Path.Combine(directory, fileName); this.Directory = directory; this.FileName = fileName; this.Content = content; }
/********* ** Private methods *********/ /// <summary>Load the data from each available content pack.</summary> private IEnumerable <ContentPackData> LoadContentPackData() { ConfigReader configReader = new ConfigReader(this.Monitor); foreach (IContentPack contentPack in this.GetAllContentPacks()) { this.Monitor.Log($"Loading content pack '{contentPack.Manifest.Name}'...", LogLevel.Debug); ContentPackData data = configReader.Load(contentPack); if (data != null) { yield return(data); } } }
private void loadData(string dir) { // read info if (!File.Exists(Path.Combine(dir, "content-pack.json"))) { Log.warn($"\tNo {dir}/content-pack.json!"); return; } ContentPackData info = this.Helper.ReadJsonFile <ContentPackData>(Path.Combine(dir, "content-pack.json")); // load content pack IContentPack contentPack = this.Helper.CreateTransitionalContentPack(dir, id: Guid.NewGuid().ToString("N"), name: info.Name, description: info.Description, author: info.Author, version: new SemanticVersion(info.Version)); this.loadData(contentPack); }
private void loadData(string dir) { // read initial info IContentPack temp = this.Helper.ContentPacks.CreateFake(dir); ContentPackData info = temp.ReadJsonFile <ContentPackData>("content-pack.json"); if (info == null) { Log.warn($"\tNo {dir}/content-pack.json!"); return; } // load content pack IContentPack contentPack = this.Helper.ContentPacks.CreateTemporary(dir, id: Guid.NewGuid().ToString("N"), name: info.Name, description: info.Description, author: info.Author, version: new SemanticVersion(info.Version)); this.loadData(contentPack); }
/// <summary>Validate the configuration for a content pack and remove invalid settings.</summary> /// <param name="contentPack">The content pack to load.</param> /// <param name="config">The config settings.</param> private ContentPackData ValidateData(IContentPack contentPack, LocationConfig config) { ContentPackData data = new ContentPackData { ContentPack = contentPack }; string currentStep = "Entry"; try { // validate locations if (config.Locations != null) { currentStep = "Locations"; foreach (Location location in config.Locations) { if (!this.AssertFileExists(contentPack, "location", location.FileName)) { continue; } if (!this.AffectedLocations.Add(location.MapName)) { this.Monitor.Log($" Skipped {location}: that map is already being modified.", LogLevel.Error); continue; } if (!this.LocationTypes.Contains(location.Type)) { this.Monitor.Log($" Location {location} has unknown type, using 'Default' instead.", LogLevel.Warn); location.Type = "Default"; } data.Locations.Add(location); } } // validate overrides if (config.Overrides != null) { currentStep = "Overrides"; foreach (Override @override in config.Overrides) { if (!this.AssertFileExists(contentPack, "override", @override.FileName)) { continue; } if (!this.AffectedLocations.Add(@override.MapName)) { this.Monitor.Log($" Skipped {@override}: that map is already being modified.", LogLevel.Error); continue; } data.Overrides.Add(@override); } } // validate redirects if (config.Redirects != null) { currentStep = "Redirects"; foreach (Redirect redirect in config.Redirects) { if (!File.Exists(Path.Combine(Game1.content.RootDirectory, $"{redirect.FromFile}.xnb"))) { this.Monitor.Log($" Skipped {redirect}: file {redirect.FromFile}.xnb doesn't exist in the game's content folder.", LogLevel.Error); continue; } if (!this.AssertFileExists(contentPack, "redirect", redirect.ToFile)) { continue; } data.Redirects.Add(redirect); } } // validate tilesheets if (config.Tilesheets != null) { currentStep = "Tilesheets"; foreach (Tilesheet tilesheet in config.Tilesheets) { if (tilesheet.FileName != null) { if (tilesheet.Seasonal) { bool filesExist = this.AssertFileExists(contentPack, "tilesheet", $"{tilesheet.FileName}_spring") && this.AssertFileExists(contentPack, "tilesheet", $"{tilesheet.FileName}_summer") && this.AssertFileExists(contentPack, "tilesheet", $"{tilesheet.FileName}_fall") && this.AssertFileExists(contentPack, "tilesheet", $"{tilesheet.FileName}_winter"); if (!filesExist) { continue; } } else if (!this.AssertFileExists(contentPack, "tilesheet", tilesheet.FileName)) { continue; } } data.Tilesheets.Add(tilesheet); } } // validate tiles if (config.Tiles != null) { currentStep = "Tiles"; foreach (Tile tile in config.Tiles) { if (!this.ValidLayers.Contains(tile.LayerId)) { this.Monitor.Log($" Skipped {tile}: unknown layer '{tile.LayerId}'.", LogLevel.Error); continue; } data.Tiles.Add(tile); } } // validate properties if (config.Properties != null) { currentStep = "Properties"; foreach (Property property in config.Properties) { if (!this.ValidLayers.Contains(property.LayerId)) { this.Monitor.Log($" Skipped `{property}`: unknown layer '{property.LayerId}'.", LogLevel.Error); continue; } data.Properties.Add(property); } } // validate warps if (config.Warps != null) { currentStep = "Warps"; foreach (Warp warp in config.Warps) { data.Warps.Add(warp); } } // validate conditionals if (config.Conditionals != null) { currentStep = "Conditionals"; foreach (Conditional condition in config.Conditionals) { if (condition.Item < -1) { this.Monitor.Log($" Skipped {condition}, references null item.", LogLevel.Error); continue; } if (condition.Amount < 1) { this.Monitor.Log($" Skipped {condition}, item amount can't be less then 1.", LogLevel.Error); continue; } if (!this.AddedConditionNames.Add(condition.Name)) { this.Monitor.Log($" Skipped {condition.Name}, another condition with this name already exists.", LogLevel.Error); continue; } data.Conditionals.Add(condition); } } // validate minecarts if (config.Teleporters != null) { currentStep = "Teleporters"; foreach (TeleporterList list in config.Teleporters) { bool valid = true; foreach (TeleporterList prevList in this.AddedTeleporters) { if (prevList.ListName == list.ListName) { valid = false; foreach (TeleporterDestination dest in list.Destinations) { if (prevList.Destinations.TrueForAll(a => !a.Equals(dest))) { prevList.Destinations.Add(dest); } else { this.Monitor.Log($" Can't add teleporter destination for the `{list.ListName}` teleporter, the destination already exists: `{dest}`.", LogLevel.Error); } } this.Monitor.Log($" Teleporter updated: {prevList}", LogLevel.Trace); break; } } if (valid) { this.AddedTeleporters.Add(list); this.Monitor.Log($" Teleporter created: {list}", LogLevel.Trace); } } } // validate shops if (config.Shops != null) { currentStep = "Shops"; foreach (string shop in config.Shops) { try { ShopConfig shopConfig = contentPack.ReadJsonFile <ShopConfig>($"{shop}.json"); if (shopConfig == null) { this.Monitor.Log($" Skipped shop '{shop}.json': file does not exist.", LogLevel.Error); continue; } shopConfig.Name = shop; data.Shops.Add(shopConfig); } catch (Exception ex) { this.Monitor.Log($" Skipped shop '{shop}.json': unexpected error parsing file.", LogLevel.Error, ex); } } } } catch (Exception ex) { this.Monitor.Log($" Failed validating config (step: {currentStep}).", LogLevel.Error, ex); } return(data); }