Inheritance: IComparable
Beispiel #1
0
 void loadRecipe(Recipe recipe)
 {
     curView.Clear();
     recipe.view.ForEach((item) => { curView.Add(item); });
     curCraft.Clear();
     recipe.craft.ForEach((item) => { curCraft.Add(item); });
     curItems.Clear();
     recipe.items.ForEach((item) => { curItems.Add(item); });
     curTools.Clear();
     recipe.tools.ForEach((item) => { curTools.Add(item); });
     curOutput.Clear();
     recipe.output.ForEach((item) => { curOutput.Add(item); });
     rtbDescription.Text = recipe.desc;
     txtName.Text = recipe.name;
     txtScript.Text = recipe.script;
     numNumber.Value = recipe.number;
     numExperience.Value = recipe.exp;
     refreshAll();
 }
Beispiel #2
0
        private void btnAddUpdate_Click(object sender, EventArgs e)
        {
            // adding recipe
            if (txtName.Text == "")
            {
                Log("Name field cannot be empty");
                return;
            }
            if (curItems.Count == 0 || curOutput.Count == 0)
            {
                Log("Items or output fields cannot be empty");
                return;
            }
            for (int i = 0, j = Data.Recipes.Count; i < j; i++)
            {
                if (Data.Recipes[i].number == numNumber.Value)
                {
                    if(MessageBox.Show("A recipe with number " + numNumber.Value + " already exists (" + Data.Recipes[i].name + "), overwrite?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                        return;
                    else
                    {
                        Data.Recipes.RemoveAt(i);
                        break;
                    }
                }
            }

            Recipe rec = new Recipe();
            rec.number = (uint)numNumber.Value;
            rec.name = txtName.Text;
            rec.exp = (uint)numExperience.Value;
            rec.script = txtScript.Text;
            curView.ForEach((item) => { rec.view.Add(item); });
            curCraft.ForEach((item) => { rec.craft.Add(item); });
            curItems.ForEach((item) => { rec.items.Add(item); });
            curTools.ForEach((item) => { rec.tools.Add(item); });
            curOutput.ForEach((item) => { rec.output.Add(item); });
            rec.desc = rtbDescription.Text;
            Data.Recipes.Add(rec);
            refreshRecipes();
            Log("Recipe added");
        }
Beispiel #3
0
        private static bool parseRecipe(string rec, List<Recipe> newlist)
        {
            //                          1          2       3             4
            Regex regexp = new Regex(@"{([^}]+)}{}{([^@]+)@([^@]+)@([^@]*)@([^@]*)@([^@]*)@([^@]*)@([^@]+)@([^}]*)}");
            Match match = regexp.Match(rec);
            if(!match.Success) return false;
            // 1 pid
            // 2 name
            // 3 description
            // 4 view
            // 5 craft
            // 6 items
            // 7 tools
            // 8 output
            // 9 exp and script

            Recipe newr = new Recipe();
            newr.number = uint.Parse(match.Groups[1].Value);
            newr.name = match.Groups[2].Value;
            newr.desc = match.Groups[3].Value;
            Regex rx = new Regex(@"([A-Z0-9_]+) ([0-9]+)([&|]?)");
            MatchCollection ms = rx.Matches(match.Groups[4].Value);

            foreach(Match m in ms)
                newr.AddView(m.Groups[1].Value, uint.Parse(m.Groups[2].Value), m.Groups[3].Value == "|");

            ms = rx.Matches(match.Groups[5].Value);
            foreach(Match m in ms)
                newr.AddCraft(m.Groups[1].Value, uint.Parse(m.Groups[2].Value), m.Groups[3].Value == "|");

            ms = rx.Matches(match.Groups[6].Value);
            foreach(Match m in ms)
                newr.AddItem(m.Groups[1].Value, uint.Parse(m.Groups[2].Value), m.Groups[3].Value == "|");

            ms = rx.Matches(match.Groups[7].Value);
            foreach(Match m in ms)
                newr.AddTool(m.Groups[1].Value, uint.Parse(m.Groups[2].Value), m.Groups[3].Value == "|");

            ms = rx.Matches(match.Groups[8].Value);
            foreach(Match m in ms)
                newr.AddOutput(m.Groups[1].Value, uint.Parse(m.Groups[2].Value));

            string[] last = match.Groups[9].Value.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            if(last.Length < 2) return false;
            if(last[0] != "exp") return false;
            newr.exp = uint.Parse(last[1]);
            if(last.Length % 2 != 0) return false;
            if(last.Length > 2)
            {
                if(last[2] != "script") return false;
                newr.script = last[3];
            }
            else newr.script = "";
            newlist.Add(newr);
            return true;
        }