function recalcSectionState(curStep:Int, curDecStep:Float):Void { Reflect.setField(game, 'curStep', curStep); Reflect.setField(game, 'curDecStep', curDecStep); var rollbackFunc:Dynamic = Reflect.field(game, 'rollbackSection'); if (rollbackFunc != null) { Reflect.callMethod(game, rollbackFunc, []); return; } if (game.SONG == null || game.SONG.notes == null) { return; } var notes:Array = game.SONG.notes; var totalSections:Int = notes.length; var cumulativeSteps:Int = 0; var targetSection:Int = 0; var found:Bool = false; for (i in 0...totalSections) { var section:Dynamic = notes[i]; if (section == null) continue; var sectionBeats:Float = section.sectionBeats; if (sectionBeats == null || sectionBeats <= 0) sectionBeats = 4; cumulativeSteps += Math.round(sectionBeats * 4); if (curStep < cumulativeSteps) { targetSection = i; found = true; break; } } if (!found) { targetSection = Math.max(0, totalSections - 1); } Reflect.setField(game, 'curSection', targetSection); if (cumulativeSteps <= curStep) { var beatsAhead:Float = 4; var sectionData:Dynamic = notes[targetSection]; if (sectionData != null) { beatsAhead = sectionData.sectionBeats; if (beatsAhead == null || beatsAhead <= 0) beatsAhead = 4; } cumulativeSteps = curStep + Math.round(beatsAhead * 4); } Reflect.setField(game, 'stepsToDo', cumulativeSteps); }