-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update jint + fail gracefully on invalid enum from script
- Loading branch information
Showing
6 changed files
with
105 additions
and
97 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
174 changes: 87 additions & 87 deletions
174
Core/Key2Joy.Core/Mapping/Actions/Logic/SetDelayedFunctionsAction.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,87 +1,87 @@ | ||
using System; | ||
using System.Text.Json.Serialization; | ||
using System.Threading.Tasks; | ||
using Key2Joy.Contracts.Mapping; | ||
using Key2Joy.Contracts.Mapping.Actions; | ||
using Key2Joy.Contracts.Mapping.Triggers; | ||
|
||
namespace Key2Joy.Mapping.Actions.Logic; | ||
|
||
[Action( | ||
Description = "Timeout for a specified duration before executing a function", | ||
Visibility = MappingMenuVisibility.Never, | ||
NameFormat = "Timeout for {0}ms", | ||
GroupName = "Logic", | ||
GroupImage = "application_xp_terminal" | ||
)] | ||
public class SetDelayedFunctionsAction : CoreAction | ||
{ | ||
[JsonInclude] | ||
public TimeSpan WaitTime; | ||
|
||
public SetDelayedFunctionsAction(string name) | ||
: base(name) | ||
{ | ||
} | ||
|
||
/// <markdown-doc> | ||
/// <parent-name>Logic</parent-name> | ||
/// <path>Api/Logic</path> | ||
/// </markdown-doc> | ||
/// <summary> | ||
/// Execute functions whilst waiting the specified time between them. | ||
/// | ||
/// The first function is executed immediately. | ||
/// </summary> | ||
/// <markdown-example> | ||
/// Shows how to count down from 3 and execute a command using Lua. | ||
/// <code language="lua"> | ||
/// <![CDATA[ | ||
/// SetDelayedFunctions( | ||
/// 1000, | ||
/// function () | ||
/// Print("Aborting in 3 second...") | ||
/// end, | ||
/// function () | ||
/// Print("Three") | ||
/// end, | ||
/// function () | ||
/// Print("Two") | ||
/// end, | ||
/// function () | ||
/// Print("One") | ||
/// end, | ||
/// function () | ||
/// App.Command("abort") | ||
/// end | ||
/// ) | ||
/// ]]> | ||
/// </code> | ||
/// </markdown-example> | ||
/// <param name="waitTime">Time to wait (in milliseconds) between function calls</param> | ||
/// <param name="callbacks">One or more functions to execute</param> | ||
/// <name>SetDelayedFunctions</name> | ||
[ExposesScriptingMethod("SetDelayedFunctions")] | ||
public async void ExecuteForScript(long waitTime, params Action[] callbacks) | ||
{ | ||
this.WaitTime = TimeSpan.FromMilliseconds(waitTime); | ||
|
||
for (var i = 0; i < callbacks.Length; i++) | ||
{ | ||
if (i > 0) | ||
{ | ||
await Task.Delay(this.WaitTime); | ||
} | ||
|
||
callbacks[i].Invoke(); | ||
} | ||
} | ||
|
||
public override Task Execute(AbstractInputBag inputBag = null) => | ||
// Irrelevant because only scripts should use this function | ||
Task.Delay(this.WaitTime); | ||
|
||
public override string GetNameDisplay() => | ||
// Irrelevant because only scripts should use this function | ||
this.Name.Replace("{0}", this.WaitTime.TotalMilliseconds.ToString()); | ||
} | ||
using System; | ||
using System.Text.Json.Serialization; | ||
using System.Threading.Tasks; | ||
using Key2Joy.Contracts.Mapping; | ||
using Key2Joy.Contracts.Mapping.Actions; | ||
using Key2Joy.Contracts.Mapping.Triggers; | ||
|
||
namespace Key2Joy.Mapping.Actions.Logic; | ||
|
||
[Action( | ||
Description = "Timeout for a specified duration before executing a function", | ||
Visibility = MappingMenuVisibility.Never, | ||
NameFormat = "Timeout for {0}ms", | ||
GroupName = "Logic", | ||
GroupImage = "application_xp_terminal" | ||
)] | ||
public class SetDelayedFunctionsAction : CoreAction | ||
{ | ||
[JsonInclude] | ||
public TimeSpan WaitTime; | ||
|
||
public SetDelayedFunctionsAction(string name) | ||
: base(name) | ||
{ | ||
} | ||
|
||
/// <markdown-doc> | ||
/// <parent-name>Logic</parent-name> | ||
/// <path>Api/Logic</path> | ||
/// </markdown-doc> | ||
/// <summary> | ||
/// Execute functions whilst waiting the specified time between them. | ||
/// | ||
/// The first function is executed immediately. | ||
/// </summary> | ||
/// <markdown-example> | ||
/// Shows how to count down from 3 and execute a command using Lua. | ||
/// <code language="lua"> | ||
/// <![CDATA[ | ||
/// SetDelayedFunctions( | ||
/// 1000, | ||
/// function () | ||
/// Print("Aborting in 3 second...") | ||
/// end, | ||
/// function () | ||
/// Print("Three") | ||
/// end, | ||
/// function () | ||
/// Print("Two") | ||
/// end, | ||
/// function () | ||
/// Print("One") | ||
/// end, | ||
/// function () | ||
/// App.Command("Abort") | ||
/// end | ||
/// ) | ||
/// ]]> | ||
/// </code> | ||
/// </markdown-example> | ||
/// <param name="waitTime">Time to wait (in milliseconds) between function calls</param> | ||
/// <param name="callbacks">One or more functions to execute</param> | ||
/// <name>SetDelayedFunctions</name> | ||
[ExposesScriptingMethod("SetDelayedFunctions")] | ||
public async void ExecuteForScript(long waitTime, params Action[] callbacks) | ||
{ | ||
this.WaitTime = TimeSpan.FromMilliseconds(waitTime); | ||
|
||
for (var i = 0; i < callbacks.Length; i++) | ||
{ | ||
if (i > 0) | ||
{ | ||
await Task.Delay(this.WaitTime); | ||
} | ||
|
||
callbacks[i].Invoke(); | ||
} | ||
} | ||
|
||
public override Task Execute(AbstractInputBag inputBag = null) => | ||
// Irrelevant because only scripts should use this function | ||
Task.Delay(this.WaitTime); | ||
|
||
public override string GetNameDisplay() => | ||
// Irrelevant because only scripts should use this function | ||
this.Name.Replace("{0}", this.WaitTime.TotalMilliseconds.ToString()); | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.