Client LuaCsForBarotrauma
FallbackLString.cs
1 #nullable enable
2 namespace Barotrauma
3 {
5  {
6  private readonly LocalizedString primary;
7  private readonly LocalizedString fallback;
8 
9  public bool PrimaryIsLoaded { get; private set; }
10 
11  private readonly bool useDefaultLanguageIfFound;
12 
14  public FallbackLString(LocalizedString primary, LocalizedString fallback, bool useDefaultLanguageIfFound = true)
15  {
16  this.useDefaultLanguageIfFound = useDefaultLanguageIfFound;
17  if (primary is FallbackLString { primary: { } innerPrimary, fallback: { } innerFallback })
18  {
19  this.primary = innerPrimary;
20  this.fallback = innerFallback.Fallback(fallback);
21  }
22  else
23  {
24  this.primary = primary;
25  this.fallback = fallback;
26  }
27  }
28 
29  protected override bool MustRetrieveValue()
30  {
31  return base.MustRetrieveValue()
32  || MustRetrieveValue(primary)
33  || MustRetrieveValue(fallback)
34  || PrimaryIsLoaded != primary.Loaded;
35  }
36 
37  public override bool Loaded => primary.Loaded || fallback.Loaded;
38  public override void RetrieveValue()
39  {
40  cachedValue = primary.Value;
41  PrimaryIsLoaded = primary.Loaded;
42 
43  bool defaultLanguageFallbackAvailable = primary is TagLString { UsingDefaultLanguageAsFallback: true };
44 
45  if (!primary.Loaded &&
46  (!defaultLanguageFallbackAvailable || !useDefaultLanguageIfFound))
47  {
48  cachedValue = fallback.Value;
49  }
50  }
51 
53  {
54  if (fallback is FallbackLString innerFallback)
55  {
56  return innerFallback.GetLastFallback();
57  }
58  return fallback;
59  }
60  }
61 }
override void RetrieveValue()
FallbackLString(LocalizedString primary, LocalizedString fallback, bool useDefaultLanguageIfFound=true)
If the text is available in the default language (English), should it be used instead of this fallbac...
LocalizedString GetLastFallback()
override bool MustRetrieveValue()
LocalizedString Fallback(LocalizedString fallback, bool useDefaultLanguageIfFound=true)
Use this text instead if the original text cannot be found.