Skip to content

Commit 5458861

Browse files
remyCasesNylux
authored andcommitted
[Major] export all items, weapons and armors in csv after loading
1 parent 1c314dd commit 5458861

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

DataLoader.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,47 @@ private static void ExportData()
7070
File.WriteAllText("json_dump_rooms.json", JsonConvert.SerializeObject(data.Rooms.Select(t => t.Name.Content)));
7171
Msl.GenerateNRandomLinesFromCode(data.Code, new GlobalDecompileContext(data, false), 100, 1, 0);
7272
}
73+
/// <summary>
74+
/// Export all items, weapons and armors in csv files.
75+
/// </summary>
76+
private static void ExportItems()
77+
{
78+
try
79+
{
80+
DirectoryInfo dir = new("export");
81+
if (dir.Exists) dir.Delete(true);
82+
dir.Create();
83+
84+
List<string>? weapons = ModLoader.GetTable("gml_GlobalScript_table_weapons");
85+
List<string>? armor = ModLoader.GetTable("gml_GlobalScript_table_armor");
86+
87+
File.WriteAllLines(
88+
Path.Join(dir.FullName, Path.DirectorySeparatorChar.ToString(), "_all_items.csv"),
89+
data.GameObjects.Select(t => t.Name.Content).Where(x => x.Contains("o_inv_")).Select(x => x.Replace("o_inv_", ""))
90+
);
91+
92+
if (weapons != null)
93+
{
94+
File.WriteAllLines(
95+
Path.Join(dir.FullName, Path.DirectorySeparatorChar.ToString(), "_all_weapons.csv"),
96+
weapons.Select(x => string.Join(';', x.Split(';').Take(4)))
97+
);
98+
}
99+
100+
if (armor != null)
101+
{
102+
File.WriteAllLines(
103+
Path.Join(dir.FullName, Path.DirectorySeparatorChar.ToString(), "_all_armors.csv"),
104+
armor.Select(x => string.Join(';', x.Split(';').Take(6)))
105+
);
106+
}
107+
}
108+
catch(Exception ex)
109+
{
110+
Log.Error(ex, "Something went wrong");
111+
throw;
112+
}
113+
}
73114
private static void ExportPreset()
74115
{
75116
GlobalDecompileContext context = new(ModLoader.Data, false);
@@ -137,6 +178,7 @@ public static async Task LoadFile(string filename, bool re = false)
137178
ModLoader.Initalize();
138179
// cleaning loot table
139180
LootUtils.ResetLootTables();
181+
ExportItems();
140182
}
141183
public static async Task<bool> DoSaveDialog()
142184
{

0 commit comments

Comments
 (0)