Esempio n. 1
0
 private void EditSetsWindow_Load(object sender, EventArgs e)
 {
     sets = FindSetsNode();
     foreach (DataNode n in sets.SubNodes)
     {
         listSets.Items.Add(n.Key);
     }
 }
 private DataNode FindInSubNodes(DataNode searchFor, DataNode source)
 {
     foreach (DataNode n in source.SubNodes)
     {
         if (n == searchFor) return n;
         var subN = FindInSubNodes(searchFor, n);
         if (subN != null) return subN;
     }
     return null;
 }
 /// <summary>
 /// Finds the parent node of the given
 /// </summary>
 /// <param name="node">The node to find the parent of</param>
 /// <returns>The parent node or null when the node has no parent</returns>
 public DataNode FindParentNode(DataNode node)
 {
     foreach (DataNode n in RootNode.SubNodes)
     {
         if (n == node) return n.Parent;
         var subN = FindInSubNodes(node, n);
         if (subN != null) return subN;
     }
     return null;
 }
Esempio n. 4
0
 private void button1_Click(object sender, EventArgs e)
 {
     using (var win = new AddSetWindow())
     {
         string[] ret = win.ShowWindow();
         var node = new DataNode(ret[0], sets);
         /*node.SubNodes.Add(new DataNode());
         sets.SubNodes.Add();
         */
     }
 }
 public EnglishReference ShowWindow(string label)
 {
     s = MainWindow.FindEnglishTokens();
     if (s == null)
     {
         MessageBox.Show("tf_english.txt hasn't been opened yet!",
                         "TF2 Items Editor",
                         MessageBoxButtons.OK,
                         MessageBoxIcon.Error);
         Close();
         return new EnglishReference();
     }
     txtReference.Text = label;
     ShowDialog();
     return ret;
 }
		private void AttributesWindow_Shown(object sender, System.EventArgs e)
		{
			if (MainWindow.itemsParser == null)
			{
				MessageBox.Show("items_game.txt hasn't been opened yet!",
								"TF2 Items Editor",
								MessageBoxButtons.OK,
								MessageBoxIcon.Error);
				Hide();
				return;
			}
			attribsNode = MainWindow.itemsParser.RootNode.SubNodes.Find(n => n.Key == "attributes");
			listAttribs.Items.Clear();
			foreach (DataNode node in attribsNode.SubNodes)
			{
				listAttribs.Items.Add(node.SubNodes.Find(n => n.Key == "name").Value);
			}
		}
Esempio n. 7
0
 /// <summary>
 /// Initializes a DataNode with only a key (this DataNode can contain SubNodes instead of a value)
 /// </summary>
 /// <param name="key">The key</param>
 /// <param name="parent">The parent of this DataNode</param>
 public DataNode(string key, DataNode parent) : this(key)
 {
     Parent = parent;
 }
