generated from coloursofnoise/TemplateMod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollabMapDataProcessor.cs
146 lines (125 loc) · 5.85 KB
/
CollabMapDataProcessor.cs
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using System;
using System.Collections.Generic;
using System.Linq;
namespace Celeste.Mod.CollabLobbyUI {
// This entire class is an exact copy from CollabUtils2 because it currently is not accessible as a public class over there
public class CollabMapDataProcessor : EverestMapDataProcessor {
public struct SpeedBerryInfo
{
public EntityID ID;
public float Gold;
public float Silver;
public float Bronze;
}
public struct ChapterPanelTriggerInfo {
public string map;
public string level;
public string id;
public int x, y;
}
public static Dictionary<string, HashSet<ChapterPanelTriggerInfo>> ChapterPanelTriggers = new Dictionary<string, HashSet<ChapterPanelTriggerInfo>>();
// the structure here is: SilverBerries[LevelSet][SID] = ID of the silver berry in that map.
// so, to check if all silvers in a levelset have been unlocked, go through all entries in SilverBerries[levelset].
public static Dictionary<string, Dictionary<string, EntityID>> SilverBerries = new Dictionary<string, Dictionary<string, EntityID>>();
public static Dictionary<string, SpeedBerryInfo> SpeedBerries = new Dictionary<string, SpeedBerryInfo>();
private string levelName;
private int levelX, levelY;
public static HashSet<string> MapsWithSilverBerries = new HashSet<string>();
public static HashSet<string> MapsWithRainbowBerries = new HashSet<string>();
public override Dictionary<string, Action<BinaryPacker.Element>> Init()
{
return new Dictionary<string, Action<BinaryPacker.Element>> {
{
"level", level => {
// be sure to write the level name down.
levelName = level.Attr("name").Split(':')[0];
if (levelName.StartsWith("lvl_")) {
levelName = levelName.Substring(4);
}
levelX = level.AttrInt("x");
levelY = level.AttrInt("y");
}
},
{
"entity:CollabUtils2/SilverBerry", silverBerry => {
if (!SilverBerries.TryGetValue(AreaKey.GetLevelSet(), out Dictionary<string, EntityID> allSilversInLevelSet)) {
allSilversInLevelSet = new Dictionary<string, EntityID>();
SilverBerries.Add(AreaKey.GetLevelSet(), allSilversInLevelSet);
}
allSilversInLevelSet[AreaKey.GetSID()] = new EntityID(levelName, silverBerry.AttrInt("id"));
MapsWithSilverBerries.Add(AreaKey.GetSID());
}
},
{
"entity:CollabUtils2/RainbowBerry", berry => MapsWithRainbowBerries.Add(AreaKey.GetSID())
},
{
"entity:CollabUtils2/SpeedBerry", speedBerry => {
SpeedBerries[AreaKey.GetSID()] = new SpeedBerryInfo() {
ID = new EntityID(levelName, speedBerry.AttrInt("id")),
Gold = speedBerry.AttrFloat("goldTime"),
Silver = speedBerry.AttrFloat("silverTime"),
Bronze = speedBerry.AttrFloat("bronzeTime")
};
}
},
{
"triggers", triggerList => {
foreach (BinaryPacker.Element trigger in triggerList.Children) {
if(trigger.Name == "CollabUtils2/ChapterPanelTrigger") {
addChapterPanelTrigger(trigger);
}
}
}
},
{
"entity:FlushelineCollab/LevelEntrance", levelEntrance => {
addChapterPanelTrigger(levelEntrance);
}
}
};
}
private void addChapterPanelTrigger(BinaryPacker.Element trigger)
{
string map = trigger.Attr("map");
string sid = AreaKey.GetSID();
string trID = trigger.Attr("id");
if (string.IsNullOrEmpty(map) || string.IsNullOrEmpty(sid)) {
try {
Logger.Log(LogLevel.Warn, "CollabLobbyUI", $"Not processing trigger {sid} / {map}: {trigger.Name} / {trigger.Package} / {string.Join(",", trigger.Attributes.Keys)} / {string.Join(",", trigger.Children.Select(e => e.Name))}.");
} catch {
Logger.Log(LogLevel.Warn, "CollabLobbyUI", $"Not processing trigger {sid} / {map} (failed some logging)");
}
return;
}
if (!ChapterPanelTriggers.ContainsKey(sid)) {
ChapterPanelTriggers[sid] = new HashSet<ChapterPanelTriggerInfo>();
}
HashSet<ChapterPanelTriggerInfo> lobbyTriggers = ChapterPanelTriggers[sid];
int x = levelX + trigger.AttrInt("x");
int y = levelY + trigger.AttrInt("y");
lobbyTriggers.Add(new ChapterPanelTriggerInfo {
map = map,
level = levelName,
x = x,
y = y,
id = trID
});
Logger.Log(LogLevel.Verbose, "CollabLobbyUI", $"addChapterPanelTrigger of lobby {sid} room {levelName}: {map} at {x}/{y} with id {trID}.");
}
public override void Reset()
{
if (SilverBerries.ContainsKey(AreaKey.GetLevelSet()))
{
SilverBerries[AreaKey.GetLevelSet()].Remove(AreaKey.GetSID());
}
SpeedBerries.Remove(AreaKey.GetSID());
MapsWithSilverBerries.Remove(AreaKey.GetSID());
MapsWithRainbowBerries.Remove(AreaKey.GetSID());
}
public override void End()
{
// nothing to do here
}
}
}