コード例 #1
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
            }
        }
コード例 #2
0
        public async Task GameInBackgroundLayerSetsAColorPerGameProcessState(bool wasInBackground, GameProcessState processState, int?startRgbColor, int?endRgbColor)
        {
            const double fadeDurationSeconds = 1;

            var expectedStartColor = startRgbColor.HasValue ? Color.FromRgb((uint)startRgbColor.Value) : (Color?)null;
            var expectedEndColor   = endRgbColor.HasValue ? Color.FromRgb((uint)endRgbColor.Value) : (Color?)null;

            var graphicsConfig = GraphicsConfig.FromFile(_gif.GraphicsConfiguration.FullName);

            var bl = new GameInBackroundLayer();

            bl.SetPrivateField("_inBackground", wasInBackground);

            var le = new LayeredEffect();

            le.Add(bl);

            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
            {
                ProcessState = processState,
                GuiColour    = graphicsConfig.GuiColour.Default,
            };

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

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

#pragma warning disable CA1508
            Assert.Equal(expectedStartColor, keyboard?[(Key)0]);
#pragma warning restore CA1508

            keyboard  = null;
            game.Now += TimeSpan.FromSeconds(fadeDurationSeconds);
            await le.Render(chroma.Object, state).ConfigureAwait(false);

#pragma warning disable CA1508
            Assert.Equal(expectedEndColor, keyboard?[(Key)0]);
#pragma warning restore CA1508
        }
コード例 #3
0
        public async Task BackgroundLayerSetsAColorPerGameProcessState(GameProcessState processState, int rgbColor, double brightness)
        {
            var graphicsConfig = GraphicsConfig.FromFile(_gif.GraphicsConfiguration.FullName);

            var le = new LayeredEffect();

            le.Add(new BackgroundLayer());

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

            CustomKeyboardEffect keyboard;

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

            var game = new GameState
            {
                ProcessState = processState,
                GuiColour    = graphicsConfig.GuiColour.Default,
            };

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

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

            Assert.Equal(Color.Black, keyboard[0]);

            var expectedColor = Color.FromRgb((uint)rgbColor).Transform(brightness);

            game.Now += TimeSpan.FromSeconds(1);
            await le.Render(chroma.Object, state).ConfigureAwait(false);

            Assert.Equal(expectedColor, keyboard[0]);
        }