Esempio n. 8
0
 /// <summary>
 /// Initializes a DataNode with a key and a value
 /// </summary>
 /// <param name="key">The key</param>
 /// <param name="value">The value</param>
 /// <param name="parent">The parent of this DataNode</param>
 public DataNode(string key, string value, DataNode parent) : this(key,value)
 {
     Parent = parent;
 }
        /// <summary>
        /// Clears all nodes and loads them from <see cref="Path"/>
        /// </summary>
        public void LoadFile()
        {
            string[] lines = File.ReadAllLines(Path);
            RootNode = new DataNode();
            Regex           regex;
            MatchCollection matches;
            var             currentNode    = new DataNode();
            bool            multiLineValue = false;
            DataNode        multiLineNode  = new DataNode();

            foreach (string _line in lines)
            {
                string line = _line.TrimEnd(TrimChars).TrimStart(TrimChars).Replace("\r\n", ""); //Can't change the value of _line, trim whitespace chars and assign to line
                if (multiLineValue)
                {
                    regex   = new Regex("(.*)\"");
                    matches = regex.Matches(line);
                    if (matches.Count == 1)
                    {
                        multiLineNode.Value += matches[0].Groups[1];
                        multiLineValue       = false;
                        currentNode.SubNodes.Add(multiLineNode);
                        Console.Write(matches[0].Groups[1] + "\r\n");
                        continue;
                    }
                    regex   = new Regex("(.*)");
                    matches = regex.Matches(line);
                    if (matches.Count == 1)
                    {
                        multiLineNode.Value += matches[0].Groups[1] + "\r\n";
                        Console.Write(matches[0].Groups[1] + "\r\n");
                        continue;
                    }
                }
                regex   = new Regex("\"(.*?)\"");
                matches = regex.Matches(line);
                if (matches.Count == 1 && line.Count(f => f == '"') == 2)
                {
                    string k = matches[0].Groups[1].Value;
                    if (currentNode.Key == null)
                    {
                        currentNode = new DataNode(k);
                    }
                    else
                    {
                        var no = new DataNode(k, currentNode);
                        currentNode.SubNodes.Add(no);
                        currentNode = no;
                    }
                    continue;
                }

                if (line.Trim(new[] { ' ', '\r', '\n', '\t' }) == "{")
                {
                    continue;
                }
                if (line.Trim(new[] { ' ', '\r', '\n', '\t' }) == "}")
                {
                    currentNode = currentNode.Parent ?? currentNode;
                    continue;
                }
                regex   = new Regex(@"""(.*?)""\s*""(.*?)""");
                matches = regex.Matches(line);
                if (matches.Count > 1)
                {
                    throw new MultipleKeyValuePairException(line);
                }
                if (matches.Count == 1)
                {
                    var k = matches[0].Groups[1].Value;
                    var v = matches[0].Groups[2].Value;
                    currentNode.SubNodes.Add(new DataNode(k, v, currentNode));
                    continue;
                }
                regex   = new Regex(@"""(.*?)""\s*""(.*)");
                matches = regex.Matches(line);
                if (matches.Count == 1)
                {
                    multiLineValue = true;
                    multiLineNode  = new DataNode(matches[0].Groups[1].Value, matches[0].Groups[2].Value + "\r\n", currentNode);
                    continue;
                }
            }
            RootNode = currentNode;
        }
Esempio n. 10
0
        private void gridSetAttributes_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.StringFormat))
            {
                DataNode attribsNode = FindAttributesNode();
                DataNode attrib = null;
                foreach (DataNode dNode in attribsNode.SubNodes)
                {
                    string data = e.Data.GetData(DataFormats.StringFormat).ToString();
                    if (dNode.SubNodes.Find(n => n.Key == "name").Value == data) attrib = dNode;
                }

                if (attrib == null) return;
                string aClass = attrib.SubNodes.Find(n => n.Key == "attribute_class").Value;
                gridSetAttributes.Rows.Add(new[] { attrib.SubNodes.Find(n => n.Key == "name").Value, aClass, "0" });
                DataNode item = FindSet(comboSets.SelectedItem.ToString());
                var itemAttribs = new DataNode("attributes", item);
                bool found = false;
                foreach (DataNode no in item.SubNodes)
                {
                    if (no.Key == "attributes")
                    {
                        itemAttribs = no;
                        found = true;
                    }
                }
                var node = new DataNode(attrib.SubNodes.Find(n => n.Key == "name").Value, itemAttribs);
                node.SubNodes.Add(new DataNode("attribute_class", aClass, node));
                node.SubNodes.Add(new DataNode("value", "0", node));
                itemAttribs.SubNodes.Add(node);
                if (!found) item.SubNodes.Add(itemAttribs);
            }
        }
        private string GetWriteText(DataNode node)
        {
            string append = "";
            if (!String.IsNullOrEmpty(node.Key))
            {
                append += (_indent ? node.GetIndentString() : "") + "\"" + node.Key + "\"";
            }
            if (node.Value != null)
            {
                append += "\t\"" + node.Value + "\"\r\n";
            }
            else
            {
				append += "\r\n" + (_indent ? node.GetIndentString() : "") +"{\r\n";
            }
            foreach (DataNode sub in node.SubNodes)
            {
                append += GetWriteText(sub);
            }
            if (node.Value == null)
            {
				append += (_indent ? node.GetIndentString() : "") + "}\r\n";
            }
            return append;
        }
Esempio n. 12
0
 /// <summary>
 /// Initializes a DataNode with only a key (this DataNode can contain SubNodes instead of a value)
 /// </summary>
 /// <param name="key">The key</param>
 /// <param name="parent">The parent of this DataNode</param>
 public DataNode(string key, DataNode parent) : this(key)
 {
     Parent = parent;
 }
Esempio n. 13
0
 /// <summary>
 /// Initializes a DataNode with a key and a value
 /// </summary>
 /// <param name="key">The key</param>
 /// <param name="value">The value</param>
 /// <param name="parent">The parent of this DataNode</param>
 public DataNode(string key, string value, DataNode parent) : this(key, value)
 {
     Parent = parent;
 }
Esempio n. 14
0
 private void grid_attribs_CellValueChanged(object sender, DataGridViewCellEventArgs e)
 {
     if (comboItems.SelectedItem == null) return;
     DataNode item = FindItem(comboItems.SelectedItem.ToString());
     DataNode attrNode = item.SubNodes.Find(n => n.Key == "attributes");
     attrNode.SubNodes.Clear();
     foreach (DataGridViewRow r in grid_attribs.Rows)
     {
         var main = new DataNode(r.Cells[0].Value.ToString(), attrNode);
         main.SubNodes.Add(new DataNode("attribute_class", r.Cells[1].Value.ToString(), main));
         main.SubNodes.Add(new DataNode("value", r.Cells[2].Value.ToString(), main));
         attrNode.SubNodes.Add(main);
         
     }
 }
Esempio n. 15
0
 private void ReferenceWindow_Load(object sender, EventArgs e)
 {
     s = MainWindow.FindEnglishTokens();
     LoadReferences();   
 }
        /// <summary>
        /// Clears all nodes and loads them from <see cref="Path"/>
        /// </summary>
        public void LoadFile()
        {
            string[] lines = File.ReadAllLines(Path);
            RootNode = new DataNode();
            Regex regex;
            MatchCollection matches;
            var currentNode = new DataNode();
            bool multiLineValue = false;
            DataNode multiLineNode = new DataNode();
            foreach (string _line in lines)
            {
                string line = _line.TrimEnd(TrimChars).TrimStart(TrimChars).Replace("\r\n", ""); //Can't change the value of _line, trim whitespace chars and assign to line
                if (multiLineValue)
                {
                    regex = new Regex("(.*)\"");
                    matches = regex.Matches(line);
                    if (matches.Count == 1)
                    {
                        multiLineNode.Value += matches[0].Groups[1];
                        multiLineValue = false;
                        currentNode.SubNodes.Add(multiLineNode);
                        Console.Write(matches[0].Groups[1] + "\r\n");
                        continue;
                    }
                    regex = new Regex("(.*)");
                    matches = regex.Matches(line);
                    if (matches.Count == 1)
                    {
                        multiLineNode.Value += matches[0].Groups[1] + "\r\n";
                        Console.Write(matches[0].Groups[1] + "\r\n");
                        continue;
                    }
                }
                regex = new Regex("\"(.*?)\"");
                matches = regex.Matches(line);
                if (matches.Count == 1 && line.Count(f => f == '"') == 2)
                {
                    string k = matches[0].Groups[1].Value;
                    if (currentNode.Key == null)
                        currentNode = new DataNode(k);
                    else
                    {
                        var no = new DataNode(k, currentNode);
                        currentNode.SubNodes.Add(no);
                        currentNode = no;
                    }
                    continue;
                }

                if (line.Trim(new[] { ' ', '\r', '\n', '\t' }) == "{")
                {
                    continue;
                }
                if (line.Trim(new[] { ' ', '\r', '\n', '\t' }) == "}")
                {
                    currentNode = currentNode.Parent ?? currentNode;
                    continue;
                }
                regex = new Regex(@"""(.*?)""\s*""(.*?)""");
                matches = regex.Matches(line);
                if (matches.Count > 1)
                {
                    throw new MultipleKeyValuePairException(line);
                }
                if (matches.Count == 1)
                {
                    var k = matches[0].Groups[1].Value;
                    var v = matches[0].Groups[2].Value;
                    currentNode.SubNodes.Add(new DataNode(k, v, currentNode));
                    continue;
                }
                regex = new Regex(@"""(.*?)""\s*""(.*)");
                matches = regex.Matches(line);
                if (matches.Count == 1)
                {
                    multiLineValue = true;
                    multiLineNode = new DataNode(matches[0].Groups[1].Value, matches[0].Groups[2].Value + "\r\n", currentNode);
                    continue;
                }

            }
            RootNode = currentNode;

        }
Esempio n. 17
0
 private void gridSetAttributes_UserDeletedRow(object sender, DataGridViewRowEventArgs e)
 {
     DataNode attribsNode = FindSetsNode().SubNodes.Find(n => n.Key == comboSets.SelectedItem.ToString()).SubNodes.Find(n => n.Key == "attributes");
      attribsNode.SubNodes.Clear();
      foreach (DataGridViewRow r in gridSetAttributes.Rows)
      {
          var node = new DataNode(r.Cells[0].Value.ToString());
          node.SubNodes.Add(new DataNode("attribute_class", r.Cells[1].Value.ToString(), node));
          node.SubNodes.Add(new DataNode("value", r.Cells[2].Value.ToString(), node));
          attribsNode.SubNodes.Add(node);
      }
 }