public void it_does_not_share_references() { _builder .WithName("name") .WithHref("href") .WithClass("class") .WithField(new FieldBuilder().WithName("name")); var action1 = _builder.Build(); var action2 = _builder.Build(); Assert.That(action1, Is.Not.SameAs(action2)); Assert.That(action1.Class, Is.Not.SameAs(action2.Class)); Assert.That(action1.Fields, Is.Not.SameAs(action2.Fields)); }
public static Actions Add(this Actions self, Action <IActionBuilder> build) { var builder = new ActionBuilder(); build(builder); var action = builder.Build(); self.Add(action); return(self); }
public void TestActionBuilderToString() { ActionBuilder builder = new ActionBuilder(); builder.AddTrigger(new CreateTrigger()) .AddCommand(new NameCommand { Name = "foo" }) .AddTrigger(new ActivateTrigger()) .AddCommand(new DiffuseCommand { Intensity = 1.0, TargetName = "foo" }); Action action = builder.Build(); Assert.AreEqual("create name foo; activate diffuse 1 name=foo", action.ToString(ActionFormat.None)); }
public IEnumerable <Action> ToActions() { List <Action> actions = new List <Action>(); foreach (Frame frame in this.Frames) { int index = this.Frames.IndexOf(frame); bool loopNow = this.IsLooping && index == this.Frames.Count - 1; ActionBuilder actionBuilder = new ActionBuilder(); CreateTrigger create = new CreateTrigger(); AdoneTrigger adone = new AdoneTrigger(); double frameDelay = frame.Delay.TotalMilliseconds; double delay = frameDelay + this.Frames.Take(index).Sum(f => f.Delay.TotalMilliseconds); create.AddCommand(new NameCommand { Name = this.Name }); create.AddCommand(new AnimateCommand { Name = "me", Animation = ".", FrameCount = 1, ImageCount = 1, FrameDelay = (int)(delay) }); adone.AddCommand(frame.Commands.ToArray()); if (loopNow) { // re-fire first frame on final frame completion adone.AddCommand(new AstartCommand { Name = this.Name }); } actionBuilder.AddTrigger(create).AddTrigger(adone); actions.Add(actionBuilder.Build()); } return(actions); }
private ConversationNode ParseStep(TextReader reader, ParsingContext context, int?parentId = null, int indentLevel = 0) { var nodeId = context.NodeId++; var actions = new List <CommandAction>(); var subSteps = new Dictionary <string, ConversationNode>(); context.LineIndentSize = ReadIndentation(reader); string line; while (context.LineIndentSize == indentLevel && (line = reader.ReadLine()) != null) { line = line.Trim(); context.LineNumber += 1; var match = _commandExpression.Match(line); if (match.Success) { subSteps.Add( match.Groups["command"].Value, ParseStep(reader, context, nodeId, indentLevel + 1)); continue; } // Only allow non-command lines if we haven't encountered any so far. if (!subSteps.Any()) { match = _speakExpression.Match(line); if (match.Success) { actions.Add(new SpeakAction(match.Groups["text"].Value.Trim(), match.Groups["actor"].Value)); context.LineIndentSize = ReadIndentation(reader); continue; } match = _actionExpression.Match(line); if (match.Success) { var actionBuilder = new ActionBuilder() .WithName(match.Groups["name"].Value) .WithArguments(match.Groups["args"].Captures.Select(c => c.Value.Trim('"'))); // TODO // if (actionBuilder.IsValid()) // { actions.Add(actionBuilder.Build()); context.LineIndentSize = ReadIndentation(reader); continue; // } // else // { // TODO THIS::: // throw new IOException($"Parse error at line {context.LineNumber}: Unsupported action."); // } } } throw new IOException($"Parse error at line {context.LineNumber}: Unexpected line."); } return(new ConversationNode(nodeId++, actions, parentId, subSteps)); }