public static NodeData CreateVectorNode(int x, int y) { NodeData union = new NodeData(); union.x = x; union.y = y; return union; }
public static NodeData CreateAudioNode(uint id, uint length) { NodeData union = new NodeData(); union.id = id; union.length = length; return union; }
public static NodeData CreateBitmapNode(uint id, ushort width, ushort height) { NodeData union = new NodeData(); union.id = id; union.width = width; union.height = height; return union; }
private Node LoadNode(XmlReader reader, Node node = null) { if (reader == null) { throw new ArgumentNullException(); } if (node == null) { if (!reader.HasAttributes) { throw new ArgumentException(); } string name = null; Node.DataType type = Node.DataType.Empty; NodeData data = new NodeData(); while (reader.MoveToNextAttribute()) { switch (reader.Name) { case "name": name = reader.Value; break; case "type": byte btype = 0; if (!byte.TryParse(reader.Value, out btype)) { switch (reader.Value.ToLower()) { case "int": case "long": case "integer": btype = 1; break; case "float": case "double": case "decimal": btype = 2; break; case "str": case "text": case "string": btype = 3; break; case "vec": case "point": case "position": case "pos": case "location": case "loc": case "coord": case "coordinate": case "vector": btype = 4; break; case "png": case "img": case "image": case "canvas": case "bitmap": btype = 5; break; case "mp3": case "music": case "sound": case "track": case "audio": btype = 6; break; case "none": case "empty": default: btype = 0; break; } } type = (Node.DataType)btype; break; case "value": switch (type) { case Node.DataType.Integer: data.Integer = long.Parse(reader.Value); break; case Node.DataType.Decimal: if (!long.TryParse(reader.Value, out data.Integer)) { data.Decimal = double.Parse(reader.Value); } break; case Node.DataType.String: if (!long.TryParse(reader.Value, out data.Integer)) { data.String = uint.Parse(reader.Value); } break; case Node.DataType.Vector: if (!long.TryParse(reader.Value, out data.Integer)) { data.x = int.Parse(reader.Value.Split(',')[0]); data.y = int.Parse(reader.Value.Split(',')[1]); } break; case Node.DataType.Bitmap: if (!long.TryParse(reader.Value, out data.Integer)) { data.id = uint.Parse(reader.Value.Split(',')[0]); data.width = ushort.Parse(reader.Value.Split(',')[1]); data.height = ushort.Parse(reader.Value.Split(',')[2]); } break; case Node.DataType.Audio: if (!long.TryParse(reader.Value, out data.Integer)) { data.id = uint.Parse(reader.Value.Split(',')[0]); data.length = uint.Parse(reader.Value.Split(',')[1]); } break; } break; } } reader.MoveToElement(); return new Node(name, type, data); } else { if (reader.IsEmptyElement) { return null; } while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: Node child = LoadNode(reader, null); node[child.Name] = child; LoadNode(reader, child); break; case XmlNodeType.EndElement: return null; default: break; } } } return null; }
public Node(string name, DataType type, NodeData data) { if (name == null) throw new ArgumentNullException(); Name = name; Data = data; }
public static NodeData CreateStringNode(uint stringid) { NodeData union = new NodeData(); union.String = stringid; return union; }
public static NodeData CreateIntegerNode(long intval) { NodeData union = new NodeData(); union.Integer = intval; return union; }
public static NodeData CreateDecimalNode(double decval) { NodeData union = new NodeData(); union.Decimal = decval; return union; }