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

luttje / Key2Joy / 6602636543

22 Oct 2023 08:16AM UTC coverage: 44.104% (-8.4%) from 52.519%
6602636543

Pull #50

github

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

764 of 2383 branches covered (0.0%)

Branch coverage included in aggregate %.

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

3896 of 8183 relevant lines covered (47.61%)

15812.68 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