Ejemplo n.º 1
0
        public void E2ESimplestApp()
        {
            var            app   = new ConsoleApp(1, 1);
            var            panel = app.LayoutRoot.Add(new SpacetimePanel(1, 1));
            SpacialElement element;
            TimeSpan       lastAge = TimeSpan.Zero;

            panel.SpaceTime.QueueAction(() =>
            {
                element = new SpacialElement();
                panel.SpaceTime.Add(element);

                panel.SpaceTime.Add(TimeFunction.Create(() =>
                {
                    lastAge = element.CalculateAge();
                    if (Time.CurrentTime.Now == TimeSpan.FromSeconds(.5))
                    {
                        Time.CurrentTime.Stop();
                        app.Stop();
                    }
                }));
            });

            panel.SpaceTime.Start();
            app.Start().Wait();
            Assert.AreEqual(.5, lastAge.TotalSeconds);
        }
Ejemplo n.º 2
0
        private void ListenForCharacterNearRightEdge()
        {
            ITimeFunction watcher = null;

            watcher = TimeFunction.Create(() =>
            {
                if (character.Left > Width - 2)
                {
                    // turn the character around so he now moves to the left
                    character.Speed.SpeedX = -8;

                    // drop a timed mine
                    var dropper = new TimedMineDropper()
                    {
                        Delay = TimeSpan.FromSeconds(4), AmmoAmount = 1, Holder = character
                    };
                    dropper.Exploded.SubscribeOnce(() => Sound.Play("PowerArgsIntro"));
                    dropper.FireInternal();

                    // eventually he will hit the left wall, remove him when that happens
                    character.Speed.ImpactOccurred.SubscribeForLifetime((i) => character.Lifetime.Dispose(), character.Lifetime);

                    // this watcher has done its job, stop watching the secne
                    watcher.Lifetime.Dispose();
                }
            });
            SpaceTime.Add(watcher);
        }
Ejemplo n.º 3
0
 private void ListenForEndOfIntro()
 {
     SpaceTime.Add(TimeFunction.Create(() =>
     {
         var remainingCount = SpaceTime.Elements.Where(e => e is FlammableLetter || e is Fire).Count();
         if (remainingCount == 0)
         {
             Cleanup();
         }
     }));
 }
Ejemplo n.º 4
0
        public bool TryRevive(LevelItem item, List <LevelItem> allItems, out ITimeFunction hydratedElement)
        {
            if (item.HasValueTag("cutscene") == false)
            {
                hydratedElement = null;
                return(false);
            }

            var scene = SceneFactory.CreateInstance <ICutScene>(item.GetTagValue("cutscene"));

            hydratedElement = TimeFunction.Create(null, init: scene.Start);
            return(true);
        }
Ejemplo n.º 5
0
        public override IEnumerable <TimeFunction> TimeFunctions(bool requiresRoundtripping = false)
        {
            if (IOInputs.SupportsGettingCreationTime && (!requiresRoundtripping || IOInputs.SupportsSettingCreationTime))
            {
                yield return(TimeFunction.Create(
                                 ((path, time) => File.SetCreationTime(path, time)),
                                 ((path) => File.GetCreationTime(path)),
                                 DateTimeKind.Local));

                yield return(TimeFunction.Create(
                                 ((path, time) => File.SetCreationTimeUtc(path, time)),
                                 ((path) => File.GetCreationTimeUtc(path)),
                                 DateTimeKind.Unspecified));

                yield return(TimeFunction.Create(
                                 ((path, time) => File.SetCreationTimeUtc(path, time)),
                                 ((path) => File.GetCreationTimeUtc(path)),
                                 DateTimeKind.Utc));
            }
            yield return(TimeFunction.Create(
                             ((path, time) => File.SetLastAccessTime(path, time)),
                             ((path) => File.GetLastAccessTime(path)),
                             DateTimeKind.Local));

            yield return(TimeFunction.Create(
                             ((path, time) => File.SetLastAccessTimeUtc(path, time)),
                             ((path) => File.GetLastAccessTimeUtc(path)),
                             DateTimeKind.Unspecified));

            yield return(TimeFunction.Create(
                             ((path, time) => File.SetLastAccessTimeUtc(path, time)),
                             ((path) => File.GetLastAccessTimeUtc(path)),
                             DateTimeKind.Utc));

            yield return(TimeFunction.Create(
                             ((path, time) => File.SetLastWriteTime(path, time)),
                             ((path) => File.GetLastWriteTime(path)),
                             DateTimeKind.Local));

            yield return(TimeFunction.Create(
                             ((path, time) => File.SetLastWriteTimeUtc(path, time)),
                             ((path) => File.GetLastWriteTimeUtc(path)),
                             DateTimeKind.Unspecified));

            yield return(TimeFunction.Create(
                             ((path, time) => File.SetLastWriteTimeUtc(path, time)),
                             ((path) => File.GetLastWriteTimeUtc(path)),
                             DateTimeKind.Utc));
        }
