summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/LanguageUnit.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Client/Assembly-CSharp/LanguageUnit.cs')
-rw-r--r--Client/Assembly-CSharp/LanguageUnit.cs79
1 files changed, 79 insertions, 0 deletions
diff --git a/Client/Assembly-CSharp/LanguageUnit.cs b/Client/Assembly-CSharp/LanguageUnit.cs
new file mode 100644
index 0000000..62ae51e
--- /dev/null
+++ b/Client/Assembly-CSharp/LanguageUnit.cs
@@ -0,0 +1,79 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using UnityEngine;
+
+public class LanguageUnit
+{
+ public bool IsEnglish;
+
+ private Dictionary<StringNames, string> AllStrings = new Dictionary<StringNames, string>();
+
+ private Dictionary<ImageNames, Sprite> AllImages = new Dictionary<ImageNames, Sprite>();
+
+ public LanguageUnit(TextAsset data, ImageData[] images)
+ {
+ foreach (ImageData imageData in images)
+ {
+ this.AllImages.Add(imageData.Name, imageData.Sprite);
+ }
+ using (StringReader stringReader = new StringReader(data.text))
+ {
+ for (string text = stringReader.ReadLine(); text != null; text = stringReader.ReadLine())
+ {
+ if (text.Length != 0)
+ {
+ int num = text.IndexOf(',');
+ if (num < 0)
+ {
+ Debug.LogWarning("Couldn't parse: " + text);
+ }
+ else
+ {
+ string text2 = text.Substring(0, num);
+ StringNames key;
+ if (!Enum.TryParse<StringNames>(text2, out key))
+ {
+ Debug.LogWarning("Couldn't parse: " + text2);
+ }
+ else
+ {
+ string value = LanguageUnit.UnescapeCodes(text.Substring(num + 1));
+ this.AllStrings.Add(key, value);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public static string UnescapeCodes(string src)
+ {
+ if (src.IndexOf("\\n") < 0)
+ {
+ return src;
+ }
+ return src.Replace("\\n", "\n");
+ }
+
+ public string GetString(StringNames stringId, params object[] parts)
+ {
+ string text;
+ if (!this.AllStrings.TryGetValue(stringId, out text))
+ {
+ return "STRMISS";
+ }
+ if (parts.Length != 0)
+ {
+ return string.Format(text, parts);
+ }
+ return text;
+ }
+
+ public Sprite GetImage(ImageNames id)
+ {
+ Sprite result;
+ this.AllImages.TryGetValue(id, out result);
+ return result;
+ }
+}