Skip to content

Commit aa1b6a7

Browse files
committed
Data export will attempt to preserve existing data (recipes, boostsets, product catalog, etc) rather than overwrite the files.
Set bonuses can now be selected from a dropdown list.
1 parent 106e928 commit aa1b6a7

File tree

14 files changed

+7286
-263
lines changed

14 files changed

+7286
-263
lines changed

Inventor/BoostSetData.cs

Lines changed: 212 additions & 212 deletions
Large diffs are not rendered by default.

Inventor/BoostSets.cs

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Specialized;
4+
using System.IO;
5+
6+
namespace Inventor
7+
{
8+
public class BoostSets
9+
{
10+
public OrderedDictionary list;
11+
12+
public BoostSets()
13+
{
14+
list = new OrderedDictionary(StringComparer.OrdinalIgnoreCase);
15+
}
16+
17+
public void Add(string name, string text)
18+
{
19+
if (list.Contains(name))
20+
{
21+
list[name] = text;
22+
}
23+
else
24+
{
25+
list.Add(name, text);
26+
}
27+
}
28+
29+
public void AddFile(string file)
30+
{
31+
// Really, really, REALLY dumb parser for files that have a single non-nesting structure.
32+
if (File.Exists(file))
33+
{
34+
int depth = 0;
35+
string line;
36+
string name = String.Empty;
37+
string text = String.Empty;
38+
StreamReader sr = new StreamReader(file);
39+
while ((line = sr.ReadLine()) != null)
40+
{
41+
string l = line.Trim().ToUpper();
42+
if (l.Equals("BOOSTSET"))
43+
{
44+
name = String.Empty;
45+
text = String.Empty;
46+
}
47+
else if (l.Equals("{"))
48+
{
49+
depth++;
50+
if (depth > 1)
51+
{
52+
text += line + Environment.NewLine;
53+
}
54+
}
55+
else if (l.Equals("}"))
56+
{
57+
depth--;
58+
if (depth > 0)
59+
{
60+
text += line + Environment.NewLine;
61+
}
62+
else
63+
{
64+
Add(name, text);
65+
}
66+
}
67+
else
68+
{
69+
if (l.IndexOf("NAME ") == 0)
70+
{
71+
name = l.Substring(5).Trim();
72+
}
73+
text += line + Environment.NewLine;
74+
}
75+
}
76+
77+
sr.Close();
78+
}
79+
}
80+
81+
public override string ToString()
82+
{
83+
string s = String.Empty;
84+
foreach (DictionaryEntry recipe in list)
85+
{
86+
s += "BoostSet" + Environment.NewLine;
87+
s += "{" + Environment.NewLine;
88+
s += recipe.Value;
89+
s += "}" + Environment.NewLine;
90+
}
91+
list.Clear();
92+
return s;
93+
}
94+
}
95+
}

Inventor/Form1.Designer.cs

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Inventor/Form1.cs

Lines changed: 70 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ public partial class Form1 : Form
1717
List<SetGroup> setGroups;
1818
List<BoostType> boostTypes;
1919
List<Salvage> salvage;
20+
List<SetBonus> setBonusData;
2021
List<int> craftingCost;
22+
List<string> boostCategories = new List<string>();
2123

