forked from EverestAPI/CelesteCollabUtils2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollabMapDataProcessor.cs
66 lines (61 loc) · 2.94 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Celeste.Mod.CollabUtils2 {
class CollabMapDataProcessor : EverestMapDataProcessor {
public struct SpeedBerryInfo {
public EntityID ID;
public int Gold;
public int Silver;
public int Bronze;
}
// 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 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"));
}
},
{
"entity:CollabUtils2/SpeedBerry", speedBerry => {
SpeedBerries[AreaKey.GetSID()] = new SpeedBerryInfo() {
ID = new EntityID(levelName, speedBerry.AttrInt("id")),
Gold = speedBerry.AttrInt("goldTime"),
Silver = speedBerry.AttrInt("silverTime"),
Bronze = speedBerry.AttrInt("bronzeTime")
};
}
}
};
}
public override void Reset() {
if (SilverBerries.ContainsKey(AreaKey.GetLevelSet())) {
SilverBerries[AreaKey.GetLevelSet()].Remove(AreaKey.GetSID());
}
SpeedBerries.Remove(AreaKey.GetSID());
}
public override void End() {
// nothing to do here
}
}
}