diff --git a/source/funkin/data/song/SongData.hx b/source/funkin/data/song/SongData.hx index a396984a9..5d9c9b7e3 100644 --- a/source/funkin/data/song/SongData.hx +++ b/source/funkin/data/song/SongData.hx @@ -498,7 +498,7 @@ class SongPlayData implements ICloneable * @since `2.2.2` */ @:optional - @:default(0) + @:default(funkin.util.Constants.DEFAULT_PREVIEW_START_TIME) public var previewStart:Float; /** @@ -507,7 +507,7 @@ class SongPlayData implements ICloneable * @since `2.2.2` */ @:optional - @:default(0.2) + @:default(funkin.util.Constants.DEFAULT_PREVIEW_END_TIME) public var previewEnd:Float; public function new() diff --git a/source/funkin/play/song/Song.hx b/source/funkin/play/song/Song.hx index 87791a89c..83b068d63 100644 --- a/source/funkin/play/song/Song.hx +++ b/source/funkin/play/song/Song.hx @@ -90,26 +90,6 @@ class Song implements IPlayStateScriptedClass implements IRegistryEntry 1 ? 0 : prevStartTime; + var prevStart:Float = _metadata.get(curVariation)?.playData?.previewStart ?? Constants.DEFAULT_PREVIEW_START_TIME; + final prevEnd:Float = _metadata.get(curVariation)?.playData?.previewEnd ?? Constants.DEFAULT_PREVIEW_END_TIME; + + if (prevStart >= prevEnd || prevStart > 1) + { + prevStart = Constants.DEFAULT_PREVIEW_START_TIME; + } + + return prevStart; } function get_previewEndTime():Float { - var prevEndTime = @:privateAccess data._metadata.get(curVariation)?.playData?.previewEnd ?? 0.2; + @:privateAccess final _metadata = data._metadata; - return prevEndTime > 1 ? 0.2 : prevEndTime; + final prevStart:Float = _metadata.get(curVariation)?.playData?.previewStart ?? Constants.DEFAULT_PREVIEW_START_TIME; + var prevEnd:Float = _metadata.get(curVariation)?.playData?.previewEnd ?? Constants.DEFAULT_PREVIEW_END_TIME; + + if (prevStart >= prevEnd || prevEnd > 1) + { + prevEnd = Constants.DEFAULT_PREVIEW_END_TIME; + } + + return prevEnd; } function get_isNew():Bool diff --git a/source/funkin/util/Constants.hx b/source/funkin/util/Constants.hx index acc2e42c6..2c0727aca 100644 --- a/source/funkin/util/Constants.hx +++ b/source/funkin/util/Constants.hx @@ -291,6 +291,16 @@ class Constants */ public static final DEFAULT_OST_NAME:String = 'OFFICIAL OST'; + /** + * The default preview start time for the songs in Freeplay. + */ + public static final DEFAULT_PREVIEW_START_TIME:Float = 0; + + /** + * The default preview end time for the songs in Freeplay. + */ + public static final DEFAULT_PREVIEW_END_TIME:Float = 0.2; + /** * The default timing format for songs. */