Files
@ f28757bb21cb
Branch filter:
Location: ATITD-Tools/Desert-Paint-Lab/ReagentManager.cs - annotation
f28757bb21cb
3.7 KiB
text/x-csharp
Refactor recipe / reaction computation into a common class. Add some file utilities for supporting Mac bundles. Add some scripts for building Mac app bundles. Add a help window that shows the missing reactions.
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 f28757bb21cb f28757bb21cb b9934660c784 b9934660c784 f28757bb21cb b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 f28757bb21cb f28757bb21cb f28757bb21cb f28757bb21cb f28757bb21cb f28757bb21cb f28757bb21cb f28757bb21cb b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 f28757bb21cb f28757bb21cb b9934660c784 f28757bb21cb b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 f28757bb21cb f28757bb21cb b9934660c784 f28757bb21cb b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 f28757bb21cb b9934660c784 f28757bb21cb b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 | using System;
using System.IO;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace DesertPaintLab
{
public class ReagentManager
{
static Regex reagentRegex = new Regex(@"(?<name>\w+)\s*\|\s*(?<red>\d+),\s*(?<green>\d+),\s*(?<blue>\d+)\s*\|\s*(?<cost>\d+)\s*\|.*");
static Regex catalystRegex = new Regex(@"(?<name>\w+)\s*\|\s*catalyst\s*\|\s*(?<cost>\d+)\s*\|.*");
static SortedDictionary<string,Reagent> reagents = new SortedDictionary<string, Reagent>();
static List<string> names = new List<string>();
static Gtk.ListStore nameStore = new Gtk.ListStore(typeof(string));
static public Gtk.ListStore NameListModel
{
get
{
return nameStore;
}
}
static public List<string> Names
{
get
{
return names;
}
}
public ReagentManager ()
{
}
public static void Load(string file)
{
Match match;
string line;
reagents.Clear();
using (StreamReader reader = new StreamReader(file))
{
while ((line = reader.ReadLine()) != null)
{
match = reagentRegex.Match(line);
if (match.Success)
{
string name = match.Groups["name"].Value;
reagents.Add(name,
new Reagent(name,
byte.Parse(match.Groups["red"].Value),
byte.Parse(match.Groups["green"].Value),
byte.Parse(match.Groups["blue"].Value),
int.Parse(match.Groups["cost"].Value)));
nameStore.AppendValues(name);
names.Add(name);
}
else
{
match = catalystRegex.Match(line);
if (match.Success)
{
string name = match.Groups["name"].Value;
int cost = int.Parse(match.Groups["cost"].Value);
reagents.Add(name, new Reagent(name, cost));
nameStore.AppendValues(name);
names.Add(name);
}
}
}
}
}
public static void InitializeReactions(ref SortedDictionary<string, SortedDictionary<string, Reaction>> reactions)
{
foreach (KeyValuePair<string, Reagent> pair1 in reagents)
{
SortedDictionary<string, Reaction> dict = new SortedDictionary<string, Reaction>();
foreach (KeyValuePair<string, Reagent> pair2 in reagents)
{
if (pair1.Key != pair2.Key)
{
dict.Add(pair2.Key, null);
}
}
reactions.Add(pair1.Key, dict);
}
}
public static void PopulateReagents(ref Gtk.ComboBox comboBox)
{
comboBox.Clear();
Gtk.CellRendererText cell = new Gtk.CellRendererText();
comboBox.PackStart(cell, false);
comboBox.AddAttribute(cell, "text", 0);
Gtk.ListStore store = new Gtk.ListStore(typeof(string));
comboBox.Model = store;
store.AppendValues("");
foreach (string name in names)
{
store.AppendValues(name);
}
}
/*
public static void PopulatePigments(ref Gtk.ComboBox comboBox)
{
comboBox.Clear();
Gtk.CellRendererText cell = new Gtk.CellRendererText();
comboBox.PackStart(cell, false);
comboBox.AddAttribute(cell, "text", 0);
Gtk.ListStore store = new Gtk.ListStore(typeof(string));
comboBox.Model = store;
store.AppendValues("");
foreach (KeyValuePair<string, Reagent> pair in reagents)
{
if (!pair.Value.IsCatalyst)
{
store.AppendValues(pair.Key);
}
}
}
*/
public static Reagent GetReagent(string reagentName)
{
Reagent returnVal;
reagents.TryGetValue(reagentName, out returnVal);
return returnVal;
}
}
}
|