Ejemplo n.º 6
0
        public override IEnumerable <TimeFunction> TimeFunctions(bool requiresRoundtripping = false)
        {
            if (IOInputs.SupportsGettingCreationTime && (!requiresRoundtripping || IOInputs.SupportsSettingCreationTime))
            {
                yield return(TimeFunction.Create(
                                 ((testDir, time) => { testDir.CreationTime = time; }),
                                 ((testDir) => testDir.CreationTime),
                                 DateTimeKind.Local));

                yield return(TimeFunction.Create(
                                 ((testDir, time) => { testDir.CreationTimeUtc = time; }),
                                 ((testDir) => testDir.CreationTimeUtc),
                                 DateTimeKind.Unspecified));

                yield return(TimeFunction.Create(
                                 ((testDir, time) => { testDir.CreationTimeUtc = time; }),
                                 ((testDir) => testDir.CreationTimeUtc),
                                 DateTimeKind.Utc));
            }
            yield return(TimeFunction.Create(
                             ((testDir, time) => { testDir.LastAccessTime = time; }),
                             ((testDir) => testDir.LastAccessTime),
                             DateTimeKind.Local));

            yield return(TimeFunction.Create(
                             ((testDir, time) => { testDir.LastAccessTimeUtc = time; }),
                             ((testDir) => testDir.LastAccessTimeUtc),
                             DateTimeKind.Unspecified));

            yield return(TimeFunction.Create(
                             ((testDir, time) => { testDir.LastAccessTimeUtc = time; }),
                             ((testDir) => testDir.LastAccessTimeUtc),
                             DateTimeKind.Utc));

            yield return(TimeFunction.Create(
                             ((testDir, time) => { testDir.LastWriteTime = time; }),
                             ((testDir) => testDir.LastWriteTime),
                             DateTimeKind.Local));

            yield return(TimeFunction.Create(
                             ((testDir, time) => { testDir.LastWriteTimeUtc = time; }),
                             ((testDir) => testDir.LastWriteTimeUtc),
                             DateTimeKind.Unspecified));

            yield return(TimeFunction.Create(
                             ((testDir, time) => { testDir.LastWriteTimeUtc = time; }),
                             ((testDir) => testDir.LastWriteTimeUtc),
                             DateTimeKind.Utc));
        }
Ejemplo n.º 7
0
        private Promise WhenNoMoreFriendlies()
        {
            var d = Deferred.Create();

            ITimeFunction t = null;;

            t = TimeFunction.Create(() =>
            {
                if (SpaceTime.CurrentSpaceTime.Elements.WhereAs <Friendly>().Count() == 0)
                {
                    t.Lifetime.Dispose();
                    d.Resolve();
                }
            }, rate: TimeSpan.FromSeconds(.1));
            SpaceTime.CurrentSpaceTime.Add(t);
            return(d.Promise);
        }
Ejemplo n.º 8
0
        public bool TryRevive(LevelItem item, List <LevelItem> allItems, out ITimeFunction hydratedElement)
        {
            var text = string.Empty;

            if (item.HasSimpleTag(EffectName) || item.HasValueTag(EffectName))
            {
                for (var x = 0; x < 500; x++)
                {
                    var next = allItems.Where(i => i.X == item.X + x && i.Y == item.Y).FirstOrDefault();
                    if (next != null)
                    {
                        next.Ignore = true;
                        text       += next.Symbol;
                    }
                    else
                    {
                        break;
                    }
                }


                var delay = item.HasValueTag(EffectName) && int.TryParse(item.GetTagValue(EffectName), out int result) ? result : 0;
                var stay  = item.HasValueTag("stay") && int.TryParse(item.GetTagValue("stay"), out int stayResult) ? stayResult : 10000;


                var effect = SceneFactory.CreateInstance <TextEffect>(EffectName);
                effect.Options = new TextEffectOptions()
                {
                    Left = item.X,
                    Top  = item.Y,
                    Text = text,
                    DurationMilliseconds = stay,
                };

                if (item.HasValueTag("triggerId") == false)
                {
                    hydratedElement = TimeFunction.CreateDelayed(delay, null, init: effect.Start);
                    return(true);
                }
                else
                {
                    hydratedElement = TimeFunction.Create(null, () =>
                    {
                        var id      = item.GetTagValue("triggerId");
                        var trigger = SpaceTime.CurrentSpaceTime.Elements.WhereAs <Trigger>().Where(t => t.Id == id).SingleOrDefault();

                        if (trigger == null)
                        {
                            throw new ArgumentException("No trigger with id: " + id);
                        }

                        trigger.Fired.SubscribeOnce((notused) =>
                        {
                            effect.Start();
                        });
                    });

                    return(true);
                }
            }

            hydratedElement = null;
            return(false);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Returns the number of seconds since January 1, 1970 UTC. Note that this does not actually return the current time, but the time at which the expression is to be evaluated.
 /// </summary>
 /// <returns></returns>
 public static InstantVector WithTime()
 {
     return(Empty().AddAction(TimeFunction.Create()));
 }