-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathCollabMapDataProcessor.cs
More file actions
157 lines (141 loc) · 7.51 KB
/
CollabMapDataProcessor.cs
File metadata and controls
157 lines (141 loc) · 7.51 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
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
147
148
149
150
151
152
153
154
155
156
157
using Microsoft.Xna.Framework;
using Monocle;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Celeste.Mod.CollabUtils2 {
public 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; // for legacy placements, should no longer be used
public int Order;
public Color? Color;
public Color? LearnedColor;
public string AreaSID;
public string Level;
public bool LegacyRenderMode; // for legacy placements, should no longer be used
}
// GymLevels: maps map SIDs to their gym level info
// GymTech: maps collab IDs and tech names to gym tech info
public static Dictionary<string, GymLevelInfo> GymLevels = new Dictionary<string, GymLevelInfo>();
public static Dictionary<string, Dictionary<string, GymTechInfo>> GymTech = new Dictionary<string, 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))
return;
string difficulty = gymMarker.Attr("difficulty"); // for legacy placements, should no longer be used
int order = gymMarker.AttrInt("order", -1);
string color = gymMarker.Attr("color");
string learnedColor = gymMarker.Attr("learnedColor");
bool legacyRenderMode = gymMarker.AttrBool("legacyRenderMode", true); // for legacy placements, should no longer be used
GymTechInfo techInfo = new() {
Difficulty = !string.IsNullOrEmpty(difficulty) ? difficulty : null,
Order = order,
Color = !string.IsNullOrEmpty(color) ? Calc.HexToColor(color) : null,
LearnedColor = !string.IsNullOrEmpty(learnedColor) ? Calc.HexToColor(learnedColor) : null,
AreaSID = AreaKey.GetSID(),
Level = levelName,
LegacyRenderMode = legacyRenderMode
};
string collabID = LobbyHelper.GetCollabNameForSID(AreaKey.GetSID());
if (GymTech.TryGetValue(collabID, out Dictionary<string, GymTechInfo> tech))
tech[techName] = techInfo;
else
GymTech.Add(collabID, new Dictionary<string, GymTechInfo> { { techName, techInfo } });
}
}
};
}
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.TryGetValue(AreaKey.GetLevelSet(), out Dictionary<string, EntityID> silverBerries))
silverBerries.Remove(AreaKey.GetSID());
SpeedBerries.Remove(AreaKey.GetSID());
MapsWithSilverBerries.Remove(AreaKey.GetSID());
MapsWithRainbowBerries.Remove(AreaKey.GetSID());
GymLevels.Remove(AreaKey.GetSID());
foreach ((string _, Dictionary<string, GymTechInfo> techForCollab) in GymTech) {
string[] affectedTech = techForCollab.Where(kvp => kvp.Value.AreaSID == AreaKey.GetSID()).Select(kvp => kvp.Key).ToArray();
foreach (string tech in affectedTech)
techForCollab.Remove(tech);
}
}
public override void End() {
// nothing to do here
}
}
}