コード例 #1
0
        public void TestPerformance()
        {
            _inputParser = InputParserBuilder.FromBare()
                           .Buttons("a", "b", "start", "select", "wait")
                           .DPad()
                           .RemappedDPad(up: "n", down: "s", left: "w", right: "e", mapsToPrefix: "")
                           .AnalogStick(prefix: "c", allowSpin: true)
                           .RemappedButtons(("p", "wait"), ("xp", "wait"), ("exp", "wait"))
                           .AliasedButtons(("honk", "y"))
                           .Touchscreen(width: 240, height: 160, multitouch: true, allowDrag: true)
                           .LengthRestrictions(maxSetLength: 2, maxSequenceLength: 4)
                           .HoldEnabled(true)
                           .Build();

            var stopwatch = Stopwatch.StartNew();

            for (int i = 0; i < 100; i++)
            {
                _inputParser.Parse("a");
                _inputParser.Parse("A");
                _inputParser.Parse("aa");
                _inputParser.Parse("123,234");
                _inputParser.Parse("11,22>33,44");
                _inputParser.Parse("a+b2startSelect");
                _inputParser.Parse("cupupcup.2up");
                _inputParser.Parse("p");
                _inputParser.Parse("phonk+left-");
                _inputParser.Parse("start9");
            }
            stopwatch.Stop();
            // check for 1k inputs per second. I get around 30k inputs per second on an i5-7600k @ 3.80GHz,
            // but this test should only fail if something got horribly slow.
            Assert.Less(stopwatch.Elapsed, TimeSpan.FromSeconds(1));
        }
コード例 #2
0
        public void TestMultitouch()
        {
            // multitouch enabled
            _inputParser = InputParserBuilder.FromBare()
                           .LengthRestrictions(maxSetLength: 2, maxSequenceLength: 4)
                           .Touchscreen(width: 240, height: 160, multitouch: true, allowDrag: true)
                           .Build();

            Assert.AreEqual(Seq(new InputSet(new List <Input>
            {
                new TouchscreenInput("234,123", "touchscreen", "234,123", 234, 123),
                new TouchscreenInput("11,22", "touchscreen", "11,22", 11, 22),
            })
                                ), _inputParser.Parse("234,123+11,22"));
            Assert.AreEqual(Seq(new InputSet(new List <Input>
            {
                new TouchscreenInput("234,123", "touchscreen", "234,123", 234, 123),
                new TouchscreenDragInput("11,22>33,44", "touchscreen", "11,22>33,44", 11, 22, 33, 44),
            })
                                ), _inputParser.Parse("234,123+11,22>33,44"));

            // multitouch disabled
            _inputParser = InputParserBuilder.FromBare()
                           .LengthRestrictions(maxSetLength: 2, maxSequenceLength: 4)
                           .Touchscreen(width: 240, height: 160, multitouch: false, allowDrag: true)
                           .Build();

            Assert.IsNull(_inputParser.Parse("234,123+11,22"));
            Assert.IsNull(_inputParser.Parse("234,123+11,22>33,44"));
            Assert.IsNull(_inputParser.Parse("234,123>0,0+11,22>33,44"));
        }
コード例 #3
0
        public void TestRetainCase()
        {
            _inputParser = InputParserBuilder.FromBare()
                           .Buttons("A")
                           .AliasedButtons(("B", "X"))
                           .RemappedButtons(("C", "Y"))
                           .AnalogInputs("UP")
                           .AliasedTouchscreenInput("MOVE1", 10, 20)
                           .LengthRestrictions(maxSetLength: 2, maxSequenceLength: 4)
                           .Build();

            Assert.AreEqual(
                Seq(new InputSet(new[] { new Input("A", "A", "a") })),
                _inputParser.Parse("a"));
            Assert.AreEqual(
                Seq(new InputSet(new[] { new Input("B", "X", "b") })),
                _inputParser.Parse("b"));
            Assert.AreEqual(
                Seq(new InputSet(new[] { new Input("Y", "Y", "c") })),
                _inputParser.Parse("c"));
            Assert.AreEqual(
                Seq(new InputSet(new[] { new AnalogInput("UP", "UP", "up.2", 0.2f) })),
                _inputParser.Parse("up.2"));
            Assert.AreEqual(
                Seq(new InputSet(new[] { new TouchscreenInput("MOVE1", "touchscreen", "move1", 10, 20) })),
                _inputParser.Parse("move1"));
        }
