public CNodeInfo(EndianBinaryReaderEx reader, CPSSGFile file) { attributeInfo = new SortedDictionary <int, CAttributeInfo>(); id = reader.ReadInt32(); name = reader.ReadPSSGString(); int attributeInfoCount = reader.ReadInt32(); CAttributeInfo ai; for (int i = 0; i < attributeInfoCount; i++) { ai = new CAttributeInfo(reader); attributeInfo.Add(ai.id, ai); file.attributeInfo[ai.id - 1] = ai; } }
public void RemoveAttributeInfo(int id) { // Shift all succeeding attributeInfos and change their id // for (int i = id - 1; i < attributeInfo.Length - 1; i++) { attributeInfo[i] = attributeInfo[i + 1]; attributeInfo[i].id--; //attributeInfo[i].id = i + 1; } Array.Resize(ref attributeInfo, attributeInfo.Length - 1); // Fix the NodeInfos foreach (CNodeInfo nInfo in nodeInfo) { List <int> keys = new List <int>(nInfo.attributeInfo.Keys); //keys.Sort(); if (nInfo.attributeInfo.ContainsKey(id) == true) { nInfo.attributeInfo.Remove(id); for (int i = id + 1; nInfo.attributeInfo.ContainsKey(i); i++) { CAttributeInfo aInfo = attributeInfo[i - 2]; nInfo.attributeInfo.Remove(i); nInfo.attributeInfo.Add(i - 1, aInfo); } } else { for (int i = 0; i < keys.Count; i++) { if (keys[i] > id) { CAttributeInfo aInfo = attributeInfo[keys[i] - 2]; nInfo.attributeInfo.Remove(keys[i]); nInfo.attributeInfo.Add(keys[i] - 1, aInfo); } } } } // Edit CNode to fix CAttr.id if (rootNode != null) { rootNode.RemoveAttributeInfo(id); } }
public CAttributeInfo AddAttributeInfo(string name, CNodeInfo nodeInfo) { // For each attributeInfo in nodeInfo, the ids have to be consecutive if (GetAttributeInfo(name).Length > 0) { return null; } if (attributeInfo == null) { attributeInfo = new CAttributeInfo[1]; } else { Array.Resize(ref attributeInfo, attributeInfo.Length + 1); } int newID = 0; List<int> currentKeys = new List<int>(nodeInfo.attributeInfo.Keys); if (currentKeys.Count > 0) { foreach (int k in currentKeys) { newID = Math.Max(newID, k); } newID++; } else { newID = attributeInfo.Length; } CAttributeInfo attrInfo = new CAttributeInfo(newID, name); if (newID == attributeInfo.Length) { attributeInfo[attrInfo.id - 1] = attrInfo; this.nodeInfo[nodeInfo.id - 1].attributeInfo.Add(attrInfo.id, attrInfo); } else { for (int i = attributeInfo.Length - 2; i >= newID - 1; i--) { attributeInfo[i + 1] = attributeInfo[i]; attributeInfo[i + 1].id = i + 2; } attributeInfo[attrInfo.id - 1] = attrInfo; this.nodeInfo[nodeInfo.id - 1].attributeInfo.Add(attrInfo.id, attrInfo); // Fix the NodeInfos foreach (CNodeInfo nInfo in this.nodeInfo) { List<int> keys = new List<int>(nInfo.attributeInfo.Keys); //keys.Sort(); if (nInfo != nodeInfo) { for (int i = keys.Count - 1; i >= 0; i--) { if (keys[i] >= newID) { CAttributeInfo aInfo = attributeInfo[keys[i]]; nInfo.attributeInfo.Remove(keys[i]); nInfo.attributeInfo.Add(keys[i] + 1, aInfo); } } } } // Edit CNode to fix CAttr.id rootNode.AddAttributeInfo(newID); } return attrInfo; }
public CAttributeInfo AddAttributeInfo(string name, CNodeInfo nodeInfo) { // For each attributeInfo in nodeInfo, the ids have to be consecutive if (GetAttributeInfo(name).Length > 0) { return(null); } if (attributeInfo == null) { attributeInfo = new CAttributeInfo[1]; } else { Array.Resize(ref attributeInfo, attributeInfo.Length + 1); } int newID = 0; List <int> currentKeys = new List <int>(nodeInfo.attributeInfo.Keys); if (currentKeys.Count > 0) { foreach (int k in currentKeys) { newID = Math.Max(newID, k); } newID++; } else { newID = attributeInfo.Length; } CAttributeInfo attrInfo = new CAttributeInfo(newID, name); if (newID == attributeInfo.Length) { attributeInfo[attrInfo.id - 1] = attrInfo; this.nodeInfo[nodeInfo.id - 1].attributeInfo.Add(attrInfo.id, attrInfo); } else { for (int i = attributeInfo.Length - 2; i >= newID - 1; i--) { attributeInfo[i + 1] = attributeInfo[i]; attributeInfo[i + 1].id = i + 2; } attributeInfo[attrInfo.id - 1] = attrInfo; this.nodeInfo[nodeInfo.id - 1].attributeInfo.Add(attrInfo.id, attrInfo); // Fix the NodeInfos foreach (CNodeInfo nInfo in this.nodeInfo) { List <int> keys = new List <int>(nInfo.attributeInfo.Keys); //keys.Sort(); if (nInfo != nodeInfo) { for (int i = keys.Count - 1; i >= 0; i--) { if (keys[i] >= newID) { CAttributeInfo aInfo = attributeInfo[keys[i]]; nInfo.attributeInfo.Remove(keys[i]); nInfo.attributeInfo.Add(keys[i] + 1, aInfo); } } } } // Edit CNode to fix CAttr.id rootNode.AddAttributeInfo(newID); } return(attrInfo); }
public CNodeInfo(EndianBinaryReaderEx reader, CPSSGFile file) { attributeInfo = new SortedDictionary<int, CAttributeInfo>(); id = reader.ReadInt32(); name = reader.ReadPSSGString(); int attributeInfoCount = reader.ReadInt32(); CAttributeInfo ai; for (int i = 0; i < attributeInfoCount; i++) { ai = new CAttributeInfo(reader); attributeInfo.Add(ai.id, ai); file.attributeInfo[ai.id - 1] = ai; } }