Skip to content

Commit

Permalink
Data export will attempt to preserve existing data (recipes, boostset…
Browse files Browse the repository at this point in the history
…s, product catalog, etc) rather than overwrite the files.

Set bonuses can now be selected from a dropdown list.
  • Loading branch information
Fusionette committed Jul 1, 2022
1 parent 106e928 commit aa1b6a7
Show file tree
Hide file tree
Showing 14 changed files with 7,286 additions and 263 deletions.
424 changes: 212 additions & 212 deletions Inventor/BoostSetData.cs

Large diffs are not rendered by default.

95 changes: 95 additions & 0 deletions Inventor/BoostSets.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using System;
using System.Collections;
using System.Collections.Specialized;
using System.IO;

namespace Inventor
{
public class BoostSets
{
public OrderedDictionary list;

public BoostSets()
{
list = new OrderedDictionary(StringComparer.OrdinalIgnoreCase);
}

public void Add(string name, string text)
{
if (list.Contains(name))
{
list[name] = text;
}
else
{
list.Add(name, text);
}
}

public void AddFile(string file)
{
// Really, really, REALLY dumb parser for files that have a single non-nesting structure.
if (File.Exists(file))
{
int depth = 0;
string line;
string name = String.Empty;
string text = String.Empty;
StreamReader sr = new StreamReader(file);
while ((line = sr.ReadLine()) != null)
{
string l = line.Trim().ToUpper();
if (l.Equals("BOOSTSET"))
{
name = String.Empty;
text = String.Empty;
}
else if (l.Equals("{"))
{
depth++;
if (depth > 1)
{
text += line + Environment.NewLine;
}
}
else if (l.Equals("}"))
{
depth--;
if (depth > 0)
{
text += line + Environment.NewLine;
}
else
{
Add(name, text);
}
}
else
{
if (l.IndexOf("NAME ") == 0)
{
name = l.Substring(5).Trim();
}
text += line + Environment.NewLine;
}
}

sr.Close();
}
}

public override string ToString()
{
string s = String.Empty;
foreach (DictionaryEntry recipe in list)
{
s += "BoostSet" + Environment.NewLine;
s += "{" + Environment.NewLine;
s += recipe.Value;
s += "}" + Environment.NewLine;
}
list.Clear();
return s;
}
}
}
22 changes: 22 additions & 0 deletions Inventor/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 70 additions & 21 deletions Inventor/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public partial class Form1 : Form
List<SetGroup> setGroups;
List<BoostType> boostTypes;
List<Salvage> salvage;
List<SetBonus> setBonusData;
List<int> craftingCost;
List<string> boostCategories = new List<string>();

public Form1()
{
Expand All @@ -26,10 +28,13 @@ public Form1()
setGroups = JsonConvert.DeserializeObject<List<SetGroup>>(LoadConfig("SetGroups", Properties.Resources.SetGroups));
boostTypes = JsonConvert.DeserializeObject<List<BoostType>>(LoadConfig("BoostTypes", Properties.Resources.BoostTypes));
salvage = JsonConvert.DeserializeObject<List<Salvage>>(LoadConfig("Salvage", Properties.Resources.Salvage));
craftingCost = JsonConvert.DeserializeObject<List<int>>(LoadConfig("CraftingCost", Properties.Resources.CraftingCost));
foreach (SetGroup group in setGroups) setGroupName.Items.Add(group);
foreach (BoostType boostType in boostTypes) boostTypeList.Items.Add(boostType);
this.Icon = Icon.FromHandle(boostSet.GetIcon(config, "Superior").GetHicon());
setBonusData = JsonConvert.DeserializeObject<List<SetBonus>>(LoadConfig("SetBonus", Properties.Resources.SetBonus));
craftingCost = JsonConvert.DeserializeObject<List<int>>(LoadConfig("CraftingCost", Properties.Resources.CraftingCost));
foreach (SetGroup group in setGroups) setGroupName.Items.Add(group);
foreach (BoostType boostType in boostTypes) boostTypeList.Items.Add(boostType);
setBonusList.DisplayMember = "displayList";
setBonusList.DataSource = setBonusData;
this.Icon = Icon.FromHandle(boostSet.GetIcon(config, "Superior").GetHicon());
}

private string LoadConfig(string filename, string resource)
Expand All @@ -53,7 +58,8 @@ private void LoadBoostset(string filename)
private void SaveBoostset(string filename)
{
UpdateBoostSet();
File.WriteAllText(filename, JsonConvert.SerializeObject(boostSet));
File.WriteAllText(filename, JsonConvert.SerializeObject(boostSet, Formatting.Indented,
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }));
}