コード例 #4
0
        public void TestTouchscreenAlias()
        {
            _inputParser = InputParserBuilder.FromBare()
                           .Buttons("a")
                           .Touchscreen(width: 240, height: 160, multitouch: false, allowDrag: false)
                           .AliasedTouchscreenInput("move1", x: 42, y: 69)
                           .LengthRestrictions(maxSetLength: 2, maxSequenceLength: 4)
                           .Build();

            Assert.AreEqual(Seq(
                                new InputSet(new List <Input> {
                new Input("a", "a", "a")
            }),
                                new InputSet(new List <Input> {
                new TouchscreenInput("move1", "touchscreen", "move1", 42, 69)
            }),
                                new InputSet(new List <Input> {
                new TouchscreenInput("move1", "touchscreen", "move1", 42, 69)
            }),
                                new InputSet(new List <Input> {
                new Input("a", "a", "a")
            })
                                ), _inputParser.Parse("amove12a"));
            Assert.AreEqual(Seq(
                                new InputSet(new List <Input> {
                new TouchscreenInput("234,123", "touchscreen", "234,123", 234, 123)
            }),
                                new InputSet(new List <Input> {
                new TouchscreenInput("move1", "touchscreen", "move1", 42, 69)
            })
                                ), _inputParser.Parse("234,123move1"));
            Assert.IsNull(_inputParser.Parse("234,123+move1"));
        }
コード例 #5
0
        public void TestTouchscreenDrag()
        {
            // drag enabled
            _inputParser = InputParserBuilder.FromBare()
                           .Buttons("a")
                           .Touchscreen(width: 240, height: 160, multitouch: false, allowDrag: true)
                           .LengthRestrictions(maxSetLength: 2, maxSequenceLength: 4)
                           .Build();

            Assert.AreEqual(Seq(
                                new InputSet(new List <Input> {
                new Input("a", "a", "a")
            }),
                                new InputSet(new List <Input>
            {
                new TouchscreenDragInput("234,123>222,111", "touchscreen", "234,123>222,111", 234, 123, 222, 111)
            }),
                                new InputSet(new List <Input> {
                new Input("a", "a", "a")
            })
                                ), _inputParser.Parse("a234,123>222,111a"));
            Assert.AreEqual(Seq(
                                new InputSet(new List <Input>
            {
                new TouchscreenDragInput("239,159>0,0", "touchscreen", "239,159>0,0", 239, 159, 0, 0)
            })
                                ), _inputParser.Parse("239,159>0,0"));
            // allow leading zeroes
            Assert.AreEqual(Seq(
                                new InputSet(new List <Input>
            {
                new TouchscreenDragInput("000,000>000,000", "touchscreen", "000,000>000,000", 0, 0, 0, 0)
            })
                                ), _inputParser.Parse("000,000>000,000"));
            Assert.AreEqual(Seq(
                                new InputSet(new List <Input>
            {
                new TouchscreenDragInput("012,023>0,0", "touchscreen", "012,023>0,0", 12, 23, 0, 0)
            })
                                ), _inputParser.Parse("012,023>0,0"));
            // out of bounds
            Assert.IsNull(_inputParser.Parse("240,159>0,0"));
            Assert.IsNull(_inputParser.Parse("239,160>0,0"));
            Assert.IsNull(_inputParser.Parse("0,0>239,160"));
            Assert.IsNull(_inputParser.Parse("0,0>239,160"));
            // reject non-ascii decimal number symbols
            Assert.IsNull(_inputParser.Parse("১২৩,꧑꧒꧓>৪৫,꧔꧕"));

            // drag disabled
            _inputParser = InputParserBuilder.FromBare()
                           .Buttons("a")
                           .Touchscreen(width: 240, height: 160, multitouch: false, allowDrag: false)
                           .LengthRestrictions(maxSetLength: 2, maxSequenceLength: 4)
                           .Build();

            Assert.IsNull(_inputParser.Parse("a234,123>222,111a"));
            Assert.IsNull(_inputParser.Parse("239,159>0,0"));
        }
コード例 #6
0
        public void TestConflictWithWait()
        {
            _inputParser = InputParserBuilder.FromBare()
                           .Buttons("a", "wait")
                           .LengthRestrictions(maxSetLength: 2, maxSequenceLength: 4)
                           .Build();

            Assert.AreEqual(Seq(Set("a"), Set("wait")), _inputParser.Parse("await"));
            Assert.IsNull(_inputParser.Parse("a+wait"));
        }
コード例 #7
0
        public void TestConflicts()
        {
            _inputParser = InputParserBuilder.FromBare()
                           .Buttons("a")
                           .DPad()
                           .LengthRestrictions(maxSetLength: 2, maxSequenceLength: 4)
                           .Build();

            AssertInput("aupdown", Seq(Set("a"), Set("up"), Set("down")));
            AssertInput("aup+down", null);
            AssertInput("adown+up", null);
            AssertInput("aupleft", Seq(Set("a"), Set("up"), Set("left")));
            AssertInput("aup+left", Seq(Set("a"), Set("up", "left")));
        }
