Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion managed/managed.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand All @@ -11,6 +12,7 @@
<BaseOutputPath>build\</BaseOutputPath>
<OutputPath>$(BaseOutputPath)Release\SwiftlyS2</OutputPath>
<AssemblyName>SwiftlyS2</AssemblyName>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>

</PropertyGroup>

Expand Down
1 change: 1 addition & 0 deletions managed/src/SwiftlyS2.Core/Modules/Plugins/SwiftlyCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public SwiftlyCore(string contextId, string contextBaseDirectory, Type contextTy
.AddSingleton(coreProvider.GetRequiredService<TraceManager>())

.AddSingleton<EventSubscriber>()
.AddSingleton<IEventSubscriber>(provider => provider.GetRequiredService<EventSubscriber>())
.AddSingleton<PluginConfigurationService>()
.AddSingleton<GameEventService>()
.AddSingleton<NetMessageService>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ public CancellationTokenSource DelayAndRepeat(int delayTick, int periodTick, boo
return cts;
}

public CancellationTokenSource AddTimer(int delayTick, Action task) {
CleanFinishedTimers();
var cts = SchedulerManager.AddTimer(delayTick, 0, task, _lifecycleCts.Token);
lock (_lock) {
_timers.Add(cts);
}
return cts;
}

private void CleanFinishedTimers() {
lock (_lock) {
_timers.RemoveAll(timer => timer.IsCancellationRequested);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,12 @@ public interface ISchedulerService {
/// <param name="task">The task to execute.</param>
/// <returns>A CancellationTokenSource that can be used to cancel the timer.</returns>
CancellationTokenSource DelayAndRepeat(int delayTick, int periodTick, bool stopOnMapChange, Action task);

/// <summary>
/// Add a timer to the scheduler with flexible delay and period configuration.
/// </summary>
/// <param name="delayTick">The delay of the timer in ticks.</param>
/// <param name="task">The task to execute.</param>
/// <returns>A CancellationTokenSource that can be used to cancel the timer.</returns>
CancellationTokenSource AddTimer(int delayTick, Action task);
}