コード例 #1
0
        public static void LoadContentPacks(object sender, EventArgs e)
        {
            foreach (IContentPack contentPack in Helper.ContentPacks.GetOwned())
            {
                bool haveProducerRulesFile = File.Exists(Path.Combine(contentPack.DirectoryPath, ProducerRulesJson));
                if (haveProducerRulesFile)
                {
                    ProducerFrameworkModEntry.ModMonitor.Log($"Reading content pack: {contentPack.Manifest.Name} {contentPack.Manifest.Version} from {contentPack.DirectoryPath}");
                    List <ProducerRule> producerItems = contentPack.ReadJsonFile <List <ProducerRule> >(ProducerRulesJson);
                    ProducerController.AddProducerItems(producerItems, contentPack.Translation);
                }
                else
                {
                    ProducerFrameworkModEntry.ModMonitor.Log($"Content pack: {contentPack.Manifest.Name} {contentPack.Manifest.Version} from {contentPack.DirectoryPath}\nIt does not have an {ProducerRulesJson} file.", LogLevel.Trace);
                }

                bool haveProducersConfigFile = File.Exists(Path.Combine(contentPack.DirectoryPath, ProducersConfigJson));
                if (haveProducersConfigFile)
                {
                    ProducerFrameworkModEntry.ModMonitor.Log($"Reading content pack: {contentPack.Manifest.Name} {contentPack.Manifest.Version} from {contentPack.DirectoryPath}");
                    List <ProducerConfig> producersConfigs = contentPack.ReadJsonFile <List <ProducerConfig> >(ProducersConfigJson);
                    ProducerController.AddProducersConfig(producersConfigs);
                }
                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 (!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);
                }
            }
        }
コード例 #2
0
        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);
        }