/// <summary> /// Initializes a new instance of the <see cref="BulletMLLib.BulletMLAction"/> class. /// </summary> /// <param name="repeatNumMax">Repeat number max.</param> /// <param name="node">Node.</param> /// <param name="owner">Owner.</param> public BulletMLAction(int repeatNumMax, BulletMLNode node, BulletMLTask owner) : base(node, owner) { Debug.Assert(null != Node); Debug.Assert(null != Owner); this.RepeatNumMax = repeatNumMax; }
/// <summary> /// Initializes a new instance of the <see cref="BulletMLLib.BulletMLTask"/> class. /// </summary> /// <param name="node">Node.</param> /// <param name="owner">Owner.</param> public BulletMLTask(BulletMLNode node, BulletMLTask owner) { ChildTasks = new List<BulletMLTask>(); ParamList = new List<float>(); TaskFinished = false; this.Owner = owner; this.Node = node; }
/// <summary> /// Initializes a new instance of the <see cref="BulletMLLib.BulletMLFire"/> class. /// </summary> /// <param name="node">Node.</param> /// <param name="owner">Owner.</param> public BulletMLFire(BulletMLNode node, BulletMLTask owner) : base(node, owner) { Debug.Assert(null != Node); Debug.Assert(null != Owner); //First try and get the nodes striaght from our node DirNode = node.GetChild(ENodeName.direction); SpeedNode = node.GetChild(ENodeName.speed); RefNode = node.GetChild(ENodeName.bulletRef); BulletNode = node.GetChild(ENodeName.bullet); //ok fire nodes HAVE TO have either a ref or a bullet node Debug.Assert((null != RefNode) || (null != BulletNode)); //what we gonna use to set the direction if we couldnt find a node? if (null == DirNode) { if (null != RefNode) { //Get the direction from the reference node DirNode = RefNode.GetChild(ENodeName.direction); } else if (BulletNode != null) { //Set teh driection from teh bullet node DirNode = BulletNode.GetChild(ENodeName.direction); } } //what we gonna use to set teh speed if we couldnt find a node? if (null == SpeedNode) { if (null != RefNode) { //set the speed from teh refernce node SpeedNode = RefNode.GetChild(ENodeName.speed); } else if (null != BulletNode) { //set teh speed from the bullet node SpeedNode = BulletNode.GetChild(ENodeName.speed); } } }
/// <summary> /// Initializes a new instance of the <see cref="BulletMLLib.BulletMLTask"/> class. /// </summary> /// <param name="node">Node.</param> /// <param name="owner">Owner.</param> public BulletMLChangeSpeed(BulletMLNode node, BulletMLTask owner) : base(node, owner) { Debug.Assert(null != Node); Debug.Assert(null != Owner); }
/// <summary> /// Initializes a new instance of the <see cref="BulletMLLib.BulletMLTask"/> class. /// </summary> /// <param name="node">Node.</param> /// <param name="owner">Owner.</param> public BulletMLAccel(BulletMLNode node, BulletMLTask owner) : base(node, owner) { Debug.Assert(null != Node); Debug.Assert(null != Owner); }
/// <summary> /// Initialize this bullet with a top level node /// </summary> /// <param name="rootNode">This is a top level node... find the first "top" node and use it to define this bullet</param> public void InitTop(BulletMLNode rootNode) { Debug.Assert(null != rootNode); //clear everything out _tasks.Clear(); _fireData.Clear(); _activeTaskNum = 0; //Grab that top level node MyNode = rootNode; //okay find the item labelled 'top' BulletMLNode topNode = rootNode.FindLabelNode("top", ENodeName.action); if (topNode != null) { //We found a top node, add a task for it, also add a firedata for the task BulletMLTask task = CreateTask(); //parse the nodes into the task list task.Parse(topNode, this); } else { //ok there is no 'top' node, so that means we have a list of 'top#' nodes for (int i = 1; i < 10; i++) { topNode = rootNode.FindLabelNode("top" + i, ENodeName.action); if (topNode != null) { //found a top num node, add a task and firedata for it BulletMLTask task = CreateTask(); //parse the nodes into the task list task.Parse(topNode, this); } } } }
/// <summary> /// This bullet is fired from another bullet, initialize it from the node that fired it /// </summary> /// <param name="subNode">Sub node that defines this bullet</param> public void Init(BulletMLNode subNode) { Debug.Assert(null != subNode); //clear everything out _activeTaskNum = 0; //Grab that top level node MyNode = subNode; //Either get the first task, or create a task for the node //If this dude is from a FireRef task, there will already be a plain task in there with all the required params BulletMLTask task = ((0 != _tasks.Count) ? _tasks[0] : CreateTask()); //parse the nodes into the task list task.Parse(subNode, this); }
/// BulletMLの弾幕定義を自分にセット public void SetBullet(BulletMLNode tree) { InitTop(tree); }
/// <summary> /// Initializes a new instance of the <see cref="BulletMLLib.BulletMLTask"/> class. /// </summary> /// <param name="node">Node.</param> /// <param name="owner">Owner.</param> public BulletMLSetDirection(BulletMLNode node, BulletMLTask owner) : base(node, owner) { Debug.Assert(null != Node); Debug.Assert(null != Owner); }
/// <summary> /// Parses a bulletml document into this bullet pattern /// </summary> /// <param name="xmlFileName">Xml file name.</param> public bool ParseXML(string xmlFileName) { XmlReaderSettings settings = new XmlReaderSettings(); settings.DtdProcessing = DtdProcessing.Ignore; using (XmlReader reader = XmlReader.Create(xmlFileName, settings)) { //Open the file. XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(reader); XmlNode rootXmlNode = xmlDoc.DocumentElement; //make sure it is actually an xml node if (rootXmlNode.NodeType == XmlNodeType.Element) { //eat up the name of that xml node string strElementName = rootXmlNode.Name; if (("bulletml" != strElementName) || !rootXmlNode.HasChildNodes) { //The first node HAS to be bulletml Debug.Assert(false); return false; } //Create the root node of the bulletml tree RootNode = new BulletMLNode(); //Read in the whole bulletml tree if (!RootNode.Parse(rootXmlNode, null)) { //an error ocurred reading in the tree return false; } Debug.Assert(ENodeName.bulletml == RootNode.Name); //Find what kind of pattern this is: horizontal or vertical XmlNamedNodeMap mapAttributes = rootXmlNode.Attributes; for (int i = 0; i < mapAttributes.Count; i++) { //will only have the name attribute string strName = mapAttributes.Item(i).Name; string strValue = mapAttributes.Item(i).Value; if ("type" == strName) { //if this is a top level node, "type" will be veritcal or horizontal Orientation = StringToPatternType(strValue); } } } else { //should be an xml node!!! Debug.Assert(false); return false; } } //grab that filename Filename = xmlFileName; return true; }
/// <summary> /// Parse a specified node and bullet into this task /// </summary> /// <param name="myNode">the node for this dude</param> /// <param name="bullet">the bullet this dude is controlling</param> public virtual void Parse(BulletMLNode myNode, Bullet bullet) { Debug.Assert(null != myNode); Debug.Assert(null != bullet); foreach (BulletMLNode childNode in myNode.ChildNodes) { //construct the correct type of node switch (childNode.Name) { case ENodeName.repeat: { Parse(childNode, bullet); } break; case ENodeName.action: { int repeatNum = 1; //find how many times to repeat this action BulletMLNode RepeatNode = childNode.FindParentNode(ENodeName.repeat); if (null != RepeatNode) { repeatNum = (int)RepeatNode.GetChildValue(ENodeName.times, this); } BulletMLAction task = new BulletMLAction(repeatNum, myNode, this); ChildTasks.Add(task); task.Parse(childNode, bullet); } break; case ENodeName.actionRef: { //find the referenced node BulletMLNode refNode = myNode.GetRootNode().FindLabelNode(childNode.Label, ENodeName.action); //find how many times to repeat the referenced action int repeatNum = 1; BulletMLNode RepeatNode = myNode.FindParentNode(ENodeName.repeat); if (null != RepeatNode) { repeatNum = (int)RepeatNode.GetChildValue(ENodeName.times, this); } BulletMLAction task = new BulletMLAction(repeatNum, refNode, this); ChildTasks.Add(task); for (int i = 0; i < childNode.ChildNodes.Count; i++) { task.ParamList.Add(childNode.ChildNodes[i].GetValue(this)); } task.Parse(refNode, bullet); } break; case ENodeName.changeSpeed: { ChildTasks.Add(new BulletMLChangeSpeed(childNode, this)); } break; case ENodeName.changeDirection: { ChildTasks.Add(new BulletMLChangeDirection(childNode, this)); } break; case ENodeName.fire: { ChildTasks.Add(new BulletMLFire(childNode, this)); } break; case ENodeName.fireRef: { //find the node that was referenced BulletMLNode refNode = myNode.GetRootNode().FindLabelNode(childNode.Label, ENodeName.fire); BulletMLFire fire = new BulletMLFire(refNode, this); ChildTasks.Add(fire); for (int i = 0; i < childNode.ChildNodes.Count; i++) { fire.ParamList.Add(childNode.ChildNodes[i].GetValue(this)); } } break; case ENodeName.wait: { ChildTasks.Add(new BulletMLWait(childNode, this)); } break; case ENodeName.speed: { //speed nodes are special, just pull the value out and set up the bullet bullet.GetFireData().speedInit = true; bullet.Velocity = childNode.GetValue(this); } break; case ENodeName.direction: { ChildTasks.Add(new BulletMLSetDirection(childNode, this)); } break; case ENodeName.vanish: { ChildTasks.Add(new BulletMLVanish(childNode, this)); } break; case ENodeName.accel: { ChildTasks.Add(new BulletMLAccel(childNode, this)); } break; } } //After all the nodes are read in, initialize the node Init(); }
/// <summary> /// Initializes a new instance of the <see cref="BulletMLLib.BulletMLTask"/> class. /// </summary> /// <param name="node">Node.</param> /// <param name="owner">Owner.</param> public BulletMLWait(BulletMLNode node, BulletMLTask owner) : base(node, owner) { Debug.Assert(null != Node); Debug.Assert(null != Owner); }
/// <summary> /// Parse the specified bulletNodeElement. /// Read all the data from the xml node into this dude. /// </summary> /// <param name="bulletNodeElement">Bullet node element.</param> public bool Parse(XmlNode bulletNodeElement, BulletMLNode parentNode) { Debug.Assert(null != bulletNodeElement); //grab the parent node Parent = parentNode; //get the node type Name = BulletMLNode.StringToName(bulletNodeElement.Name); //Parse all our attributes XmlNamedNodeMap mapAttributes = bulletNodeElement.Attributes; for (int i = 0; i < mapAttributes.Count; i++) { string strName = mapAttributes.Item(i).Name; string strValue = mapAttributes.Item(i).Value; if ("type" == strName) { //skip the type attribute in top level nodes if (ENodeName.bulletml == Name) { continue; } //get the bullet node type NodeType = BulletMLNode.StringToType(strValue); } else if ("label" == strName) { //label is just a text value Label = strValue; } } //parse all the child nodes if (bulletNodeElement.HasChildNodes) { for (XmlNode childNode = bulletNodeElement.FirstChild; null != childNode; childNode = childNode.NextSibling) { //if the child node is a text node, parse it into this dude if (XmlNodeType.Text == childNode.NodeType) { //Get the text of the child xml node, but store it in THIS bullet node NodeEquation.Parse(childNode.Value); continue; } //create a new node BulletMLNode childBulletNode = new BulletMLNode(); //read in the node if (!childBulletNode.Parse(childNode, this)) { return false; } //store the node ChildNodes.Add(childBulletNode); } } return true; }
/// <summary> /// Initializes a new instance of the <see cref="BulletMLLib.BulletMLTask"/> class. /// </summary> /// <param name="node">Node.</param> /// <param name="owner">Owner.</param> public BulletMLChangeSpeed(BulletMLNode node, BulletMLTask owner) : base(node, owner) { Debug.Assert(null != Node); Debug.Assert(null != Owner); }