Skip to content
This repository was archived by the owner on Aug 29, 2022. It is now read-only.

Commit 39a17f8

Browse files
ShadowMarionotweuz
authored andcommitted
Time signatures
1 parent 72594cf commit 39a17f8

5 files changed

Lines changed: 213 additions & 139 deletions

File tree

source/Conductor.hx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,20 @@ class Conductor
128128
bpmChangeMap.push(event);
129129
}
130130

131-
var deltaSteps:Int = Math.round(song.notes[i].sectionBeats * 4);
131+
var deltaSteps:Int = Math.round(getSectionBeats(song, i) * 4);
132132
totalSteps += deltaSteps;
133133
totalPos += ((60 / curBPM) * 1000 / 4) * deltaSteps;
134134
}
135135
trace("new BPM map BUDDY " + bpmChangeMap);
136136
}
137137

138+
static function getSectionBeats(song:SwagSong, section:Int)
139+
{
140+
var val:Null<Float> = null;
141+
if(song.notes[section] != null) val = song.notes[section].sectionBeats;
142+
return val != null ? val : 4;
143+
}
144+
138145
inline public static function calculateCrochet(bpm:Float){
139146
return (60/bpm)*1000;
140147
}

source/MusicBeatState.hx

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import flixel.FlxBasic;
1616

1717
class MusicBeatState extends FlxUIState
1818
{
19-
private var lastBeat:Float = 0;
20-
private var lastStep:Float = 0;
19+
private var curSection:Int = 0;
20+
private var stepsToDo:Int = 0;
2121

2222
private var curStep:Int = 0;
2323
private var curBeat:Int = 0;
@@ -47,14 +47,55 @@ class MusicBeatState extends FlxUIState
4747
updateCurStep();
4848
updateBeat();
4949

50-
if (oldStep != curStep && curStep > 0)
51-
stepHit();
50+
if (oldStep != curStep)
51+
{
52+
if(curStep > 0)
53+
stepHit();
54+
55+
if(PlayState.SONG != null)
56+
{
57+
if (oldStep < curStep)
58+
updateSection();
59+
else
60+
rollbackSection();
61+
}
62+
}
5263

5364
if(FlxG.save.data != null) FlxG.save.data.fullscreen = FlxG.fullscreen;
5465

5566
super.update(elapsed);
5667
}
5768

69+
private function updateSection():Void
70+
{
71+
if(stepsToDo < 1) stepsToDo = Math.round(getBeatsOnSection() * 4);
72+
while(curStep >= stepsToDo)
73+
{
74+
curSection++;
75+
var beats:Float = getBeatsOnSection();
76+
stepsToDo += Math.round(beats * 4);
77+
sectionHit();
78+
}
79+
}
80+
81+
private function rollbackSection():Void
82+
{
83+
if(curStep < 0) return;
84+
85+
curSection = 0;
86+
stepsToDo = Math.round(getBeatsOnSection() * 4);
87+
for (i in 0...PlayState.SONG.notes.length)
88+
{
89+
if (PlayState.SONG.notes[i] != null)
90+
{
91+
stepsToDo += Math.round(getBeatsOnSection() * 4);
92+
if(stepsToDo > curStep) return;
93+
94+
curSection++;
95+
}
96+
}
97+
}
98+
5899
private function updateBeat():Void
59100
{
60101
curBeat = Math.floor(curStep / 4);
@@ -111,6 +152,18 @@ class MusicBeatState extends FlxUIState
111152

112153
public function beatHit():Void
113154
{
114-
//do literally nothing dumbass
155+
//trace('Beat: ' + curBeat);
156+
}
157+
158+
public function sectionHit():Void
159+
{
160+
//trace('Section: ' + curSection);
161+
}
162+
163+
function getBeatsOnSection()
164+
{
165+
var val:Null<Float> = 4;
166+
if(PlayState.SONG != null && PlayState.SONG.notes[curSection] != null) val = PlayState.SONG.notes[curSection].sectionBeats;
167+
return val == null ? 4 : val;
115168
}
116169
}

