1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-15 11:22:55 +00:00

Merge branch 'feature/instrumental-select-hud' into rewrite/master

This commit is contained in:
Cameron Taylor 2024-09-03 11:25:34 -04:00
commit 930f5ff5a6
8 changed files with 322 additions and 21 deletions

2
assets

@ -1 +1 @@
Subproject commit 67c2375ef0d6e8d48dea50bc17e8252219c05a97 Subproject commit 1def6d3bf4300fd9f22834e42063d5836bdd96f9

View file

@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- If the value isn't present, it will use the `playData.characters.opponent`, but if it is present, it will be used (even if it's empty, in which case no vocals will be used for the opponent) - If the value isn't present, it will use the `playData.characters.opponent`, but if it is present, it will be used (even if it's empty, in which case no vocals will be used for the opponent)
- Added `playData.characters.playerVocals` to specify which vocal track(s) to play for the player. - Added `playData.characters.playerVocals` to specify which vocal track(s) to play for the player.
- If the value isn't present, it will use the `playData.characters.player`, but if it is present, it will be used (even if it's empty, in which case no vocals will be used for the player) - If the value isn't present, it will use the `playData.characters.player`, but if it is present, it will be used (even if it's empty, in which case no vocals will be used for the player)
- Added `offsets.altVocals` field to apply vocal offsets when alternate instrumentals are used.
## [2.2.3] ## [2.2.3]
### Added ### Added

View file

@ -257,13 +257,21 @@ class SongOffsets implements ICloneable<SongOffsets>
public var altInstrumentals:Map<String, Float>; public var altInstrumentals:Map<String, Float>;
/** /**
* The offset, in milliseconds, to apply to the song's vocals, relative to the chart. * The offset, in milliseconds, to apply to the song's vocals, relative to the song's base instrumental.
* These are applied ON TOP OF the instrumental offset. * These are applied ON TOP OF the instrumental offset.
*/ */
@:optional @:optional
@:default([]) @:default([])
public var vocals:Map<String, Float>; public var vocals:Map<String, Float>;
/**
* The offset, in milliseconds, to apply to the songs vocals, relative to each alternate instrumental.
* This is useful for the circumstance where, for example, an alt instrumental has a few seconds of lead in before the song starts.
*/
@:optional
@:default([])
public var altVocals:Map<String, Map<String, Float>>;
public function new(instrumental:Float = 0.0, ?altInstrumentals:Map<String, Float>, ?vocals:Map<String, Float>) public function new(instrumental:Float = 0.0, ?altInstrumentals:Map<String, Float>, ?vocals:Map<String, Float>)
{ {
this.instrumental = instrumental; this.instrumental = instrumental;
@ -293,11 +301,19 @@ class SongOffsets implements ICloneable<SongOffsets>
return value; return value;
} }
public function getVocalOffset(charId:String):Float public function getVocalOffset(charId:String, ?instrumental:String):Float
{ {
if (!this.vocals.exists(charId)) return 0.0; if (instrumental == null)
{
return this.vocals.get(charId); if (!this.vocals.exists(charId)) return 0.0;
return this.vocals.get(charId);
}
else
{
if (!this.altVocals.exists(instrumental)) return 0.0;
if (!this.altVocals.get(instrumental).exists(charId)) return 0.0;
return this.altVocals.get(instrumental).get(charId);
}
} }
public function setVocalOffset(charId:String, value:Float):Float public function setVocalOffset(charId:String, value:Float):Float
@ -320,7 +336,7 @@ class SongOffsets implements ICloneable<SongOffsets>
*/ */
public function toString():String public function toString():String
{ {
return 'SongOffsets(${this.instrumental}ms, ${this.altInstrumentals}, ${this.vocals})'; return 'SongOffsets(${this.instrumental}ms, ${this.altInstrumentals}, ${this.vocals}, ${this.altVocals})';
} }
} }

View file

