1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-12-23 21:56:46 +00:00

Work in progress

This commit is contained in:
EliteMasterEric 2024-02-05 13:35:30 -05:00
parent 334d267ffc
commit 167976c8ba
5 changed files with 76 additions and 18 deletions

2
assets

@ -1 +1 @@
Subproject commit b2f8b6a780316959d0a79adc6dbf61f9e4ca675f
Subproject commit 5479e17b1085f72e05f1c1f9e0a668ef832d3341

View file

@ -87,6 +87,12 @@ typedef PlayStateParams =
* @default `bf`, or the first character in the song's character list.
*/
?targetCharacter:String,
/**
* The instrumental to play with.
* Significant if the `targetSong` supports alternate instrumentals.
* @default `null`
*/
?targetInstrumental:String,
/**
* Whether the song should start in Practice Mode.
* @default `false`
@ -448,7 +454,7 @@ class PlayState extends MusicBeatSubState
function get_currentChart():SongDifficulty
{
if (currentSong == null || currentDifficulty == null) return null;
return currentSong.getDifficulty(currentDifficulty);
return currentSong.getDifficulty(currentDifficulty, currentPlayerId);
}
/**
@ -2650,13 +2656,16 @@ class PlayState extends MusicBeatSubState
{
// Stop the music.
FlxG.sound.music.pause();
vocals.stop();
if (vocals != null) vocals.stop();
}
else
{
FlxG.sound.music.pause();
vocals.pause();
remove(vocals);
if (vocals != null)
{
vocals.pause();
remove(vocals);
}
}
// Remove reference to stage and remove sprites from it to save memory.

View file

@ -184,7 +184,10 @@ class Song implements IPlayStateScriptedClass implements IRegistryEntry<SongMeta
difficulty.characters = metadata.playData.characters;
difficulties.set(diffId, difficulty);
var variationSuffix = (metadata.variation != null
&& metadata.variation != ''
&& metadata.variation != Constants.DEFAULT_VARIATION) ? '-${metadata.variation}' : '';
difficulties.set('$diffId$variationSuffix', difficulty);
}
}
}
@ -224,7 +227,8 @@ class Song implements IPlayStateScriptedClass implements IRegistryEntry<SongMeta
trace('Fabricated new difficulty for $diffId.');
difficulty = new SongDifficulty(this, diffId, variation);
var metadata = _metadata.get(variation);
difficulties.set(diffId, difficulty);
var variationSuffix = (variation != null && variation != '' && variation != Constants.DEFAULT_VARIATION) ? '-$variation' : '';
difficulties.set('$diffId$variationSuffix', difficulty);
if (metadata != null)
{
@ -256,11 +260,14 @@ class Song implements IPlayStateScriptedClass implements IRegistryEntry<SongMeta
* @param diffId The difficulty ID, such as `easy` or `hard`.
* @return The difficulty data.
*/
public inline function getDifficulty(?diffId:String):Null<SongDifficulty>
public inline function getDifficulty(?diffId:String, ?variation:String):Null<SongDifficulty>
{
if (diffId == null) diffId = listDifficulties()[0];
return difficulties.get(diffId);
if (variation == null) variation = Constants.DEFAULT_VARIATION;
var variationSuffix = (variation != null && variation != '' && variation != Constants.DEFAULT_VARIATION) ? '-$variation' : '';
return difficulties.get('$diffId$variationSuffix');
}
/**
@ -272,12 +279,16 @@ class Song implements IPlayStateScriptedClass implements IRegistryEntry<SongMeta
{
if (variationId == '') variationId = null;
var diffFiltered:Array<String> = difficulties.keys().array().filter(function(diffId:String):Bool {
if (variationId == null) return true;
// The difficulties array contains entries like 'normal', 'nightmare-erect', and 'normal-pico',
// so we have to map it to the actual difficulty names.
// We also filter out difficulties that don't match the variation or that don't exist.
var diffFiltered:Array<String> = difficulties.keys().array().map(function(diffId:String):Null<String> {
var difficulty:Null<SongDifficulty> = difficulties.get(diffId);
if (difficulty == null) return false;
return difficulty.variation == variationId;
});
if (difficulty == null) return null;
if (variationId != null && difficulty.variation != variationId) return null;
return difficulty.difficulty;
}).nonNull().unique();
diffFiltered.sort(SortUtil.defaultsThenAlphabetically.bind(Constants.DEFAULT_DIFFICULTY_LIST));
@ -286,8 +297,9 @@ class Song implements IPlayStateScriptedClass implements IRegistryEntry<SongMeta
public function hasDifficulty(diffId:String, ?variationId:String):Bool
{
if (variationId == '') variationId = null;
var difficulty:Null<SongDifficulty> = difficulties.get(diffId);
if (variationId == '') variationId = Constants.DEFAULT_VARIATION;
var variationSuffix:String = (variationId == Constants.DEFAULT_VARIATION) ? '' : '-$variationId';
var difficulty:Null<SongDifficulty> = difficulties.get('$diffId$variationSuffix');
return variationId == null ? (difficulty != null) : (difficulty != null && difficulty.variation == variationId);
}

View file

@ -54,6 +54,14 @@ import funkin.util.MathUtil;
import lime.app.Future;
import lime.utils.Assets;
/**
* Parameters used to initialize the FreeplayState.
*/
typedef FreeplayStateParams =
{
?character:String;
};
class FreeplayState extends MusicBeatSubState
{
var songs:Array<Null<FreeplaySongData>> = [];
@ -64,6 +72,9 @@ class FreeplayState extends MusicBeatSubState
var curSelected:Int = 0;
var currentDifficulty:String = Constants.DEFAULT_DIFFICULTY;
// Params
var currentCharacter:String;
var fp:FreeplayScore;
var txtCompletion:AtlasText;
var lerpCompletion:Float = 0;
@ -99,12 +110,13 @@ class FreeplayState extends MusicBeatSubState
var stickerSubState:StickerSubState;
//
static var rememberedDifficulty:Null<String> = Constants.DEFAULT_DIFFICULTY;
static var rememberedSongId:Null<String> = null;
public function new(?stickers:StickerSubState = null)
public function new(?params:FreeplayParams, ?stickers:StickerSubState)
{
currentCharacter = params?.character ?? Constants.DEFAULT_CHARACTER;
if (stickers != null)
{
stickerSubState = stickers;
@ -844,6 +856,13 @@ class FreeplayState extends MusicBeatSubState
changeDiff(1);
}
// TODO: DEBUG REMOVE THIS
if (FlxG.keys.justPressed.P)
{
currentCharacter = (currentCharacter == "bf") ? "pico" : "bf";
changeSelection(0);
}
if (controls.BACK && !typing.hasFocus)
{
FlxTween.globalManager.clear();

View file

@ -23,6 +23,24 @@ class ArrayTools
return result;
}
/**
* Returns a copy of the array with all `null` elements removed.
* @param array The array to remove `null` elements from.
* @return A copy of the array with all `null` elements removed.
*/
public static function nonNull<T>(array:Array<Null<T>>):Array<T>
{
var result:Array<T> = [];
for (element in array)
{
if (element != null)
{
result.push(element);
}
}
return result;
}
/**
* Return the first element of the array that satisfies the predicate, or null if none do.
* @param input The array to search