2224
public Form1()
2325
{
@@ -26,10 +28,13 @@ public Form1()
2628
setGroups = JsonConvert.DeserializeObject<List<SetGroup>>(LoadConfig("SetGroups", Properties.Resources.SetGroups));
2729
boostTypes = JsonConvert.DeserializeObject<List<BoostType>>(LoadConfig("BoostTypes", Properties.Resources.BoostTypes));
2830
salvage = JsonConvert.DeserializeObject<List<Salvage>>(LoadConfig("Salvage", Properties.Resources.Salvage));
29-
craftingCost = JsonConvert.DeserializeObject<List<int>>(LoadConfig("CraftingCost", Properties.Resources.CraftingCost));
30-
foreach (SetGroup group in setGroups) setGroupName.Items.Add(group);
31-
foreach (BoostType boostType in boostTypes) boostTypeList.Items.Add(boostType);
32-
this.Icon = Icon.FromHandle(boostSet.GetIcon(config, "Superior").GetHicon());
31+
setBonusData = JsonConvert.DeserializeObject<List<SetBonus>>(LoadConfig("SetBonus", Properties.Resources.SetBonus));
32+
craftingCost = JsonConvert.DeserializeObject<List<int>>(LoadConfig("CraftingCost", Properties.Resources.CraftingCost));
33+
foreach (SetGroup group in setGroups) setGroupName.Items.Add(group);
34+
foreach (BoostType boostType in boostTypes) boostTypeList.Items.Add(boostType);
35+
setBonusList.DisplayMember = "displayList";
36+
setBonusList.DataSource = setBonusData;
37+
this.Icon = Icon.FromHandle(boostSet.GetIcon(config, "Superior").GetHicon());
3338
}
3439

3540
private string LoadConfig(string filename, string resource)
@@ -53,7 +58,8 @@ private void LoadBoostset(string filename)
5358
private void SaveBoostset(string filename)
5459
{
5560
UpdateBoostSet();
56-
File.WriteAllText(filename, JsonConvert.SerializeObject(boostSet));
61+
File.WriteAllText(filename, JsonConvert.SerializeObject(boostSet, Formatting.Indented,
62+
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }));
5763
}
5864

5965
private void UpdateFormData()
@@ -120,7 +126,8 @@ private void Form1_FormClosing(object sender, FormClosingEventArgs e)
120126

