private StateInfo ReadState(XElement stateNode) { var info = new StateInfo(); info.Name = stateNode.RequireAttribute("name").Value; var logic = new List<IEffectPartInfo>(); var init = new List<IEffectPartInfo>(); foreach (var child in stateNode.Elements()) { switch (child.Name.LocalName) { case "Trigger": var t = _triggerReader.Load(child); if (t.Priority == null) t.Priority = ((IXmlLineInfo)child).LineNumber; info.Triggers.Add(t); break; case "Initialize": init.AddRange(child.Elements().Select(e => _effectReader.LoadPart(e))); break; case "Logic": logic.AddRange(child.Elements().Select(e => _effectReader.LoadPart(e))); break; default: var mode = child.TryAttribute<string>("mode"); if (mode != null && mode.ToUpper() == "REPEAT") logic.Add(_effectReader.LoadPart(child)); else init.Add(_effectReader.LoadPart(child)); break; } } info.Initializer = new EffectInfo() { Parts = init }; info.Logic = new EffectInfo() { Parts = logic }; return info; }
private void WriteState(StateInfo state, XmlWriter writer) { writer.WriteStartElement("State"); writer.WriteAttributeString("name", state.Name); writer.WriteStartElement("Initialize"); foreach (var part in state.Initializer.Parts) { _effectWriter.WritePart(part, writer); } writer.WriteEndElement(); writer.WriteStartElement("Logic"); foreach (var part in state.Logic.Parts) { _effectWriter.WritePart(part, writer); } writer.WriteEndElement(); foreach (var trigger in state.Triggers.OrderBy(t => t.Priority)) _triggerWriter.Write(trigger, writer); writer.WriteEndElement(); }