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

luttje / Key2Joy / 6598306412

21 Oct 2023 03:54PM UTC coverage: 45.09% (-7.4%) from 52.519%
6598306412

Pull #50

github

web-flow
Merge bff596568 into 14b7ce9a7
Pull Request #50: Add XInput in preparation for gamepad triggers + add xmldoc

751 of 2289 branches covered (0.0%)

Branch coverage included in aggregate %.

2384 of 2384 new or added lines in 80 files covered. (100.0%)

3845 of 7904 relevant lines covered (48.65%)

15964.61 hits per line

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

76.81
/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
using Key2Joy.LowLevelInput;
8

9
namespace Key2Joy.Mapping;
10

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

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

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

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

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

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

38
            return;
×
39
        }
40

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

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

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

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

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

70
    public static List<MappedOption> GenerateOppositePressStateMappings(List<MappedOption> mappings)
71
    {
72
        List<MappedOption> newOptions = new();
4✔
73

74
        foreach (var pressVariant in mappings)
14✔
75
        {
76
            var actionCopy = (AbstractAction)pressVariant.Action.Clone();
3✔
77
            var triggerCopy = (AbstractTrigger)pressVariant.Trigger.Clone();
3✔
78

79
            if (actionCopy is IPressState actionWithPressState)
3✔
80
            {
81
                actionWithPressState.PressState = actionWithPressState.PressState == PressState.Press ? PressState.Release : PressState.Press;
1!
82
            }
83

84
            if (triggerCopy is IPressState triggerWithPressState)
3✔
85
            {
86
                triggerWithPressState.PressState = triggerWithPressState.PressState == PressState.Press ? PressState.Release : PressState.Press;
1!
87
            }
88

89
            MappedOption variantOption = new()
3✔
90
            {
3✔
91
                Action = actionCopy,
3✔
92
                Trigger = triggerCopy,
3✔
93
            };
3✔
94
            variantOption.SetParent(pressVariant);
3✔
95

96
            newOptions.Add(variantOption);
3✔
97
        }
98

99
        return newOptions;
4✔
100
    }
101
}
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