-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathCollabMapDataProcessor.cs
125 lines (113 loc) · 5.47 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
using System;
using System.Collections.Generic;
namespace Celeste.Mod.CollabUtils2 {
class CollabMapDataProcessor : EverestMapDataProcessor {
public struct SpeedBerryInfo {
public EntityID ID;
public float Gold;
public float Silver;
public float Bronze;
}
public struct GymLevelInfo {
public string[] Tech;
public string Flag;
}
public struct GymTechInfo {
public string Difficulty;
public string AreaSID;
public string Level;
}
public static Dictionary<string, GymLevelInfo> GymLevels = new Dictionary<string, GymLevelInfo>();
public static Dictionary<string, GymTechInfo> GymTech = new Dictionary<string, GymTechInfo>();
// 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;
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);
}
}
},
{
"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") {
addGymInfoFromChapterPanelTrigger(trigger);
}
}
}
},
{
"entity:FlushelineCollab/LevelEntrance", levelEntrance => {
addGymInfoFromChapterPanelTrigger(levelEntrance);
}
},
{
"entity:CollabUtils2/GymMarker", gymMarker => {
string techName = gymMarker.Attr("name");
if (!string.IsNullOrEmpty(techName)) {
GymTech[techName] = new GymTechInfo {
Difficulty = gymMarker.Attr("difficulty", "beginner"),
AreaSID = AreaKey.GetSID(),
Level = levelName
};
}
}
}
};
}
private static void addGymInfoFromChapterPanelTrigger(BinaryPacker.Element trigger) {
string map = trigger.Attr("map");
string tech = trigger.Attr("tech");
if (!string.IsNullOrEmpty(map) && !string.IsNullOrEmpty(tech)) {
GymLevels[map] = new GymLevelInfo {
Tech = trigger.Attr("tech").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries),
Flag = trigger.Attr("flag")
};
}
}
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
}
}
}