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

luttje / Key2Joy / 6599225437

21 Oct 2023 07:19PM UTC coverage: 44.768% (-7.8%) from 52.519%
6599225437

Pull #50

github

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

758 of 2325 branches covered (0.0%)

Branch coverage included in aggregate %.

2834 of 2834 new or added lines in 98 files covered. (100.0%)

3875 of 8024 relevant lines covered (48.29%)

13037.59 hits per line

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

79.71
/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 object Clone() => new MappedOption(this.Guid)
131!
63
    {
131✔
64
        Trigger = this.Trigger != null ? (AbstractTrigger)this.Trigger.Clone() : null,
131✔
65
        Action = (AbstractAction)this.Action.Clone(),
131✔
66
        ParentGuid = this.ParentGuid,
131✔
67
    };
131✔
68

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

80
        foreach (var mapping in mappings)
14✔
81
        {
82
            newOptions.Add(GenerateReverseMapping(mapping));
3✔
83
        }
84

85
        return newOptions;
4✔
86
    }
87

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

101
        if (mapping.Action is IProvideReverseAspect action)
3✔
102
        {
103
            action.MakeReverse(actionCopy);
1✔
104
        }
105

106
        if (mapping.Trigger is IProvideReverseAspect trigger)
3✔
107
        {
108
            trigger.MakeReverse(triggerCopy);
1✔
109
        }
110

111
        MappedOption variantOption = new()
3✔
112
        {
3✔
113
            Action = actionCopy,
3✔
114
            Trigger = triggerCopy,
3✔
115
        };
3✔
116

117
        if (!dontSetParent)
3✔
118
        {
119
            variantOption.SetParent(mapping);
3✔
120
        }
121

122
        return variantOption;
3✔
123
    }
124
}
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