示例#1
0
        public ActionsRaisers(NonNullList <IActionConfiguration> actionConfigurations, NonNullList <IActionsRaisers> actionsRaisers)
        {
            if (actionConfigurations == null)
            {
                throw new ArgumentNullException(nameof(actionConfigurations));
            }
            if (actionsRaisers == null)
            {
                throw new ArgumentNullException(nameof(actionsRaisers));
            }

            var actionsEvents = new Dictionary <int, IEvents>();

            foreach (var action in actionConfigurations)
            {
                actionsEvents.Add(
                    action.Id,
                    new Events(
                        NonNullList.Of(
                            actionsRaisers
                            .SelectMany(actionsRaiser => actionsRaiser.Events)
                            .Where(eventsDictionary => eventsDictionary.Key == action.Id)
                            .Select(eventsDictionary => eventsDictionary.Value)
                            .ToArray()
                            )
                        )
                    );
            }

            Events = actionsEvents;
        }
示例#2
0
        public RootPlusHotelAndRestaurantSectionsNavigator(IDispatcher dispatcher) : base(NonNullList <NonBlankTrimmedString> .Empty, dispatcher)
        {
            if (dispatcher == null)
            {
                throw new ArgumentNullException("dispatcher");
            }

            // This is the only route that this class directly creates..
            _getRoot = AddRelativeRoute(
                segments: NonNullList <string> .Empty,
                routeAction: new NavigateToRoot(),
                urlGenerator: () => GetPath()
                );

            // .. however it does also create some other navigators that will declare routes under the "hotel" section and the "restaurant" section
            // (and we'll need to add the routes that these navigators declare to this instance's total set of known routes()
            PullInRoutesFrom(Hotels = new RootPlusDynamicIdItemPagesNavigator <Hotel>(
                                 parentSegments: NonNullList.Of(new NonBlankTrimmedString("hotel")),
                                 dispatcher: dispatcher
                                 ));
            PullInRoutesFrom(Restaurants = new RootPlusDynamicIdItemPagesNavigator <Restaurant>(
                                 parentSegments: NonNullList.Of(new NonBlankTrimmedString("restaurant")),
                                 dispatcher: dispatcher
                                 ));
        }
示例#3
0
        public One(ICore core)
        {
            if (core == null)
            {
                throw new ArgumentNullException(nameof(core));
            }

            _core = core;
            _core.Layers.Reset(NonNullList.Of(0));
            _core.Layers.Controls.Clear();
        }
示例#4
0
 protected override State GetInitialState()
 {
     return(new State(
                inputValue: "",
                todos: NonNullList.Of(
                    new TaskDetails(_nextAvailableId++, "Learn C#", done: true),
                    new TaskDetails(_nextAvailableId++, "Learn React", done: false),
                    new TaskDetails(_nextAvailableId++, "Build an awesome app with C# and React", done: false)
                    )
                ));
 }
示例#5
0
        public Level(ICore core)
        {
            if (core == null)
            {
                throw new ArgumentNullException(nameof(core));
            }

            _core = core;
            _core.Layers.Reset(NonNullList.Of(0));
            _core.ActivateActions();
            _resourcePool = new ResourcePool();
        }
        public Touch(ICore core)
        {
            if (core == null)
            {
                throw new ArgumentNullException(nameof(core));
            }

            _core = core;
            _core.Layers.Reset(NonNullList.Of(0));
            _core.Layers.Controls.Clear();

            _textBox = new TextBox("Touch", _core.Resolution.MultiplyClamp(10), _core.Resolution);
            _textBox.UpdatePosition(_core.Resolution.MultiplyClamp(4), _core.Resolution.MultiplyClamp(4));
        }