private void UpdateFormData()
Expand Down Expand Up @@ -120,7 +126,8 @@ private void Form1_FormClosing(object sender, FormClosingEventArgs e)

private void createDataFiles_Click(object sender, EventArgs e)
{
UpdateBoostSet();
createDataFiles.Enabled = false;
UpdateBoostSet();
Directory.CreateDirectory(config.data + "Defs/Account");
Directory.CreateDirectory(config.data + "Defs/Boostsets");
Directory.CreateDirectory(config.data + "Defs/Powers");
Expand All @@ -129,20 +136,54 @@ private void createDataFiles_Click(object sender, EventArgs e)
Directory.CreateDirectory(config.data + "Texts/English/Boostset");
Directory.CreateDirectory(config.data + "Texts/English/Powers");

File.WriteAllText(config.data + "Defs/Account/Product_Catalog.def", boostSet.GetProductCatalog());
File.WriteAllText(config.data + "Defs/Invention/Recipes.recipe", boostSet.GetDropRecipe(craftingCost, salvage));
File.WriteAllText(config.data + "Defs/Invention/Merits.recipe", boostSet.GetMeritsRecipe());
File.WriteAllText(config.data + "Defs/Invention/Store.recipe", boostSet.GetStoreRecipe());
File.WriteAllText(config.data + "texts/English/Bases/Recipes.ms", boostSet.DumpCache());
boostSet.catalog.AddFile(config.data + "Defs/Account/Product_Catalog.def");
File.WriteAllText(config.data + "Defs/Account/Product_Catalog.def", boostSet.GetProductCatalog());

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

File.WriteAllText(config.data + "Defs/Powers/Boosts.categories", boostSet.GetBoostsCategories());
File.WriteAllText(config.data + "Defs/Powers/Boosts.powersets", boostSet.GetBoostsPowerSets());
foreach (Boost boost in boostSet.boostList) File.WriteAllText(config.data + "Defs/Powers/Boosts_Crafted_" + boost.name + ".powers", boostSet.GetPowers(boost, false, "Crafted_", "Attuned_"));
foreach (Boost boost in boostSet.boostList) File.WriteAllText(config.data + "Defs/Powers/Boosts_Attuned_" + boost.name + ".powers", boostSet.GetPowers(boost, true, "Attuned_", null));
File.WriteAllText(config.data + "Texts/English/Powers/Boosts." + boostSet.name + ".ms", boostSet.DumpCache());
boostSet.recipes.AddFile(config.data + "Defs/Invention/Recipes.recipe");
File.WriteAllText(config.data + "Defs/Invention/Recipes.recipe", boostSet.GetDropRecipe(craftingCost, salvage));
boostSet.recipes.AddFile(config.data + "Defs/Invention/Merits.recipe");
File.WriteAllText(config.data + "Defs/Invention/Merits.recipe", boostSet.GetMeritsRecipe());
boostSet.recipes.AddFile(config.data + "Defs/Invention/Store.recipe");
File.WriteAllText(config.data + "Defs/Invention/Store.recipe", boostSet.GetStoreRecipe());

File.WriteAllText(config.data + "texts/English/Bases/Recipes.ms", boostSet.pstring.ToString());

boostSet.pstring.AddFile(config.data + "Texts/English/Boostset/Boostsets.ms");
boostSet.boostsets.AddFile(config.data + "Defs/Boostsets/Boostsets.def");
File.WriteAllText(config.data + "Defs/Boostsets/Boostsets.def", boostSet.GetBoostSetDef());
File.WriteAllText(config.data + "Texts/English/Boostset/Boostsets.ms", boostSet.pstring.ToString());

boostCategories.Clear();
if (File.Exists(config.data + "Defs/Powers/Boosts.categories"))
{
string line;
StreamReader file = new StreamReader(config.data + "Defs/Powers/Boosts.categories");
while ((line = file.ReadLine()) != null)
{
line = line.Trim();
if (line.ToUpper().IndexOf("POWERSETS ") == 0)
{
boostCategories.Add(line.Substring(10).Trim());
}
}

file.Close();
}
File.WriteAllText(config.data + "Defs/Powers/Boosts.categories", boostSet.GetBoostsCategories(boostCategories));

foreach (Boost boost in boostSet.boostList)
{
Directory.CreateDirectory(config.data + "Defs/Powers/Boosts/Crafted_" + boost.name);
File.WriteAllText(config.data + "Defs/Powers/Boosts/Crafted_" + boost.name + ".powersets", boostSet.GetBoostsPowerSet(boost, "Crafted_"));
File.WriteAllText(config.data + "Defs/Powers/Boosts/Crafted_" + boost.name + "/Crafted_" + boost.name + ".powers", boostSet.GetPowers(boost, false, "Crafted_", "Attuned_"));
Directory.CreateDirectory(config.data + "Defs/Powers/Boosts/Attuned_" + boost.name);
File.WriteAllText(config.data + "Defs/Powers/Boosts/Attuned_" + boost.name + ".powersets", boostSet.GetBoostsPowerSet(boost, "Attuned_"));
File.WriteAllText(config.data + "Defs/Powers/Boosts/Attuned_" + boost.name + "/Attuned_" + boost.name + ".powers", boostSet.GetPowers(boost, true, "Attuned_", null));
}

File.WriteAllText(config.data + "Texts/English/Powers/Boosts." + boostSet.name + ".ms", boostSet.pstring.ToString());

if (File.Exists(config.images + boostSet.iconName + ".png"))
{
Expand Down Expand Up @@ -192,9 +233,10 @@ private void createDataFiles_Click(object sender, EventArgs e)
File.WriteAllText(config.thumbs + "enhancements_images.txt", enhancementsList);
File.WriteAllText(config.thumbs + "recipes_images.txt", recipesList);
}
}
createDataFiles.Enabled = true;
}