コード例 #8
0
        public void TestRejectDuplicates()
        {
            _inputParser = InputParserBuilder.FromBare()
                           .Buttons("a")
                           .AliasedButtons(("n", "up"))
                           .AnalogInputs("up")
                           .Touchscreen(width: 240, height: 160, multitouch: true, allowDrag: true)
                           .AliasedTouchscreenInput("move1", 11, 22)
                           .LengthRestrictions(maxSetLength: 2, maxSequenceLength: 4)
                           .Build();

            Assert.IsNull(_inputParser.Parse("a+a"));
            Assert.IsNull(_inputParser.Parse("up+up.1"));
            Assert.IsNull(_inputParser.Parse("n+up"));
            Assert.IsNull(_inputParser.Parse("11,22+11,22"));
            Assert.IsNull(_inputParser.Parse("11,22>50,60+11,22>50,60"));
            Assert.IsNull(_inputParser.Parse("11,22+move1"));
        }
コード例 #9
0
        public void TestRemapping()
        {
            _inputParser = InputParserBuilder.FromBare()
                           .Buttons("y")
                           .RemappedButtons(("honk", "y"))
                           .LengthRestrictions(maxSetLength: 2, maxSequenceLength: 4)
                           .Build();

            InputSequence?result = _inputParser.Parse("honky");

            Assert.AreEqual(Seq(
                                new InputSet(new List <Input> {
                new Input("y", "y", "honk")
            }),
                                new InputSet(new List <Input> {
                new Input("y", "y", "y")
            })
                                ), result);
        }
コード例 #10
0
        public void TestHold()
        {
            InputParserBuilder builder = InputParserBuilder.FromBare()
                                         .Buttons("a")
                                         .LengthRestrictions(maxSetLength: 2, maxSequenceLength: 1);

            // hold enabled
            _inputParser = builder.HoldEnabled(true).Build();
            AssertInput("a", Seq(Set("a")));
            Assert.AreEqual(Seq(new InputSet(new List <Input>
            {
                new Input("a", "a", "a"), new Input("hold", "hold", "-")
            })
                                ), _inputParser.Parse("a-"));

            // hold disabled
            _inputParser = builder.HoldEnabled(false).Build();
            AssertInput("a", Seq(Set("a")));
            AssertInput("a-", null);
        }
コード例 #11
0
        public void TestBasicInputs()
        {
            _inputParser = InputParserBuilder.FromBare()
                           .Buttons("a", "b", "start", "select")
                           .LengthRestrictions(maxSetLength: 2, maxSequenceLength: 4)
                           .Build();

            // good cases
            AssertInput("aa", Seq(Set("a"), Set("a")));
            AssertInput("a2a", Seq(Set("a"), Set("a"), Set("a")));
            AssertInput("a2a2", Seq(Set("a"), Set("a"), Set("a"), Set("a")));
            AssertInput("start4", Seq(Set("start"), Set("start"), Set("start"), Set("start")));
            AssertInput("a+b2startselect", Seq(Set("a", "b"), Set("a", "b"), Set("start"), Set("select")));
            AssertInput("b+a", Seq(Set("b", "a"))); // order is preserved

            // bad cases
            AssertInput("x", null);         // not a button
            AssertInput("a+b+start", null); // set too long
            AssertInput("a5", null);        // sequence too long
        }
コード例 #12
0
        public void TestAnalog()
        {
            _inputParser = InputParserBuilder.FromBare()
                           .Buttons("a")
                           .AnalogInputs("up")
                           .LengthRestrictions(maxSetLength: 2, maxSequenceLength: 4)
                           .Build();

            Assert.AreEqual(Seq(
                                new InputSet(new List <Input> {
                new Input("a", "a", "a")
            }),
                                new InputSet(new List <Input> {
                new AnalogInput("up", "up", "up.2", 0.2f)
            }),
                                new InputSet(new List <Input> {
                new AnalogInput("up", "up", "up.2", 0.2f)
            }),
                                new InputSet(new List <Input> {
                new Input("a", "a", "a")
            })
                                ), _inputParser.Parse("aup.22a"));
            Assert.AreEqual(Seq(
                                new InputSet(new List <Input> {
                new AnalogInput("up", "up", "UP", 1.0f)
            })
                                ), _inputParser.Parse("UP"));
            Assert.AreEqual(Seq(
                                new InputSet(new List <Input> {
                new AnalogInput("up", "up", "up.9", 0.9f)
            })
                                ), _inputParser.Parse("up.9"));
            Assert.IsNull(_inputParser.Parse("up."));
            Assert.IsNull(_inputParser.Parse("up.0"));
            Assert.IsNull(_inputParser.Parse("up.10"));
        }