示例#7
0
        public void Reset(NonNullList <int> ids)
        {
            if (ids == null)
            {
                throw new ArgumentNullException(nameof(ids));
            }

            _stageLayers            = NonNullList.Of(ids.Select(id => new Layer(_resolution, Wrapper, id)).ToArray()); // Build up new layers.
            _stageWrapper.InnerHTML = "";                                                                              // reset HTML (there is no event listeners on the children, so this should be fine.

            foreach (var layer in _stageLayers)
            {
                _stageWrapper.AppendChild(layer.CanvasElement);
            }

            Resize(true);             // There is a chance that the window dimensions have not changed, so force the resize, otherwise it would exit early.
        }
示例#8
0
        public Zoom(ICore core)
        {
            if (core == null)
            {
                throw new ArgumentNullException(nameof(core));
            }

            _core = core;
            _core.Layers.Reset(NonNullList.Of(0));
            _core.DeactivateActions();
            _core.ActivateActions(NonNullList.Of(
                                      DefaultActions.Up,
                                      DefaultActions.Left,
                                      DefaultActions.Down,
                                      DefaultActions.Button1
                                      ));

            _resourcePool = new ResourcePool();
        }
示例#9
0
            public ICoreStageFactory SetActions(NonNullList <ActionConfiguration> actions)
            {
                if (actions == null)
                {
                    throw new ArgumentNullException(nameof(actions));
                }

                ActionEvents = new Input.Combined.ActionsRaisers(
                    NonNullList.Of <IActionConfiguration>(actions.ToArray()),
                    NonNullList.Of <IActionsRaisers>(
                        new Input.Keyboard.ActionsRaisers(Layers, NonNullList.Of <IActionConfigurationKeyboard>(actions.ToArray())),
                        new Input.Mouse.ActionsRaisers(Resolution, Layers, NonNullList.Of <IActionConfigurationMouse>(actions.ToArray())),
                        new Input.Touch.ActionsRaisers(Resolution, Layers, NonNullList.Of <IActionConfigurationTouch>(actions.ToArray()))
                        )
                    ).Events;

                ActionsRenders = actions.ToDictionary(
                    actionConfiguration => actionConfiguration.Id,
                    actionConfiguration => actionConfiguration.As <IActionConfigurationRenderer>()
                    );

                return(this);
            }
示例#10
0
        public RayCaster(ICore core)
        {
            if (core == null)
            {
                throw new ArgumentNullException(nameof(core));
            }

            _core = core;
            _core.Layers.Reset(NonNullList.Of(0));
            _core.ActivateActions();


            _player = new Player(15.3, -1.2, Math.PI * 0.3);
            _map    = new Map(32);

            /*var display = Document.getElementById('display');
             * var controls = new Controls();
             * var camera = new Camera(display, MOBILE ? 160 : 320, 0.8);
             * var loop = new GameLoop();
             *
             * map.randomize();*/

            // taken from https://github.com/hunterloftis/playfuljs-demos/blob/gh-pages/raycaster/index.html
        }