source/PauseSubState.hx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,6 @@ class PauseSubState extends MusicBeatSubstate
202202
FlxG.sound.music.volume = 0;
203203
PlayState.changedDifficulty = true;
204204
PlayState.chartingMode = false;
205-
skipTimeTracker = null;
206-
207-
if(skipTimeText != null)
208-
{
209-
skipTimeText.kill();
210-
remove(skipTimeText);
211-
skipTimeText.destroy();
212-
}
213-
skipTimeText = null;
214205
return;
215206
}
216207

@@ -224,6 +215,7 @@ class PauseSubState extends MusicBeatSubstate
224215
close();
225216
case 'Change Difficulty':
226217
menuItems = difficultyChoices;
218+
deleteSkipTimeText();
227219
regenMenu();
228220
case 'Toggle Practice Mode':
229221
PlayState.instance.practiceMode = !PlayState.instance.practiceMode;
@@ -282,6 +274,18 @@ class PauseSubState extends MusicBeatSubstate
282274
}
283275
}
284276

277+
function deleteSkipTimeText()
278+
{
279+
if(skipTimeText != null)
280+
{
281+
skipTimeText.kill();
282+
remove(skipTimeText);
283+
skipTimeText.destroy();
284+
}
285+
skipTimeText = null;
286+
skipTimeTracker = null;
287+
}
288+
285289
public static function restartSong(noTrans:Bool = false)
286290
{
287291
PlayState.instance.paused = true; // For lua

source/PlayState.hx

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ class PlayState extends MusicBeatState
12291229
FlxG.worldBounds.set(0, 0, FlxG.width, FlxG.height);
12301230

12311231
FlxG.fixedTimestep = false;
1232-
moveCameraSection(0);
1232+
moveCameraSection();
12331233

12341234
healthBarBG = new AttachedSprite('healthBar');
12351235
healthBarBG.y = FlxG.height * 0.89;
@@ -3313,6 +3313,7 @@ class PlayState extends MusicBeatState
33133313
camHUD.zoom = FlxMath.lerp(1, camHUD.zoom, CoolUtil.boundTo(1 - (elapsed * 3.125 * camZoomingDecay), 0, 1));
33143314
}
33153315

3316+
FlxG.watch.addQuick("secShit", curSection);
33163317
FlxG.watch.addQuick("beatShit", curBeat);
33173318
FlxG.watch.addQuick("stepShit", curStep);
33183319

@@ -3962,10 +3963,10 @@ class PlayState extends MusicBeatState
39623963
callOnLuas('onEvent', [eventName, value1, value2]);
39633964
}
39643965

