Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSpringCollab2020MapDataProcessor.cs
More file actions
Latest commit
107 lines (96 loc) · 5.9 KB
/
Copy pathSpringCollab2020MapDataProcessor.cs
File metadata and controls
107 lines (96 loc) · 5.9 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
usingSystem;
usingSystem.Collections.Generic;
namespaceCeleste.Mod.SpringCollab2020{
classSpringCollab2020MapDataProcessor:EverestMapDataProcessor{
// the structure here is: FlagTouchSwitches[AreaSID][ModeID][flagName] = list of entity ids for flag touch switches in this group on this map.
publicstaticDictionary<string,List<Dictionary<string,List<EntityID>>>>FlagTouchSwitches=newDictionary<string,List<Dictionary<string,List<EntityID>>>>();
privatestringlevelName;
// we want to match multi-room strawberry seeds with the strawberry that has the same name.
privateDictionary<string,List<BinaryPacker.Element>>multiRoomStrawberrySeedsByName=newDictionary<string,List<BinaryPacker.Element>>();
privateDictionary<string,EntityID>multiRoomStrawberryIDsByName=newDictionary<string,EntityID>();
privateDictionary<string,BinaryPacker.Element>multiRoomStrawberriesByName=newDictionary<string,BinaryPacker.Element>();
publicoverrideDictionary<string,Action<BinaryPacker.Element>>Init(){
returnnewDictionary<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:SpringCollab2020/FlagTouchSwitch", flagTouchSwitch =>{
stringflag=flagTouchSwitch.Attr("flag");
Dictionary<string,List<EntityID>>allTouchSwitchesInMap=FlagTouchSwitches[AreaKey.SID][(int)AreaKey.Mode];
// if no dictionary entry exists for this flag, create one. otherwise, get it.
List<EntityID>entityIDs;
if(!allTouchSwitchesInMap.ContainsKey(flag)){
entityIDs=newList<EntityID>();
allTouchSwitchesInMap[flag]=entityIDs;
}else{
entityIDs=allTouchSwitchesInMap[flag];
}
// add this flag touch switch to the dictionary.
entityIDs.Add(newEntityID(levelName,flagTouchSwitch.AttrInt("id")));
}
},
{
"entity:SpringCollab2020/MultiRoomStrawberrySeed", strawberrySeed =>{
// auto-attribute indices for seeds, and save them.
stringberryName=strawberrySeed.Attr("strawberryName");
if(multiRoomStrawberrySeedsByName.ContainsKey(berryName)){
if(strawberrySeed.AttrInt("index")<0){
strawberrySeed.SetAttr("index",multiRoomStrawberrySeedsByName[berryName].Count);
}
multiRoomStrawberrySeedsByName[berryName].Add(strawberrySeed);
}else{
if(strawberrySeed.AttrInt("index")<0){
strawberrySeed.SetAttr("index",0);
}
multiRoomStrawberrySeedsByName[berryName]=newList<BinaryPacker.Element>(){strawberrySeed};
}
}
},
{
"entity:SpringCollab2020/MultiRoomStrawberry", strawberry =>{
// save the strawberry IDs.
stringberryName=strawberry.Attr("name");
multiRoomStrawberryIDsByName[berryName]=newEntityID(levelName,strawberry.AttrInt("id"));
multiRoomStrawberriesByName[berryName]=strawberry;
}
}
};
}
publicoverridevoidReset(){
if(!FlagTouchSwitches.ContainsKey(AreaKey.SID)){
// create an entry for the current map SID.
FlagTouchSwitches[AreaKey.SID]=newList<Dictionary<string,List<EntityID>>>();
}
while(FlagTouchSwitches[AreaKey.SID].Count<=(int)AreaKey.Mode){
// fill out the empty space before the current map MODE with empty dictionaries.
FlagTouchSwitches[AreaKey.SID].Add(newDictionary<string,List<EntityID>>());
}
// reset the dictionary for the current map and mode.
FlagTouchSwitches[AreaKey.SID][(int)AreaKey.Mode]=newDictionary<string,List<EntityID>>();
}
publicoverridevoidEnd(){
foreach(stringstrawberryNameinmultiRoomStrawberrySeedsByName.Keys){
if(!multiRoomStrawberryIDsByName.ContainsKey(strawberryName)){
Logger.Log(LogLevel.Warn,"SpringCollab2020MapDataProcessor",$"Multi-room strawberry seeds with name {strawberryName} didn't match any multi-room strawberry");
}else{
// give the strawberry ID to the seeds.
EntityIDstrawberryID=multiRoomStrawberryIDsByName[strawberryName];
foreach(BinaryPacker.ElementstrawberrySeedinmultiRoomStrawberrySeedsByName[strawberryName]){
strawberrySeed.SetAttr("berryLevel",strawberryID.Level);
strawberrySeed.SetAttr("berryID",strawberryID.ID);
}
// and give the expected seed count to the strawberry.
multiRoomStrawberriesByName[strawberryName].SetAttr("seedCount",multiRoomStrawberrySeedsByName[strawberryName].Count);
}
}
multiRoomStrawberrySeedsByName.Clear();
multiRoomStrawberryIDsByName.Clear();
}
}
}