@ -20,7 +20,7 @@ class SongRegistry extends BaseRegistry<Song, SongMetadata>
* Handle breaking changes by incrementing this value * Handle breaking changes by incrementing this value
* and adding migration to the `migrateStageData()` function. * and adding migration to the `migrateStageData()` function.
*/ */
public static final SONG_METADATA_VERSION:thx.semver.Version = "2.2.3"; public static final SONG_METADATA_VERSION:thx.semver.Version = "2.2.4";
public static final SONG_METADATA_VERSION_RULE:thx.semver.VersionRule = "2.2.x"; public static final SONG_METADATA_VERSION_RULE:thx.semver.VersionRule = "2.2.x";

View file

@ -668,7 +668,7 @@ class PlayState extends MusicBeatSubState
// Prepare the current song's instrumental and vocals to be played. // Prepare the current song's instrumental and vocals to be played.
if (!overrideMusic && currentChart != null) if (!overrideMusic && currentChart != null)
{ {
currentChart.cacheInst(); currentChart.cacheInst(currentInstrumental);
currentChart.cacheVocals(); currentChart.cacheVocals();
} }
@ -677,7 +677,7 @@ class PlayState extends MusicBeatSubState
if (currentChart.offsets != null) if (currentChart.offsets != null)
{ {
Conductor.instance.instrumentalOffset = currentChart.offsets.getInstrumentalOffset(); Conductor.instance.instrumentalOffset = currentChart.offsets.getInstrumentalOffset(currentInstrumental);
} }
Conductor.instance.mapTimeChanges(currentChart.timeChanges); Conductor.instance.mapTimeChanges(currentChart.timeChanges);
@ -860,7 +860,7 @@ class PlayState extends MusicBeatSubState
{ {
// Stop the vocals if they already exist. // Stop the vocals if they already exist.
if (vocals != null) vocals.stop(); if (vocals != null) vocals.stop();
vocals = currentChart.buildVocals(); vocals = currentChart.buildVocals(currentInstrumental);
if (vocals.members.length == 0) if (vocals.members.length == 0)
{ {
@ -1791,7 +1791,7 @@ class PlayState extends MusicBeatSubState
{ {
// Stop the vocals if they already exist. // Stop the vocals if they already exist.
if (vocals != null) vocals.stop(); if (vocals != null) vocals.stop();
vocals = currentChart.buildVocals(); vocals = currentChart.buildVocals(currentInstrumental);
if (vocals.members.length == 0) if (vocals.members.length == 0)
{ {

View file

@ -533,6 +533,28 @@ class Song implements IPlayStateScriptedClass implements IRegistryEntry<SongMeta
return variation.playData.difficulties.contains(diffId); return variation.playData.difficulties.contains(diffId);
} }
/**
* Return the list of available alternate instrumentals.
* Scripts can override this, fun.
* @param variationId
* @param difficultyId
*/
public function listAltInstrumentalIds(difficultyId:String, variationId:String):Array<String>
{
var targetDifficulty:Null<SongDifficulty> = getDifficulty(difficultyId, variationId);
if (targetDifficulty == null) return [];
return targetDifficulty?.characters?.altInstrumentals ?? [];
}
public function getBaseInstrumentalId(difficultyId:String, variationId:String):String
{
var targetDifficulty:Null<SongDifficulty> = getDifficulty(difficultyId, variationId);
if (targetDifficulty == null) return '';
return targetDifficulty?.characters?.instrumental ?? '';
}
/** /**
* Purge the cached chart data for each difficulty of this song. * Purge the cached chart data for each difficulty of this song.
*/ */
@ -851,7 +873,7 @@ class SongDifficulty
* @param charId The player ID. * @param charId The player ID.
* @return The generated vocal group. * @return The generated vocal group.
*/ */
public function buildVocals():VoicesGroup public function buildVocals(?instId:String = ''):VoicesGroup
{ {
var result:VoicesGroup = new VoicesGroup(); var result:VoicesGroup = new VoicesGroup();
@ -870,8 +892,8 @@ class SongDifficulty
result.addOpponentVoice(FunkinSound.load(opponentVoice)); result.addOpponentVoice(FunkinSound.load(opponentVoice));
} }
result.playerVoicesOffset = offsets.getVocalOffset(characters.player); result.playerVoicesOffset = offsets.getVocalOffset(characters.player, instId);
result.opponentVoicesOffset = offsets.getVocalOffset(characters.opponent); result.opponentVoicesOffset = offsets.getVocalOffset(characters.opponent, instId);
return result; return result;
} }

View file

@ -0,0 +1,176 @@
package funkin.ui.freeplay;
import funkin.graphics.shaders.PureColor;
import funkin.input.Controls;
import flixel.group.FlxSpriteGroup;
import funkin.graphics.FunkinSprite;
import flixel.util.FlxColor;
import flixel.util.FlxTimer;
import flixel.text.FlxText;
import flixel.text.FlxText.FlxTextAlign;
@:nullSafety
class CapsuleOptionsMenu extends FlxSpriteGroup
{
var capsuleMenuBG:FunkinSprite;
var parent:FreeplayState;
var queueDestroy:Bool = false;
var instrumentalIds:Array<String> = [''];
var currentInstrumentalIndex:Int = 0;
var currentInstrumental:FlxText;
public function new(parent:FreeplayState, x:Float = 0, y:Float = 0, instIds:Array<String>):Void
{
super(x, y);
this.parent = parent;
this.instrumentalIds = instIds;
capsuleMenuBG = FunkinSprite.createSparrow(0, 0, 'freeplay/instBox/instBox');
capsuleMenuBG.animation.addByPrefix('open', 'open0', 24, false);
capsuleMenuBG.animation.addByPrefix('idle', 'idle0', 24, true);
capsuleMenuBG.animation.addByPrefix('open', 'open0', 24, false);
currentInstrumental = new FlxText(0, 36, capsuleMenuBG.width, '');
currentInstrumental.setFormat('VCR OSD Mono', 40, FlxTextAlign.CENTER, true);
final PAD = 4;
var leftArrow = new InstrumentalSelector(parent, PAD, 30, false, parent.getControls());
var rightArrow = new InstrumentalSelector(parent, capsuleMenuBG.width - leftArrow.width - PAD, 30, true, parent.getControls());
var label:FlxText = new FlxText(0, 5, capsuleMenuBG.width, 'INSTRUMENTAL');
label.setFormat('VCR OSD Mono', 24, FlxTextAlign.CENTER, true);
add(capsuleMenuBG);
add(leftArrow);
add(rightArrow);
add(label);
add(currentInstrumental);
capsuleMenuBG.animation.finishCallback = function(_) {
capsuleMenuBG.animation.play('idle', true);
};
capsuleMenuBG.animation.play('open', true);
}
public override function update(elapsed:Float):Void
{
super.update(elapsed);
if (queueDestroy)
{
destroy();
return;
}
@:privateAccess
if (parent.controls.BACK)
{
close();
return;
}
var changedInst = false;
if (parent.getControls().UI_LEFT_P)
{
currentInstrumentalIndex = (currentInstrumentalIndex + 1) % instrumentalIds.length;
changedInst = true;
}
if (parent.getControls().UI_RIGHT_P)
{
currentInstrumentalIndex = (currentInstrumentalIndex - 1 + instrumentalIds.length) % instrumentalIds.length;
changedInst = true;
}
if (!changedInst && currentInstrumental.text == '') changedInst = true;
if (changedInst)
{
currentInstrumental.text = instrumentalIds[currentInstrumentalIndex].toTitleCase() ?? '';
if (currentInstrumental.text == '') currentInstrumental.text = 'Default';
}
if (parent.getControls().ACCEPT)
{
onConfirm(instrumentalIds[currentInstrumentalIndex] ?? '');
}
}
public function close():Void
{
// Play in reverse.
capsuleMenuBG.animation.play('open', true, true);
capsuleMenuBG.animation.finishCallback = function(_) {
parent.cleanupCapsuleOptionsMenu();
queueDestroy = true;
};
}
/**
* Override this with `capsuleOptionsMenu.onConfirm = myFunction;`
*/
public dynamic function onConfirm(targetInstId:String):Void
{
throw 'onConfirm not implemented!';
}
}
/**
* The difficulty selector arrows to the left and right of the difficulty.
*/
class InstrumentalSelector extends FunkinSprite
{
var controls:Controls;
var whiteShader:PureColor;
var parent:FreeplayState;
var baseScale:Float = 0.6;
public function new(parent:FreeplayState, x:Float, y:Float, flipped:Bool, controls:Controls)
{
super(x, y);
this.parent = parent;
this.controls = controls;
frames = Paths.getSparrowAtlas('freeplay/freeplaySelector');
animation.addByPrefix('shine', 'arrow pointer loop', 24);
animation.play('shine');
whiteShader = new PureColor(FlxColor.WHITE);
shader = whiteShader;
flipX = flipped;
scale.x = scale.y = 1 * baseScale;
updateHitbox();
}
override function update(elapsed:Float):Void
{
if (flipX && controls.UI_RIGHT_P) moveShitDown();
if (!flipX && controls.UI_LEFT_P) moveShitDown();
super.update(elapsed);
}
function moveShitDown():Void
{
offset.y -= 5;
whiteShader.colorSet = true;
scale.x = scale.y = 0.5 * baseScale;
new FlxTimer().start(2 / 24, function(tmr) {
scale.x = scale.y = 1 * baseScale;
whiteShader.colorSet = false;
updateHitbox();
});
}
}

View file

@ -789,7 +789,7 @@ class FreeplayState extends MusicBeatSubState
funnyMenu.init(FlxG.width, 0, tempSong, styleData); funnyMenu.init(FlxG.width, 0, tempSong, styleData);
funnyMenu.onConfirm = function() { funnyMenu.onConfirm = function() {
capsuleOnConfirmDefault(funnyMenu); capsuleOnOpenDefault(funnyMenu);
}; };
funnyMenu.y = funnyMenu.intendedY(i + 1) + 10; funnyMenu.y = funnyMenu.intendedY(i + 1) + 10;
funnyMenu.targetPos.x = funnyMenu.x; funnyMenu.targetPos.x = funnyMenu.x;
@ -1864,7 +1864,86 @@ class FreeplayState extends MusicBeatSubState
capsuleOnConfirmDefault(targetSong); capsuleOnConfirmDefault(targetSong);
} }
function capsuleOnConfirmDefault(cap:SongMenuItem):Void /**
* Called when hitting ENTER to open the instrumental list.
*/
function capsuleOnOpenDefault(cap:SongMenuItem):Void
{
var targetSongId:String = cap?.songData?.songId ?? 'unknown';
var targetSongNullable:Null<Song> = SongRegistry.instance.fetchEntry(targetSongId);
if (targetSongNullable == null)
{
FlxG.log.warn('WARN: could not find song with id (${targetSongId})');
return;
}
var targetSong:Song = targetSongNullable;
var targetDifficultyId:String = currentDifficulty;
var targetVariation:Null<String> = targetSong.getFirstValidVariation(targetDifficultyId, currentCharacter);
var targetLevelId:Null<String> = cap?.songData?.levelId;
PlayStatePlaylist.campaignId = targetLevelId ?? null;
var targetDifficulty:Null<SongDifficulty> = targetSong.getDifficulty(targetDifficultyId, targetVariation);
if (targetDifficulty == null)
{
FlxG.log.warn('WARN: could not find difficulty with id (${targetDifficultyId})');
return;
}
trace('target difficulty: ${targetDifficultyId}');
trace('target variation: ${targetDifficulty?.variation ?? Constants.DEFAULT_VARIATION}');
var baseInstrumentalId:String = targetSong.getBaseInstrumentalId(targetDifficultyId, targetDifficulty?.variation ?? Constants.DEFAULT_VARIATION) ?? '';
var altInstrumentalIds:Array<String> = targetSong.listAltInstrumentalIds(targetDifficultyId,
targetDifficulty?.variation ?? Constants.DEFAULT_VARIATION) ?? [];
if (altInstrumentalIds.length > 0)
{
var instrumentalIds = [baseInstrumentalId].concat(altInstrumentalIds);
openInstrumentalList(cap, instrumentalIds);
}
else
{
trace('NO ALTS');
capsuleOnConfirmDefault(cap);
}
}
public function getControls():Controls
{
return controls;
}
function openInstrumentalList(cap:SongMenuItem, instrumentalIds:Array<String>):Void
{
busy = true;
capsuleOptionsMenu = new CapsuleOptionsMenu(this, cap.x + 175, cap.y + 115, instrumentalIds);
capsuleOptionsMenu.cameras = [funnyCam];
capsuleOptionsMenu.zIndex = 10000;
add(capsuleOptionsMenu);
capsuleOptionsMenu.onConfirm = function(targetInstId:String) {
capsuleOnConfirmDefault(cap, targetInstId);
};
}
var capsuleOptionsMenu:Null<CapsuleOptionsMenu> = null;
public function cleanupCapsuleOptionsMenu():Void
{
this.busy = false;
if (capsuleOptionsMenu != null)
{
remove(capsuleOptionsMenu);
capsuleOptionsMenu = null;
}
}
/**
* Called when hitting ENTER to play the song.
*/
function capsuleOnConfirmDefault(cap:SongMenuItem, ?targetInstId:String):Void
{ {
busy = true; busy = true;
letterSort.inputEnabled = false; letterSort.inputEnabled = false;
@ -1891,8 +1970,9 @@ class FreeplayState extends MusicBeatSubState
return; return;
} }
var baseInstrumentalId:String = targetDifficulty?.characters?.instrumental ?? ''; var baseInstrumentalId:String = targetSong?.getBaseInstrumentalId(targetDifficultyId, targetDifficulty.variation ?? Constants.DEFAULT_VARIATION) ?? '';
var altInstrumentalIds:Array<String> = targetDifficulty?.characters?.altInstrumentals ?? []; var altInstrumentalIds:Array<String> = targetSong?.listAltInstrumentalIds(targetDifficultyId,
targetDifficulty.variation ?? Constants.DEFAULT_VARIATION) ?? [];
var targetInstId:String = baseInstrumentalId; var targetInstId:String = baseInstrumentalId;
@ -1902,6 +1982,8 @@ class FreeplayState extends MusicBeatSubState
{ {
targetInstId = altInstrumentalIds[0]; targetInstId = altInstrumentalIds[0];
} }
if (targetInstId == null) targetInstId = baseInstrumentalId;
#end #end
// Visual and audio effects. // Visual and audio effects.
@ -2027,10 +2109,13 @@ class FreeplayState extends MusicBeatSubState
if (previewSongId == null) return; if (previewSongId == null) return;
var previewSong:Null<Song> = SongRegistry.instance.fetchEntry(previewSongId); var previewSong:Null<Song> = SongRegistry.instance.fetchEntry(previewSongId);
var currentVariation = previewSong?.getVariationsByCharacter(currentCharacter) ?? Constants.DEFAULT_VARIATION_LIST;
var songDifficulty:Null<SongDifficulty> = previewSong?.getDifficulty(currentDifficulty, var songDifficulty:Null<SongDifficulty> = previewSong?.getDifficulty(currentDifficulty,
previewSong?.getVariationsByCharacter(currentCharacter) ?? Constants.DEFAULT_VARIATION_LIST); previewSong?.getVariationsByCharacter(currentCharacter) ?? Constants.DEFAULT_VARIATION_LIST);
var baseInstrumentalId:String = songDifficulty?.characters?.instrumental ?? '';
var altInstrumentalIds:Array<String> = songDifficulty?.characters?.altInstrumentals ?? []; var baseInstrumentalId:String = previewSong?.getBaseInstrumentalId(currentDifficulty, songDifficulty?.variation ?? Constants.DEFAULT_VARIATION) ?? '';
var altInstrumentalIds:Array<String> = previewSong?.listAltInstrumentalIds(currentDifficulty,
songDifficulty?.variation ?? Constants.DEFAULT_VARIATION) ?? [];
var instSuffix:String = baseInstrumentalId; var instSuffix:String = baseInstrumentalId;