예제 #1
0
        public void FindActivePresetFilesIncludesUnknownCategories()
        {
            using var dirOpts = new TestFolder(_gof.FullName);
            dirOpts.WriteText(@"Bindings\StartPreset.start", "Custom\nCustom2\nKeyboard\nCustom\nCustom2");

            var gof = new GameOptionsFolder(dirOpts.Name);

            Assert.True(gof.IsValid);

            var files = BindingPreset.FindActivePresetFiles(_gif, gof);

            Assert.Equal(_bindingCategories + 1, files.Count);

            var expected = new Dictionary <BindingCategory, string>
            {
                [BindingCategory.GeneralControls] = dirOpts.Resolve(@"Bindings\Custom.3.0.binds"),
                [BindingCategory.ShipControls]    = dirOpts.Resolve(@"Bindings\Custom2.3.0.binds"),
                [BindingCategory.SrvControls]     = Path.Combine(_gif.FullName, @"ControlSchemes\Keyboard.binds"),
                [BindingCategory.OnFootControls]  = dirOpts.Resolve(@"Bindings\Custom.3.0.binds"),
                [(BindingCategory)4] = dirOpts.Resolve(@"Bindings\Custom2.3.0.binds"),
            };

            foreach (var category in expected.Keys)
            {
                Assert.Equal(expected[category], files[category]);
            }
        }
예제 #2
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);
        }
예제 #3
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
            }
        }
예제 #4
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);
        }
예제 #5
0
        public void FindActivePresetFilesReturnsNullWhenNeither1Or4PresetFilesAreDefined()
        {
            using var dirOpts = new TestFolder(_gof.FullName);
            dirOpts.WriteText(@"Bindings\StartPreset.start", "Custom\nCustom2");

            var gof = new GameOptionsFolder(dirOpts.Name);

            Assert.True(gof.IsValid);

            var files = BindingPreset.FindActivePresetFiles(_gif, gof);

            Assert.Null(files);
        }
예제 #6
0
        public void FindActivePresetFilesReturnsNullWhenAPresetFileIsMissing()
        {
            using var dirOpts = new TestFolder(_gof.FullName);
            dirOpts.WriteText(@"Bindings\StartPreset.start", "Custom\nCustom2\nMISSING_PRESET\nKeyboard");

            var gof = new GameOptionsFolder(dirOpts.Name);

            Assert.True(gof.IsValid);

            var files = BindingPreset.FindActivePresetFiles(_gif, gof);

            Assert.Null(files);
        }
예제 #7
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);
        }
예제 #8
0
        public void SupportsSingleLineStartPresets()
        {
            using var dirOpts = new TestFolder(_gof.FullName);
            dirOpts.WriteText(@"Bindings\StartPreset.start", "Custom");

            var gof = new GameOptionsFolder(dirOpts.Name);

            Assert.True(gof.IsValid);

            var files = BindingPreset.FindActivePresetFiles(_gif, gof);

            Assert.Equal(_bindingCategories, files.Count);

            var expectedFile = dirOpts.Resolve(@"Bindings\Custom.3.0.binds");

            Assert.All(files.Values, x => Assert.Equal(expectedFile, x));
        }
예제 #9
0
        private static Key GetKey(BindingPreset binds, string binding)
        {
            var bps = binds.Bindings[binding].Primary;

            return(KeyMappings.EliteKeys[bps.Key]);
        }
예제 #10
0
        private static Key GetKey(BindingPreset binds, string binding)
        {
            var bps = binds.Bindings[binding].Primary;

            return(KeyMappings.TryGetKey(bps.Key, "en-US", false, out var key, new NativeMethodsStub()) ? key : 0);
        }
예제 #11
0
 private void BindingsWatcher_Changed(object sender, BindingPreset e)
 {
     _modifierKeysWatcher.Watch(GetAllModifiers(e.Bindings.Values), e.KeyboardLayout);
     _gameState.BindingPreset = e;
     OnChanged(ChangeType.BindingPreset);
 }
예제 #12
0
 private void BindingsWatcher_Changed(object sender, BindingPreset e)
 {
     _modifierKeysWatcher.Watch(GetAllModifiers(e.Bindings.Values));
     GameState.Bindings = e.Bindings;
     OnChanged();
 }