Beispiel #1
0
        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);
        }