コード例 #1
0
ファイル: Mod.Creation.cs プロジェクト: xivdev/Penumbra
    // 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;
        }
        }
    }
コード例 #2
0
        public static SingleModGroup?Load(JObject json, DirectoryInfo basePath)
        {
            var options = json["Options"];
            var ret     = new SingleModGroup
            {
                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())
                {
                    var subMod = new SubMod();
                    subMod.Load(basePath, child, out _);
                    ret.OptionData.Add(subMod);
                }
            }

            return(ret);
        }
コード例 #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(),
            });
コード例 #4
0
ファイル: Mod.Meta.Migration.cs プロジェクト: xivdev/Penumbra
        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;
            }
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #7
0
        public IModGroup Convert(SelectType type)
        {
            switch (type)
            {
            case SelectType.Multi: return(this);

            case SelectType.Single:
                var multi = new SingleModGroup()
                {
                    Name        = Name,
                    Description = Description,
                    Priority    = Priority,
                };
                multi.OptionData.AddRange(PrioritizedOptions.Select(p => p.Mod));
                return(multi);

            default: throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
コード例 #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);
        }