-
Notifications
You must be signed in to change notification settings - Fork 3
/
TextChanger.cs
71 lines (61 loc) · 1.74 KB
/
TextChanger.cs
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
using Modding;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HKSecondQuest
{
/// <summary>
/// Identifies a changed text
/// </summary>
class TextReplacement
{
public string Key;
public string SheetKey;
public string Text;
public TextReplacement(string key, string text, string sheetKey="")
{
Key = key;
Text = text;
SheetKey = sheetKey;
}
}
/// <summary>
/// Handles text changes
/// </summary>
public class TextChanger
{
/// <summary>
/// All changed texts
/// </summary>
List<TextReplacement> texts = new List<TextReplacement>();
public bool Enabled = true;
public void Hook()
{
ModHooks.LanguageGetHook += OnLanguageGet;
}
/// <summary>
/// Returns a changed text if one is available, otherwise the original
/// </summary>
public string OnLanguageGet(string key, string sheetTitle, string orig)
{
if (!Enabled) return orig;
foreach(TextReplacement textReplacement in texts)
{
if (textReplacement.Key == key && (textReplacement.SheetKey == "" || textReplacement.SheetKey == sheetTitle))
{
return textReplacement.Text;
}
}
return orig;
}
/// <summary>
/// Add a new text change
/// </summary>
public void AddReplacement(string key, string text, string sheetKey="")
{
texts.Add(new TextReplacement(key, text, sheetKey));
}
}
}