public static bool LoadContentPack(IContentPack contentPack, EventArgs e) { string contentPackConfigJson = GetActualCaseForFileName(contentPack.DirectoryPath, ContentPackConfigJson); bool haveContentPackConfigFile = contentPackConfigJson != null; if (haveContentPackConfigFile) { ContentPackConfig contentPackConfig = contentPack.ReadJsonFile <ContentPackConfig>(contentPackConfigJson); ContentPackConfigController.AddConfig(contentPackConfig, contentPack.Manifest.UniqueID); } else { ProducerFrameworkModEntry.ModMonitor.Log($"Content pack: {contentPack.Manifest.Name} {contentPack.Manifest.Version} from {contentPack.DirectoryPath}\nIt does not have an {ContentPackConfigJson} file.", LogLevel.Trace); } string producersConfigJson = GetActualCaseForFileName(contentPack.DirectoryPath, ProducersConfigJson); bool haveProducersConfigFile = producersConfigJson != null; ProducerFrameworkModEntry.ModMonitor.Log($"Reading content pack: {contentPack.Manifest.Name} {contentPack.Manifest.Version} from {contentPack.DirectoryPath}"); if (haveProducersConfigFile) { List <ProducerConfig> producersConfigs = contentPack.ReadJsonFile <List <ProducerConfig> >(producersConfigJson); ProducerController.AddProducersConfig(producersConfigs, contentPack.Manifest.UniqueID); } else { ProducerFrameworkModEntry.ModMonitor.Log($"Content pack: {contentPack.Manifest.Name} {contentPack.Manifest.Version} from {contentPack.DirectoryPath}\nIt does not have an {ProducersConfigJson} file.", LogLevel.Trace); } if (e is SaveLoadedEventArgs) { string producerRulesJson = GetActualCaseForFileName(contentPack.DirectoryPath, ProducerRulesJson); bool haveProducerRulesFile = producerRulesJson != null; if (haveProducerRulesFile) { List <ProducerRule> producerItems = contentPack.ReadJsonFile <List <ProducerRule> >(producerRulesJson); ProducerController.AddProducerItems(producerItems, contentPack.Translation, contentPack.Manifest.UniqueID); } else { ProducerFrameworkModEntry.ModMonitor.Log($"Content pack: {contentPack.Manifest.Name} {contentPack.Manifest.Version} from {contentPack.DirectoryPath}\nIt does not have an {ProducerRulesJson} file.", LogLevel.Trace); } if (!haveProducerRulesFile && !haveProducersConfigFile) { ProducerFrameworkModEntry.ModMonitor.Log($"Ignoring content pack: {contentPack.Manifest.Name} {contentPack.Manifest.Version} from {contentPack.DirectoryPath}\nIt does not have any of the required files.", LogLevel.Warn); return(false); } } return(true); }
/// <summary> /// Adds or replace the content pack global config. /// </summary> /// <param name="config">The config to be added or replaced.</param> /// <param name="modUniqueId">The mod unique id.</param> /// public static void AddConfig(ContentPackConfig config, string modUniqueId) { Repository[modUniqueId] = config; }
/// <summary>Loads all the sprites from the specified directory into the correct sprite pool.</summary> /// <param name="directory">The absolute directory containing the sprites.</param> /// <param name="contentPack">The content pack currently being loaded.</param> /// <param name="season">The season to load the images into.</param> private void LoadSpritesFromDirectory(string directory, IContentPack contentPack, ContentPackConfig contentPackConfig, string season) { foreach (var file in Directory.GetFiles(directory)) { // ensure file is an image file if (!file.EndsWith(".png")) { this.Monitor.Log($"Invalid file in folder: {file}"); continue; } // get the grass texture var relativePath = Path.Combine(season, Path.GetFileName(file)); // a rare bug on Unix causes Directory.GetFiles(string) to return invalid files, it'll return a list of the expected files as well as a copy of each file but prefixed with "._" // these files don't actually exist and cause the below to throw an exception, I tried checking if the files started with "._" but that didn't work, in the end silently // catching the exception and ignoring it seemed to be the only way for it to work. silently catching shouldn't be a problem here as that shouldn't throw any other exception anyway Texture2D grassTexture; try { grassTexture = contentPack.LoadAsset <Texture2D>(relativePath); } catch { continue; } if (grassTexture == null) { this.Monitor.Log($"Failed to get grass sprite. Path expected: {relativePath}"); continue; } // add the texture to the correct sprite pool var whiteListedLocations = contentPackConfig.WhiteListedLocations ?? new List <string>(); whiteListedLocations.AddRange(contentPackConfig.WhiteListedGrass.FirstOrDefault(whiteListedGrass => whiteListedGrass.Key.ToLower() == new FileInfo(file).Name.ToLower()).Value ?? new List <string>()); var blackListedLocations = contentPackConfig.BlackListedLocations ?? new List <string>(); blackListedLocations.AddRange(contentPackConfig.BlackListedGrass.FirstOrDefault(blackListedGrass => blackListedGrass.Key.ToLower() == new FileInfo(file).Name.ToLower()).Value ?? new List <string>()); switch (season) { case "spring": SpringSpritePool.AddCustomGrass(grassTexture, whiteListedLocations, blackListedLocations); break; case "summer": SummerSpritePool.AddCustomGrass(grassTexture, whiteListedLocations, blackListedLocations); break; case "fall": FallSpritePool.AddCustomGrass(grassTexture, whiteListedLocations, blackListedLocations); break; case "winter": WinterSpritePool.AddCustomGrass(grassTexture, whiteListedLocations, blackListedLocations); break; } } }