예제 #1
0
        public void assign_actions()
        {
            var catalog = new ActionCatalogItem()
            {
                ActionName = "test action"
            };

            catalog.Actions = new ObservableCollection <ButtonAction>()
            {
                new ButtonAction()
                {
                    ScanCode = 1
                },
                new ButtonAction()
                {
                    ScanCode = 2
                },
                new ButtonAction()
                {
                    ScanCode = 3
                },
            };
            var map = new HOTASButton()
            {
                MapName = "test map", MapId = 43, Type = HOTASButton.ButtonType.Button
            };

            var mapVm = new ButtonMapViewModel(map);

            Assert.Empty(mapVm.Actions);
            mapVm.AssignActions(catalog);
            Assert.NotEmpty(mapVm.GetHotasActions());
            Assert.NotEmpty(mapVm.Actions);
            Assert.Same(catalog, mapVm.ActionItem);
        }
예제 #2
0
        public void record_macro_start_can_execute_not_disabled()
        {
            var catalog = new ActionCatalogItem()
            {
                ActionName = "test action"
            };

            catalog.Actions = new ObservableCollection <ButtonAction>()
            {
                new ButtonAction()
                {
                    ScanCode = 1
                },
                new ButtonAction()
                {
                    ScanCode = 2
                },
                new ButtonAction()
                {
                    ScanCode = 3
                },
            };
            var map = new HOTASButton()
            {
                MapName = "test map", MapId = 43, Type = HOTASButton.ButtonType.Button, ActionCatalogItem = catalog
            };
            var mapVm = new ButtonMapViewModel(map);

            mapVm.IsDisabledForced = false;
            Assert.True(mapVm.RecordMacroStartCommand.CanExecute(default));
예제 #3
0
        public void record_sets_history_empty_when_no_items()
        {
            var map = new HOTASButton();

            map.Record();
            map.Cancel();
            Assert.Empty(map.ActionCatalogItem.Actions);
        }
예제 #4
0
        public void record_sets_keyboard_state_true()
        {
            Keyboard.IsKeySuppressionActive = false;
            var map = new HOTASButton();

            map.Record();
            Assert.True(Keyboard.IsKeySuppressionActive);
        }
예제 #5
0
        public void cancel_sets_keyboard_state_false()
        {
            Keyboard.IsKeySuppressionActive = false;
            var map = new HOTASButton();

            map.Record();
            map.Cancel();
            Assert.False(Keyboard.IsKeySuppressionActive);
        }
예제 #6
0
        public void remove_mode_profile_only_one_profile()
        {
            var subDevice = Substitute.For <IHOTASDevice>();
            var buttonMap = new ObservableCollection <IHotasBaseMap>();
            var map       = new HOTASButton()
            {
                MapId = 1, IsShift = true, ShiftModePage = 1
            };

            buttonMap.Add(map);
            subDevice.ButtonMap.Returns(buttonMap);

            var deviceId = Guid.NewGuid();

            subDevice.DeviceId = deviceId;

            var subDeviceFactory = Substitute.For <HOTASDeviceFactory>();

            subDeviceFactory.CreateHOTASDevice(Arg.Any <IDirectInput>(), Arg.Any <Guid>(), Arg.Any <Guid>(),
                                               Arg.Any <string>(), Arg.Any <IHOTASQueue>()).Returns(subDevice);

            var profile = new Dictionary <int, ObservableCollection <IHotasBaseMap> >()
            {
                {
                    1, new ObservableCollection <IHotasBaseMap> {
                        buttonMap[0]
                    }
                }
            };

            subDevice.ModeProfiles.Returns(profile);

            var list = new HOTASCollection(Substitute.For <DirectInputFactory>(), Substitute.For <JoystickFactory>(), Substitute.For <HOTASQueueFactory>(Substitute.For <IKeyboard>()), subDeviceFactory);

            list.AddDevice(subDevice);
            list.ListenToAllDevices();

            var item = new ModeActivationItem()
            {
                DeviceId = deviceId,
                ButtonId = 1,
                Mode     = 1
            };

            list.ModeProfileActivationButtons.Add(1, item);

            Assert.True(map.IsShift);
            Assert.Equal(1, map.ShiftModePage);

            var isRemoved = list.RemoveModeProfile(item);

            Assert.Empty(list.ModeProfileActivationButtons);
            Assert.True(isRemoved);
            Assert.False(map.IsShift);
            Assert.Equal(0, map.ShiftModePage);
            Assert.Equal(1, list.Mode);
        }
예제 #7
0
        public void record_adds_action()
        {
            var map = new HOTASButton();

            map.Record();

            Keyboard.SimulateKeyPressTest(1, false, false);

            Assert.Single(map.ActionCatalogItem.Actions);
        }
예제 #8
0
        public void reset_shift()
        {
            var map = new HOTASButton {
                IsShift = true, ShiftModePage = 1
            };

            map.ResetShift();
            Assert.False(map.IsShift);
            Assert.Equal(0, map.ShiftModePage);
        }
예제 #9
0
        public void is_macro_true_with_one_item_time_not_zero()
        {
            var map = new HOTASButton();

            map.ActionCatalogItem.Actions.Add(new ButtonAction()
            {
                TimeInMilliseconds = 1
            });
            Assert.True(map.IsMacro);
        }
예제 #10
0
        public void record_clears_actions()
        {
            var map = new HOTASButton();

            map.ActionCatalogItem.Actions.Add(new ButtonAction()
            {
                ScanCode = 1, IsExtended = true, TimeInMilliseconds = 1
            });
            map.Record();
            Assert.Empty(map.ActionCatalogItem.Actions);
        }
예제 #11
0
        public void to_string()
        {
            var map = new HOTASButton()
            {
                MapName = "test map", MapId = 43, Type = HOTASButton.ButtonType.Button, ActionCatalogItem = new ActionCatalogItem()
                {
                    ActionName = "test action"
                }
            };
            var mapVm = new ButtonMapViewModel(map);

            Assert.Equal($"ButtonMap MapId:{map.MapId}, {map.MapName}", mapVm.ToString());
        }
예제 #12
0
        public void record_sets_history_with_one_item()
        {
            var map  = new HOTASButton();
            var item = new ButtonAction()
            {
                ScanCode = 1, IsExtended = true, TimeInMilliseconds = 1
            };

            map.ActionCatalogItem.Actions.Add(item);
            map.Record();
            map.Cancel();
            Assert.NotEmpty(map.ActionCatalogItem.Actions);
            Assert.Same(item, map.ActionCatalogItem.Actions.First());
        }
예제 #13
0
        public void to_string()
        {
            var map = new HOTASButton();

            map.ActionCatalogItem.Actions.Add(new ButtonAction()
            {
                ScanCode = 48, IsKeyUp = true
            });
            Assert.Equal("[KEY_B^]", map.ToString());
            map.ActionCatalogItem.Actions.Add(new ButtonAction()
            {
                ScanCode = 49
            });
            Assert.Equal("[KEY_B^][KEY_Nv]", map.ToString());
        }
예제 #14
0
        public void constructor_param()
        {
            var map = new HOTASButton()
            {
                MapName = "test map", MapId = 43, Type = HOTASButton.ButtonType.Button, ActionCatalogItem = new ActionCatalogItem()
                {
                    ActionName = "test action"
                }
            };
            var mapVm = new ButtonMapViewModel(map);

            Assert.Empty(mapVm.Actions);
            Assert.NotNull(mapVm.ActionItem);
            Assert.Equal(43, mapVm.ButtonId);
            Assert.Equal("test map", mapVm.ButtonName);
            Assert.Equal(HOTASButton.ButtonType.Button, mapVm.Type);
            Assert.Equal("test action", mapVm.ActionItem.ActionName);
            Assert.False(mapVm.IsRecording);
            Assert.False(mapVm.IsDisabledForced);
        }
예제 #15
0
        public void stop_keeps_only_new_actions()
        {
            var map  = new HOTASButton();
            var item = new ButtonAction()
            {
                ScanCode = 1, IsExtended = true, TimeInMilliseconds = 1
            };

            map.ActionCatalogItem.Actions.Add(item);
            map.Record();

            var newItem = new ButtonAction()
            {
                ScanCode = 1, IsExtended = true, TimeInMilliseconds = 1
            };

            map.ActionCatalogItem.Actions.Add(newItem);

            map.Stop();
            Assert.NotSame(item, map.ActionCatalogItem.Actions.First());
            Assert.Same(newItem, map.ActionCatalogItem.Actions.First());
        }
예제 #16
0
        public void clear_button_map()
        {
            var deviceVm = CreateDeviceViewMode("Test Device", out var hotasDevice);
            var list     = new ObservableCollection <IHotasBaseMap>();

            list.Add(new HOTASButton()
            {
                MapId = 48, Type = HOTASButton.ButtonType.Button, ActionCatalogItem = new ActionCatalogItem()
                {
                    Actions = new ObservableCollection <ButtonAction>()
                    {
                        new ButtonAction()
                    }
                }, ActionName = "first"
            });
            var testButton = new HOTASButton()
            {
                MapId             = 49,
                Type              = HOTASButton.ButtonType.Button,
                ActionCatalogItem = new ActionCatalogItem()
                {
                    Actions = new ObservableCollection <ButtonAction>()
                    {
                        new ButtonAction()
                    }
                },
                ActionName = "<No Action>"
            };

            list.Add(testButton);

            hotasDevice.ApplyButtonMap(list);

            deviceVm.RebuildMap();
            Assert.NotEmpty(testButton.ActionCatalogItem.Actions);
            deviceVm.ClearButtonMap();
            Assert.Empty(testButton.ActionCatalogItem.Actions);
        }
예제 #17
0
        public void activate_shift_mode_page()
        {
            var shiftModePage    = 43;
            var newShiftModePage = 1;
            var catalog          = new ActionCatalogItem()
            {
                ActionName = "test action"
            };

            catalog.Actions = new ObservableCollection <ButtonAction>()
            {
                new ButtonAction()
                {
                    ScanCode = 1
                },
                new ButtonAction()
                {
                    ScanCode = 2
                },
                new ButtonAction()
                {
                    ScanCode = 3
                },
            };
            var map = new HOTASButton()
            {
                MapName = "test map", MapId = 43, Type = HOTASButton.ButtonType.Button, ShiftModePage = shiftModePage
            };

            var mapVm = new ButtonMapViewModel(map);

            mapVm.AssignActions(catalog);
            Assert.Equal(shiftModePage, mapVm.ActivateShiftModePage);

            Assert.PropertyChanged(mapVm, "ActivateShiftModePage", () => mapVm.ActivateShiftModePage = 1);
            Assert.NotEqual(shiftModePage, mapVm.ActivateShiftModePage);
            Assert.Equal(newShiftModePage, mapVm.ActivateShiftModePage);
        }
예제 #18
0
        public void action_name_changed()
        {
            var catalog = new ActionCatalogItem()
            {
                ActionName = "test action"
            };

            catalog.Actions = new ObservableCollection <ButtonAction>()
            {
                new ButtonAction()
                {
                    ScanCode = 1
                },
                new ButtonAction()
                {
                    ScanCode = 2
                },
                new ButtonAction()
                {
                    ScanCode = 3
                },
            };
            var map = new HOTASButton()
            {
                MapName = "test map", MapId = 43, Type = HOTASButton.ButtonType.Button
            };

            var mapVm = new ButtonMapViewModel(map);

            mapVm.AssignActions(catalog);

            Assert.Equal("test action", mapVm.ActionName);

            var newActionName = "new action name";

            Assert.PropertyChanged(mapVm, "ActionName", () => mapVm.ActionName = newActionName);
            Assert.Equal(newActionName, mapVm.ActionItem.ActionName);
        }
예제 #19
0
        public void rebuild_button_action_view_model()
        {
            var catalog = new ActionCatalogItem()
            {
                ActionName = "test action"
            };

            catalog.Actions = new ObservableCollection <ButtonAction>()
            {
                new ButtonAction()
                {
                    ScanCode = 1
                },
                new ButtonAction()
                {
                    ScanCode = 2
                },
                new ButtonAction()
                {
                    ScanCode = 3
                },
            };
            var map = new HOTASButton()
            {
                MapName = "test map", MapId = 43, Type = HOTASButton.ButtonType.Button
            };

            var mapVm = new ButtonMapViewModel(map);

            mapVm.AssignActions(catalog);
            Assert.NotEmpty(mapVm.Actions);
            mapVm.Actions.Clear();
            mapVm.ReBuildButtonActionViewModel();
            Assert.NotEmpty(mapVm.Actions);
            Assert.Equal("ESCAPE", mapVm.Actions[0].ScanCode);
        }
예제 #20
0
        private static void SerializeButton(JsonWriter writer, JsonSerializer serializer, HOTASButton button)
        {
            var propList = typeof(HOTASButton).GetProperties();

            writer.WriteStartObject();
            foreach (var prop in propList)
            {
                if (prop.GetCustomAttributes(true).Any(x => x is JsonIgnoreAttribute))
                {
                    continue;
                }

                var value = prop.GetValue(button);

                if (prop.Name == nameof(button.ShiftModePage) && (int)prop.GetValue(button) == 0)
                {
                    continue;
                }
                if (prop.Name == nameof(button.IsShift) && (bool)prop.GetValue(button) == false)
                {
                    continue;
                }

                writer.WritePropertyName(prop.Name);
                serializer.Serialize(writer, value);
            }
            writer.WriteEndObject();
        }
예제 #21
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (objectType == typeof(IHOTASDevice))
            {
                var device = new HOTASDevice();
                try
                {
                    serializer.Populate(reader, device);
                }
                catch (Exception e)
                {
                    Logging.Log.Error(e, "Failed to deserialize a HOTASDevice");
                    throw;
                }
                return(device);
            }

            if (objectType == typeof(HOTASButton))
            {
                var buttonMap = new HOTASButton();
                try
                {
                    serializer.Populate(reader, buttonMap);
                }
                catch (Exception e)
                {
                    Logging.Log.Error(e, "Failed to deserialize a HOTASButton");
                    throw;
                }
                return(buttonMap);
            }

            if (objectType == typeof(ButtonAction))
            {
                var action = new ButtonAction();
                try
                {
                    serializer.Populate(reader, action);
                }
                catch (Exception e)
                {
                    Logging.Log.Error(e, "Failed to deserialize a ButtonAction");
                    throw;
                }
                return(action);
            }

            var dic = new Dictionary <int, ObservableCollection <IHotasBaseMap> >();

            var jsonDictionary = JObject.Load(reader);

            foreach (var kv in jsonDictionary)
            {
                var key       = int.Parse(kv.Key);
                var jsonArray = kv.Value;
                var list      = new ObservableCollection <IHotasBaseMap>();

                foreach (var jsonObject in jsonArray)
                {
                    IHotasBaseMap map;
                    var           testValue = jsonObject.Value <string>("Type");
                    Enum.TryParse(testValue, out HOTASButton.ButtonType testType);

                    try
                    {
                        switch (testType)
                        {
                        case HOTASButton.ButtonType.AxisLinear:
                        case HOTASButton.ButtonType.AxisRadial:
                            map = new HOTASAxis();
                            serializer.Populate(jsonObject.CreateReader(), map);
                            break;

                        default:
                            map = new HOTASButton();
                            serializer.Populate(jsonObject.CreateReader(), map);
                            break;
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        throw;
                    }
                    list.Add(map);
                }
                dic.Add(key, list);
            }

            return(dic);
        }
예제 #22
0
        public void is_macro_false_when_empty()
        {
            var map = new HOTASButton();

            Assert.False(map.IsMacro);
        }
예제 #23
0
        public void apply_activation_button_to_all_profiles()
        {
            var subDevice         = Substitute.For <IHOTASDevice>();
            var buttonMapProfile1 = new ObservableCollection <IHotasBaseMap>();
            var button_1_1        = new HOTASButton()
            {
                MapId = 1, IsShift = false, ShiftModePage = 1
            };
            var button_1_2 = new HOTASButton()
            {
                MapId = 2, IsShift = false, ShiftModePage = 2
            };
            var button_1_3 = new HOTASAxis()
            {
                MapId = 3, ButtonMap = new ObservableCollection <HOTASButton>()
                {
                    new HOTASButton()
                    {
                        MapId = 3, ShiftModePage = 3
                    }
                }
            };

            buttonMapProfile1.Add(button_1_1);
            buttonMapProfile1.Add(button_1_2);
            buttonMapProfile1.Add(button_1_3);

            var buttonMapProfile2 = new ObservableCollection <IHotasBaseMap>();
            var button_2_1        = new HOTASButton()
            {
                MapId = 1, IsShift = false, ShiftModePage = 0
            };                                                                                    //simulate a new profile that does not have links back to previous profiles
            var button_2_2 = new HOTASButton()
            {
                MapId = 2, IsShift = false, ShiftModePage = 0
            };                                                                                    //simulate a new profile that does not have links back to previous profiles
            var button_2_3 = new HOTASAxis()
            {
                MapId = 3, ButtonMap = new ObservableCollection <HOTASButton>()
                {
                    new HOTASButton()
                    {
                        MapId = 3, ShiftModePage = 0
                    }
                }
            };

            buttonMapProfile2.Add(button_2_1);
            buttonMapProfile2.Add(button_2_2);
            buttonMapProfile2.Add(button_2_3);

            subDevice.ButtonMap.Returns(buttonMapProfile1);


            var deviceId = Guid.NewGuid();

            subDevice.DeviceId = deviceId;

            var subDeviceFactory = Substitute.For <HOTASDeviceFactory>();

            subDeviceFactory.CreateHOTASDevice(Arg.Any <IDirectInput>(), Arg.Any <Guid>(), Arg.Any <Guid>(),
                                               Arg.Any <string>(), Arg.Any <IHOTASQueue>()).Returns(subDevice);

            var profiles = new Dictionary <int, ObservableCollection <IHotasBaseMap> >()
            {
                {
                    1, buttonMapProfile1
                },
                {
                    2, buttonMapProfile2
                },
                {
                    3, buttonMapProfile2
                }
            };

            subDevice.ModeProfiles.Returns(profiles);

            var list = new HOTASCollection(Substitute.For <DirectInputFactory>(), Substitute.For <JoystickFactory>(), Substitute.For <HOTASQueueFactory>(Substitute.For <IKeyboard>()), subDeviceFactory);

            list.AddDevice(subDevice);
            list.ListenToAllDevices();

            var item1 = new ModeActivationItem()
            {
                DeviceId = deviceId,
                ButtonId = 1,
                Mode     = 1
            };

            var item2 = new ModeActivationItem()
            {
                DeviceId = deviceId,
                ButtonId = 2,
                Mode     = 2
            };

            var item3 = new ModeActivationItem()
            {
                DeviceId = deviceId,
                ButtonId = 3,
                Mode     = 3
            };

            list.ModeProfileActivationButtons.Add(1, item1);
            list.ModeProfileActivationButtons.Add(2, item2);
            list.ModeProfileActivationButtons.Add(3, item3);

            Assert.Equal(0, button_2_1.ShiftModePage);
            Assert.Equal(0, button_2_2.ShiftModePage);
            Assert.Equal(0, button_2_3.ButtonMap[0].ShiftModePage);

            list.ApplyActivationButtonToAllProfiles();

            Assert.Equal(1, button_2_1.ShiftModePage);
            Assert.Equal(2, button_2_2.ShiftModePage);
            Assert.Equal(3, button_2_3.ButtonMap[0].ShiftModePage);
        }