public override DesignData ImportDesign() { string filename = GetImportFileName(); if (!File.Exists(filename)) { return(null); } DesignData design = new DesignData(); DesignItemCol designItems = new DesignItemCol(); StreamReader reader = new StreamReader(File.OpenRead(filename)); string[] TextArr; string Text; char[] Separator = { ' ' }; try { while (reader.Peek() > -1) { Text = reader.ReadLine(); if (IsMultiBlock(Text)) { TextArr = Text.Split(Separator); DesignItem designItem = new DesignItem(); designItem.ItemID = short.Parse(TextArr[0]); designItem.X = int.Parse(TextArr[1]); designItem.Y = int.Parse(TextArr[2]); designItem.Z = int.Parse(TextArr[3]); designItems.Add(designItem); } } design.ImportItems(designItems, true, false); } catch { } finally { reader.Close(); } return(design); }
// Extract the user selected items private void StartExtraction(object state) { ExtractRequestArgs args = CreateExtractRequestArgs(); // submit the request to the server ExtractResponse resp = Connection.ExtractDesign(args); if (resp == null) { RaiseExtractedEvent(null); return; } else { _items = resp.Items != null ? resp.Items : new DesignItemCol(); } if (_frozen && _mode == ExtractMode.Area) { for (int i = 0; i < resp.Rects.Count; ++i) { ExtractFrozenItems(resp.Rects[i], resp.Map, _hues); } } if (resp == null || resp.Items.Count == 0) { RaiseExtractedEvent(null); } DesignData design = null; if (resp.Items.Count > 0) { design = new DesignData(_name, _category, _subsection); design.ImportItems(resp.Items, true, _foundation); } RaiseExtractedEvent(design); }
public ArrayList ImportDesigns() { ArrayList designs = new ArrayList(); string filename = GetImportFileName(); if (filename == null || !File.Exists(filename)) { return(designs); } try { using (StreamReader reader = new StreamReader(File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read))) { string line; char[] delimiter = new char[] { '\t' }; DesignData design = null; DesignItemCol designItems = new DesignItemCol(); while ((line = reader.ReadLine()) != null) { if (line.Length == 0) { continue; } string[] Values = line.Split(delimiter); if (Values.Length > 5) // this is the multi header line { if (design != null && designItems.Count > 0) { design.ImportItems(designItems, true, true); designs.Add(design); design = null; designItems.Clear(); } design = new DesignData("Multi " + designs.Count + 1, "multicache", "misc"); } else if (Values.Length == 5) // this is a multi component { if (design != null) { DesignItem item = new DesignItem(); item.ItemID = Convert.ToInt16(Values[0]); item.X = Convert.ToInt32(Values[2]); item.Y = Convert.ToInt32(Values[3]); item.Z = Convert.ToInt32(Values[4]); if (item.ItemID != 1) { designItems.Add(item); } } } } reader.Close(); if (design != null && designItems.Count > 0) { design.ImportItems(designItems, true, true); designs.Add(design); } } } catch { } return(designs); }
public override DesignData ImportDesign() { string filename = GetImportFileName(); if (!File.Exists(filename)) { return(null); } DesignData design = new DesignData(); DesignItemCol designItems = new DesignItemCol(); char[] Separator = { ' ' }; try { XmlDocument document = new XmlDocument(); document.Load(filename); XmlNodeList itemNodes = document.SelectNodes("//export/tile"); for (int i = 0; i < itemNodes.Count; ++i) { XmlNode node = itemNodes[i]; string Value = null; int id = 0; int x = 0; int y = 0; int z = 0; int hue = 0; Value = node.Attributes.GetNamedItem("id").Value; if (Value != null && Value.Length > 0) { id = int.Parse(Value); } Value = node.Attributes.GetNamedItem("x").Value; if (Value != null && Value.Length > 0) { x = int.Parse(Value); } Value = node.Attributes.GetNamedItem("y").Value; if (Value != null && Value.Length > 0) { y = int.Parse(Value); } Value = node.Attributes.GetNamedItem("z").Value; if (Value != null && Value.Length > 0) { z = int.Parse(Value); } Value = node.Attributes.GetNamedItem("hue").Value; if (Value != null && Value.Length > 0) { hue = int.Parse(Value); } designItems.Add(new DesignItem(id, x, y, z, GetZLevel(z), hue)); } design.ImportItems(designItems, true, false); } catch (Exception e) { design = null; MessageBox.Show("The import failed due to the following error.\n" + e.Message); } return(design); }