1 using System.Collections.Immutable;
7 [NotSyncedInMultiplayer]
14 XDocument doc = XMLExtensions.TryLoadXml(Path);
17 var languageName = mainElement.GetAttributeIdentifier(
"language", TextManager.DefaultLanguage.Value);
20 if (!TextManager.TextPacks.ContainsKey(language))
22 TextManager.TextPacks.TryAdd(language, ImmutableList<TextPack>.Empty);
24 var newPack =
new TextPack(
this, mainElement, language);
25 var newList = TextManager.TextPacks[language].Add(newPack);
26 TextManager.TextPacks.TryRemove(language, out _);
27 TextManager.TextPacks.TryAdd(language, newList);
28 TextManager.IncrementLanguageVersion();
33 foreach (var kvp
in TextManager.TextPacks.ToArray())
35 var newList = kvp.Value.Where(p => p.ContentFile !=
this).ToImmutableList();
36 TextManager.TextPacks.TryRemove(kvp.Key, out _);
37 if (newList.Count != 0) { TextManager.TextPacks.TryAdd(kvp.Key, newList); }
39 TextManager.IncrementLanguageVersion();
40 if (!TextManager.TextPacks.ContainsKey(GameSettings.CurrentConfig.Language) &&
41 GameSettings.CurrentConfig.Language != TextManager.DefaultLanguage)
43 DebugConsole.AddWarning($
"The language {GameSettings.CurrentConfig.Language} is no longer available. Switching to {TextManager.DefaultLanguage}...");
44 var config = GameSettings.CurrentConfig;
45 config.Language = TextManager.DefaultLanguage;
46 GameSettings.SetCurrentConfig(config);
50 public override void Sort()
52 foreach (var language
in TextManager.TextPacks.Keys.ToList())
54 TextManager.TextPacks[language] =
55 TextManager.TextPacks[language].Sort((t1, t2) => (t1.ContentFile.ContentPackage?.Index ??
int.MaxValue) - (t2.ContentFile.ContentPackage?.Index ??
int.MaxValue));
Base class for content file types, which are loaded from filelist.xml via reflection....
TextFile(ContentPackage contentPackage, ContentPath path)
override void UnloadFile()