3965-
function moveCameraSection(?id:Int = 0):Void {
3966-
if(SONG.notes[id] == null) return;
3966+
function moveCameraSection():Void {
3967+
if(SONG.notes[curSection] == null) return;
39673968

3968-
if (gf != null && SONG.notes[id].gfSection)
3969+
if (gf != null && SONG.notes[curSection].gfSection)
39693970
{
39703971
camFollow.set(gf.getMidpoint().x, gf.getMidpoint().y);
39713972
camFollow.x += gf.cameraPosition[0] + girlfriendCameraOffset[0];
@@ -3975,7 +3976,7 @@ class PlayState extends MusicBeatState
39753976
return;
39763977
}
39773978

3978-
if (!SONG.notes[id].mustHitSection)
3979+
if (!SONG.notes[curSection].mustHitSection)
39793980
{
39803981
moveCamera(true);
39813982
callOnLuas('onMoveCamera', ['dad']);
@@ -4754,7 +4755,6 @@ class PlayState extends MusicBeatState
47544755
} else if(!note.noAnimation) {
47554756
var altAnim:String = note.animSuffix;
47564757

4757-
var curSection:Int = Math.floor(curStep / 16);
47584758
if (SONG.notes[curSection] != null)
47594759
{
47604760
if (SONG.notes[curSection].altAnim) {
@@ -5238,34 +5238,6 @@ class PlayState extends MusicBeatState
52385238
notes.sort(FlxSort.byY, ClientPrefs.downScroll ? FlxSort.ASCENDING : FlxSort.DESCENDING);
52395239
}
52405240

5241-
if (SONG.notes[Math.floor(curStep / 16)] != null)
5242-
{
5243-
if (SONG.notes[Math.floor(curStep / 16)].changeBPM)
5244-
{
5245-
Conductor.changeBPM(SONG.notes[Math.floor(curStep / 16)].bpm);
5246-
//FlxG.log.add('CHANGED BPM!');
5247-
setOnLuas('curBpm', Conductor.bpm);
5248-
setOnLuas('crochet', Conductor.crochet);
5249-
setOnLuas('stepCrochet', Conductor.stepCrochet);
5250-
}
5251-
setOnLuas('mustHitSection', SONG.notes[Math.floor(curStep / 16)].mustHitSection);
5252-
setOnLuas('altAnim', SONG.notes[Math.floor(curStep / 16)].altAnim);
5253-
setOnLuas('gfSection', SONG.notes[Math.floor(curStep / 16)].gfSection);
5254-
// else
5255-
// Conductor.changeBPM(SONG.bpm);
5256-
}
5257-
// FlxG.log.add('change bpm' + SONG.notes[Std.int(curStep / 16)].changeBPM);
5258-
5259-
if (generatedMusic && PlayState.SONG.notes[Std.int(curStep / 16)] != null && !endingSong && !isCameraOnForcedPos)
5260-
{
5261-
moveCameraSection(Std.int(curStep / 16));
5262-
}
5263-
if (camZooming && FlxG.camera.zoom < 1.35 && ClientPrefs.camZooms && curBeat % 4 == 0)
5264-
{
5265-
FlxG.camera.zoom += 0.015 * camZoomingMult;
5266-
camHUD.zoom += 0.03 * camZoomingMult;
5267-
}
5268-
52695241
iconP1.scale.set(1.2, 1.2);
52705242
iconP2.scale.set(1.2, 1.2);
52715243

@@ -5374,6 +5346,39 @@ class PlayState extends MusicBeatState
53745346
}
53755347
}
53765348

5349+
override function sectionHit()
5350+
{
5351+
super.sectionHit();
5352+
5353+
if (SONG.notes[curSection] != null)
5354+
{
5355+
if (generatedMusic && !endingSong && !isCameraOnForcedPos)
5356+
{
5357+
moveCameraSection();
5358+
}
5359+
5360+
if (camZooming && FlxG.camera.zoom < 1.35 && ClientPrefs.camZooms)
5361+
{
5362+
FlxG.camera.zoom += 0.015 * camZoomingMult;
5363+
camHUD.zoom += 0.03 * camZoomingMult;
5364+
}
5365+
5366+
if (SONG.notes[curSection].changeBPM)
5367+
{
5368+
Conductor.changeBPM(SONG.notes[curSection].bpm);
5369+
setOnLuas('curBpm', Conductor.bpm);
5370+
setOnLuas('crochet', Conductor.crochet);
5371+
setOnLuas('stepCrochet', Conductor.stepCrochet);
5372+
}
5373+
setOnLuas('mustHitSection', SONG.notes[curSection].mustHitSection);
5374+
setOnLuas('altAnim', SONG.notes[curSection].altAnim);
5375+
setOnLuas('gfSection', SONG.notes[curSection].gfSection);
5376+
}
5377+
5378+
setOnLuas('curSection', curSection);
5379+
callOnLuas('onSectionHit', []);
5380+
}
5381+
53775382
public function callOnLuas(event:String, args:Array<Dynamic>, ignoreStops=false, ?exclusions:Array<String>):Dynamic {
53785383
var returnVal:Dynamic = FunkinLua.Function_Continue;
53795384
#if LUA_ALLOWED

0 commit comments

Comments
 (0)