Skip to content

Commit 8e54b89

Browse files
committed
use full classes for stringtable
1 parent 582066b commit 8e54b89

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

OpenLocoTool/DatFileParsing/SawyerStreamReader.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,10 @@ public static ILocoObject LoadFull(string filename, ILogger? logger = null, bool
123123
var lang = (LanguageId)data[ptr++];
124124
var ini = ptr;
125125

126-
while (data[ptr++] != '\0')
127-
{
128-
;
129-
}
126+
while (data[ptr++] != '\0') ;
130127

131128
var str = Encoding.ASCII.GetString(data[ini..(ptr - 1)]); // do -1 to exclude the \0
132-
if (!languageDict.TryAdd(lang, str))
129+
if (!languageDict.TryAdd(lang, new StringTableEntry { String = str }))
133130
{
134131
//Logger.Error($"Key {(i, lang)} already exists (this shouldn't happen)");
135132
break;

OpenLocoTool/DatFileParsing/Typedefs.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
global using Speed32 = System.Int32;
1010
global using MicroZ = System.Byte;
1111
global using SoundObjectId = System.Byte;
12-
global using StringTable = System.Collections.Generic.Dictionary<string, System.Collections.Generic.Dictionary<OpenLocoTool.LanguageId, string>>;
1312
using System.ComponentModel;
1413

1514
namespace OpenLocoTool.DatFileParsing
@@ -23,4 +22,30 @@ public record Pos2(
2322
{
2423
public static int StructSize => 0x04;
2524
}
26-
}
25+
26+
// this is only required because WinForms' DataGridView cannot handle plain old dictionary<foo, string>, because string type doesn't have the getter+setter it needs
27+
//public class StringTable
28+
//{
29+
// Dictionary<string, StringTableInner> table = new();
30+
//}
31+
32+
public class StringTable
33+
{
34+
public Dictionary<string, Dictionary<LanguageId, StringTableEntry>> table { get; set; } = new();
35+
36+
public void Add(string key, Dictionary<LanguageId, StringTableEntry> value) => table.Add(key, value);
37+
38+
public Dictionary<LanguageId, StringTableEntry> this[string key]
39+
{
40+
get => table[key];
41+
set => table[key] = value;
42+
}
43+
44+
public Dictionary<string, Dictionary<LanguageId, StringTableEntry>>.KeyCollection Keys => table.Keys;
45+
}
46+
47+
public class StringTableEntry
48+
{
49+
public string String { get; set; }
50+
}
51+
}

OpenLocoToolGui/StringTableUserControl.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using OpenLocoTool;
2+
using OpenLocoTool.DatFileParsing;
23
using System.ComponentModel;
34

45
namespace OpenLocoToolGui
@@ -9,7 +10,7 @@ public partial class StringTableUserControl : UserControl
910

1011
public StringTableUserControl() => InitializeComponent();
1112

12-
public void SetDataBinding(Dictionary<string, Dictionary<LanguageId, string>> data)
13+
public void SetDataBinding(StringTable data)
1314
{
1415
blKeys.Clear();
1516
foreach (var key in data.Keys)

0 commit comments

Comments
 (0)