Skip to content

Commit

Permalink
chore: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkAtra committed Dec 31, 2024
1 parent 42b2e57 commit 7eac7db
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 39 deletions.
9 changes: 0 additions & 9 deletions ListUtils.cs
Original file line number Diff line number Diff line change
@@ -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<T> Convert<T>(DynamicBuffer<T> buffer) where T : unmanaged {
var _list = new List<T>();
foreach (var entity in buffer) {
_list.Add(entity);
}
return _list;
}

public static List<T> Convert<T>(NativeArray<T> array) where T : unmanaged {
var _list = new List<T>();
foreach (var entity in array) {
Expand Down
2 changes: 1 addition & 1 deletion activity/ServerBootstrapSystemPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace v_rising_discord_bot_companion.activity;
[HarmonyPatch(typeof(ServerBootstrapSystem))]
public class ServerBootstrapSystemPatches {

private static readonly List<PlayerActivity> _playerActivities = new();
private static readonly List<PlayerActivity> _playerActivities = [];

public static List<PlayerActivity> getPlayerActivities() {
removeExpiredPlayerActivities();
Expand Down
2 changes: 1 addition & 1 deletion command/ServerWebAPISystemPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private static HttpServiceReceiveThread.RequestHandler BuildAdapter(Func<HttpLis

object responseData;
if (commandResponse.Status is Status.FAILED or Status.PENDING) {
Plugin.Logger.LogInfo($"Request with url '{context.Request.Url.ToString()}' failed with message: {commandResponse.Exception?.Message}");
Plugin.Logger.LogError($"Request with url '{context.Request.Url.ToString()}' failed with message: {commandResponse.Exception?.Message}");
context.Response.StatusCode = 500;
responseData = new Problem(
Type: "about:blank",
Expand Down
2 changes: 1 addition & 1 deletion killfeed/VampireDownedServerEventSystemPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace v_rising_discord_bot_companion.killfeed;
[HarmonyPatch(typeof(VampireDownedServerEventSystem))]
public class VampireDownedServerEventSystemPatches {

private static readonly List<PvpKill> _pvpKills = new();
private static readonly List<PvpKill> _pvpKills = [];

public static List<PvpKill> getPvpKills() {
removeExpiredPvpKills();
Expand Down
17 changes: 6 additions & 11 deletions query/AsyncQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,17 @@

namespace v_rising_discord_bot_companion.query;

public class AsyncQuery<T> : Query {
public class AsyncQuery(
Func<object> 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<T> _action;

public AsyncQuery(Func<T> action) {
Status = Status.PENDING;
_action = action;
}

public void Invoke() {
try {
Data = _action();
Data = action();
Status = Status.SUCCESSFUL;
} catch (Exception e) {
Exception = e;
Expand Down
6 changes: 0 additions & 6 deletions query/Query.cs

This file was deleted.

21 changes: 11 additions & 10 deletions query/QueryDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@ public class QueryDispatcher : MonoBehaviour {

public static QueryDispatcher Instance = null!;

private readonly Queue<Query> _pendingQueries = new();
private readonly Queue<AsyncQuery> _pendingQueries = new();

public AsyncQuery Dispatch(Func<object> 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<T> Dispatch<T>(Func<T> query) {
var commandResponse = new AsyncQuery<T>(query);
_pendingQueries.Enqueue(commandResponse);
return commandResponse;
var pendingCommand = _pendingQueries.Dequeue();
pendingCommand.Invoke();
}
}

0 comments on commit 7eac7db

Please sign in to comment.