Skip to content

Commit 50bfaa8

Browse files
committed
Merge branch 'development'
2 parents 7eab864 + cc1f3a9 commit 50bfaa8

File tree

6 files changed

+25
-29
lines changed

6 files changed

+25
-29
lines changed

NWN.Anvil.Tests/src/main/Services/Scheduler/SchedulerServiceTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public async Task ScheduleDelayRunsTaskAfterDelay(int delayMs)
3939
[TestCase(500)]
4040
[TestCase(1000)]
4141
[TestCase(5000)]
42-
public async Task ScheduleAndCancelDoesNotRunTask(int delayMs)
42+
public Task ScheduleAndCancelDoesNotRunTask(int delayMs)
4343
{
4444
TimeSpan delay = TimeSpan.FromMilliseconds(delayMs);
4545

@@ -49,7 +49,7 @@ public async Task ScheduleAndCancelDoesNotRunTask(int delayMs)
4949
}, delay);
5050

5151
task.Cancel();
52-
await NwTask.Delay(delay + TimeSpan.FromSeconds(1));
52+
return NwTask.Delay(delay + TimeSpan.FromSeconds(1));
5353
}
5454

5555
[Test(Description = "Scheduling a repeating task correctly schedules and runs the task with the specified interval.")]

NWN.Anvil/src/main/API/Async/NwTask.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@ public static class NwTask
2727
/// </summary>
2828
/// <param name="delay">How long to wait.</param>
2929
/// <param name="cancellationToken">A cancellation token that should be used to cancel the work.</param>
30-
public static async Task Delay(TimeSpan delay, CancellationToken? cancellationToken = null)
30+
public static Task Delay(TimeSpan delay, CancellationToken? cancellationToken = null)
3131
{
3232
Stopwatch stopwatch = Stopwatch.StartNew();
33-
await RunAndAwait(() => delay < stopwatch.Elapsed, cancellationToken);
33+
return RunAndAwait(() => delay < stopwatch.Elapsed, cancellationToken);
3434
}
3535