private void bonusAddNew_Click(object sender, EventArgs e)
private void bonusAddNew_Click(object sender, EventArgs e)
{
Bonus bonus = new Bonus();
if (!string.IsNullOrEmpty(bonusAutoPowers.Text))
Expand Down Expand Up @@ -486,5 +528,12 @@ private void salvageAdd_Click(object sender, EventArgs e)
AddSalvageToTree(s, salvageTree.Nodes[(int)s.level]);
}
}
}

private void setBonusList_SelectedIndexChanged(object sender, EventArgs e)
{
SetBonus selected = (SetBonus)setBonusList.SelectedItem;
setBonusLabel.Text = selected.displayShortHelp + Environment.NewLine + selected.displayHelp;
bonusAutoPowers.Text = selected.fullName;
}
}
}
6 changes: 6 additions & 0 deletions Inventor/Inventor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,20 @@
</ItemGroup>
<ItemGroup>
<Compile Include="BoostSetData.cs" />
<Compile Include="BoostSets.cs" />
<Compile Include="Config.cs" />
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Parser.cs" />
<Compile Include="ProductCatalog.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PString.cs" />
<Compile Include="Recipes.cs" />
<Compile Include="Salvage.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
Expand Down Expand Up @@ -200,6 +205,7 @@
</ItemGroup>
<ItemGroup>
<Content Include="Inventor.ico" />
<Content Include="Resources\SetBonus.txt" />
<None Include="Resources\Salvage.txt" />
<None Include="Resources\Config.txt" />
</ItemGroup>
Expand Down
61 changes: 61 additions & 0 deletions Inventor/PString.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Force.Crc32;

namespace Inventor
{
class PString
{
public Dictionary<string, string> cache = new Dictionary<string, string>();

public string Add(string text)
{
string hash = "P" + Crc32Algorithm.Compute(Encoding.ASCII.GetBytes(text));
if (!cache.ContainsKey(hash)) cache.Add(hash, text);
return hash;
}

public void AddFile(string file)
{
if (File.Exists(file))
{
Parser parser = new Parser(File.ReadAllText(file), null);
if (parser.ParseNext(null))
{
foreach (KeyValuePair<string, string> pstring in parser.results)
{
if (!cache.ContainsKey(pstring.Key)) cache.Add(pstring.Key, pstring.Value);
}
}
}
}

public void AddPath(string dir)
{
if (Directory.Exists(dir))
{
foreach (string file in Directory.GetFiles(dir))
{
if (file.ToLower().EndsWith(".ms"))
{
AddFile(file);
}
}
}
}

public override string ToString()
{
string s = String.Empty;
foreach (KeyValuePair<string, string> entry in cache.OrderBy(x => x.Value))
{
s += "\"" + entry.Key + "\" \"" + entry.Value + "\"" + Environment.NewLine;
}
cache.Clear();
return s;
}
}
}
Loading

0 comments on commit aa1b6a7

Please sign in to comment.