示例#11
0
        private static void WithTests()
        {
            QUnit.Module("WithTests");

            QUnit.Test("Simple string property update using With directly", assert =>
            {
                var x = new SomethingWithStringId("abc");
                x     = x.With(_ => _.Id, "def");
                assert.Equal(x.Id, "def");
            });

            QUnit.Test("With does not affect original instance", assert =>
            {
                var x0 = new SomethingWithStringId("abc");
                var x1 = x0.With(_ => _.Id, "def");
                assert.Equal(x0.Id, "abc");
                assert.Equal(x1.Id, "def");
            });

            QUnit.Test("Simple string property update of property on a base class using With directly", assert =>
            {
                // This test is just to ensure that there's no monkey business involved when targeting properties on a base class (as there are
                // with interface properties - see above)
                var x = new SecurityPersonDetails(1, "test", 10);
                x     = x.With(_ => _.Name, "test2");
                assert.Equal(x.Name, "test2");
            });

            QUnit.Test("Simple string property update using With indirectly", assert =>
            {
                var x         = new SomethingWithStringId("abc");
                var idUpdater = x.With(_ => _.Id);
                x             = idUpdater("def");
                assert.Equal(x.Id, "def");
            });

            QUnit.Test("Simple string property update using GetProperty and With", assert =>
            {
                var x = new SomethingWithStringId("abc");
                var propertyToUpdate = x.GetProperty(_ => _.Id);
                x = x.With(propertyToUpdate, "def");
                assert.Equal(x.Id, "def");
            });

            QUnit.Test("Single-element NonNullList<string> property update using With directly", assert =>
            {
                var x = new SomethingWithNonNullListStringValues(NonNullList.Of("abc", "def"));
                x     = x.With(_ => _.Values, 1, "xyz");
                assert.Equal(x.Values[1], "xyz");
            });

            QUnit.Test("Single-element NonNullList<string> property update using GetProperty and With", assert =>
            {
                var x = new SomethingWithNonNullListStringValues(NonNullList.Of("abc", "def"));
                var propertyToUpdate = x.GetProperty(_ => _.Values);
                x = x.With <SomethingWithNonNullListStringValues, string>(propertyToUpdate, 1, "xyz");
                assert.Equal(x.Values[1], "xyz");
            });

            QUnit.Test("Single-element Set<string> (legacy compatibility alias for NonNullList) property update using GetProperty and With", assert =>
            {
#pragma warning disable CS0618 // Ignore the fact that Set is obsolete
                var x = new SomethingWithNonNullListStringValues(Set.Of("abc", "def"));
#pragma warning restore CS0618
                var propertyToUpdate = x.GetProperty(_ => _.Values);
                x = x.With <SomethingWithNonNullListStringValues, string>(propertyToUpdate, 1, "xyz");
                assert.Equal(x.Values[1], "xyz");
            });

            QUnit.Test("The Validate method (if there is one defined with zero parameters) should be called after With", assert =>
            {
                var x = new SomethingWithNonZeroKey(123);
                assert.Throws(
                    () => x.With(_ => _.Key, (uint)0),
                    "The Validate method should be called after With"
                    );
            });

            // When first changing the Clone behaviour within ImmutabilityHelpers to work with Bridge 16 (which changes how properties are defined on objects), there was a
            // bug introduced where the updating properties on the clone would update the values on the original value too! These tests confirm that that bug is no more.
            QUnit.Test("Simple string property update against an interface using With directly", assert =>
            {
                // Inspired by issue https://github.com/ProductiveRage/Bridge.Immutable/issues/4
                IAmImmutableAndHaveName viaInterfacePerson = new PersonDetails(1, "test");
                viaInterfacePerson = viaInterfacePerson.With(_ => _.Name, "test2");
                assert.Equal(viaInterfacePerson.Name, "test2");
            });
            QUnit.Test("Double-check must-not-affect-original-instance when targeting property on base class", assert =>
            {
                var x0 = new SecurityPersonDetails(1, "test", 10);
                var x1 = x0.With(_ => _.Name, "test2");
                assert.Equal(x0.Name, "test");
                assert.Equal(x1.Name, "test2");
            });
        }
