Add quick interactions locally

This commit is contained in:
2025-03-31 04:02:39 +02:00
parent 5bb7a207f2
commit b7d4531ec8
134 changed files with 15494 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
using System;
using System.Reflection;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Barotrauma;
using HarmonyLib;
using Microsoft.Xna.Framework;
using QIDependencyInjection;
namespace QuickInteractions
{
// Idk, mb it should be just an extension to LuaCsTimer
[Singleton]
public class Debouncer : IDisposable
{
public static LuaCsTimer Timer => GameMain.LuaCs.Timer;
[Dependency] public Logger Logger { get; set; }
private Dictionary<string, LuaCsTimer.TimedAction> Scheduled = new();
public void Debounce(string name, int millisecondDelay, Action action)
{
LuaCsTimer.TimedAction timedAction = new LuaCsTimer.TimedAction((object[] args) =>
{
action();
Scheduled.Remove(name);
},
millisecondDelay
);
if (Scheduled.ContainsKey(name))
{
Timer.timedActions.Remove(Scheduled[name]);
Scheduled[name] = timedAction;
Timer.AddTimer(timedAction);
}
else
{
Timer.AddTimer(timedAction);
Scheduled[name] = timedAction;
}
}
public void Dispose()
{
foreach (var timedAction in Scheduled.Values)
{
Timer.timedActions.Remove(timedAction);
}
Scheduled.Clear();
}
}
}