-
Notifications
You must be signed in to change notification settings - Fork 36
/
stage.js
85 lines (73 loc) · 2.22 KB
/
stage.js
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
class Stage{
constructor(){
this.name = "";
/** @type {string} */
this.labels = "";
this.startCycle = 0;
this.endCycle = 0;
}
}
class StageLevel{
constructor(){
this.appearance = 0; // The order of appearance
this.unique = 0; // Different levels are assigned to all levels
}
}
class StageLevelMap{
constructor(){
/** @type {Object.<string, Object.<string, StageLevel>>} */
this.map_ = {};
/** @type {Object.<string, number>} */
this.laneID_Map = {};
}
get(laneName, stageName){
return this.map_[laneName][stageName];
}
has(laneName, stageName){
return (laneName in this.map_) && (stageName in this.map_[laneName]);
}
/** @param {string} laneName
* @param {string} stageName
* @param {Lane} lane
*/
update(laneName, stageName, lane){
if (this.has(laneName, stageName)) {
if (this.map_[laneName][stageName].appearance > lane.level) {
this.map_[laneName][stageName].appearance = lane.level;
}
}
else{
if (!(laneName in this.map_)) {
this.map_[laneName] = {};
this.laneID_Map[laneName] = Object.keys(this.laneID_Map).length;
// レーンが増えたため,ID を振り直す
let i = 0;
for (let key in Object.keys(this.laneID_Map).sort()) {
this.laneID_Map[key] = i;
i++;
}
}
let level = new StageLevel;
level.appearance = lane.level;
level.unique = Object.keys(this.map_[laneName]).length;
this.map_[laneName][stageName] = level;
}
}
get laneNum(){
return Object.keys(this.laneID_Map).length;
}
getLaneID(laneName){
return this.laneID_Map[laneName];
}
}
class Lane{
constructor(){
this.level = 0; // 1サイクル以上のステージの数
/** @type {Array<Stage>} */
this.stages = [];
}
}
module.exports.Stage = Stage;
module.exports.StageLevel = StageLevel;
module.exports.StageLevelMap = StageLevelMap;
module.exports.Lane = Lane;