-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBus.cs
More file actions
74 lines (67 loc) · 2.26 KB
/
Copy pathBus.cs
File metadata and controls
74 lines (67 loc) · 2.26 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
using APCEvents;
using APCEvents.APCIn;
using APCEvents.Debug;
using APCGear.Audio;
using Godot;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
public partial class Bus : Node
{
private static readonly Dictionary<Type, Func<Object>> _mapping = new Dictionary<Type, Func<Object>>() {
//[typeof(CycleLedEvent)] = () => CycleLedEvent.instance,
};
//public static Dictionary<procedural, Func<Object>> emitter = {};
private static T GetEvent<T, APCEventArgs>()
where T : APCEvent<APCEventArgs>, new()
where APCEventArgs : IAPCArgs
{
if (_mapping.ContainsKey(typeof(T)))
{
return _mapping[typeof(T)]() as T;
}
var presEvent = new T();
_mapping.Add(typeof(T), () => presEvent);
return presEvent;
}
public static void Subscribe<T, APCEventArgs>(Action<APCEventArgs> action) where T : APCEvent<APCEventArgs>, new()
where APCEventArgs : IAPCArgs
{
var presEvent = GetEvent<T, APCEventArgs>();
//GD.Print(presEvent);
presEvent.Subscribe(action);
}
public static string debugStringify(Object t) {
Type myClassType = t.GetType();
PropertyInfo[] properties = myClassType.GetProperties();
if (myClassType.ToString() == "APCGear.Audio.AudioSessionsRefreshArgs")
{
return "";
}
string result = "{ \n";
foreach (PropertyInfo property in properties)
{
result += property.Name + ": " + property.GetValue(t, null) + "\n";
}
result += "}\n";
GD.Print(result);
return result;
}
public static void Publish<T, APCEventArgs>(APCEventArgs args) where T : APCEvent<APCEventArgs>, new()
where APCEventArgs : IAPCArgs
{
var presEvent = GetEvent<T, APCEventArgs>();
var debugEvent = GetEvent<APCEvents.Debug.DbgEvent, DebugString>();
if (presEvent.ToString() != "APCGear.Audio.AudioSessionsRefresh") GD.Print("Firing: ", presEvent);
presEvent.Publish(args);
debugEvent.Publish(new DebugString()
{
name = presEvent.ToString(),
args = debugStringify(args)
});
}
public override void _Ready()
{
}
}