From a28c15a7546ce4d259a93024b6c592ed204488de Mon Sep 17 00:00:00 2001
From: Frakist <90983918+Frakist@users.noreply.github.com>
Date: Fri, 28 Jul 2023 10:31:24 +0300
Subject: [PATCH] new offset setting (testing required)
---
.gitignore | 3 +-
project.xml | 2 -
source/funkin/backend/system/Conductor.hx | 16 ++-
source/funkin/backend/system/macros/import.hx | 1 -
source/funkin/editors/charter/Charter.hx | 106 ++++++------------
source/funkin/game/PlayState.hx | 6 +-
source/funkin/options/Options.hx | 1 +
.../options/categories/GameplayOptions.hx | 30 +++++
8 files changed, 84 insertions(+), 81 deletions(-)
diff --git a/.gitignore b/.gitignore
index df3d060e..48a3f3f2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,4 +7,5 @@ latest/windows/haxe/
!.vscode/tasks.json
.haxelib/
docs/doc.xml
-mods/Baldi's Basics in Funkin'/
\ No newline at end of file
+mods/Baldi's Basics in Funkin'/
+project.xml
\ No newline at end of file
diff --git a/project.xml b/project.xml
index ca1e52bc..c134ef6e 100644
--- a/project.xml
+++ b/project.xml
@@ -185,8 +185,6 @@
-
-
diff --git a/source/funkin/backend/system/Conductor.hx b/source/funkin/backend/system/Conductor.hx
index d38db2c8..e54d00b6 100644
--- a/source/funkin/backend/system/Conductor.hx
+++ b/source/funkin/backend/system/Conductor.hx
@@ -58,8 +58,16 @@ class Conductor
/**
* Current position of the song, in milliseconds.
*/
- public static var songPosition:Float;
+ public static var songPosition(get, default):Float;
+ private static function get_songPosition() {
+ if (songOffset != Options.songOffset) trace(songOffset = Options.songOffset);
+ return songPosition - songOffset;
+ }
+ /**
+ * Offset of the song
+ */
+ public static var songOffset:Float = 0;
/**
* Current step
@@ -159,15 +167,15 @@ class Conductor
private static function __updateSongPos(elapsed:Float) {
if (FlxG.sound.music == null || !FlxG.sound.music.playing) {
- lastSongPos = FlxG.sound.music != null ? FlxG.sound.music.time : 0;
+ lastSongPos = FlxG.sound.music != null ? FlxG.sound.music.time - songOffset : -songOffset;
return;
}
- if (lastSongPos != (lastSongPos = FlxG.sound.music.time)) {
+ if (lastSongPos != (lastSongPos = FlxG.sound.music.time - songOffset)) {
// update conductor
songPosition = lastSongPos;
} else {
- songPosition += elapsed * 1000;
+ songPosition = songPosition + songOffset + elapsed * 1000;
}
}
diff --git a/source/funkin/backend/system/macros/import.hx b/source/funkin/backend/system/macros/import.hx
index a4ee0488..670edbee 100644
--- a/source/funkin/backend/system/macros/import.hx
+++ b/source/funkin/backend/system/macros/import.hx
@@ -1,5 +1,4 @@
#if macro
import haxe.macro.*;
import haxe.macro.Expr;
-import haxe.macro.Type;
#end
\ No newline at end of file
diff --git a/source/funkin/editors/charter/Charter.hx b/source/funkin/editors/charter/Charter.hx
index 1f3f3305..8ff3b364 100644
--- a/source/funkin/editors/charter/Charter.hx
+++ b/source/funkin/editors/charter/Charter.hx
@@ -585,8 +585,6 @@ class Charter extends UIState {
if (FlxG.mouse.justPressed)
FlxG.mouse.getWorldPosition(charterCamera, dragStartPos);
if (gridBackdropDummy.hovered) {
- // SETUP
-
// AUTO DETECT
if (FlxG.mouse.pressed && (Math.abs(mousePos.x - dragStartPos.x) > 20 || Math.abs(mousePos.y - dragStartPos.y) > 20))
gridActionType = BOX;
@@ -602,7 +600,7 @@ class Charter extends UIState {
note.updatePos(FlxG.keys.pressed.SHIFT ? (mousePos.y / 40) : Math.floor(mousePos.y / 40), id, 0, 0);
notesGroup.add(note);
selection = [note];
- addToUndo(CPlaceNote(note));
+ addToUndo(CCreateSelection([note]));
}
}
}
@@ -670,18 +668,37 @@ class Charter extends UIState {
return null;
}
+ public function createSelection(selection:Selection, addToUndo:Bool = true) {
+ if (selection.length <= 0) return [];
+
+ selection.loop(function (n:CharterNote) {
+ notesGroup.add(n);
+ n.revive();
+ }, function (e:CharterEvent) {
+ eventsGroup.add(e);
+ e.revive();
+ });
+ sortNotes();
+
+ if (addToUndo)
+ this.addToUndo(CCreateSelection(selection));
+ return [];
+ }
+
public function deleteSelection(selection:Selection, addToUndo:Bool = true) {
if (selection.length <= 0) return [];
- selection.loop(function (note:CharterNote) {
- notesGroup.remove(note, true);
- note.kill();
- this.selection.remove(note);
- }, function (event:CharterEvent) {
- eventsGroup.remove(event, true);
- event.kill();
- this.selection.remove(event);
- });
+ for (objects in [notesGroup, eventsGroup]) {
+ var group = cast(objects, FlxTypedGroup);
+ var member = 0;
+ while(member < group.members.length) {
+ var s = group.members[member];
+ if (selection.contains(s))
+ deleteSingleSelection(s, false);
+ else member++;
+ }
+ }
+ sortNotes();
if (addToUndo)
this.addToUndo(CDeleteSelection(selection));
@@ -1017,40 +1034,14 @@ class Charter extends UIState {
selection = [];
var v = undoList.shift();
switch(v) {
- case null:
- // do nothing
+ case null: // do nothing
case CCreateSelection(selection):
- selection.loop(function (n:CharterNote) {
- notesGroup.remove(n, true);
- n.kill();
- this.selection.remove(n);
- }, function (e:CharterEvent) {
- eventsGroup.remove(e, true);
- e.kill();
- this.selection.remove(e);
- });
+ deleteSelection(selection, false);
case CDeleteSelection(selection):
- selection.loop(function (n:CharterNote) {
- notesGroup.add(n);
- n.revive();
- }, function (e:CharterEvent) {
- eventsGroup.add(e);
- e.revive();
- });
- sortNotes();
- case CPlaceNote(note):
- notesGroup.remove(note, true);
- note.kill();
- selection.remove(note);
+ createSelection(selection, false);
case CSustainChange(changes):
for(n in changes)
n.note.updatePos(n.note.step, n.note.id, n.before, n.note.type);
- case CPlaceEvent(event):
- eventsGroup.remove(event, true);
- event.kill();
- selection.remove(event);
- case CEditEvent(event, oldEvents, newEvents):
- //
case CSelectionDrag(selection, change):
for (s in selection)
if (s.draggable) s.handleDrag(change * -1);
@@ -1079,32 +1070,11 @@ class Charter extends UIState {
selection = [];
var v = redoList.shift();
switch(v) {
- case null:
- // do nothing
+ case null: // do nothing
case CCreateSelection(selection):
- selection.loop(function (n:CharterNote) {
- notesGroup.add(n);
- n.revive();
- }, function (e:CharterEvent) {
- eventsGroup.add(e);
- e.revive();
- });
+ createSelection(selection, false);
case CDeleteSelection(selection):
- selection.loop(function (n:CharterNote) {
- notesGroup.remove(n, true);
- n.kill();
- }, function (e:CharterEvent) {
- eventsGroup.remove(e, true);
- e.kill();
- });
- case CPlaceNote(note):
- notesGroup.add(note);
- note.revive();
- case CPlaceEvent(event):
- eventsGroup.add(event);
- event.revive();
- case CEditEvent(event, oldEvents, newEvents):
- //
+ deleteSelection(selection, false);
case CSustainChange(changes):
for(n in changes)
n.note.updatePos(n.note.step, n.note.id, n.after, n.note.type);
@@ -1264,7 +1234,6 @@ class Charter extends UIState {
public function updateBPMEvents(newEvent:CharterEvent) {
buildEvents();
- // Za BPM
Conductor.mapBPMChanges(PlayState.SONG);
Conductor.changeBPM(PlayState.SONG.meta.bpm, cast PlayState.SONG.meta.beatsPerMesure.getDefault(4), cast PlayState.SONG.meta.stepsPerBeat.getDefault(4));
@@ -1276,13 +1245,10 @@ class Charter extends UIState {
}
enum CharterChange {
- CPlaceNote(note:CharterNote);
- CSustainChange(notes:Array);
- CPlaceEvent(event:CharterEvent); // TODO
- CEditEvent(event:CharterEvent, oldEvents:Array, newEvents:Array); // TODO
CCreateSelection(selection:Selection);
CDeleteSelection(selection:Selection);
CSelectionDrag(selection:Selection, change:FlxPoint);
+ CSustainChange(notes:Array);
CCreateStrumLine(strumLineID:Int, strumLine:ChartStrumLine);
CDeleteStrumLine(strumLineID:Int, strumLine:ChartStrumLine);
}
diff --git a/source/funkin/game/PlayState.hx b/source/funkin/game/PlayState.hx
index 1987c295..e9c02856 100644
--- a/source/funkin/game/PlayState.hx
+++ b/source/funkin/game/PlayState.hx
@@ -809,7 +809,7 @@ class PlayState extends MusicBeatState
startedCountdown = true;
Conductor.songPosition = 0;
- Conductor.songPosition -= Conductor.crochet * introLength;
+ Conductor.songPosition -= Conductor.crochet * introLength - Conductor.songOffset;
var swagCounter:Int = 0;
@@ -1040,7 +1040,7 @@ class PlayState extends MusicBeatState
FlxG.sound.music.play();
Conductor.songPosition = FlxG.sound.music.time;
- vocals.time = Conductor.songPosition;
+ vocals.time = Conductor.songPosition + Conductor.songOffset;
vocals.play();
scripts.call("onVocalsResync");
}
@@ -1128,7 +1128,7 @@ class PlayState extends MusicBeatState
{
if (startedCountdown)
{
- Conductor.songPosition += elapsed * 1000;
+ Conductor.songPosition += Conductor.songOffset + elapsed * 1000;
if (Conductor.songPosition >= 0)
startSong();
}
diff --git a/source/funkin/options/Options.hx b/source/funkin/options/Options.hx
index bc5fb232..2ab18f71 100644
--- a/source/funkin/options/Options.hx
+++ b/source/funkin/options/Options.hx
@@ -31,6 +31,7 @@ class Options
public static var betaUpdates:Bool = false;
public static var splashesEnabled:Bool = true;
public static var hitWindow:Float = 250;
+ public static var songOffset:Float = 0;
public static var framerate:Int = 120;
public static var gpuOnlyBitmaps:Bool = #if mac false #else true #end; // causes issues on mac
diff --git a/source/funkin/options/categories/GameplayOptions.hx b/source/funkin/options/categories/GameplayOptions.hx
index c17964e8..397b8069 100644
--- a/source/funkin/options/categories/GameplayOptions.hx
+++ b/source/funkin/options/categories/GameplayOptions.hx
@@ -1,6 +1,9 @@
package funkin.options.categories;
+import funkin.backend.system.Conductor;
+
class GameplayOptions extends OptionsScreen {
+ var __metronome = FlxG.sound.load(Paths.sound('editors/charter/metronome'));
public override function new() {
super("Gameplay", 'Change Gameplay options such as Downscroll, Scroll Speed, Naughtyness...');
add(new Checkbox(
@@ -11,6 +14,14 @@ class GameplayOptions extends OptionsScreen {
"Ghost Tapping",
"If unchecked, trying to hit any strum that have no note that can be hit will cause a miss.",
"ghostTapping"));
+ add(new NumOption(
+ "Song Offset",
+ "Changes the offset at which the song should start",
+ -999, // minimum
+ 999, // maximum
+ 1, // change
+ "songOffset", // save name or smth
+ __changeOffset)); // callback
add(new Checkbox(
"Naughtyness",
"If unchecked, will censor Week 7 cutscenes",
@@ -20,4 +31,23 @@ class GameplayOptions extends OptionsScreen {
"If unchecked, will disable camera zooming every 4 beats",
"camZoomOnBeat"));
}
+ private function __changeOffset(offset) Conductor.songOffset = offset;
+ var __lastBeat:Int = 0;
+ var __lastSongBeat:Int = 0;
+ override function update(elapsed) {
+ super.update(elapsed);
+ FlxG.camera.zoom = CoolUtil.fpsLerp(FlxG.camera.zoom, 1, 0.04);
+ if (members[2].selected) {
+ FlxG.sound.music.volume = 0.5;
+ if (__lastBeat != Conductor.curBeat) {
+ FlxG.camera.zoom += 0.03;
+ __lastBeat = Conductor.curBeat;
+ }
+ if (__lastSongBeat != Math.floor(Conductor.getStepForTime(FlxG.sound.music.time / 2) / Conductor.stepsPerBeat)) {
+ __metronome.replay();
+ __lastSongBeat = Math.floor(Conductor.getStepForTime(FlxG.sound.music.time / 2) / Conductor.stepsPerBeat);
+ }
+ }
+ else FlxG.sound.music.volume = 1;
+ }
}
\ No newline at end of file