示例#12
0
        private static void NonNullListTests()
        {
            QUnit.Module("NonNullListTests");

            QUnit.Test("NonNullList.OrderBy - numeric sequence permutations", assert =>
            {
                for (var numberOfItems = 0; numberOfItems <= 4; numberOfItems++)
                {
                    var data = Enumerable.Range(0, numberOfItems);
                    var expectedResultAsString = string.Join(", ", data);
                    foreach (var permutation in GetPermutations(data.ToArray()).Select(permutation => NonNullList.Of(permutation).OrderBy(value => value)))
                    {
                        var actualResultAsString = string.Join(", ", permutation);
                        assert.Equal(actualResultAsString, expectedResultAsString);
                    }
                }
            });

            QUnit.Test("NonNullList.Map - items change (no index passed to lambda)", assert =>
            {
                var actual = NonNullList.Of(1, 2, 3, 4).Map(value => value + 1);
                assert.Equal(
                    actual: string.Join(",", actual),
                    expected: "2,3,4,5"
                    );
            });

            QUnit.Test("NonNullList.Map - items change (index passed to lambda)", assert =>
            {
                var actual = NonNullList.Of(1, 2, 3, 4).Map((value, index) => value + index);
                assert.Equal(
                    actual: string.Join(",", actual),
                    expected: "1,3,5,7"
                    );
            });

            QUnit.Test("NonNullList.Map - items don't change and so list returning unaltered", assert =>
            {
                var items = NonNullList.Of(1, 2, 3, 4);
                assert.Equal(
                    actual: items.Map(value => value),
                    expected: items
                    );
            });

            QUnit.Test("NonNullList.Map - items don't change (according to Equals override) and so list returning unaltered", assert =>
            {
                var items = NonNullList.Of(new StandardObjectWithCustomEquality("abc"));
                assert.Equal(
                    actual: items.Map(value => new StandardObjectWithCustomEquality("abc")),
                    expected: items
                    );
            });

            QUnit.Test("NonNullList.Map - items [ObjectLiteral] don't change (according to Equals override) and so list returning unaltered", assert =>
            {
                // Use NonBlankTrimmedString from ProductiveRage.Immutable.Extensions because that is an [ObjectLiteral] with a custom Equals method and referencing
                // that assembly pulls through the [ObjectLiteral] hacks that are required until the Bridge Team (hopefully) improve the support for them
                var items = NonNullList.Of(new NonBlankTrimmedString("abc"));
                assert.Equal(
                    actual: items.Map(value => new NonBlankTrimmedString("abc")),
                    expected: items
                    );
            });
        }
        public static NonNullList <ActionConfiguration> GetActionConfigurations(Resolution resolution)
        {
            if (resolution == null)
            {
                throw new ArgumentNullException(nameof(resolution));
            }

            var spacer              = resolution.Multiply(2);
            var defaultRadius       = resolution.Multiply(8);
            var actionButtonsRadius = resolution.Multiply(16);

            var down = new ActionConfiguration(
                Down,
                Events.KeyCodes._downArrow,
                new Circle(
                    resolution.Clamp(spacer + (defaultRadius * 3)),
                    resolution.Clamp(resolution.Height - defaultRadius - spacer),
                    defaultRadius
                    ),
                resolution
                );

            var up = new ActionConfiguration(
                Up,
                Events.KeyCodes._upArrow,
                new Circle(
                    down.Circle.X,
                    resolution.Clamp(down.Circle.Y - (defaultRadius * 4)),
                    defaultRadius
                    ),
                resolution
                );

            var left = new ActionConfiguration(
                Left,
                Events.KeyCodes._leftArrow,
                new Circle(
                    resolution.Clamp(defaultRadius + spacer),
                    resolution.Clamp(down.Circle.Y - (defaultRadius * 2)),
                    defaultRadius
                    ),
                resolution
                );

            var right = new ActionConfiguration(
                Right,
                Events.KeyCodes._rightArrow,
                new Circle(
                    resolution.Clamp(left.Circle.X + (defaultRadius * 4)),
                    left.Circle.Y,
                    defaultRadius
                    ),
                resolution
                );

            var button1 = new ActionConfiguration(
                Button1,
                Events.KeyCodes._space,
                new Circle(
                    resolution.Clamp(resolution.Width - actionButtonsRadius - spacer),
                    resolution.Clamp(resolution.Height - actionButtonsRadius - spacer),
                    actionButtonsRadius
                    ),
                resolution
                );

            var menu = new ActionConfiguration(
                Menu,
                Events.KeyCodes._m,
                new Circle(
                    resolution.Clamp(resolution.Width - defaultRadius - spacer),
                    resolution.Clamp(defaultRadius + spacer),
                    defaultRadius
                    ),
                resolution
                );

            return(NonNullList.Of(
                       up,
                       down,
                       left,
                       right,
                       button1,
                       menu
                       ));
        }
        public static void Go()
        {
            QUnit.Module("QueryString Parsing");

            QUnit.Test("Match ''", assert =>
            {
                var rawQueryString = "";
                var queryString    = QueryString.Parse(rawQueryString);
                assert.Equal(queryString["x"].Count, 0);
                assert.Equal(queryString.ToString(), rawQueryString);
            });

            QUnit.Test("Match 'x=1'", assert =>
            {
                var rawQueryString = "x=1";
                var queryString    = QueryString.Parse(rawQueryString);
                assert.Equal(queryString["x"].Count, 1);
                assert.OptionalEqual(queryString["x"][0], "1");
                assert.Equal(queryString.ToString(), rawQueryString);
            });

            QUnit.Test("Match '?x=1'", assert =>
            {
                assert.Throws(() => QueryString.Parse("?x=1"), "The QueryString should not include the leading '?' character");
            });

            QUnit.Test("Match 'x=1&x=2'", assert =>
            {
                var rawQueryString = "x=1&x=2";
                var queryString    = QueryString.Parse(rawQueryString);
                assert.Equal(queryString["x"].Count, 2);
                assert.OptionalEqual(queryString["x"][0], "1");
                assert.OptionalEqual(queryString["x"][1], "2");
                assert.Equal(queryString.ToString(), rawQueryString);
            });

            QUnit.Test("Match 'x=1&y=&z'", assert =>
            {
                var rawQueryString = "x=1&y=&z";
                var queryString    = QueryString.Parse(rawQueryString);
                assert.Equal(queryString["x"].Count, 1);
                assert.OptionalEqual(queryString["x"][0], "1");
                assert.Equal(queryString["y"].Count, 1);
                assert.OptionalEqual(queryString["y"][0], "");
                assert.Equal(queryString["z"].Count, 1);
                assert.OptionalEqual(queryString["z"][0], Optional <string> .Missing);
                assert.Equal(queryString.ToString(), rawQueryString);
            });

            QUnit.Test("Match 'x=test%20value'", assert =>
            {
                var rawQueryString = "x=test%20value";
                var queryString    = QueryString.Parse(rawQueryString);
                assert.Equal(queryString["x"].Count, 1);
                assert.OptionalEqual(queryString["x"][0], "test value");
                assert.Equal(queryString.ToString(), rawQueryString);
            });

            QUnit.Test("Match '%20%20x=test%20value'", assert =>
            {
                var rawQueryString = "%20%20x=test%20value";
                var queryString    = QueryString.Parse(rawQueryString);
                assert.Equal(queryString["x"].Count, 0);
                assert.Equal(queryString["  x"].Count, 1);
                assert.OptionalEqual(queryString["  x"][0], "test value");
                assert.Equal(queryString.ToString(), rawQueryString);
            });

            QUnit.Module("QueryString Manipulating");

            QUnit.Test("Add 'x=2' to 'x=1'", assert =>
            {
                var queryString = QueryString.Parse("x=1").Add("x", "2");
                assert.Equal(queryString["x"].Count, 2);
                assert.OptionalEqual(queryString["x"][0], "1");
                assert.OptionalEqual(queryString["x"][1], "2");
                assert.Equal(queryString.ToString(), "x=1&x=2");
            });

            QUnit.Test("Remove 'x' from 'x=1&x=2'", assert =>
            {
                var queryString = QueryString.Parse("x=1&x=2").RemoveIfPresent("x");
                assert.Equal(queryString["x"].Count, 0);
                assert.Equal(queryString.ToString(), "");
            });

            // This tests a fix around AddToQueryIfDefined where NonBlankTrimmedString is used, since NonBlankTrimmedString became an [ObjectLiteral]
            QUnit.Test("Test ToString() after call AddToQueryIfDefined with NonBlankTrimmedString", assert =>
            {
                var url = new UrlDetails(NonNullList.Of(new NonBlankTrimmedString("home"))).AddToQueryIfDefined("q", Optional.For(new NonBlankTrimmedString("test")));
                assert.Equal(url.ToString(), "/home?q=test");
            });
        }