forked from creepycats/SCPCosmetics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlugin.cs
More file actions
93 lines (80 loc) · 2.64 KB
/
Plugin.cs
File metadata and controls
93 lines (80 loc) · 2.64 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
89
90
91
92
93
namespace SCPCosmetics
{
using Exiled.API.Features;
using HarmonyLib;
using MEC;
using SCPCosmetics.Cosmetics.Glows;
using SCPCosmetics.Cosmetics.Hats;
using SCPCosmetics.Cosmetics.Pets;
using SCPCosmetics.Types;
using System;
using System.Collections.Generic;
public class Plugin : Plugin<Config.Config>
{
public override string Name => "SCPCosmetics";
public override string Author => "creepycats";
public override Version Version => new(2, 0, 1);
public static Plugin Instance { get; set; }
public int PetIDNumber = 1000;
private Harmony _harmony;
private CoroutineHandle updateLoop;
public List<CosmeticHandler> CosmeticHandlers = new List<CosmeticHandler>();
public override void OnEnabled()
{
Instance = this;
// REGISTER NEW COSMETIC HANDLERS HERE
CosmeticHandlers = new List<CosmeticHandler>()
{
new HatsHandler(),
new GlowsHandler(),
new PetsHandler(),
};
foreach (CosmeticHandler cosmeticHandler in CosmeticHandlers)
{
cosmeticHandler.RegisterCosmetic();
}
updateLoop = Timing.RunCoroutine(UpdateDistributor());
if (_harmony is null)
{
_harmony = new("SCPCosmetics");
_harmony.PatchAll();
}
base.OnEnabled();
}
public override void OnDisabled()
{
foreach (CosmeticHandler cosmeticHandler in CosmeticHandlers)
{
cosmeticHandler.RegisterCosmetic();
}
CosmeticHandlers = new List<CosmeticHandler>();
Timing.KillCoroutines(updateLoop);
base.OnDisabled();
}
public CosmeticHandler GetCosmeticHandler(Type handlerType)
{
foreach (CosmeticHandler cosmeticHandler in CosmeticHandlers)
{
if (cosmeticHandler.GetType() == handlerType) return cosmeticHandler;
}
return null;
}
public static IEnumerator<float> UpdateDistributor()
{
for (; ; )
{
yield return Timing.WaitForOneFrame;
foreach(CosmeticHandler handler in Instance.CosmeticHandlers)
{
try
{
handler.DistributeUpdate();
} catch (Exception e)
{
Log.Error(e);
}
}
}
}
}
}