Skip to content

Commit

Permalink
Fix new analysis errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhett12321 committed Dec 8, 2023
1 parent f2bf18e commit cc1f3a9
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task ScheduleDelayRunsTaskAfterDelay(int delayMs)
[TestCase(500)]
[TestCase(1000)]
[TestCase(5000)]
public async Task ScheduleAndCancelDoesNotRunTask(int delayMs)
public Task ScheduleAndCancelDoesNotRunTask(int delayMs)
{
TimeSpan delay = TimeSpan.FromMilliseconds(delayMs);

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

task.Cancel();
await NwTask.Delay(delay + TimeSpan.FromSeconds(1));
return NwTask.Delay(delay + TimeSpan.FromSeconds(1));
}

[Test(Description = "Scheduling a repeating task correctly schedules and runs the task with the specified interval.")]
Expand Down
20 changes: 10 additions & 10 deletions NWN.Anvil/src/main/API/Async/NwTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ public static class NwTask
/// </summary>
/// <param name="delay">How long to wait.</param>
/// <param name="cancellationToken">A cancellation token that should be used to cancel the work.</param>
public static async Task Delay(TimeSpan delay, CancellationToken? cancellationToken = null)
public static Task Delay(TimeSpan delay, CancellationToken? cancellationToken = null)
{
Stopwatch stopwatch = Stopwatch.StartNew();
await RunAndAwait(() => delay < stopwatch.Elapsed, cancellationToken);
return RunAndAwait(() => delay < stopwatch.Elapsed, cancellationToken);
}

/// <summary>
/// Waits until the specified amount of frames have passed.
/// </summary>
/// <param name="frames">The number of frames to wait.</param>
/// <param name="cancellationToken">A cancellation token that should be used to cancel the work.</param>
public static async Task DelayFrame(int frames, CancellationToken? cancellationToken = null)
public static Task DelayFrame(int frames, CancellationToken? cancellationToken = null)
{
await RunAndAwait(() =>
return RunAndAwait(() =>
{
bool retVal = frames <= 0;
frames--;
Expand All @@ -51,9 +51,9 @@ await RunAndAwait(() =>
/// <summary>
/// Waits until the next server frame/loop.
/// </summary>
public static async Task NextFrame()
public static Task NextFrame()
{
await DelayFrame(1);
return DelayFrame(1);
}

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

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

/// <summary>
Expand Down
6 changes: 1 addition & 5 deletions NWN.Anvil/src/main/API/Nui/NuiWindowEventService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,10 @@ public void Subscribe(NuiWindowToken token, Action<ModuleEvents.OnNuiEvent> hand
eventHandlers[token.Player] = playerHandlers;
}

if (playerHandlers.ContainsKey(token.Token))
if (!playerHandlers.TryAdd(token.Token, handler))
{
playerHandlers[token.Token] += handler;
}
else
{
playerHandlers[token.Token] = handler;
}
}

public void Unsubscribe(NuiWindowToken token, Action<ModuleEvents.OnNuiEvent> handler)
Expand Down
16 changes: 8 additions & 8 deletions NWN.Anvil/src/main/API/Objects/NwCreature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1084,18 +1084,18 @@ public async Task ActionInteractObject(NwPlaceable placeable)
/// Instructs this creature to approach and lock the specified door.
/// </summary>
/// <param name="door">The door to lock.</param>
public async Task ActionLockObject(NwDoor door)
public Task ActionLockObject(NwDoor door)
{
await DoActionLockObject(door);
return DoActionLockObject(door);
}

/// <summary>
/// Instructs this creature to approach and lock the specified placeable.
/// </summary>
/// <param name="placeable">The placeable to lock.</param>
public async Task ActionLockObject(NwPlaceable placeable)
public Task ActionLockObject(NwPlaceable placeable)
{
await DoActionLockObject(placeable);
return DoActionLockObject(placeable);
}

/// <summary>
Expand Down Expand Up @@ -1216,18 +1216,18 @@ public async Task ActionUnequipItem(NwItem item)
/// Instructs this creature to approach and unlock the specified door.
/// </summary>
/// <param name="door">The door to unlock.</param>
public async Task ActionUnlockObject(NwDoor door)
public Task ActionUnlockObject(NwDoor door)
{
await DoActionUnlockObject(door);
return DoActionUnlockObject(door);
}

/// <summary>
/// Instructs this creature to approach and unlock the specified placeable.
/// </summary>
/// <param name="placeable">The placeable to unlock.</param>
public async Task ActionUnlockObject(NwPlaceable placeable)
public Task ActionUnlockObject(NwPlaceable placeable)
{
await DoActionUnlockObject(placeable);
return DoActionUnlockObject(placeable);
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions NWN.Anvil/src/main/API/Objects/NwGameObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,9 @@ public async void EndConversation()
/// Rotates this object to face towards target.
/// </summary>
/// <param name="target">The target object to face.</param>
public async Task FaceToObject(NwGameObject target)
public Task FaceToObject(NwGameObject target)
{
await FaceToPoint(target.Position);
return FaceToPoint(target.Position);
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions NWN.Anvil/src/main/API/Objects/NwStationary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ public void CreateTrap(TrapBaseType trap, string disarm = "", string triggered =
NWScript.CreateTrapOnObject((int)trap, this, sOnDisarmScript: disarm, sOnTrapTriggeredScript: triggered);
}

public override async Task FaceToPoint(Vector3 point)
public override Task FaceToPoint(Vector3 point)
{
Vector3 direction = Vector3.Normalize(point - Position);
await base.FaceToPoint(Position - direction);
return base.FaceToPoint(Position - direction);
}

/// <summary>
Expand Down

0 comments on commit cc1f3a9

Please sign in to comment.