diff --git a/ListUtils.cs b/ListUtils.cs index 0359123..72e3e1b 100644 --- a/ListUtils.cs +++ b/ListUtils.cs @@ -1,19 +1,10 @@ using System.Collections.Generic; using Unity.Collections; -using Unity.Entities; namespace v_rising_discord_bot_companion; public static class ListUtils { - public static List Convert(DynamicBuffer buffer) where T : unmanaged { - var _list = new List(); - foreach (var entity in buffer) { - _list.Add(entity); - } - return _list; - } - public static List Convert(NativeArray array) where T : unmanaged { var _list = new List(); foreach (var entity in array) { diff --git a/activity/ServerBootstrapSystemPatches.cs b/activity/ServerBootstrapSystemPatches.cs index a57440a..0a80016 100644 --- a/activity/ServerBootstrapSystemPatches.cs +++ b/activity/ServerBootstrapSystemPatches.cs @@ -13,7 +13,7 @@ namespace v_rising_discord_bot_companion.activity; [HarmonyPatch(typeof(ServerBootstrapSystem))] public class ServerBootstrapSystemPatches { - private static readonly List _playerActivities = new(); + private static readonly List _playerActivities = []; public static List getPlayerActivities() { removeExpiredPlayerActivities(); diff --git a/command/ServerWebAPISystemPatches.cs b/command/ServerWebAPISystemPatches.cs index f4c934d..94ea2fd 100644 --- a/command/ServerWebAPISystemPatches.cs +++ b/command/ServerWebAPISystemPatches.cs @@ -66,7 +66,7 @@ private static HttpServiceReceiveThread.RequestHandler BuildAdapter(Func _pvpKills = new(); + private static readonly List _pvpKills = []; public static List getPvpKills() { removeExpiredPvpKills(); diff --git a/query/AsyncQuery.cs b/query/AsyncQuery.cs index ec06c7f..21154d9 100644 --- a/query/AsyncQuery.cs +++ b/query/AsyncQuery.cs @@ -2,22 +2,17 @@ namespace v_rising_discord_bot_companion.query; -public class AsyncQuery : Query { +public class AsyncQuery( + Func action +) { - public Status Status { get; private set; } - public T? Data { get; private set; } + public Status Status { get; private set; } = Status.PENDING; + public object? Data { get; private set; } public Exception? Exception { get; private set; } - private readonly Func _action; - - public AsyncQuery(Func action) { - Status = Status.PENDING; - _action = action; - } - public void Invoke() { try { - Data = _action(); + Data = action(); Status = Status.SUCCESSFUL; } catch (Exception e) { Exception = e; diff --git a/query/Query.cs b/query/Query.cs deleted file mode 100644 index 7c175b5..0000000 --- a/query/Query.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace v_rising_discord_bot_companion.query; - -public interface Query { - - public void Invoke(); -} diff --git a/query/QueryDispatcher.cs b/query/QueryDispatcher.cs index ec1ae7b..2929f58 100644 --- a/query/QueryDispatcher.cs +++ b/query/QueryDispatcher.cs @@ -8,22 +8,23 @@ public class QueryDispatcher : MonoBehaviour { public static QueryDispatcher Instance = null!; - private readonly Queue _pendingQueries = new(); + private readonly Queue _pendingQueries = new(); + + public AsyncQuery Dispatch(Func query) { + var commandResponse = new AsyncQuery(query); + _pendingQueries.Enqueue(commandResponse); + return commandResponse; + } private void Awake() { Instance = this; } private void Update() { - if (_pendingQueries.Count > 0) { - var pendingCommand = _pendingQueries.Dequeue(); - pendingCommand.Invoke(); + if (_pendingQueries.Count <= 0) { + return; } - } - - public AsyncQuery Dispatch(Func query) { - var commandResponse = new AsyncQuery(query); - _pendingQueries.Enqueue(commandResponse); - return commandResponse; + var pendingCommand = _pendingQueries.Dequeue(); + pendingCommand.Invoke(); } }