using System; using System.Collections.Generic; using ColdMint.scripts.utils; namespace ColdMint.scripts.contribute; /// /// Contributor data Manager /// 贡献者数据管理器 /// public static class ContributorDataManager { private static Dictionary>? _contributorTypeDictionary; private static readonly ContributorData[] ContributorArray = [ new ContributorData { Name = "Cold-Mint", Url = "https://github.com/Cold-Mint", ContributorTypes = [ContributorType.Coder] }, new ContributorData { Name = "Web13234", Url = "https://github.com/Web13234", ContributorTypes = [ContributorType.Coder] }, new ContributorData { Name = "HYPERLINK BLOCKED", Url = "https://www.pixiv.net/users/74412798", ContributorTypes = [ContributorType.Artist] } ]; /// /// Get contributor totals /// 获取贡献者总数 /// /// public static int GetContributorTotals() { return ContributorArray.Length; } /// /// Gets a dictionary of contribution types to the contributor array /// 获取贡献类型到贡献者数组的字典 /// /// ///Cache the results after calling this method, as it is very expensive to generate results. ///调用此方法后请将结果缓存起来,因为生成结果是非常昂贵的。 /// /// /// public static Dictionary? GetContributorTypeToContributorDataArray() { if (_contributorTypeDictionary == null) { return null; } var result = new Dictionary(); foreach (var contributorType in _contributorTypeDictionary.Keys) { result[contributorType] = _contributorTypeDictionary[contributorType].ToArray(); } return result; } /// /// Register all contributor data /// 注册所有的贡献者数据 /// public static void RegisterAllContributorData() { if (_contributorTypeDictionary!= null) { return; } foreach (var contributorData in ContributorArray) { RegisterContributorData(contributorData); } } /// /// Gets a string description of a contribution type /// 获取某个贡献类型的字符串描述 /// /// /// /// public static string? ContributorTypeToString(ContributorType contributorType) { return contributorType switch { ContributorType.Coder => TranslationServerUtils.Translate("ui_coder"), ContributorType.Artist => TranslationServerUtils.Translate("ui_artist"), ContributorType.Musician => TranslationServerUtils.Translate("ui_musician"), ContributorType.CharacterVoice => TranslationServerUtils.Translate("ui_character_voice"), ContributorType.Translator => TranslationServerUtils.Translate("ui_translator"), _ => throw new ArgumentOutOfRangeException(nameof(contributorType), contributorType, null) }; } /// /// Register contributor data to the type dictionary /// 注册贡献者数据到类型字典 /// /// /// private static void AddContributorDataToTypeDictionary(ContributorType contributorType, ContributorData contributorData) { if (_contributorTypeDictionary == null) { return; } if (_contributorTypeDictionary.ContainsKey(contributorType)) { _contributorTypeDictionary[contributorType].Add(contributorData); } else { _contributorTypeDictionary[contributorType] = [contributorData]; } } /// /// Register Contributor data /// 注册贡献者数据 /// /// private static void RegisterContributorData(ContributorData contributorData) { if (contributorData.Name == null || contributorData.ContributorTypes == null) { return; } _contributorTypeDictionary ??= new Dictionary>(); foreach (var contributorDataContributorType in contributorData.ContributorTypes) { AddContributorDataToTypeDictionary(contributorDataContributorType, contributorData); } } }