-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyLib.cs
More file actions
50 lines (44 loc) · 1.91 KB
/
KeyLib.cs
File metadata and controls
50 lines (44 loc) · 1.91 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
using System;
using System.Collections.Generic;
using System.Linq;
using BepInEx;
using KeyGeneralPurposeLibrary.Assets;
using KeyGeneralPurposeLibrary.BehaviourManipulation;
using KeyGeneralPurposeLibrary.PowersLib;
namespace KeyGeneralPurposeLibrary {
[BepInPlugin(KeyGeneralPurposeLibraryConfig.PluginGuid, KeyGeneralPurposeLibraryConfig.PluginName, KeyGeneralPurposeLibraryConfig.PluginVersion)]
public class KeyLib : BaseUnityPlugin {
private static readonly List<KLibComponent> Components = new List<KLibComponent>();
public void Awake() {
Logger.LogInfo($"Started loading {KeyGeneralPurposeLibraryConfig.PluginName}...");
LoadComponent<KeyGenLibHarmonyPatchCollection>();
LoadComponent<KeyGenLibFileAssetManager>();
LoadComponent<KeyGenLibCustomTraitManager>();
LoadComponent<KeyGenLibCustomItemManager>();
LoadComponent<KeyGenLibGodPowerLibrary>();
Logger.LogInfo($"{KeyGeneralPurposeLibraryConfig.PluginName} finished loading successfully!");
}
private void LoadComponent<T>() where T : KLibComponent, new() {
Logger.LogInfo($"Loading {typeof(T).FullName}...");
try {
Components.Add(new T());
} catch (Exception e) {
Logger.LogError($"Failed to load {typeof(T).FullName}!");
Logger.LogError(e);
return;
}
Logger.LogInfo($"Loaded {typeof(T).FullName}!");
}
private void Update() {
foreach (KLibComponent component in Components.Where(component => component.IsInitialized == false).Where(_ => global::Config.game_loaded)) {
component.Initialize();
}
foreach (KLibComponent component in Components) {
component.Update();
}
}
public static T Get<T>() where T : KLibComponent, new() {
return Components.Where(component => component is T).Cast<T>().FirstOrDefault() ?? throw new ApplicationException($"Component {typeof(T).FullName} not found!");
}
}
}