-
Notifications
You must be signed in to change notification settings - Fork 1
/
AdvancedStringDB.cs
184 lines (170 loc) · 6.35 KB
/
AdvancedStringDB.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using System.Text;
namespace SpecialItemPack
{
public class AdvancedStringDB
{
public StringTableManager.GungeonSupportedLanguages CurrentLanguage
{
get
{
return GameManager.Options.CurrentLanguage;
}
set
{
StringTableManager.SetNewLanguage(value, true);
}
}
public AdvancedStringDB()
{
ETGMod.Databases.Strings.OnLanguageChanged += this.LanguageChanged;
this.Core = new AdvancedStringDBTable(() => StringTableManager.CoreTable);
this.Items = new AdvancedStringDBTable(() => StringTableManager.ItemTable);
this.Enemies = new AdvancedStringDBTable(() => StringTableManager.EnemyTable);
this.Intro = new AdvancedStringDBTable(() => StringTableManager.IntroTable);
this.Synergies = new AdvancedStringDBTable(() => AdvancedStringDB.SynergyTable);
}
public void LanguageChanged(StringTableManager.GungeonSupportedLanguages newLang)
{
this.Core.LanguageChanged();
this.Items.LanguageChanged();
this.Enemies.LanguageChanged();
this.Intro.LanguageChanged();
this.Synergies.LanguageChanged();
Action<StringTableManager.GungeonSupportedLanguages> onLanguageChanged = this.OnLanguageChanged;
if (onLanguageChanged == null)
{
return;
}
onLanguageChanged(newLang);
}
public static Dictionary<string, StringTableManager.StringCollection> SynergyTable
{
get
{
StringTableManager.GetSynergyString("ThisExistsOnlyToLoadTables");
return (Dictionary<string, StringTableManager.StringCollection>)AdvancedStringDB.m_synergyTable.GetValue(null);
}
}
public readonly AdvancedStringDBTable Core;
public readonly AdvancedStringDBTable Items;
public readonly AdvancedStringDBTable Enemies;
public readonly AdvancedStringDBTable Intro;
public readonly AdvancedStringDBTable Synergies;
public static FieldInfo m_synergyTable = typeof(StringTableManager).GetField("m_synergyTable", BindingFlags.NonPublic | BindingFlags.Static);
public Action<StringTableManager.GungeonSupportedLanguages> OnLanguageChanged;
}
public sealed class AdvancedStringDBTable
{
public Dictionary<string, StringTableManager.StringCollection> Table
{
get
{
Dictionary<string, StringTableManager.StringCollection> result;
if ((result = this._CachedTable) == null)
{
result = (this._CachedTable = this._GetTable());
}
return result;
}
}
public StringTableManager.StringCollection this[string key]
{
get
{
return this.Table[key];
}
set
{
this.Table[key] = value;
int num = this._ChangeKeys.IndexOf(key);
if (num > 0)
{
this._ChangeValues[num] = value;
}
else
{
this._ChangeKeys.Add(key);
this._ChangeValues.Add(value);
}
JournalEntry.ReloadDataSemaphore++;
}
}
internal AdvancedStringDBTable(Func<Dictionary<string, StringTableManager.StringCollection>> _getTable)
{
this._ChangeKeys = new List<string>();
this._ChangeValues = new List<StringTableManager.StringCollection>();
this._GetTable = _getTable;
}
public bool ContainsKey(string key)
{
return this.Table.ContainsKey(key);
}
public void Set(string key, string value)
{
StringTableManager.StringCollection stringCollection = new StringTableManager.SimpleStringCollection();
stringCollection.AddString(value, 1f);
if (this.Table.ContainsKey(key))
{
this.Table[key] = stringCollection;
}
else
{
this.Table.Add(key, stringCollection);
}
int num = this._ChangeKeys.IndexOf(key);
if (num > 0)
{
this._ChangeValues[num] = stringCollection;
}
else
{
this._ChangeKeys.Add(key);
this._ChangeValues.Add(stringCollection);
}
JournalEntry.ReloadDataSemaphore++;
}
public void SetComplex(string key, List<string> values, List<float> weights)
{
StringTableManager.StringCollection stringCollection = new StringTableManager.ComplexStringCollection();
for(int i=0; i<values.Count; i++)
{
string value = values[i];
float weight = weights[i];
stringCollection.AddString(value, weight);
}
this.Table[key] = stringCollection;
int num = this._ChangeKeys.IndexOf(key);
if (num > 0)
{
this._ChangeValues[num] = stringCollection;
}
else
{
this._ChangeKeys.Add(key);
this._ChangeValues.Add(stringCollection);
}
JournalEntry.ReloadDataSemaphore++;
}
public string Get(string key)
{
return StringTableManager.GetString(key);
}
public void LanguageChanged()
{
this._CachedTable = null;
Dictionary<string, StringTableManager.StringCollection> table = this.Table;
for (int i = 0; i < this._ChangeKeys.Count; i++)
{
table[this._ChangeKeys[i]] = this._ChangeValues[i];
}
}
private readonly Func<Dictionary<string, StringTableManager.StringCollection>> _GetTable;
private Dictionary<string, StringTableManager.StringCollection> _CachedTable;
private readonly List<string> _ChangeKeys;
private readonly List<StringTableManager.StringCollection> _ChangeValues;
}
}