private static Language MergeLanguages(Language orig, patch_Language mod) { if (orig == null) { return(mod); } if (string.IsNullOrEmpty(orig.Label) && string.IsNullOrEmpty(orig.IconPath)) { orig.Id = mod.Id; orig.FontFace = mod.FontFace; orig.FontFaceSize = mod.FontFaceSize; orig.FilePath = mod.FilePath; orig.Label = mod.Label; orig.IconPath = mod.IconPath; orig.Icon = mod.Icon; orig.Order = mod.Order; orig.SplitRegex = mod.SplitRegex; orig.CommaCharacters = mod.CommaCharacters; orig.PeriodCharacters = mod.PeriodCharacters; } foreach (KeyValuePair <string, string> kvp in mod.Dialog) { orig.Dialog[kvp.Key] = kvp.Value; } foreach (KeyValuePair <string, string> kvp in mod.Cleaned) { orig.Cleaned[kvp.Key] = kvp.Value; } return(orig); }
private static void _SetItem(Dictionary <string, string> dict, string key, string value, Language _lang) { patch_Language lang = (patch_Language)_lang; if (lang.Dialog != dict || lang.ReadCount == null || string.IsNullOrEmpty(lang.CurrentlyReadingFrom) || key == "EVEREST_SPLIT_BETWEEN_FILES") { // Skip conflict checking when the dictionary is from an unknown source. } else { if (!lang.ReadCount.TryGetValue(key, out int count)) { count = lang.Dialog.ContainsKey(key) ? 1 : 0; } count++; lang.ReadCount[key] = count; if (!lang.LineSources.TryGetValue(key, out string sourcePrev)) { sourcePrev = "?!?!?!"; } lang.LineSources[key] = lang.CurrentlyReadingFrom; if (count >= 2) { Logger.Log(LogLevel.Warn, "Language", $"Conflict for dialog key {lang.Id}/{key} ({sourcePrev} vs {lang.CurrentlyReadingFrom})"); } } dict[key] = value; }
private static IEnumerable <string> _GetLanguageText(string path, Encoding encoding) { patch_Language lang = (patch_Language)_NewLanguage(); bool ready = LoadOrigLanguage && File.Exists(path); if (ready) { lang.CurrentlyReadingFrom = "Celeste"; foreach (string text in File.ReadLines(path, encoding)) { yield return(text); } } path = path.Substring(Everest.Content.PathContentOrig.Length + 1); path = path.Replace('\\', '/'); path = path.Substring(0, path.Length - 4); string dummy = $"LANGUAGE={path.Substring(7).ToLowerInvariant()}"; if (!ready) { ready = true; // Feed a dummy language line. All empty languages are removed afterwards. yield return(dummy); } if (!LoadModLanguage) { yield break; } foreach (ModContent content in Everest.Content.Mods) { foreach (ModAsset asset in content.Map .Where(entry => entry.Value.Type == typeof(AssetTypeDialog) && entry.Key.Equals(path, StringComparison.InvariantCultureIgnoreCase)) .Select(entry => entry.Value)) { lang.CurrentlyReadingFrom = asset.Source?.Name ?? "???"; using (StreamReader reader = new StreamReader(asset.Stream, encoding)) while (reader.Peek() != -1) { yield return(reader.ReadLine().Trim('\r', '\n').Trim()); } // Feed a new key to be sure that the last key in the file is cut off. // That will prevent mod B from corrupting the last key of mod A if its language txt is bad. lang.CurrentlyReadingFrom = null; yield return("EVEREST_SPLIT_BETWEEN_FILES= New file"); } } }
public static Language LoadLanguage(string filename) { patch_Language.LoadingLanguage = null; patch_Language.LoadOrigLanguage = true; patch_Language.LoadModLanguage = false; Language lang = orig_LoadLanguage(filename); patch_Language.LoadingLanguage = null; Dialog.Languages.Remove(lang.Id); string pathExp = filename.Substring(Everest.Content.PathContentOrig.Length + 1).Replace('\\', '/'); foreach (ModAsset asset in Everest.Content.Mods .Select(mod => mod.Map.TryGetValue(pathExp, out ModAsset asset) ? asset : null) .Where(asset => asset != null && asset.Type == typeof(AssetTypeDialogExport)) ) { lang = MergeLanguages(lang, (patch_Language)patch_Language.FromModExport(asset)); } patch_Language filler = (patch_Language)(patch_Language.LoadingLanguage = new Language()); filler.LineSources = new Dictionary <string, string>(); filler.ReadCount = new Dictionary <string, int>(); if (lang != null) { foreach (KeyValuePair <string, string> kvp in lang.Dialog) { filler.Dialog[kvp.Key] = kvp.Value; // filler.ReadCount[kvp.Key] = -1; // Ignores vanilla conflicts. } } patch_Language.LoadOrigLanguage = false; patch_Language.LoadModLanguage = true; lang = MergeLanguages(lang, (patch_Language)Language.FromTxt(filename)); patch_Language.LoadingLanguage = null; if (lang != null) { lang.Dialog.Remove("EVEREST_SPLIT_BETWEEN_FILES"); lang.Cleaned.Remove("EVEREST_SPLIT_BETWEEN_FILES"); if (lang.Dialog.Count > 0) { Dialog.Languages[lang.Id] = lang; } } return(lang); }