From 916d929c0744fa40458b9de8b9101f2765018282 Mon Sep 17 00:00:00 2001 From: henry3218 Date: Sat, 25 Oct 2025 22:12:46 +0800 Subject: [PATCH] Normalize newline endings and clean redundant usings --- mod/CHEVALIER/InterestingTrait.cs | 2 +- mod/CHEVALIER/code/stats.cs | 122 +++------- mod/WARRIOR/InterestingTrait.cs | 4 +- mod/WARRIOR/code/Config.cs | 2 +- mod/WARRIOR/code/NotificationHelper.cs | 13 +- mod/WARRIOR/code/stats.cs | 174 ++++---------- .../Code/Utils/GeneralUtils.cs" | 2 +- .../Code/WordLibraryManager.cs" | 221 +++++++++--------- 8 files changed, 199 insertions(+), 341 deletions(-) diff --git a/mod/CHEVALIER/InterestingTrait.cs b/mod/CHEVALIER/InterestingTrait.cs index 4e522bdd..af7787d1 100644 --- a/mod/CHEVALIER/InterestingTrait.cs +++ b/mod/CHEVALIER/InterestingTrait.cs @@ -46,4 +46,4 @@ protected override void OnModLoad() } } } -} \ No newline at end of file +} diff --git a/mod/CHEVALIER/code/stats.cs b/mod/CHEVALIER/code/stats.cs index dc44f4c2..222b36f9 100644 --- a/mod/CHEVALIER/code/stats.cs +++ b/mod/CHEVALIER/code/stats.cs @@ -1,86 +1,36 @@ -diff --git a/mod/CHEVALIER/code/stats.cs b/mod/CHEVALIER/code/stats.cs -index aecccbebd38802857f546b393ba30e2c699fa30e..0690b3affa9b9e0570f24298379603fda4d2cf7a 100644 ---- a/mod/CHEVALIER/code/stats.cs -+++ b/mod/CHEVALIER/code/stats.cs -@@ -1,54 +1,41 @@ --namespace Chevalier.code -+namespace Chevalier.code - { - internal class stats - { - public static BaseStatAsset Resist; - public static BaseStatAsset Comprehension; - - public static void Init() - { -- BaseStatAsset Chevalier = new BaseStatAsset(); -- Chevalier.id = "Chevalier"; -- Chevalier.normalize = true; -- Chevalier.normalize_min = -9999999; -- Chevalier.normalize_max = 9999999; -- //Chevalier.multiplier = true; -- Chevalier.used_only_for_civs = false; -- AssetManager.base_stats_library.add(Chevalier); -+ EnsureStat("Chevalier", -9999999f, 9999999f); - - // 定义 Resist 属性 -- Resist = new BaseStatAsset(); -- Resist.id = "Resist"; -- Resist.normalize = true; -- Resist.normalize_min = 0; -- Resist.normalize_max = 999999; -- Resist.used_only_for_civs = false; -- AssetManager.base_stats_library.add(Resist); -+ Resist = EnsureStat("Resist", 0f, 999999f); - -- BaseStatAsset Dodge = new BaseStatAsset(); -- Dodge.id = "Dodge";// 闪避率 -- Dodge.normalize = true; -- Dodge.normalize_min = 0; -- Dodge.normalize_max = 99999; -- Dodge.used_only_for_civs = false; -- AssetManager.base_stats_library.add(Dodge); -- -- BaseStatAsset Accuracy = new BaseStatAsset(); -- Accuracy.id = "Accuracy";// 命中率 -- Accuracy.normalize = true; -- Accuracy.normalize_min = 0; -- Accuracy.normalize_max = 99999; -- Accuracy.used_only_for_civs = false; -- AssetManager.base_stats_library.add(Accuracy); -+ EnsureStat("Dodge", 0f, 99999f); -+ EnsureStat("Accuracy", 0f, 99999f); - - // 定义领悟度属性 -- Comprehension = new BaseStatAsset(); -- Comprehension.id = "Comprehension"; -- Comprehension.normalize = true; -- Comprehension.normalize_min = 0; -- Comprehension.normalize_max = 99999; -- Comprehension.used_only_for_civs = false; -- AssetManager.base_stats_library.add(Comprehension); -+ Comprehension = EnsureStat("Comprehension", 0f, 99999f); -+ } -+ -+ private static BaseStatAsset EnsureStat(string pId, float pMin, float pMax) -+ { -+ var existing = AssetManager.base_stats_library.get(pId); -+ if (existing == null) -+ { -+ existing = new BaseStatAsset -+ { -+ id = pId -+ }; -+ AssetManager.base_stats_library.add(existing); -+ } -+ -+ existing.normalize = true; -+ existing.normalize_min = pMin; -+ existing.normalize_max = pMax; -+ existing.used_only_for_civs = false; -+ return existing; - } - } --} -\ No newline at end of file -+} +namespace Chevalier.code +{ + internal static class stats + { + public static BaseStatAsset Resist; + public static BaseStatAsset Comprehension; + + public static void Init() + { + EnsureStat("Chevalier", -9999999f, 9999999f); + Resist = EnsureStat("Resist", 0f, 999999f); + EnsureStat("Dodge", 0f, 99999f); + EnsureStat("Accuracy", 0f, 99999f); + Comprehension = EnsureStat("Comprehension", 0f, 99999f); + } + + private static BaseStatAsset EnsureStat(string pId, float pMin, float pMax) + { + var existing = AssetManager.base_stats_library.get(pId); + if (existing == null) + { + existing = new BaseStatAsset + { + id = pId + }; + AssetManager.base_stats_library.add(existing); + } + + existing.normalize = true; + existing.normalize_min = pMin; + existing.normalize_max = pMax; + existing.used_only_for_civs = false; + return existing; + } + } +} diff --git a/mod/WARRIOR/InterestingTrait.cs b/mod/WARRIOR/InterestingTrait.cs index 4208bbef..0b8eb1a7 100644 --- a/mod/WARRIOR/InterestingTrait.cs +++ b/mod/WARRIOR/InterestingTrait.cs @@ -1,8 +1,6 @@ using HarmonyLib; using PeerlessOverpoweringWarrior.code; using NeoModLoader.api; -using System.IO; -using PeerlessOverpoweringWarrior.code; namespace PeerlessOverpoweringWarrior { @@ -55,4 +53,4 @@ protected override void OnModLoad() } } } -} \ No newline at end of file +} diff --git a/mod/WARRIOR/code/Config.cs b/mod/WARRIOR/code/Config.cs index 407e1b60..f2fb4dd2 100644 --- a/mod/WARRIOR/code/Config.cs +++ b/mod/WARRIOR/code/Config.cs @@ -160,4 +160,4 @@ public static void NotifyXuanZhenBreakthroughCallBack(bool newValue) NotifyXuanZhenBreakthrough = newValue; } } -} \ No newline at end of file +} diff --git a/mod/WARRIOR/code/NotificationHelper.cs b/mod/WARRIOR/code/NotificationHelper.cs index d264231a..1e937093 100644 --- a/mod/WARRIOR/code/NotificationHelper.cs +++ b/mod/WARRIOR/code/NotificationHelper.cs @@ -2,6 +2,7 @@ using UnityEngine.UI; using System.Collections.Generic; using System.Collections; +using PeerlessOverpoweringWarrior.code.Config; namespace PeerlessOverpoweringWarrior.code { @@ -156,19 +157,19 @@ private static bool ShouldShowNotification(string newTrait) // 检查是否是特定的高级境界突破 if (newTrait == "Warrior91" || newTrait == "Warrior91+") // 合道境 { - return PeerlessOverpoweringWarrior.code.Config.WarriorConfig.NotifyHarmonyBreakthrough; + return WarriorConfig.NotifyHarmonyBreakthrough; } else if (newTrait == "Warrior92" || newTrait == "Warrior92+") // 斩我境 { - return PeerlessOverpoweringWarrior.code.Config.WarriorConfig.NotifyZhanWoBreakthrough; + return WarriorConfig.NotifyZhanWoBreakthrough; } else if (newTrait == "Warrior93" || newTrait == "Warrior93+") // 武极境 { - return PeerlessOverpoweringWarrior.code.Config.WarriorConfig.NotifyWuJiBreakthrough; + return WarriorConfig.NotifyWuJiBreakthrough; } else if (newTrait == "FormationRealm6") // 玄真境 { - return PeerlessOverpoweringWarrior.code.Config.WarriorConfig.NotifyXuanZhenBreakthrough; + return WarriorConfig.NotifyXuanZhenBreakthrough; } // 其他境界突破默认显示通知 @@ -198,7 +199,7 @@ public static void ShowGrottoNotification(Actor actor, string traitId) public static void ShowFormationRealm6Notification(Actor actor) { // 检查是否需要显示通知 - if (!PeerlessOverpoweringWarrior.code.Config.WarriorConfig.NotifyXuanZhenBreakthrough) + if (!WarriorConfig.NotifyXuanZhenBreakthrough) { return; // 根据配置跳过通知 } @@ -571,4 +572,4 @@ IEnumerator FadeOut() Destroy(gameObject); } } -} \ No newline at end of file +} diff --git a/mod/WARRIOR/code/stats.cs b/mod/WARRIOR/code/stats.cs index 85f05758..94b6044c 100644 --- a/mod/WARRIOR/code/stats.cs +++ b/mod/WARRIOR/code/stats.cs @@ -1,130 +1,44 @@ -diff --git a/mod/WARRIOR/code/stats.cs b/mod/WARRIOR/code/stats.cs -index e192474c0fe97cb50b4b4d9b63bafcea8a275aba..5fe7ca1cca2184649467eff5671ebd2e88009673 100644 ---- a/mod/WARRIOR/code/stats.cs -+++ b/mod/WARRIOR/code/stats.cs -@@ -1,95 +1,58 @@ --namespace PeerlessOverpoweringWarrior.code -+namespace PeerlessOverpoweringWarrior.code - { - internal class stats - { - public static BaseStatAsset Resist; - public static BaseStatAsset TrueGang; - public static BaseStatAsset TrueGangTrueDamageMultiplier; // 真罡真伤倍数 - public static BaseStatAsset TrueGangHealMultiplier; // 真罡回血倍数 - public static BaseStatAsset TrueGangDamageReductionMultiplier; // 真罡伤害稀释倍数 - - public static BaseStatAsset Pattern; - - public static void Init() - { -- BaseStatAsset Warrior = new BaseStatAsset(); -- Warrior.id = "Warrior"; -- Warrior.normalize = true; -- Warrior.normalize_min = -9999999; -- Warrior.normalize_max = 9999999; -- //Warrior.multiplier = true; -- Warrior.used_only_for_civs = false; -- AssetManager.base_stats_library.add(Warrior); -+ EnsureStat("Warrior", -9999999f, 9999999f); - - // 定义阵纹属性 -- Pattern = new BaseStatAsset(); -- Pattern.id = "Pattern"; -- Pattern.normalize = true; -- Pattern.normalize_min = -9999999; -- Pattern.normalize_max = 9999999; -- Pattern.used_only_for_civs = false; -- AssetManager.base_stats_library.add(Pattern); -+ Pattern = EnsureStat("Pattern", -9999999f, 9999999f); - - // 定义真罡属性,与武道气血使用相同的上下限 -- TrueGang = new BaseStatAsset(); -- TrueGang.id = "TrueGang"; -- TrueGang.normalize = true; -- TrueGang.normalize_min = -9999999; -- TrueGang.normalize_max = 9999999; -- TrueGang.used_only_for_civs = false; -- AssetManager.base_stats_library.add(TrueGang); -+ TrueGang = EnsureStat("TrueGang", -9999999f, 9999999f); - - // 定义真罡真伤倍数属性 -- TrueGangTrueDamageMultiplier = new BaseStatAsset(); -- TrueGangTrueDamageMultiplier.id = "TrueGangTrueDamageMultiplier"; -- TrueGangTrueDamageMultiplier.normalize = true; -- TrueGangTrueDamageMultiplier.normalize_min = 0; -- TrueGangTrueDamageMultiplier.normalize_max = 999999; -- TrueGangTrueDamageMultiplier.used_only_for_civs = false; -- AssetManager.base_stats_library.add(TrueGangTrueDamageMultiplier); -+ TrueGangTrueDamageMultiplier = EnsureStat("TrueGangTrueDamageMultiplier", 0f, 999999f); - - // 定义真罡回血倍数属性 -- TrueGangHealMultiplier = new BaseStatAsset(); -- TrueGangHealMultiplier.id = "TrueGangHealMultiplier"; -- TrueGangHealMultiplier.normalize = true; -- TrueGangHealMultiplier.normalize_min = 0; -- TrueGangHealMultiplier.normalize_max = 999999; -- TrueGangHealMultiplier.used_only_for_civs = false; -- AssetManager.base_stats_library.add(TrueGangHealMultiplier); -+ TrueGangHealMultiplier = EnsureStat("TrueGangHealMultiplier", 0f, 999999f); - - // 定义真罡伤害稀释倍数属性 -- TrueGangDamageReductionMultiplier = new BaseStatAsset(); -- TrueGangDamageReductionMultiplier.id = "TrueGangDamageReductionMultiplier"; -- TrueGangDamageReductionMultiplier.normalize = true; -- TrueGangDamageReductionMultiplier.normalize_min = 0; -- TrueGangDamageReductionMultiplier.normalize_max = 999999; -- TrueGangDamageReductionMultiplier.used_only_for_civs = false; -- AssetManager.base_stats_library.add(TrueGangDamageReductionMultiplier); -+ TrueGangDamageReductionMultiplier = EnsureStat("TrueGangDamageReductionMultiplier", 0f, 999999f); - - // 定义 Resist 属性 -- Resist = new BaseStatAsset(); -- Resist.id = "Resist"; -- Resist.normalize = true; -- Resist.normalize_min = 0; -- Resist.normalize_max = 999999; -- Resist.used_only_for_civs = false; -- AssetManager.base_stats_library.add(Resist); -+ Resist = EnsureStat("Resist", 0f, 999999f); - -- BaseStatAsset Dodge = new BaseStatAsset(); -- Dodge.id = "Dodge";// 闪避率 -- Dodge.normalize = true; -- Dodge.normalize_min = 0; -- Dodge.normalize_max = 99999; -- Dodge.used_only_for_civs = false; -- AssetManager.base_stats_library.add(Dodge); -+ EnsureStat("Dodge", 0f, 99999f); -+ EnsureStat("Accuracy", 0f, 99999f); -+ } - -- BaseStatAsset Accuracy = new BaseStatAsset(); -- Accuracy.id = "Accuracy";// 命中率 -- Accuracy.normalize = true; -- Accuracy.normalize_min = 0; -- Accuracy.normalize_max = 99999; -- Accuracy.used_only_for_civs = false; -- AssetManager.base_stats_library.add(Accuracy); -+ private static BaseStatAsset EnsureStat(string pId, float pMin, float pMax) -+ { -+ var existing = AssetManager.base_stats_library.get(pId); -+ if (existing == null) -+ { -+ existing = new BaseStatAsset -+ { -+ id = pId -+ }; -+ AssetManager.base_stats_library.add(existing); -+ } -+ -+ existing.normalize = true; -+ existing.normalize_min = pMin; -+ existing.normalize_max = pMax; -+ existing.used_only_for_civs = false; -+ return existing; - } - } --} -\ No newline at end of file -+} +namespace PeerlessOverpoweringWarrior.code +{ + internal static class stats + { + public static BaseStatAsset Resist; + public static BaseStatAsset TrueGang; + public static BaseStatAsset TrueGangTrueDamageMultiplier; + public static BaseStatAsset TrueGangHealMultiplier; + public static BaseStatAsset TrueGangDamageReductionMultiplier; + public static BaseStatAsset Pattern; + + public static void Init() + { + EnsureStat("Warrior", -9999999f, 9999999f); + Pattern = EnsureStat("Pattern", -9999999f, 9999999f); + TrueGang = EnsureStat("TrueGang", -9999999f, 9999999f); + TrueGangTrueDamageMultiplier = EnsureStat("TrueGangTrueDamageMultiplier", 0f, 999999f); + TrueGangHealMultiplier = EnsureStat("TrueGangHealMultiplier", 0f, 999999f); + TrueGangDamageReductionMultiplier = EnsureStat("TrueGangDamageReductionMultiplier", 0f, 999999f); + Resist = EnsureStat("Resist", 0f, 999999f); + EnsureStat("Dodge", 0f, 99999f); + EnsureStat("Accuracy", 0f, 99999f); + } + + private static BaseStatAsset EnsureStat(string pId, float pMin, float pMax) + { + var existing = AssetManager.base_stats_library.get(pId); + if (existing == null) + { + existing = new BaseStatAsset + { + id = pId + }; + AssetManager.base_stats_library.add(existing); + } + + existing.normalize = true; + existing.normalize_min = pMin; + existing.normalize_max = pMax; + existing.used_only_for_civs = false; + return existing; + } + } +} diff --git "a/mod/\350\245\277\345\271\273\344\270\255\346\226\207\345\220\215/Code/Utils/GeneralUtils.cs" "b/mod/\350\245\277\345\271\273\344\270\255\346\226\207\345\220\215/Code/Utils/GeneralUtils.cs" index c8c3a06a..768cc00d 100644 --- "a/mod/\350\245\277\345\271\273\344\270\255\346\226\207\345\220\215/Code/Utils/GeneralUtils.cs" +++ "b/mod/\350\245\277\345\271\273\344\270\255\346\226\207\345\220\215/Code/Utils/GeneralUtils.cs" @@ -57,4 +57,4 @@ public static TextAsset[] LoadAllFrom(string pPath) } return text_assets.ToArray(); } -} \ No newline at end of file +} diff --git "a/mod/\350\245\277\345\271\273\344\270\255\346\226\207\345\220\215/Code/WordLibraryManager.cs" "b/mod/\350\245\277\345\271\273\344\270\255\346\226\207\345\220\215/Code/WordLibraryManager.cs" index 30f227bd..4625a6aa 100644 --- "a/mod/\350\245\277\345\271\273\344\270\255\346\226\207\345\220\215/Code/WordLibraryManager.cs" +++ "b/mod/\350\245\277\345\271\273\344\270\255\346\226\207\345\220\215/Code/WordLibraryManager.cs" @@ -1,113 +1,108 @@ -diff --git a/mod/西幻中文名/Code/WordLibraryManager.cs b/mod/西幻中文名/Code/WordLibraryManager.cs -index fba866e3a12b88bb16ea25feea74f79fec4c516e..ccc45008fc39988fbc5ca6553acb8a12aec06075 100644 ---- a/mod/西幻中文名/Code/WordLibraryManager.cs -+++ b/mod/西幻中文名/Code/WordLibraryManager.cs -@@ -4,65 +4,99 @@ using System.Linq; - using Chinese_Name.utils; - using UnityEngine; - - namespace Chinese_Name; - - public class WordLibraryManager : AssetLibrary - { - internal static readonly WordLibraryManager Instance = new(); - private static HashSet submitted_dir = new HashSet(); - public override void init() - { - base.init(); - id = "WordLibraryManager"; - SubmitDirectoryToLoad(Path.Combine(ModClass.Instance.GetDeclaration().FolderPath, "word_libraries/default")); - } - internal void Reload() - { - HashSet reload_dir = new HashSet(submitted_dir); - submitted_dir.Clear(); - foreach (var dir in reload_dir) - { - SubmitDirectoryToLoad(dir); - } - } - /// -- /// ָĴʿȡһ -+ /// ָĴʿȡһ - /// -- /// ָʿid, ΪӦļļȥ׺ -- /// ָʿһ, ʿⲻ򷵻ؿմ -+ /// ָʿid, ΪӦļļȥ׺ -+ /// ָʿһ, ʿⲻ򷵻ؿմ - public static string GetRandomWord(string pId) - { - if (Instance.dict.TryGetValue(pId, out WordLibraryAsset asset) && asset.words.Count > 0) - { - return Instance.dict[pId].GetRandom(); - } - return ""; - } - public static void SubmitDirectoryToLoad(string pDirectory) - { - if (submitted_dir.Contains(pDirectory)) return; - TextAsset[] text_assets = GeneralUtils.LoadAllFrom(pDirectory); - foreach (TextAsset text_asset in text_assets) - { -- Instance.add(new WordLibraryAsset(text_asset.name, text_asset.text.Replace("\r", "").Split('\n').ToList())); -+ var words = NormalizeWords(text_asset.text.Replace("\r", "").Split('\n')); -+ AddOrReplace(text_asset.name, words); - } - submitted_dir.Add(pDirectory); - } - - public static void Submit(string pId, List pWords) - { -+ AddOrReplace(pId, NormalizeWords(pWords)); -+ } -+ -+ private static void AddOrReplace(string pId, List pWords) -+ { -+ if (Instance.dict.TryGetValue(pId, out var existingAsset)) -+ { -+ existingAsset.words.Clear(); -+ existingAsset.words.AddRange(pWords); -+ return; -+ } -+ - Instance.add(new WordLibraryAsset(pId, pWords)); - } - - public static void SubmitForPatch(string pId, List pWords) - { -- if (Instance.dict.ContainsKey(pId)) -+ var sanitizedWords = NormalizeWords(pWords); -+ if (Instance.dict.TryGetValue(pId, out var existingAsset)) - { -- Instance.dict[pId].words.AddRange(pWords); -+ foreach (var word in sanitizedWords) -+ { -+ if (!existingAsset.words.Contains(word)) -+ { -+ existingAsset.words.Add(word); -+ } -+ } - } - else - { -- Instance.add(new WordLibraryAsset(pId, pWords)); -+ Instance.add(new WordLibraryAsset(pId, sanitizedWords)); - } - } --} -\ No newline at end of file -+ -+ private static List NormalizeWords(IEnumerable pWords) -+ { -+ if (pWords == null) -+ { -+ return new List(); -+ } -+ -+ return pWords -+ .Select(word => word?.Trim()) -+ .Where(word => !string.IsNullOrEmpty(word)) -+ .Distinct() -+ .ToList(); -+ } -+} +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Chinese_Name.utils; +using UnityEngine; + +namespace Chinese_Name; + +public class WordLibraryManager : AssetLibrary +{ + internal static readonly WordLibraryManager Instance = new(); + private static readonly HashSet submitted_dir = new(); + + public override void init() + { + base.init(); + id = "WordLibraryManager"; + SubmitDirectoryToLoad(Path.Combine(ModClass.Instance.GetDeclaration().FolderPath, "word_libraries/default")); + } + + internal void Reload() + { + var reloadDir = new HashSet(submitted_dir); + submitted_dir.Clear(); + foreach (var dir in reloadDir) + { + SubmitDirectoryToLoad(dir); + } + } + + public static string GetRandomWord(string pId) + { + if (Instance.dict.TryGetValue(pId, out var asset) && asset.words.Count > 0) + { + return asset.GetRandom(); + } + + return string.Empty; + } + + public static void SubmitDirectoryToLoad(string pDirectory) + { + if (submitted_dir.Contains(pDirectory)) + { + return; + } + + var textAssets = GeneralUtils.LoadAllFrom(pDirectory); + foreach (var textAsset in textAssets) + { + var words = NormalizeWords(textAsset.text.Replace("\r", string.Empty).Split('\n')); + AddOrReplace(textAsset.name, words); + } + + submitted_dir.Add(pDirectory); + } + + public static void Submit(string pId, List pWords) + { + AddOrReplace(pId, NormalizeWords(pWords)); + } + + private static void AddOrReplace(string pId, List pWords) + { + if (Instance.dict.TryGetValue(pId, out var existingAsset)) + { + existingAsset.words.Clear(); + existingAsset.words.AddRange(pWords); + } + else + { + Instance.add(new WordLibraryAsset(pId, pWords)); + } + } + + public static void SubmitForPatch(string pId, List pWords) + { + var sanitizedWords = NormalizeWords(pWords); + if (Instance.dict.TryGetValue(pId, out var existingAsset)) + { + foreach (var word in sanitizedWords) + { + if (!existingAsset.words.Contains(word)) + { + existingAsset.words.Add(word); + } + } + } + else + { + Instance.add(new WordLibraryAsset(pId, sanitizedWords)); + } + } + + private static List NormalizeWords(IEnumerable pWords) + { + if (pWords == null) + { + return new List(); + } + + return pWords + .Select(word => word?.Trim()) + .Where(word => !string.IsNullOrEmpty(word)) + .Distinct() + .ToList(); + } +}