• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

luttje / Key2Joy / 6602669847

22 Oct 2023 08:23AM UTC coverage: 44.094% (-8.4%) from 52.519%
6602669847

push

github

web-flow
Add XInput in preparation for gamepad triggers + add xmldoc (#50)

* Add XInput in preparation for gamepad triggers + add xmldoc

* add parent-child relation between mapped options

* add remove child mappings option + remove debug context menu

* x86 > AnyCPU (gives more sensible errors in WinForms Designer) - Fixed Designer failing on MappingForm

* Fix polling gamepad

* Add gamepad input trigger and config control + Fix mapping list not updating correctly

* remove broken and quite useless test

* update readme with warning regarding #46 + update readme special thanks

* add warning on same gamepad id trigger and action

* attempt to give github actions more time before timeout (tests sometimes fail)

* use current default mapping profile from app (so we dont have to copy it to tests everytime manually)

* Add gamepad button trigger

* Add multi-property edit mode

* Show physical gamepad connection warning

* give even more time for tests so they dont fail

* Block arming mappings if simulated gamepad index collides with physical gamepad

* Cleanup + add GamePad Trigger Trigger

* Fix combined trigger remove not working

* Separate stick action and allow custom scaling

* improve stick feeling

* fix parent picker

* update default mappings

* add trigger and try work out conflicts between physical and simulated devices (no luck yet)

* Fix simulated gamepad recognized as physical

* Show gamepad devices in UI

* fix mapping form + add more multi-edit type support

* make reverse mapping tool more useful

* easily setup/update reverse mappings while creating/updating a mapping

* update readme screenshots + prefer 'Arm' terminology for enabling profile

* support more nullable types in mapping profile

* simplify groups

* add configurable grouping

* prevent wonky sorting across groups

* Add easy switch group option

* Fix being able to create corrupt profile

* fail loading ... (continued)

762 of 2383 branches covered (0.0%)

Branch coverage included in aggregate %.

3060 of 3060 new or added lines in 106 files covered. (100.0%)

3897 of 8183 relevant lines covered (47.62%)

12635.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.57
/Core/Key2Joy.Core/Mapping/MappedOption.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Text.Json.Serialization;
4
using Key2Joy.Contracts.Mapping;
5
using Key2Joy.Contracts.Mapping.Actions;
6
using Key2Joy.Contracts.Mapping.Triggers;
7

8
namespace Key2Joy.Mapping;
9

10
public class MappedOption : AbstractMappedOption
11
{
12
    [JsonIgnore]
13
    public bool IsChild => this.ParentGuid != null;
×
14

15
    [JsonIgnore]
16
    public MappedOption Parent { get; set; }
39✔
17

18
    [JsonIgnore]
19
    public IList<MappedOption> Children { get; set; } = new List<MappedOption>();
440✔
20

21
    public MappedOption()
22
        : base()
139✔
23
        => this.Guid = Guid.NewGuid();
139✔
24

25
    public MappedOption(Guid guid)
26
        : base()
131✔
27
        => this.Guid = guid;
131✔
28

29
    public void SetParent(MappedOption parent)
30
    {
31
        if (parent == null)
3!
32
        {
33
            this.Parent.Children.Remove(this);
×
34
            this.ParentGuid = null;
×
35
            this.Parent = null;
×
36

37
            return;
×
38
        }
39

40
        this.ParentGuid = parent.Guid;
3✔
41
        this.Parent = parent;
3✔
42
        parent.Children.Add(this);
3✔
43
    }
3✔
44

45
    public bool IsChildOf(MappedOption parent)
46
        => this.ParentGuid != null && this.ParentGuid == parent.Guid;
×
47

48
    public void Initialize(IList<MappedOption> allMappedOptions)
49
    {
50
        this.Children = new List<MappedOption>();
131✔
51

52
        foreach (var mappedOption in allMappedOptions)
11,788✔
53
        {
54
            if (mappedOption.ParentGuid.Equals(this.Guid))
5,763✔
55
            {
56
                this.Children.Add(mappedOption);
36✔
57
                mappedOption.Parent = this;
36✔
58
            }
59
        }
60
    }
131✔
61

62
    public override string ToString()
63
        => $"[{this.Guid}] Trigger: {this.Trigger} -> Action: {this.Action}";
×
64

65
    /// <inheritdoc/>
66
    public override object Clone() => new MappedOption(this.Guid)
131!
67
    {
131✔
68
        Trigger = this.Trigger != null ? (AbstractTrigger)this.Trigger.Clone() : null,
131✔
69
        Action = (AbstractAction)this.Action.Clone(),
131✔
70
        ParentGuid = this.ParentGuid,
131✔
71
    };
131✔
72

73
    /// <summary>
74
    /// Goes through all provided mappings and asks them to provide the reverse for their
75
    /// action and trigger. If no <see cref="IProvideReverseAspect"/> is implemented, a
76
    /// copy of the current mapping is returned.
77
    /// </summary>
78
    /// <param name="mappings"></param>
79
    /// <returns></returns>
80
    public static List<MappedOption> GenerateReverseMappings(List<MappedOption> mappings)
81
    {
82
        List<MappedOption> newOptions = new();
4✔
83

84
        foreach (var mapping in mappings)
14✔
85
        {
86
            newOptions.Add(GenerateReverseMapping(mapping));
3✔
87
        }
88

89
        return newOptions;
4✔
90
    }
91

92
    /// <summary>
93
    /// Asks the provided mappings for a variant with reverse action and trigger.
94
    /// If no <see cref="IProvideReverseAspect"/> is implemented, a copy of the
95
    /// current mapping is returned.
96
    /// </summary>
97
    /// <param name="mapping"></param>
98
    /// <param name="dontSetParent">Optionally dont set the parent, useful to get a reverse that wont be saved.</param>
99
    /// <returns></returns>
100
    public static MappedOption GenerateReverseMapping(MappedOption mapping, bool dontSetParent = false)
101
    {
102
        var actionCopy = (AbstractAction)mapping.Action.Clone();
3✔
103
        var triggerCopy = (AbstractTrigger)mapping.Trigger.Clone();
3✔
104

105
        if (mapping.Action is IProvideReverseAspect action)
3✔
106
        {
107
            action.MakeReverse(actionCopy);
1✔
108
        }
109

110
        if (mapping.Trigger is IProvideReverseAspect trigger)
3✔
111
        {
112
            trigger.MakeReverse(triggerCopy);
1✔
113
        }
114

115
        MappedOption variantOption = new()
3✔
116
        {
3✔
117
            Action = actionCopy,
3✔
118
            Trigger = triggerCopy,
3✔
119
        };
3✔
120

121
        if (!dontSetParent)
3✔
122
        {
123
            variantOption.SetParent(mapping);
3✔
124
        }
125

126
        return variantOption;
3✔
127
    }
128
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc