-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding more tests, fixing bugs in the process (#48)
* Add config manager tests * legacy config and mapping profile tests (should fix #42) * remove comment, problem was caused by transfer across appdomain (or to/fro scripting environment) * Test core functionality #48 + includes minor refactoring to be able to test + added docs * Add interop tests + implement and test async test utility (refactors away from singletons) * fix not all tests running in workflow * config and interop tests * Refactor and allow mocking global input hook class * add capture action test * Make Execute override optional for script only methods * add dependency injection + refactor and try test gamepad service * Refactor config singleton to using dependency injection * add tests for scripting * add tests for plugin set + fix plugin showing as loaded even if checksum match failed * fix tests failing because it relied on config exist (I guess the test order was accidentally correct earlier, this means we should really fix cleanup so we catch this sooner) * refactor docs code + fix wrong enum summary * refactor docs builder and start testing it a bit * fix cmd project structure * ignore designer files in tests * cleanup and refactor UI code + show latest version in help * truncate listview action column * allow user config to minimize app when pressing X (defaults to shut down app) resolves #45
- Loading branch information
Showing
193 changed files
with
32,318 additions
and
23,981 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,49 @@ | ||
using System.Collections.Generic; | ||
using System.Text.Json.Serialization; | ||
using System.Threading.Tasks; | ||
using Key2Joy.Contracts.Mapping.Triggers; | ||
|
||
namespace Key2Joy.Contracts.Mapping.Actions; | ||
|
||
public abstract class AbstractAction : AbstractMappingAspect | ||
{ | ||
[JsonIgnore] | ||
public bool IsStarted { get; set; } | ||
|
||
protected AbstractTriggerListener Listener { get; set; } | ||
|
||
protected IList<AbstractAction> OtherActions; | ||
|
||
public abstract Task Execute(AbstractInputBag inputBag = null); | ||
|
||
public virtual string GetNameDisplay() => this.Name; | ||
|
||
public AbstractAction(string name) | ||
: base(name) { } | ||
|
||
public virtual void OnStartListening(AbstractTriggerListener listener, ref IList<AbstractAction> otherActions) | ||
=> this.SetStartData(listener, ref otherActions); | ||
|
||
public virtual void OnStopListening(AbstractTriggerListener listener) | ||
{ | ||
this.IsStarted = false; | ||
|
||
this.Listener = null; | ||
} | ||
|
||
public void SetStartData(AbstractTriggerListener listener, ref IList<AbstractAction> otherActions) | ||
{ | ||
this.IsStarted = true; | ||
this.Listener = listener; | ||
this.OtherActions = otherActions; | ||
} | ||
} | ||
using System.Collections.Generic; | ||
using System.Text.Json.Serialization; | ||
using System.Threading.Tasks; | ||
using Key2Joy.Contracts.Mapping.Triggers; | ||
using Key2Joy.Contracts.Util; | ||
|
||
namespace Key2Joy.Contracts.Mapping.Actions; | ||
|
||
public abstract class AbstractAction : AbstractMappingAspect | ||
{ | ||
[JsonIgnore] | ||
public bool IsStarted { get; set; } | ||
|
||
protected AbstractTriggerListener Listener { get; set; } | ||
|
||
protected IList<AbstractAction> OtherActions; | ||
|
||
/// <summary> | ||
/// This method is called to execute the action. It can optionally be override, by | ||
/// default it throws a NotImplementedException, which is useful for actions that | ||
/// only have a script implementation (on other methods). | ||
/// </summary> | ||
/// <param name="inputBag"></param> | ||
/// <returns></returns> | ||
/// <exception cref="System.NotImplementedException"></exception> | ||
public virtual Task Execute(AbstractInputBag inputBag = null) => throw new System.NotImplementedException(); | ||
|
||
public virtual string GetNameDisplay() => this.Name; | ||
|
||
public AbstractAction(string name) | ||
: base(name) { } | ||
|
||
public virtual void OnStartListening(AbstractTriggerListener listener, ref IList<AbstractAction> otherActions) | ||
=> this.SetStartData(listener, ref otherActions); | ||
|
||
public virtual void OnStopListening(AbstractTriggerListener listener) | ||
{ | ||
this.IsStarted = false; | ||
|
||
this.Listener = null; | ||
} | ||
|
||
public void SetStartData(AbstractTriggerListener listener, ref IList<AbstractAction> otherActions) | ||
{ | ||
this.IsStarted = true; | ||
this.Listener = listener; | ||
this.OtherActions = otherActions; | ||
} | ||
} |
115 changes: 65 additions & 50 deletions
115
Core/Key2Joy.Contracts/Mapping/Triggers/AbstractTrigger.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,65 @@ | ||
using System; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Key2Joy.Contracts.Mapping.Triggers; | ||
|
||
public abstract class AbstractTrigger : AbstractMappingAspect | ||
{ | ||
public event EventHandler<TriggerExecutingEventArgs> Executing; | ||
|
||
[JsonIgnore] | ||
public AbstractInputBag LastInputBag { get; protected set; } | ||
[JsonIgnore] | ||
public DateTime LastActivated { get; protected set; } | ||
[JsonIgnore] | ||
public bool ExecutedLastActivation { get; protected set; } | ||
|
||
public AbstractTrigger(string name) | ||
: base(name) { } | ||
|
||
/// <summary> | ||
/// Must return a singleton listener that will listen for triggers. | ||
/// | ||
/// When the user starts their mappings, this listener will be given each relevant mapping to look for. | ||
/// </summary> | ||
/// <returns>Singleton trigger listener</returns> | ||
public abstract AbstractTriggerListener GetTriggerListener(); | ||
|
||
/// <summary> | ||
/// Must return an input value unique in the profile. Like a Keys combination or an AxisDirection. | ||
/// Will be used to quickly lookup input triggers and their corresponding action | ||
/// </summary> | ||
/// <returns></returns> | ||
public abstract string GetUniqueKey(); | ||
|
||
public virtual bool GetShouldExecute() | ||
{ | ||
TriggerExecutingEventArgs eventArgs = new(); | ||
|
||
Executing?.Invoke(this, eventArgs); | ||
|
||
return !eventArgs.Handled; | ||
} | ||
|
||
public virtual void DoActivate(AbstractInputBag inputBag, bool executed = false) | ||
{ | ||
this.LastActivated = DateTime.Now; | ||
this.LastInputBag = inputBag; | ||
this.ExecutedLastActivation = executed; | ||
} | ||
} | ||
using System; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Key2Joy.Contracts.Mapping.Triggers; | ||
|
||
public abstract class AbstractTrigger : AbstractMappingAspect | ||
{ | ||
public event EventHandler<TriggerExecutingEventArgs> Executing; | ||
|
||
[JsonIgnore] | ||
public AbstractInputBag LastInputBag { get; protected set; } | ||
|
||
[JsonIgnore] | ||
public DateTime LastActivated { get; protected set; } | ||
|
||
[JsonIgnore] | ||
public bool ExecutedLastActivation { get; protected set; } | ||
|
||
public AbstractTrigger(string name) | ||
: base(name) { } | ||
|
||
/// <summary> | ||
/// Must return a singleton listener that will listen for triggers. | ||
/// | ||
/// When the user starts their mappings, this listener will be given each relevant mapping to look for. | ||
/// </summary> | ||
/// <returns>Singleton trigger listener</returns> | ||
public abstract AbstractTriggerListener GetTriggerListener(); | ||
|
||
/// <summary> | ||
/// Must return an input value unique in the profile. Like a Keys combination or an AxisDirection. | ||
/// Will be used to quickly lookup input triggers and their corresponding action | ||
/// </summary> | ||
/// <returns></returns> | ||
public abstract string GetUniqueKey(); | ||
|
||
/// <summary> | ||
/// Through this the trigger can decide if it wants to execute. By default it calls the | ||
/// <see cref="Executing"/> event and executes if it's not handled. | ||
/// This method is only called after the trigger listener has asked which mapped options | ||
/// should even be considered to excecute through <see cref="AbstractTriggerListener.TriggerActivating"/>. | ||
/// </summary> | ||
/// <returns></returns> | ||
public virtual bool GetShouldExecute() | ||
{ | ||
TriggerExecutingEventArgs eventArgs = new(); | ||
|
||
Executing?.Invoke(this, eventArgs); | ||
|
||
return !eventArgs.Handled; | ||
} | ||
|
||
/// <summary> | ||
/// Called when the trigger has been considered for triggering. By default it just registers | ||
/// the last activation time and input bag. | ||
/// </summary> | ||
/// <param name="inputBag"></param> | ||
/// <param name="executed"></param> | ||
public virtual void DoActivate(AbstractInputBag inputBag, bool executed = false) | ||
{ | ||
this.LastActivated = DateTime.Now; | ||
this.LastInputBag = inputBag; | ||
this.ExecutedLastActivation = executed; | ||
} | ||
} |
Oops, something went wrong.