121127
private void createDataFiles_Click(object sender, EventArgs e)
122128
{
123-
UpdateBoostSet();
129+
createDataFiles.Enabled = false;
130+
UpdateBoostSet();
124131
Directory.CreateDirectory(config.data + "Defs/Account");
125132
Directory.CreateDirectory(config.data + "Defs/Boostsets");
126133
Directory.CreateDirectory(config.data + "Defs/Powers");
@@ -129,20 +136,54 @@ private void createDataFiles_Click(object sender, EventArgs e)
129136
Directory.CreateDirectory(config.data + "Texts/English/Boostset");
130137
Directory.CreateDirectory(config.data + "Texts/English/Powers");
131138

132-
File.WriteAllText(config.data + "Defs/Account/Product_Catalog.def", boostSet.GetProductCatalog());
133-
File.WriteAllText(config.data + "Defs/Invention/Recipes.recipe", boostSet.GetDropRecipe(craftingCost, salvage));
134-
File.WriteAllText(config.data + "Defs/Invention/Merits.recipe", boostSet.GetMeritsRecipe());
135-
File.WriteAllText(config.data + "Defs/Invention/Store.recipe", boostSet.GetStoreRecipe());
136-
File.WriteAllText(config.data + "texts/English/Bases/Recipes.ms", boostSet.DumpCache());
139+
boostSet.catalog.AddFile(config.data + "Defs/Account/Product_Catalog.def");
140+
File.WriteAllText(config.data + "Defs/Account/Product_Catalog.def", boostSet.GetProductCatalog());
137141

138-
File.WriteAllText(config.data + "Defs/Boostsets/Boostsets.def", boostSet.GetBoostSetDef());
139-
File.WriteAllText(config.data + "Texts/English/Boostset/Boostsets.ms", boostSet.DumpCache());
142+
boostSet.pstring.AddFile(config.data + "texts/English/Bases/Recipes.ms");
140143

141-
File.WriteAllText(config.data + "Defs/Powers/Boosts.categories", boostSet.GetBoostsCategories());
142-
File.WriteAllText(config.data + "Defs/Powers/Boosts.powersets", boostSet.GetBoostsPowerSets());
143-
foreach (Boost boost in boostSet.boostList) File.WriteAllText(config.data + "Defs/Powers/Boosts_Crafted_" + boost.name + ".powers", boostSet.GetPowers(boost, false, "Crafted_", "Attuned_"));
144-
foreach (Boost boost in boostSet.boostList) File.WriteAllText(config.data + "Defs/Powers/Boosts_Attuned_" + boost.name + ".powers", boostSet.GetPowers(boost, true, "Attuned_", null));
145-
File.WriteAllText(config.data + "Texts/English/Powers/Boosts." + boostSet.name + ".ms", boostSet.DumpCache());
144+
boostSet.recipes.AddFile(config.data + "Defs/Invention/Recipes.recipe");
145+
File.WriteAllText(config.data + "Defs/Invention/Recipes.recipe", boostSet.GetDropRecipe(craftingCost, salvage));
146+
boostSet.recipes.AddFile(config.data + "Defs/Invention/Merits.recipe");
147+
File.WriteAllText(config.data + "Defs/Invention/Merits.recipe", boostSet.GetMeritsRecipe());
148+
boostSet.recipes.AddFile(config.data + "Defs/Invention/Store.recipe");
149+
File.WriteAllText(config.data + "Defs/Invention/Store.recipe", boostSet.GetStoreRecipe());
150+
151+
File.WriteAllText(config.data + "texts/English/Bases/Recipes.ms", boostSet.pstring.ToString());
152+
153+
boostSet.pstring.AddFile(config.data + "Texts/English/Boostset/Boostsets.ms");
154+
boostSet.boostsets.AddFile(config.data + "Defs/Boostsets/Boostsets.def");
155+
File.WriteAllText(config.data + "Defs/Boostsets/Boostsets.def", boostSet.GetBoostSetDef());
156+
File.WriteAllText(config.data + "Texts/English/Boostset/Boostsets.ms", boostSet.pstring.ToString());
157+
158+
boostCategories.Clear();
159+
if (File.Exists(config.data + "Defs/Powers/Boosts.categories"))
160+
{
161+
string line;
162+
StreamReader file = new StreamReader(config.data + "Defs/Powers/Boosts.categories");
163+
while ((line = file.ReadLine()) != null)
164+
{
165+
line = line.Trim();
166+
if (line.ToUpper().IndexOf("POWERSETS ") == 0)
167+
{
168+
boostCategories.Add(line.Substring(10).Trim());
169+
}
170+
}
171+
172+
file.Close();
173+
}
174+
File.WriteAllText(config.data + "Defs/Powers/Boosts.categories", boostSet.GetBoostsCategories(boostCategories));
175+
176+
foreach (Boost boost in boostSet.boostList)
177+
{
178+
Directory.CreateDirectory(config.data + "Defs/Powers/Boosts/Crafted_" + boost.name);
179+
File.WriteAllText(config.data + "Defs/Powers/Boosts/Crafted_" + boost.name + ".powersets", boostSet.GetBoostsPowerSet(boost, "Crafted_"));
180+
File.WriteAllText(config.data + "Defs/Powers/Boosts/Crafted_" + boost.name + "/Crafted_" + boost.name + ".powers", boostSet.GetPowers(boost, false, "Crafted_", "Attuned_"));
181+
Directory.CreateDirectory(config.data + "Defs/Powers/Boosts/Attuned_" + boost.name);
182+
File.WriteAllText(config.data + "Defs/Powers/Boosts/Attuned_" + boost.name + ".powersets", boostSet.GetBoostsPowerSet(boost, "Attuned_"));
183+
File.WriteAllText(config.data + "Defs/Powers/Boosts/Attuned_" + boost.name + "/Attuned_" + boost.name + ".powers", boostSet.GetPowers(boost, true, "Attuned_", null));
184+
}
185+
186+
File.WriteAllText(config.data + "Texts/English/Powers/Boosts." + boostSet.name + ".ms", boostSet.pstring.ToString());
146187

147188
if (File.Exists(config.images + boostSet.iconName + ".png"))
148189
{
@@ -192,9 +233,10 @@ private void createDataFiles_Click(object sender, EventArgs e)
192233
File.WriteAllText(config.thumbs + "enhancements_images.txt", enhancementsList);
193234
File.WriteAllText(config.thumbs + "recipes_images.txt", recipesList);
194235
}
195-
}
236+
createDataFiles.Enabled = true;
237+
}
196238

