示例#1
0
 public IEnumerable <ResourceMod> GetOrderedAndEnabledModList()
 {
     return(ModSettings
            .Where(x => x.Enabled)
            .OrderBy(x => x.Priority)
            .Select(x => x.Mod));
 }
示例#2
0
        public IEnumerable <ModInfo> GetOrderedAndEnabledModSettings(bool invertOrder = false)
        {
            var query = ModSettings
                        .Where(x => x.Enabled);

            if (!invertOrder)
            {
                return(query.OrderBy(x => x.Priority));
            }

            return(query.OrderByDescending(x => x.Priority));
        }
示例#3
0
        public void Load(bool invertOrder = false)
        {
            // find the collection json
            var collectionPath = Path.Combine(_basePath.FullName, "collection.json");

            if (File.Exists(collectionPath))
            {
                try
                {
                    ModSettings = JsonConvert.DeserializeObject <List <ModInfo> >(File.ReadAllText(collectionPath));
                    ModSettings = ModSettings.OrderBy(x => x.Priority).ToList();
                }
                catch (Exception e)
                {
                    PluginLog.Error($"failed to read log collection information, failed path: {collectionPath}, err: {e.Message}");
                }
            }

#if DEBUG
            if (ModSettings != null)
            {
                foreach (var ms in ModSettings)
                {
                    PluginLog.Information(
                        "mod: {ModName} Enabled: {Enabled} Priority: {Priority}",
                        ms.FolderName, ms.Enabled, ms.Priority
                        );
                }
            }
#endif

            ModSettings ??= new();
            var foundMods = new List <string>();

            foreach (var modDir in _basePath.EnumerateDirectories())
            {
                var metaFile = modDir.EnumerateFiles().FirstOrDefault(f => f.Name == "meta.json");

                if (metaFile == null)
                {
                    PluginLog.LogError("mod meta is missing for resource mod: {ResourceModLocation}", modDir);
                    continue;
                }

                var meta = JsonConvert.DeserializeObject <ModMeta>(File.ReadAllText(metaFile.FullName));

                var mod = new ResourceMod
                {
                    Meta        = meta,
                    ModBasePath = modDir
                };

                var modEntry = FindOrCreateModSettings(mod);
                foundMods.Add(modDir.Name);
                mod.RefreshModFiles();
            }

            // remove any mods from the collection we didn't find
            ModSettings = ModSettings.Where(
                x =>
                foundMods.Any(
                    fm => string.Equals(x.FolderName, fm, StringComparison.InvariantCultureIgnoreCase)
                    )
                ).ToList();

            // if anything gets removed above, the priority ordering gets f****d, so we need to resort and reindex them otherwise BAD THINGS HAPPEN
            ModSettings = ModSettings.OrderBy(x => x.Priority).ToList();
            var p = 0;
            foreach (var modSetting in ModSettings)
            {
                modSetting.Priority = p++;
            }

            // reorder the resourcemods list so we can just directly iterate
            EnabledMods = GetOrderedAndEnabledModList(invertOrder).ToArray();

            // write the collection metadata back to disk
            Save();
        }