summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/LanguageUnit.cs
blob: 62ae51e71931166add6555783327820da39b1d90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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;
	}
}