197-
private void bonusAddNew_Click(object sender, EventArgs e)
239+
private void bonusAddNew_Click(object sender, EventArgs e)
198240
{
199241
Bonus bonus = new Bonus();
200242
if (!string.IsNullOrEmpty(bonusAutoPowers.Text))
@@ -486,5 +528,12 @@ private void salvageAdd_Click(object sender, EventArgs e)
486528
AddSalvageToTree(s, salvageTree.Nodes[(int)s.level]);
487529
}
488530
}
489-
}
531+
532+
private void setBonusList_SelectedIndexChanged(object sender, EventArgs e)
533+
{
534+
SetBonus selected = (SetBonus)setBonusList.SelectedItem;
535+
setBonusLabel.Text = selected.displayShortHelp + Environment.NewLine + selected.displayHelp;
536+
bonusAutoPowers.Text = selected.fullName;
537+
}
538+
}
490539
}

Inventor/Inventor.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,20 @@
7474
</ItemGroup>
7575
<ItemGroup>
7676
<Compile Include="BoostSetData.cs" />
77+
<Compile Include="BoostSets.cs" />
7778
<Compile Include="Config.cs" />
7879
<Compile Include="Form1.cs">
7980
<SubType>Form</SubType>
8081
</Compile>
8182
<Compile Include="Form1.Designer.cs">
8283
<DependentUpon>Form1.cs</DependentUpon>
8384
</Compile>
85+
<Compile Include="Parser.cs" />
86+
<Compile Include="ProductCatalog.cs" />
8487
<Compile Include="Program.cs" />
8588
<Compile Include="Properties\AssemblyInfo.cs" />
89+
<Compile Include="PString.cs" />
90+
<Compile Include="Recipes.cs" />
8691
<Compile Include="Salvage.cs" />
8792
<EmbeddedResource Include="Form1.resx">
8893
<DependentUpon>Form1.cs</DependentUpon>
@@ -200,6 +205,7 @@
200205
</ItemGroup>
201206
<ItemGroup>
202207
<Content Include="Inventor.ico" />
208+
<Content Include="Resources\SetBonus.txt" />
203209
<None Include="Resources\Salvage.txt" />
204210
<None Include="Resources\Config.txt" />
205211
</ItemGroup>

Inventor/PString.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text;
6+
using Force.Crc32;
7+
8+
namespace Inventor
9+
{
10+
class PString
11+
{
12+
public Dictionary<string, string> cache = new Dictionary<string, string>();
13+
14+
public string Add(string text)
15+
{
16+
string hash = "P" + Crc32Algorithm.Compute(Encoding.ASCII.GetBytes(text));
17+
if (!cache.ContainsKey(hash)) cache.Add(hash, text);
18+
return hash;
19+
}
20+
21+
public void AddFile(string file)
22+
{
23+
if (File.Exists(file))
24+
{
25+
Parser parser = new Parser(File.ReadAllText(file), null);
26+
if (parser.ParseNext(null))
27+
{
28+
foreach (KeyValuePair<string, string> pstring in parser.results)
29+
{
30+
if (!cache.ContainsKey(pstring.Key)) cache.Add(pstring.Key, pstring.Value);
31+
}
32+
}
33+
}
34+
}
35+
36+
public void AddPath(string dir)
37+
{
38+
if (Directory.Exists(dir))
39+
{
40+
foreach (string file in Directory.GetFiles(dir))
41+
{
42+
if (file.ToLower().EndsWith(".ms"))
43+
{
44+
AddFile(file);
45+
}
46+
}
47+
}
48+
}
49+
50+
public override string ToString()
51+
{
52+
string s = String.Empty;
53+
foreach (KeyValuePair<string, string> entry in cache.OrderBy(x => x.Value))
54+
{
55+
s += "\"" + entry.Key + "\" \"" + entry.Value + "\"" + Environment.NewLine;
56+
}
57+
cache.Clear();
58+
return s;
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)