-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathRTextPageBase.cs
56 lines (43 loc) · 1.5 KB
/
RTextPageBase.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
using System.Collections.Generic;
using System.Linq;
using PDTools.Utils;
using Syroot.BinaryData;
namespace PDTools.RText;
public abstract class RTextPageBase
{
public string Name { get; set; }
// We need to have them ordered, game uses binary searching
public SortedDictionary<string, RTextPairUnit> PairUnits { get; set; }
= new SortedDictionary<string, RTextPairUnit>(AlphaNumStringComparer.Default);
public void EditRow(int id, string label, string data)
{
if (!PairExists(label))
return;
PairUnits[label] = new RTextPairUnit(id, label, data);
}
public int AddRow(int id, string label, string data)
{
var index = PairUnits.Count;
PairUnits.Add(label, new RTextPairUnit(id, label, data));
return index;
}
public void DeleteRow(string label)
=> PairUnits.Remove(label);
public int GetLastId()
=> PairUnits.Max(p => p.Value.ID);
public bool PairExists(string label)
=> PairUnits.ContainsKey(label);
public void AddPairs(Dictionary<string, string> pairs)
{
int lastId = GetLastId();
foreach (var elem in pairs)
{
if (PairUnits.TryGetValue(elem.Key, out RTextPairUnit pair))
pair.Value = elem.Value;
else
AddRow(++lastId, elem.Key, elem.Value);
}
}
public abstract void Read(BinaryStream reader);
public abstract void Write(BinaryStream writer, int baseOffset, int baseDataOffset);
}