private void LoadLogic(string logicString) { logicString = Migrator.ApplyMigrations(logicString); var logic = LogicFile.FromJson(logicString); try { var itemsById = logic.Logic.ToDictionary(item => item.Id); VerifyLogic(logic, itemsById); _logic = logic; _itemsById = itemsById; _singleItemSelectorForm.SetLogicFile(_logic); _multiItemSelectorForm.SetLogicFile(_logic); nItem.Maximum = _logic.Logic.Count - 1; SetIndex((int)nItem.Value); } catch (Exception e) { MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void mImport_Click(object sender, EventArgs e) { if (openLogic.ShowDialog() == DialogResult.OK) { using (var logicFile = new StreamReader(File.Open(openLogic.FileName, FileMode.Open))) { var logicString = logicFile.ReadToEnd(); logicString = Migrator.ApplyMigrations(logicString); LoadLogic(logicString); } } }
private void LoadLogic(string logicString) { logicString = Migrator.ApplyMigrations(logicString); ItemList = new List <ItemLogic>(); string[] lines = logicString.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); ItemSelectorForm.ResetItems(); ITEM_NAMES = DEFAULT_ITEM_NAMES.ToArray(); int i = 0; while (true) { if (i == lines.Length) { break; } if (lines[i].StartsWith("#")) { i++; continue; } if (lines[i].Contains("-")) { var itemName = lines[i].Substring(2); if (ItemList.Count >= ITEM_NAMES.Length) { var newList = ITEM_NAMES.ToList(); newList.Add(itemName); ItemSelectorForm.AddItem(itemName); ITEM_NAMES = newList.ToArray(); } i++; continue; } else { ItemLogic l = new ItemLogic(); l.Dependence = new List <int>(); if (lines[i] != "") { foreach (string j in lines[i].Split(',')) { l.Dependence.Add(Convert.ToInt32(j)); } ; } ; l.Conditional = new List <List <int> >(); if (lines[i + 1] != "") { foreach (string j in lines[i + 1].Split(';')) { List <int> c = new List <int>(); foreach (string k in j.Split(',')) { c.Add(Convert.ToInt32(k)); } ; l.Conditional.Add(c); } ; } ; l.Time_Needed = Convert.ToInt32(lines[i + 2]); l.Time_Available = Convert.ToInt32(lines[i + 3]); var trickInfo = lines[i + 4].Split(new char[] { ';' }, 2); l.IsTrick = trickInfo.Length > 1; l.TrickTooltip = l.IsTrick ? trickInfo[1] : null; if (string.IsNullOrWhiteSpace(l.TrickTooltip)) { l.TrickTooltip = null; } ItemList.Add(l); i += 5; }; } ; nItem.Maximum = ITEM_NAMES.Length - 1; SetIndex((int)nItem.Value); }
private void mImport_Click(object sender, EventArgs e) { if (openLogic.ShowDialog() == DialogResult.OK) { StreamReader LogicFile = new StreamReader(File.Open(openLogic.FileName, FileMode.Open)); ItemList = new List <ItemLogic>(); var logicString = LogicFile.ReadToEnd(); logicString = Migrator.ApplyMigrations(logicString); string[] lines = logicString.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); ItemSelectorForm.ResetItems(); ITEM_NAMES = DEFAULT_ITEM_NAMES.ToArray(); int i = 0; while (true) { if (i == lines.Length) { break; } ; if (lines[i].Contains("-")) { var itemName = lines[i].Substring(2); if (ItemList.Count >= ITEM_NAMES.Length) { var newList = ITEM_NAMES.ToList(); newList.Add(itemName); ItemSelectorForm.AddItem(itemName); ITEM_NAMES = newList.ToArray(); } i++; continue; } else { ItemLogic l = new ItemLogic(); l.Dependence = new List <int>(); if (lines[i] != "") { foreach (string j in lines[i].Split(',')) { l.Dependence.Add(Convert.ToInt32(j)); } ; } ; l.Conditional = new List <List <int> >(); if (lines[i + 1] != "") { foreach (string j in lines[i + 1].Split(';')) { List <int> c = new List <int>(); foreach (string k in j.Split(',')) { c.Add(Convert.ToInt32(k)); } ; l.Conditional.Add(c); } ; } ; l.Time_Needed = Convert.ToInt32(lines[i + 2]); l.Time_Available = Convert.ToInt32(lines[i + 3]); ItemList.Add(l); i += 4; }; } ; LogicFile.Close(); nItem.Value = 1; nItem.Value = 0; nItem.Maximum = ITEM_NAMES.Length - 1; } ; }