/// <summary> /// Find a node of a specific type and label /// Recurse into the xml tree until we find it! /// </summary> /// <returns>The label node.</returns> /// <param name="label">Label of the node we are looking for</param> /// <param name="name">name of the node we are looking for</param> public BulletMLNode FindLabelNode(string strLabel, ENodeName eName) { //this uses breadth first search, since labelled nodes are usually top level //Check if any of our child nodes match the request for (int i = 0; i < ChildNodes.Count; i++) { if ((eName == ChildNodes[i].Name) && (strLabel == ChildNodes[i].Label)) { return(ChildNodes[i]); } } //recurse into the child nodes and see if we find any matches for (int i = 0; i < ChildNodes.Count; i++) { BulletMLNode foundNode = ChildNodes[i].FindLabelNode(strLabel, eName); if (null != foundNode) { return(foundNode); } } //didnt find a BulletMLNode with that name :( return(null); }
/// <summary> /// Get a direct child node of a specific type. Does not recurse! /// </summary> /// <returns>The child.</returns> /// <param name="name">type of node we want. null if not found</param> public BulletMLNode GetChild(ENodeName name) { foreach (BulletMLNode node in ChildNodes) { if (node.Name == name) { return(node); } } return(null); }
/// <summary> /// Gets the value of a specific type of child node for a task /// </summary> /// <returns>The child value. return 0.0 if no node found</returns> /// <param name="name">type of child node we want.</param> /// <param name="task">Task to get a value for</param> public float GetChildValue(ENodeName name, BulletMLTask task, Bullet bullet) { foreach (BulletMLNode tree in ChildNodes) { if (tree.Name == name) { return(tree.GetValue(task, bullet)); } } return(0.0f); }
/// <summary> /// given a label and name, find the task that matches /// </summary> /// <returns>The task by label and name.</returns> /// <param name="strLabel">String label of the task</param> /// <param name="eName">the name of the node the task should be attached to</param> public BulletMLTask FindTaskByLabelAndName(string strLabel, ENodeName eName) { //check if any of teh child tasks have a task with that label foreach (BulletMLTask childTask in Tasks) { BulletMLTask foundTask = childTask.FindTaskByLabelAndName(strLabel, eName); if (null != foundTask) { return(foundTask); } } return(null); }
/// <summary> /// Find a parent node of the specified node type /// </summary> /// <returns>The first parent node of that type, null if none found</returns> /// <param name="nodeType">Node type to find.</param> public BulletMLNode FindParentNode(ENodeName nodeType) { //first check if we have a parent node if (null == Parent) { return(null); } if (nodeType == Parent.Name) { //Our parent matches the query, return it! return(Parent); } //recurse into parent nodes to check grandparents, etc. return(Parent.FindParentNode(nodeType)); }
/// <summary> /// given a label and name, find the task that matches /// </summary> /// <returns>The task by label and name.</returns> /// <param name="strLabel">String label of the task</param> /// <param name="eName">the name of the node the task should be attached to</param> public BulletMLTask FindTaskByLabelAndName(string strLabel, ENodeName eName) { //check if this is the correct task if ((strLabel == Node.Label) && (eName == Node.Name)) { return(this); } //check if any of teh child tasks have a task with that label foreach (var childTask in ChildTasks) { var foundTask = childTask.FindTaskByLabelAndName(strLabel, eName); if (null != foundTask) { return(foundTask); } } return(null); }
/// <summary> /// Given a node type, create the correct node. /// </summary> /// <returns>An instance of the correct node type</returns> /// <param name="nodeType">Node type that we want.</param> public static BulletMLNode CreateNode(ENodeName nodeType) { switch (nodeType) { case ENodeName.bullet: { return new BulletNode(); } case ENodeName.action: { return new ActionNode(); } case ENodeName.fire: { return new FireNode(); } case ENodeName.changeDirection: { return new ChangeDirectionNode(); } case ENodeName.changeSpeed: { return new ChangeSpeedNode(); } case ENodeName.accel: { return new AccelNode(); } case ENodeName.wait: { return new WaitNode(); } case ENodeName.repeat: { return new RepeatNode(); } case ENodeName.bulletRef: { return new BulletRefNode(); } case ENodeName.actionRef: { return new ActionRefNode(); } case ENodeName.fireRef: { return new FireRefNode(); } case ENodeName.vanish: { return new VanishNode(); } case ENodeName.horizontal: { return new HorizontalNode(); } case ENodeName.vertical: { return new VerticalNode(); } case ENodeName.term: { return new TermNode(); } case ENodeName.times: { return new TimesNode(); } case ENodeName.direction: { return new DirectionNode(); } case ENodeName.speed: { return new SpeedNode(); } case ENodeName.param: { return new ParamNode(); } case ENodeName.trigger: { return new TriggerNode(); } case ENodeName.bulletml: { return new BulletMLNode(ENodeName.bulletml); } default: { throw new Exception("Unhandled type of ENodeName: \"" + nodeType.ToString() + "\""); } } }
/// <summary> /// Find a node of a specific type and label /// Recurse into the xml tree until we find it! /// </summary> /// <returns>The label node.</returns> /// <param name="label">Label of the node we are looking for</param> /// <param name="name">name of the node we are looking for</param> public BulletMLNode FindLabelNode(string strLabel, ENodeName eName) { //this uses breadth first search, since labelled nodes are usually top level //Check if any of our child nodes match the request for (int i = 0; i < ChildNodes.Count; i++) { if ((eName == ChildNodes[i].Name) && (strLabel == ChildNodes[i].Label)) { return ChildNodes[i]; } } //recurse into the child nodes and see if we find any matches for (int i = 0; i < ChildNodes.Count; i++) { BulletMLNode foundNode = ChildNodes[i].FindLabelNode(strLabel, eName); if (null != foundNode) { return foundNode; } } //didnt find a BulletMLNode with that name :( return null; }
/// <summary> /// Initializes a new instance of the <see cref="BulletMLLib.BulletNode"/> class. /// this is the constructor used by sub classes /// </summary> /// <param name="eNodeType">the node type.</param> public BulletNode(ENodeName eNodeType) : base(eNodeType) { }
/// <summary> /// Initializes a new instance of the <see cref="BulletMLLib.BulletMLNode"/> class. /// </summary> public BulletMLNode(ENodeName nodeType) { ChildNodes = new List <BulletMLNode>(); Name = nodeType; NodeType = ENodeType.none; }
/// <summary> /// given a label and name, find the task that matches /// </summary> /// <returns>The task by label and name.</returns> /// <param name="strLabel">String label of the task</param> /// <param name="eName">the name of the node the task should be attached to</param> public BulletMLTask FindTaskByLabelAndName(string strLabel, ENodeName eName) { //check if any of teh child tasks have a task with that label foreach (BulletMLTask childTask in Tasks) { BulletMLTask foundTask = childTask.FindTaskByLabelAndName(strLabel, eName); if (null != foundTask) { return foundTask; } } return null; }
/// <summary> /// Get a direct child node of a specific type. Does not recurse! /// </summary> /// <returns>The child.</returns> /// <param name="name">type of node we want. null if not found</param> public BulletMLNode GetChild(ENodeName name) { foreach (BulletMLNode node in ChildNodes) { if (node.Name == name) { return node; } } return null; }
/// <summary> /// Initializes a new instance of the <see cref="BulletMLLib.BulletMLNode"/> class. /// </summary> public BulletMLNode(ENodeName nodeType) { ChildNodes = new List<BulletMLNode>(); Name = nodeType; NodeType = ENodeType.none; }
/// <summary> /// Given a node type, create the correct node. /// </summary> /// <returns>An instance of the correct node type</returns> /// <param name="nodeType">Node type that we want.</param> public static BulletMLNode CreateNode(ENodeName nodeType) { switch (nodeType) { case ENodeName.bullet: { return(new BulletNode()); } case ENodeName.action: { return(new ActionNode()); } case ENodeName.fire: { return(new FireNode()); } case ENodeName.changeDirection: { return(new ChangeDirectionNode()); } case ENodeName.changeSpeed: { return(new ChangeSpeedNode()); } case ENodeName.accel: { return(new AccelNode()); } case ENodeName.wait: { return(new WaitNode()); } case ENodeName.repeat: { return(new RepeatNode()); } case ENodeName.bulletRef: { return(new BulletRefNode()); } case ENodeName.actionRef: { return(new ActionRefNode()); } case ENodeName.fireRef: { return(new FireRefNode()); } case ENodeName.vanish: { return(new VanishNode()); } case ENodeName.horizontal: { return(new HorizontalNode()); } case ENodeName.vertical: { return(new VerticalNode()); } case ENodeName.term: { return(new TermNode()); } case ENodeName.times: { return(new TimesNode()); } case ENodeName.direction: { return(new DirectionNode()); } case ENodeName.speed: { return(new SpeedNode()); } case ENodeName.param: { return(new ParamNode()); } case ENodeName.bulletml: { return(new BulletMLNode(ENodeName.bulletml)); } default: { throw new Exception("Unhandled type of ENodeName: \"" + nodeType.ToString() + "\""); } } }
/// <summary> /// Initializes a new instance of the <see cref="BulletMLLib.FireNode"/> class. /// this is the constructor used by sub classes /// </summary> /// <param name="eNodeType">the node type.</param> public FireNode(ENodeName eNodeType) : base(eNodeType) { }
/// <summary> /// Initializes a new instance of the <see cref="BulletMLLib.ActionNode"/> class. /// this is the constructor used by sub classes /// </summary> /// <param name="eNodeType">the node type.</param> public ActionNode(ENodeName eNodeType) : base(eNodeType) { }
/// <summary> /// given a label and name, find the task that matches /// </summary> /// <returns>The task by label and name.</returns> /// <param name="strLabel">String label of the task</param> /// <param name="eName">the name of the node the task should be attached to</param> public BulletMLTask FindTaskByLabelAndName(string strLabel, ENodeName eName) { //check if this is the corretc task if ((strLabel == Node.Label) && (eName == Node.Name)) { return this; } //check if any of teh child tasks have a task with that label foreach (BulletMLTask childTask in ChildTasks) { BulletMLTask foundTask = childTask.FindTaskByLabelAndName(strLabel, eName); if (null != foundTask) { return foundTask; } } return null; }
/// <summary> /// Find a parent node of the specified node type /// </summary> /// <returns>The first parent node of that type, null if none found</returns> /// <param name="nodeType">Node type to find.</param> public BulletMLNode FindParentNode(ENodeName nodeType) { //first check if we have a parent node if (null == Parent) { return null; } else if (nodeType == Parent.Name) { //Our parent matches the query, reutrn it! return Parent; } else { //recurse into parent nodes to check grandparents, etc. return Parent.FindParentNode(nodeType); } }
/// <summary> /// Gets the value of a specific type of child node for a task /// </summary> /// <returns>The child value. return 0.0 if no node found</returns> /// <param name="name">type of child node we want.</param> /// <param name="task">Task to get a value for</param> public float GetChildValue(ENodeName name, BulletMLTask task, Bullet bullet) { foreach (BulletMLNode tree in ChildNodes) { if (tree.Name == name) { return tree.GetValue(task, bullet); } } return 0.0f; }