3636
/// <summary>
3737
/// Waits until the specified amount of frames have passed.
3838
/// </summary>
3939
/// <param name="frames">The number of frames to wait.</param>
4040
/// <param name="cancellationToken">A cancellation token that should be used to cancel the work.</param>
41-
public static async Task DelayFrame(int frames, CancellationToken? cancellationToken = null)
41+
public static Task DelayFrame(int frames, CancellationToken? cancellationToken = null)
4242
{
43-
await RunAndAwait(() =>
43+
return RunAndAwait(() =>
4444
{
4545
bool retVal = frames <= 0;
4646
frames--;
@@ -51,9 +51,9 @@ await RunAndAwait(() =>
5151
/// <summary>
5252
/// Waits until the next server frame/loop.
5353
/// </summary>
54-
public static async Task NextFrame()
54+
public static Task NextFrame()
5555
{
56-
await DelayFrame(1);
56+
return DelayFrame(1);
5757
}
5858

5959
/// <summary>
@@ -88,20 +88,20 @@ public static IAwaitable SwitchToMainThread()
8888
/// </summary>
8989
/// <param name="test">The test expression.</param>
9090
/// <param name="cancellationToken">A cancellation token that should be used to cancel the work.</param>
91-
public static async Task WaitUntil(Func<bool> test, CancellationToken? cancellationToken = null)
91+
public static Task WaitUntil(Func<bool> test, CancellationToken? cancellationToken = null)
9292
{
93-
await RunAndAwait(test, cancellationToken);
93+
return RunAndAwait(test, cancellationToken);
9494
}
9595

9696
/// <summary>
9797
/// Waits until the specified value source changes.
9898
/// </summary>
9999
/// <param name="valueSource">The watched value source.</param>
100100
/// <param name="cancellationToken">A cancellation token that should be used to cancel the work.</param>
101-
public static async Task WaitUntilValueChanged<T>(Func<T> valueSource, CancellationToken? cancellationToken = null)
101+
public static Task WaitUntilValueChanged<T>(Func<T> valueSource, CancellationToken? cancellationToken = null)
102102
{
103103
T currentVal = valueSource();
104-
await RunAndAwait(() => !Equals(currentVal, valueSource()), cancellationToken);
104+
return RunAndAwait(() => !Equals(currentVal, valueSource()), cancellationToken);
105105
}
106106

107107
/// <summary>

NWN.Anvil/src/main/API/Nui/NuiWindowEventService.cs

+1-5
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,10 @@ public void Subscribe(NuiWindowToken token, Action<ModuleEvents.OnNuiEvent> hand
2424
eventHandlers[token.Player] = playerHandlers;
2525
}
2626

27-
if (playerHandlers.ContainsKey(token.Token))
27+
if (!playerHandlers.TryAdd(token.Token, handler))
2828
{
2929
playerHandlers[token.Token] += handler;
3030
}
31-
else
32-
{
33-
playerHandlers[token.Token] = handler;
34-
}
3531
}
3632

3733
public void Unsubscribe(NuiWindowToken token, Action<ModuleEvents.OnNuiEvent> handler)

NWN.Anvil/src/main/API/Objects/NwCreature.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1084,18 +1084,18 @@ public async Task ActionInteractObject(NwPlaceable placeable)
10841084
/// Instructs this creature to approach and lock the specified door.
10851085
/// </summary>
10861086
/// <param name="door">The door to lock.</param>
1087-
public async Task ActionLockObject(NwDoor door)
1087+
public Task ActionLockObject(NwDoor door)
10881088
{
1089-
await DoActionLockObject(door);
1089+
return DoActionLockObject(door);
10901090
}
10911091

10921092
/// <summary>
10931093
/// Instructs this creature to approach and lock the specified placeable.
10941094
/// </summary>
10951095
/// <param name="placeable">The placeable to lock.</param>
1096-
public async Task ActionLockObject(NwPlaceable placeable)
1096+
public Task ActionLockObject(NwPlaceable placeable)
10971097
{
1098-
await DoActionLockObject(placeable);
1098+
return DoActionLockObject(placeable);
10991099
}
11001100

11011101
/// <summary>
@@ -1216,18 +1216,18 @@ public async Task ActionUnequipItem(NwItem item)
12161216
/// Instructs this creature to approach and unlock the specified door.
12171217
/// </summary>
12181218
/// <param name="door">The door to unlock.</param>
1219-
public async Task ActionUnlockObject(NwDoor door)
1219+
public Task ActionUnlockObject(NwDoor door)
12201220
{
1221-
await DoActionUnlockObject(door);
1221+
return DoActionUnlockObject(door);
12221222
}
12231223

12241224
/// <summary>
12251225
/// Instructs this creature to approach and unlock the specified placeable.
12261226
/// </summary>
12271227
/// <param name="placeable">The placeable to unlock.</param>
1228-
public async Task ActionUnlockObject(NwPlaceable placeable)
1228+
public Task ActionUnlockObject(NwPlaceable placeable)
12291229
{
1230-
await DoActionUnlockObject(placeable);
1230+
return DoActionUnlockObject(placeable);
12311231
}
12321232

12331233
/// <summary>

NWN.Anvil/src/main/API/Objects/NwGameObject.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,9 @@ public async void EndConversation()
366366
/// Rotates this object to face towards target.
367367
/// </summary>
368368
/// <param name="target">The target object to face.</param>
369-
public async Task FaceToObject(NwGameObject target)
369+
public Task FaceToObject(NwGameObject target)
370370
{
371-
await FaceToPoint(target.Position);
371+
return FaceToPoint(target.Position);
372372
}
373373

374374
/// <summary>

NWN.Anvil/src/main/API/Objects/NwStationary.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ public void CreateTrap(TrapBaseType trap, string disarm = "", string triggered =
109109
NWScript.CreateTrapOnObject((int)trap, this, sOnDisarmScript: disarm, sOnTrapTriggeredScript: triggered);
110110
}
111111

112-
public override async Task FaceToPoint(Vector3 point)
112+
public override Task FaceToPoint(Vector3 point)
113113
{
114114
Vector3 direction = Vector3.Normalize(point - Position);
115-
await base.FaceToPoint(Position - direction);
115+
return base.FaceToPoint(Position - direction);
116116
}
117117

118118
/// <summary>

0 commit comments

Comments
 (0)