Exemple #1
0
    // Create a file for an option group from given data.
    internal static void CreateOptionGroup(DirectoryInfo baseFolder, SelectType type, string name,
                                           int priority, int index, string desc, IEnumerable <ISubMod> subMods)
    {
        switch (type)
        {
        case SelectType.Multi:
        {
            var group = new MultiModGroup()
            {
                Name        = name,
                Description = desc,
                Priority    = priority,
            };
            group.PrioritizedOptions.AddRange(subMods.OfType <SubMod>().Select((s, idx) => (s, idx)));
            IModGroup.Save(group, baseFolder, index);
            break;
        }

        case SelectType.Single:
        {
            var group = new SingleModGroup()
            {
                Name        = name,
                Description = desc,
                Priority    = priority,
            };
            group.OptionData.AddRange(subMods.OfType <SubMod>());
            IModGroup.Save(group, baseFolder, index);
            break;
        }
        }
    }
        public static MultiModGroup?Load(JObject json, DirectoryInfo basePath)
        {
            var options = json["Options"];
            var ret     = new MultiModGroup()
            {
                Name        = json[nameof(Name)]?.ToObject <string>() ?? string.Empty,
                Description = json[nameof(Description)]?.ToObject <string>() ?? string.Empty,
                Priority    = json[nameof(Priority)]?.ToObject <int>() ?? 0,
            };

            if (ret.Name.Length == 0)
            {
                return(null);
            }

            if (options != null)
            {
                foreach (var child in options.Children())
                {
                    if (ret.PrioritizedOptions.Count == IModGroup.MaxMultiOptions)
                    {
                        PluginLog.Warning($"Multi Group {ret.Name} has more than {IModGroup.MaxMultiOptions} options, ignoring excessive options.");
                        break;
                    }
                    var subMod = new SubMod();
                    subMod.Load(basePath, child, out var priority);
                    ret.PrioritizedOptions.Add((subMod, priority));
                }
            }

            return(ret);
        }
Exemple #3
0
        private static SubMod GetSubMod(Mod mod, int groupIdx, int optionIdx)
        {
            if (groupIdx == -1 && optionIdx == 0)
            {
                return(mod._default);
            }

            return(mod._groups[groupIdx] switch
            {
                SingleModGroup s => s.OptionData[optionIdx],
                MultiModGroup m => m.PrioritizedOptions[optionIdx].Mod,
                _ => throw new InvalidOperationException(),
            });
        private static void ConvertGroup(Mod mod, OptionGroupV0 group, ref int priority, HashSet <FullPath> seenMetaFiles)
        {
            if (group.Options.Count == 0)
            {
                return;
            }

            switch (group.SelectionType)
            {
            case SelectType.Multi:

                var optionPriority = 0;
                var newMultiGroup  = new MultiModGroup()
                {
                    Name        = group.GroupName,
                    Priority    = priority++,
                    Description = string.Empty,
                };
                mod._groups.Add(newMultiGroup);
                foreach (var option in group.Options)
                {
                    newMultiGroup.PrioritizedOptions.Add((SubModFromOption(mod.ModPath, option, seenMetaFiles), optionPriority++));
                }

                break;

            case SelectType.Single:
                if (group.Options.Count == 1)
                {
                    AddFilesToSubMod(mod._default, mod.ModPath, group.Options[0], seenMetaFiles);
                    return;
                }

                var newSingleGroup = new SingleModGroup()
                {
                    Name        = group.GroupName,
                    Priority    = priority++,
                    Description = string.Empty,
                };
                mod._groups.Add(newSingleGroup);
                foreach (var option in group.Options)
                {
                    newSingleGroup.OptionData.Add(SubModFromOption(mod.ModPath, option, seenMetaFiles));
                }

                break;
            }
        }
Exemple #5
0
        public void ChangeGroupDescription(Mod mod, int groupIdx, string newDescription)
        {
            var group = mod._groups[groupIdx];

            if (group.Description == newDescription)
            {
                return;
            }

            var _ = group switch
            {
                SingleModGroup s => s.Description = newDescription,
                MultiModGroup m => m.Description = newDescription,
                _ => newDescription,
            };

            ModOptionChanged.Invoke(ModOptionChangeType.DisplayChange, mod, groupIdx, -1, -1);
        }
Exemple #6
0
        public void ChangeGroupPriority(Mod mod, int groupIdx, int newPriority)
        {
            var group = mod._groups[groupIdx];

            if (group.Priority == newPriority)
            {
                return;
            }

            var _ = group switch
            {
                SingleModGroup s => s.Priority = newPriority,
                MultiModGroup m => m.Priority = newPriority,
                _ => newPriority,
            };

            ModOptionChanged.Invoke(ModOptionChangeType.PriorityChanged, mod, groupIdx, -1, -1);
        }
Exemple #7
0
        public IModGroup Convert(SelectType type)
        {
            switch (type)
            {
            case SelectType.Single: return(this);

            case SelectType.Multi:
                var multi = new MultiModGroup()
                {
                    Name        = Name,
                    Description = Description,
                    Priority    = Priority,
                };
                multi.PrioritizedOptions.AddRange(OptionData.Select((o, i) => (o, i)));
                return(multi);

            default: throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
Exemple #8
0
        public void RenameModGroup(Mod mod, int groupIdx, string newName)
        {
            var group   = mod._groups[groupIdx];
            var oldName = group.Name;

            if (oldName == newName || !VerifyFileName(mod, group, newName, true))
            {
                return;
            }

            group.DeleteFile(mod.ModPath, groupIdx);

            var _ = group switch
            {
                SingleModGroup s => s.Name = newName,
                MultiModGroup m => m.Name = newName,
                _ => newName,
            };

            ModOptionChanged.Invoke(ModOptionChangeType.GroupRenamed, mod, groupIdx, -1, -1);
        }