Skip to content

Commit ae370d3

Browse files
i hate u github 2
1 parent ea31f4d commit ae370d3

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
package core.backend;
2+
3+
import flixel.FlxSubState;
4+
5+
class MusicBeatSubState extends FlxSubState
6+
{
7+
public function new()
8+
{
9+
super();
10+
}
11+
12+
private var curSection:Int = 0;
13+
private var stepsToDo:Int = 0;
14+
15+
private var lastBeat:Float = 0;
16+
private var lastStep:Float = 0;
17+
18+
private var curStep:Int = 0;
19+
private var curBeat:Int = 0;
20+
21+
private var curDecStep:Float = 0;
22+
private var curDecBeat:Float = 0;
23+
private var controls(get, never):Controls;
24+
25+
inline function get_controls():Controls
26+
return Controls.instance;
27+
28+
override function update(elapsed:Float)
29+
{
30+
//everyStep();
31+
if(!persistentUpdate) MusicBeatState.timePassedOnState += elapsed;
32+
var oldStep:Int = curStep;
33+
34+
updateCurStep();
35+
updateBeat();
36+
37+
if (oldStep != curStep)
38+
{
39+
if(curStep > 0)
40+
stepHit();
41+
42+
if(PlayState.SONG != null)
43+
{
44+
if (oldStep < curStep)
45+
updateSection();
46+
else
47+
rollbackSection();
48+
}
49+
}
50+
51+
super.update(elapsed);
52+
}
53+
54+
private function updateSection():Void
55+
{
56+
if(stepsToDo < 1) stepsToDo = Math.round(getBeatsOnSection() * 4);
57+
while(curStep >= stepsToDo)
58+
{
59+
curSection++;
60+
var beats:Float = getBeatsOnSection();
61+
stepsToDo += Math.round(beats * 4);
62+
sectionHit();
63+
}
64+
}
65+
66+
private function rollbackSection():Void
67+
{
68+
if(curStep < 0) return;
69+
70+
var lastSection:Int = curSection;
71+
curSection = 0;
72+
stepsToDo = 0;
73+
for (i in 0...PlayState.SONG.notes.length)
74+
{
75+
if (PlayState.SONG.notes[i] != null)
76+
{
77+
stepsToDo += Math.round(getBeatsOnSection() * 4);
78+
if(stepsToDo > curStep) break;
79+
80+
curSection++;
81+
}
82+
}
83+
84+
if(curSection > lastSection) sectionHit();
85+
}
86+
87+
private function updateBeat():Void
88+
{
89+
curBeat = Math.floor(curStep / 4);
90+
curDecBeat = curDecStep/4;
91+
}
92+
93+
private function updateCurStep():Void
94+
{
95+
var lastChange = Conductor.getBPMFromSeconds(Conductor.songPosition);
96+
97+
var shit = ((Conductor.songPosition - ClientPrefs.data.noteOffset) - lastChange.songTime) / lastChange.stepCrochet;
98+
curDecStep = lastChange.stepTime + shit;
99+
curStep = lastChange.stepTime + Math.floor(shit);
100+
}
101+
102+
public function stepHit():Void
103+
{
104+
if (curStep % 4 == 0)
105+
beatHit();
106+
}
107+
108+
public function beatHit():Void
109+
{
110+
//do literally nothing dumbass
111+
}
112+
113+
public function sectionHit():Void
114+
{
115+
//yep, you guessed it, nothing again, dumbass
116+
}
117+
118+
function getBeatsOnSection()
119+
{
120+
var val:Null<Float> = 4;
121+
if(PlayState.SONG != null && PlayState.SONG.notes[curSection] != null) val = PlayState.SONG.notes[curSection].sectionBeats;
122+
return val == null ? 4 : val;
123+
}
124+
}

0 commit comments

Comments
 (0)