-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathFrameworkBridge.cs
More file actions
88 lines (75 loc) · 2.47 KB
/
FrameworkBridge.cs
File metadata and controls
88 lines (75 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using LabApi.Features.Console;
using LabApi.Loader;
using MEC;
using SER.Code.Extensions;
using SER.Code.MethodSystem;
namespace SER.Code.Helpers;
public class FrameworkBridge
{
public record struct Framework(string Name, Type Type);
public static readonly List<Framework> Found = [];
private readonly List<CoroutineHandle> _handles = [];
public enum Type
{
None,
Exiled,
Callvote,
Ucr
}
private readonly Framework[] _frameworks =
[
new("Callvote", Type.Callvote),
new("Exiled Loader", Type.Exiled),
new("UncomplicatedCustomRoles", Type.Ucr)
];
public void Load()
{
Found.Clear();
foreach (var framework in _frameworks)
{
_handles.Add(Timing.RunCoroutine(Await(framework)));
}
Timing.CallDelayed(3f, () =>
{
Timing.KillCoroutines(_handles.ToArray());
_handles.Clear();
Logger.Info(Found.Count == 0
? "No supported framework was found, no additional methods were added."
: $"SER has added methods for {Found.Count} supported framework(s): " +
$"{Found.Select(f => f.Type.ToString()).JoinStrings(", ")}"
);
});
}
private IEnumerator<float> Await(Framework framework)
{
// handled from forever repeating when coroutines are killed
while (true)
{
yield return Timing.WaitForSeconds(.5f);
if (IsLabAPIComatibleFrameworkLoaded(framework) || IsExiledCompatibleFrameworkLoaded(framework))
{
break;
}
}
Logger.Debug($"SER found supported framework '{framework.Type}'");
Found.Add(framework);
MethodIndex.LoadMethodsOfFramework(framework.Type);
}
private static bool IsLabAPIComatibleFrameworkLoaded(Framework framework)
{
return PluginLoader.EnabledPlugins.Any(plg => plg.Name == framework.Name);
}
private static bool IsExiledCompatibleFrameworkLoaded(Framework framework)
{
// As of right now, Callvote-Exiled is not compatible with SER.
if (framework.Type == FrameworkBridge.Type.Callvote)
{
return false;
}
if (PluginLoader.Plugins.Any(plg => plg.Key.Name == "Exiled Loader"))
{
return Exiled.Loader.Loader.Plugins.Any(plg => plg.Name == framework.Name);
}
return false;
}
}