Example #1
0
        public void ToleratesMalformedBindingPresets()
        {
            var file  = Path.Combine(_gof.FullName, @"Bindings\Malformed.3.0.binds");
            var binds = BindingPreset.FromFile(file);

            Assert.Null(binds.PresetName);
            Assert.Null(binds.Version);
            Assert.Null(binds.KeyboardLayout);
            Assert.Equal(2, binds.Bindings.Count);

            var mb1 = binds.Bindings["MalformedBinding1"];
            var mb2 = binds.Bindings["MalformedBinding2"];

            Assert.Null(mb1.Primary.Device);
            Assert.Null(mb1.Primary.Key);
            Assert.Null(mb1.Secondary.Device);
            Assert.Null(mb1.Secondary.Key);
            Assert.Single(mb1.Primary.Modifiers);
            Assert.Empty(mb1.Secondary.Modifiers);

            Assert.Null(mb2.Primary.Device);
            Assert.Null(mb2.Primary.Key);
            Assert.Null(mb2.Secondary.Device);
            Assert.Null(mb2.Secondary.Key);
            Assert.Empty(mb2.Primary.Modifiers);
            Assert.Single(mb2.Secondary.Modifiers);
        }
Example #2
0
        public async Task HyperspaceLayerPulsesJumpKeyBasedOnHazardLevel(string starClass, double stepSeconds, int[] rgbColors)
        {
            var colors = rgbColors.Select(x => Color.FromRgb((uint)x)).ToList();

            var binds        = BindingPreset.FromFile(Path.Combine(_gif.FullName, _mainFile));
            var hyperJumpKey = GetKey(binds, FlightMiscellaneous.HyperSuperCombination);

            var hyperspaceLayer = new HyperspaceLayer()
            {
                NativeMethods = new NativeMethodsStub()
            };
            var le = new LayeredEffect();

            le.Add(hyperspaceLayer);

            var chroma = new Mock <IChroma> {
                DefaultValue = DefaultValue.Mock
            };

            CustomKeyboardEffect?keyboard = null;

            Mock.Get(chroma.Object.Keyboard)
            .Setup(x => x.SetCustomAsync(It.IsAny <CustomKeyboardEffect>()))
            .Callback((CustomKeyboardEffect c) => keyboard = c);

            var game = new GameState
            {
                FsdJumpType      = StartJump.FsdJumpType.Hyperspace,
                FsdJumpStarClass = starClass,
                FsdJumpChange    = DateTimeOffset.UtcNow,
                BindingPreset    = binds,
                PressedModifiers = new DeviceKeySet(Enumerable.Empty <DeviceKey>()),
            };

            var state = new LayerRenderState(game, new ChromaColors());

            game.Now = DateTimeOffset.UtcNow;
            await le.Render(chroma.Object, state).ConfigureAwait(false);

            Assert.False(game.InWitchSpace);

            game.Now += GameState.JumpCountdownDelay;
            await le.Render(chroma.Object, state).ConfigureAwait(false);

            Assert.True(game.InWitchSpace);
#pragma warning disable CA1508
            Assert.Equal(colors[0], keyboard?[hyperJumpKey]);
#pragma warning restore CA1508

            foreach (var color in colors.Skip(1))
            {
                keyboard  = null;
                game.Now += TimeSpan.FromSeconds(stepSeconds);
                await le.Render(chroma.Object, state).ConfigureAwait(false);

#pragma warning disable CA1508
                Assert.Equal(color, keyboard?[hyperJumpKey]);
#pragma warning restore CA1508
            }
        }
Example #3
0
        public void ReturnsNullWhenTheBindingPresetsFileIsEmpty()
        {
            using var dir = new TestFolder();
            dir.WriteText("Empty.binds", string.Empty);

            var binds = BindingPreset.FromFile(dir.Resolve("Empty.binds"));

            Assert.Null(binds);
        }
Example #4
0
        public void DeserializesBindingPresetsFiles()
        {
            var binds = BindingPreset.FromFile(Path.Combine(_gif.FullName, _mainFile));

            Assert.NotNull(binds);
            Assert.Equal("Keyboard", binds.PresetName);
            Assert.Null(binds.Version);
            Assert.Null(binds.KeyboardLayout);

            binds = BindingPreset.FromFile(Path.Combine(_gof.FullName, _customFile));

            Assert.NotNull(binds);
            Assert.Equal("Custom", binds.PresetName);
            Assert.Equal(new Version(3, 0), binds.Version);
            Assert.Equal("es-ES", binds.KeyboardLayout);
        }