2022-09-06 00:59:54 -04:00
|
|
|
package funkin.play.song;
|
|
|
|
|
2023-05-25 18:33:39 -04:00
|
|
|
import funkin.audio.VoicesGroup;
|
2023-12-06 15:04:24 -05:00
|
|
|
import funkin.audio.FunkinSound;
|
2023-12-05 02:44:57 -05:00
|
|
|
import funkin.data.IRegistryEntry;
|
|
|
|
import funkin.data.song.SongData.SongCharacterData;
|
2023-09-08 17:46:44 -04:00
|
|
|
import funkin.data.song.SongData.SongChartData;
|
|
|
|
import funkin.data.song.SongData.SongEventData;
|
|
|
|
import funkin.data.song.SongData.SongMetadata;
|
2023-12-05 02:44:57 -05:00
|
|
|
import funkin.data.song.SongData.SongNoteData;
|
|
|
|
import funkin.data.song.SongData.SongOffsets;
|
2023-09-08 17:46:44 -04:00
|
|
|
import funkin.data.song.SongData.SongTimeChange;
|
|
|
|
import funkin.data.song.SongData.SongTimeFormat;
|
2023-12-05 02:44:57 -05:00
|
|
|
import funkin.data.song.SongRegistry;
|
2024-03-12 21:34:50 -04:00
|
|
|
import funkin.modding.IScriptedClass.IPlayStateScriptedClass;
|
2023-12-05 02:44:57 -05:00
|
|
|
import funkin.modding.events.ScriptEvent;
|
2024-06-18 17:56:24 -04:00
|
|
|
import funkin.ui.freeplay.charselect.PlayableCharacter;
|
2023-12-05 02:44:57 -05:00
|
|
|
import funkin.util.SortUtil;
|
|
|
|
import openfl.utils.Assets;
|
2022-09-07 19:07:08 -04:00
|
|
|
|
2022-09-06 00:59:54 -04:00
|
|
|
/**
|
|
|
|
* This is a data structure managing information about the current song.
|
|
|
|
* This structure is created when the game starts, and includes all the data
|
|
|
|
* from the `metadata.json` file.
|
|
|
|
* It also includes the chart data, but only when this is the currently loaded song.
|
|
|
|
*
|
|
|
|
* It also receives script events; scripted classes which extend this class
|
|
|
|
* can be used to perform custom gameplay behaviors only on specific songs.
|
|
|
|
*/
|
2023-09-08 17:46:44 -04:00
|
|
|
@:nullSafety
|
|
|
|
class Song implements IPlayStateScriptedClass implements IRegistryEntry<SongMetadata>
|
2022-09-06 00:59:54 -04:00
|
|
|
{
|
2024-03-12 21:34:50 -04:00
|
|
|
/**
|
|
|
|
* The default value for the song's name
|
|
|
|
*/
|
|
|
|
public static final DEFAULT_SONGNAME:String = 'Unknown';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The default value for the song's artist
|
|
|
|
*/
|
|
|
|
public static final DEFAULT_ARTIST:String = 'Unknown';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The default value for the song's time format
|
|
|
|
*/
|
2023-09-08 17:46:44 -04:00
|
|
|
public static final DEFAULT_TIMEFORMAT:SongTimeFormat = SongTimeFormat.MILLISECONDS;
|
2024-03-12 21:34:50 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The default value for the song's divisions
|
|
|
|
*/
|
2023-09-08 17:46:44 -04:00
|
|
|
public static final DEFAULT_DIVISIONS:Null<Int> = null;
|
2024-03-12 21:34:50 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The default value for whether the song loops.
|
|
|
|
*/
|
2023-09-08 17:46:44 -04:00
|
|
|
public static final DEFAULT_LOOPED:Bool = false;
|
2024-03-12 21:34:50 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The default value for the song's playable stage.
|
|
|
|
*/
|
|
|
|
public static final DEFAULT_STAGE:String = 'mainStage';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The default value for the song's scroll speed.
|
|
|
|
*/
|
2023-09-08 17:46:44 -04:00
|
|
|
public static final DEFAULT_SCROLLSPEED:Float = 1.0;
|
|
|
|
|
2024-03-12 21:34:50 -04:00
|
|
|
/**
|
|
|
|
* The internal ID of the song.
|
|
|
|
*/
|
2023-09-08 17:46:44 -04:00
|
|
|
public final id:String;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Song metadata as parsed from the JSON file.
|
|
|
|
* This is the data for the `default` variation specifically,
|
|
|
|
* and is needed for the IRegistryEntry interface.
|
|
|
|
* Will only be null if the song data could not be loaded.
|
|
|
|
*/
|
|
|
|
public final _data:Null<SongMetadata>;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-10-26 05:46:22 -04:00
|
|
|
// key = variation id, value = metadata
|
|
|
|
final _metadata:Map<String, SongMetadata>;
|
2023-01-22 19:55:30 -05:00
|
|
|
final difficulties:Map<String, SongDifficulty>;
|
|
|
|
|
2024-03-12 21:34:50 -04:00
|
|
|
/**
|
|
|
|
* The list of variations a song has.
|
|
|
|
*/
|
2023-11-16 00:02:42 -05:00
|
|
|
public var variations(get, never):Array<String>;
|
|
|
|
|
|
|
|
function get_variations():Array<String>
|
|
|
|
{
|
|
|
|
return _metadata.keys().array();
|
|
|
|
}
|
|
|
|
|
2024-06-05 20:49:33 -04:00
|
|
|
// this returns false so that any new song can override this and return true when needed
|
|
|
|
public function isSongNew(currentDifficulty:String):Bool
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-25 18:33:39 -04:00
|
|
|
/**
|
|
|
|
* Set to false if the song was edited in the charter and should not be saved as a high score.
|
|
|
|
*/
|
|
|
|
public var validScore:Bool = true;
|
|
|
|
|
2024-03-12 21:34:50 -04:00
|
|
|
/**
|
|
|
|
* The readable name of the song.
|
|
|
|
*/
|
2023-09-08 17:46:44 -04:00
|
|
|
public var songName(get, never):String;
|
|
|
|
|
|
|
|
function get_songName():String
|
|
|
|
{
|
|
|
|
if (_data != null) return _data?.songName ?? DEFAULT_SONGNAME;
|
2023-10-26 05:46:22 -04:00
|
|
|
if (_metadata.size() > 0) return _metadata.get(Constants.DEFAULT_VARIATION)?.songName ?? DEFAULT_SONGNAME;
|
2023-09-08 17:46:44 -04:00
|
|
|
return DEFAULT_SONGNAME;
|
|
|
|
}
|
|
|
|
|
2024-03-12 21:34:50 -04:00
|
|
|
/**
|
|
|
|
* The artist of the song.
|
|
|
|
*/
|
2023-09-08 17:46:44 -04:00
|
|
|
public var songArtist(get, never):String;
|
|
|
|
|
|
|
|
function get_songArtist():String
|
|
|
|
{
|
|
|
|
if (_data != null) return _data?.artist ?? DEFAULT_ARTIST;
|
2023-10-26 05:46:22 -04:00
|
|
|
if (_metadata.size() > 0) return _metadata.get(Constants.DEFAULT_VARIATION)?.artist ?? DEFAULT_ARTIST;
|
2023-09-08 17:46:44 -04:00
|
|
|
return DEFAULT_ARTIST;
|
|
|
|
}
|
|
|
|
|
2024-05-19 01:48:51 -04:00
|
|
|
/**
|
|
|
|
* The artist of the song.
|
|
|
|
*/
|
|
|
|
public var charter(get, never):String;
|
|
|
|
|
|
|
|
function get_charter():String
|
|
|
|
{
|
|
|
|
if (_data != null) return _data?.charter ?? 'Unknown';
|
|
|
|
if (_metadata.size() > 0) return _metadata.get(Constants.DEFAULT_VARIATION)?.charter ?? 'Unknown';
|
|
|
|
return Constants.DEFAULT_CHARTER;
|
|
|
|
}
|
|
|
|
|
2023-08-04 11:18:00 -04:00
|
|
|
/**
|
|
|
|
* @param id The ID of the song to load.
|
|
|
|
* @param ignoreErrors If false, an exception will be thrown if the song data could not be loaded.
|
|
|
|
*/
|
2023-09-08 17:46:44 -04:00
|
|
|
public function new(id:String)
|
2023-01-22 19:55:30 -05:00
|
|
|
{
|
2023-09-08 17:46:44 -04:00
|
|
|
this.id = id;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
difficulties = new Map<String, SongDifficulty>();
|
|
|
|
|
2023-09-08 17:46:44 -04:00
|
|
|
_data = _fetchData(id);
|
|
|
|
|
2023-10-26 05:46:22 -04:00
|
|
|
_metadata = _data == null ? [] : [Constants.DEFAULT_VARIATION => _data];
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-09-25 23:24:18 -04:00
|
|
|
if (_data != null && _data.playData != null)
|
|
|
|
{
|
|
|
|
for (vari in _data.playData.songVariations)
|
2023-10-21 01:04:50 -04:00
|
|
|
{
|
2024-03-12 21:34:50 -04:00
|
|
|
var variMeta:Null<SongMetadata> = fetchVariationMetadata(id, vari);
|
2024-03-22 03:04:52 -04:00
|
|
|
if (variMeta != null)
|
|
|
|
{
|
|
|
|
_metadata.set(variMeta.variation, variMeta);
|
|
|
|
trace(' Loaded variation: $vari');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FlxG.log.warn('[SONG] Failed to load variation metadata (${id}:${vari}), is the path correct?');
|
|
|
|
trace(' FAILED to load variation: $vari');
|
|
|
|
}
|
2023-11-05 00:08:18 -04:00
|
|
|
}
|
2023-10-21 01:04:50 -04:00
|
|
|
}
|
2023-09-08 17:46:44 -04:00
|
|
|
|
2023-10-26 05:46:22 -04:00
|
|
|
if (_metadata.size() == 0)
|
2023-08-04 12:35:01 -04:00
|
|
|
{
|
2023-09-08 17:46:44 -04:00
|
|
|
trace('[WARN] Could not find song data for songId: $id');
|
|
|
|
return;
|
2023-08-04 12:35:01 -04:00
|
|
|
}
|
2023-09-08 17:46:44 -04:00
|
|
|
|
2023-09-25 23:24:18 -04:00
|
|
|
populateDifficulties();
|
2023-01-22 19:55:30 -05:00
|
|
|
}
|
|
|
|
|
2024-03-12 21:34:50 -04:00
|
|
|
/**
|
|
|
|
* Build a song from existing metadata rather than loading it from the `assets` folder.
|
|
|
|
* Used by the Chart Editor.
|
|
|
|
*
|
|
|
|
* @param songId The ID of the song.
|
|
|
|
* @param metadata The metadata of the song.
|
|
|
|
* @param variations The list of variations this song has.
|
|
|
|
* @param charts The chart data for each variation.
|
|
|
|
* @param includeScript Whether to initialize the scripted class tied to the song, if it exists.
|
|
|
|
* @param validScore Whether the song is elegible for highscores.
|
|
|
|
* @return The constructed song object.
|
|
|
|
*/
|
2023-07-26 16:52:58 -04:00
|
|
|
public static function buildRaw(songId:String, metadata:Array<SongMetadata>, variations:Array<String>, charts:Map<String, SongChartData>,
|
2024-03-12 21:34:50 -04:00
|
|
|
includeScript:Bool = true, validScore:Bool = false):Song
|
2023-07-26 16:52:58 -04:00
|
|
|
{
|
2024-03-12 21:34:50 -04:00
|
|
|
@:privateAccess
|
|
|
|
var result:Null<Song>;
|
|
|
|
|
|
|
|
if (includeScript && SongRegistry.instance.isScriptedEntry(songId))
|
|
|
|
{
|
|
|
|
var songClassName:String = SongRegistry.instance.getScriptedEntryClassName(songId);
|
|
|
|
|
|
|
|
@:privateAccess
|
|
|
|
result = SongRegistry.instance.createScriptedEntry(songClassName);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
@:privateAccess
|
|
|
|
result = SongRegistry.instance.createEntry(songId);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result == null) throw 'ERROR: Could not build Song instance ($songId), is the attached script bad?';
|
2023-07-26 16:52:58 -04:00
|
|
|
|
|
|
|
result._metadata.clear();
|
|
|
|
for (meta in metadata)
|
2024-03-12 21:34:50 -04:00
|
|
|
{
|
2023-10-26 05:46:22 -04:00
|
|
|
result._metadata.set(meta.variation, meta);
|
2024-03-12 21:34:50 -04:00
|
|
|
}
|
2023-07-26 16:52:58 -04:00
|
|
|
|
2023-10-11 17:33:55 -04:00
|
|
|
result.difficulties.clear();
|
2023-09-25 23:24:18 -04:00
|
|
|
result.populateDifficulties();
|
2023-07-26 16:52:58 -04:00
|
|
|
|
|
|
|
for (variation => chartData in charts)
|
2024-03-12 21:34:50 -04:00
|
|
|
{
|
2023-07-26 16:52:58 -04:00
|
|
|
result.applyChartData(chartData, variation);
|
2024-03-12 21:34:50 -04:00
|
|
|
}
|
2023-07-26 16:52:58 -04:00
|
|
|
|
|
|
|
result.validScore = validScore;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-03-12 21:34:50 -04:00
|
|
|
/**
|
|
|
|
* Retrieve a list of the raw metadata for the song.
|
|
|
|
* @return The metadata JSON objects for the song's variations.
|
|
|
|
*/
|
2023-01-22 19:55:30 -05:00
|
|
|
public function getRawMetadata():Array<SongMetadata>
|
|
|
|
{
|
2023-10-26 05:46:22 -04:00
|
|
|
return _metadata.values();
|
2023-01-22 19:55:30 -05:00
|
|
|
}
|
|
|
|
|
2024-03-20 14:37:24 -04:00
|
|
|
/**
|
|
|
|
* List the album IDs for each variation of the song.
|
|
|
|
* @return A map of variation IDs to album IDs.
|
|
|
|
*/
|
|
|
|
public function listAlbums():Map<String, String>
|
|
|
|
{
|
|
|
|
var result:Map<String, String> = new Map<String, String>();
|
|
|
|
|
|
|
|
for (difficultyId in difficulties.keys())
|
|
|
|
{
|
|
|
|
var meta:Null<SongDifficulty> = difficulties.get(difficultyId);
|
|
|
|
if (meta != null && meta.album != null)
|
|
|
|
{
|
|
|
|
result.set(difficultyId, meta.album);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-01-22 19:55:30 -05:00
|
|
|
/**
|
2023-09-25 23:24:18 -04:00
|
|
|
* Populate the difficulty data from the provided metadata.
|
|
|
|
* Does not load chart data (that is triggered later when we want to play the song).
|
2023-01-22 19:55:30 -05:00
|
|
|
*/
|
2023-09-25 23:24:18 -04:00
|
|
|
function populateDifficulties():Void
|
2023-01-22 19:55:30 -05:00
|
|
|
{
|
2023-10-26 05:46:22 -04:00
|
|
|
if (_metadata == null || _metadata.size() == 0) return;
|
2023-08-04 12:35:01 -04:00
|
|
|
|
2023-01-22 19:55:30 -05:00
|
|
|
// Variations may have different artist, time format, generatedBy, etc.
|
2023-10-26 05:46:22 -04:00
|
|
|
for (metadata in _metadata.values())
|
2023-01-22 19:55:30 -05:00
|
|
|
{
|
2023-09-08 17:46:44 -04:00
|
|
|
if (metadata == null || metadata.playData == null) continue;
|
|
|
|
|
2023-10-18 01:02:10 -04:00
|
|
|
// If there are no difficulties in the metadata, there's a problem.
|
|
|
|
if (metadata.playData.difficulties.length == 0)
|
|
|
|
{
|
2024-07-18 23:27:12 -04:00
|
|
|
trace('[WARN] Song $id has no difficulties listed in metadata!');
|
2023-10-18 01:02:10 -04:00
|
|
|
}
|
|
|
|
|
2023-05-25 18:33:39 -04:00
|
|
|
// There may be more difficulties in the chart file than in the metadata,
|
|
|
|
// (i.e. non-playable charts like the one used for Pico on the speaker in Stress)
|
|
|
|
// but all the difficulties in the metadata must be in the chart file.
|
2023-01-22 19:55:30 -05:00
|
|
|
for (diffId in metadata.playData.difficulties)
|
|
|
|
{
|
|
|
|
var difficulty:SongDifficulty = new SongDifficulty(this, diffId, metadata.variation);
|
|
|
|
|
|
|
|
difficulty.songName = metadata.songName;
|
|
|
|
difficulty.songArtist = metadata.artist;
|
2024-05-19 01:48:51 -04:00
|
|
|
difficulty.charter = metadata.charter ?? Constants.DEFAULT_CHARTER;
|
2023-01-22 19:55:30 -05:00
|
|
|
difficulty.timeFormat = metadata.timeFormat;
|
|
|
|
difficulty.divisions = metadata.divisions;
|
|
|
|
difficulty.timeChanges = metadata.timeChanges;
|
2023-05-25 18:33:39 -04:00
|
|
|
difficulty.looped = metadata.looped;
|
2023-01-22 19:55:30 -05:00
|
|
|
difficulty.generatedBy = metadata.generatedBy;
|
2024-01-14 06:46:58 -05:00
|
|
|
difficulty.offsets = metadata?.offsets ?? new SongOffsets();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2024-01-11 00:30:00 -05:00
|
|
|
difficulty.difficultyRating = metadata.playData.ratings.get(diffId) ?? 0;
|
|
|
|
difficulty.album = metadata.playData.album;
|
|
|
|
|
2023-01-22 19:55:30 -05:00
|
|
|
difficulty.stage = metadata.playData.stage;
|
2023-10-21 01:04:50 -04:00
|
|
|
difficulty.noteStyle = metadata.playData.noteStyle;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-09-25 23:24:07 -04:00
|
|
|
difficulty.characters = metadata.playData.characters;
|
2023-11-16 00:02:42 -05:00
|
|
|
|
2024-02-05 21:35:58 -05:00
|
|
|
var variationSuffix = (metadata.variation != Constants.DEFAULT_VARIATION) ? '-${metadata.variation}' : '';
|
2024-02-05 13:35:30 -05:00
|
|
|
difficulties.set('$diffId$variationSuffix', difficulty);
|
2023-01-22 19:55:30 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse and cache the chart for all difficulties of this song.
|
2024-03-12 21:34:50 -04:00
|
|
|
* @param force Whether to forcibly clear the list of charts first.
|
2023-01-22 19:55:30 -05:00
|
|
|
*/
|
2023-08-28 15:03:29 -04:00
|
|
|
public function cacheCharts(force:Bool = false):Void
|
2023-01-22 19:55:30 -05:00
|
|
|
{
|
|
|
|
if (force)
|
|
|
|
{
|
|
|
|
clearCharts();
|
|
|
|
}
|
|
|
|
|
2023-09-08 17:46:44 -04:00
|
|
|
trace('Caching ${variations.length} chart files for song $id');
|
2023-01-22 19:55:30 -05:00
|
|
|
for (variation in variations)
|
|
|
|
{
|
2023-09-08 17:46:44 -04:00
|
|
|
var version:Null<thx.semver.Version> = SongRegistry.instance.fetchEntryChartVersion(id, variation);
|
|
|
|
if (version == null) continue;
|
2023-09-18 20:02:17 -04:00
|
|
|
var chart:Null<SongChartData> = SongRegistry.instance.parseEntryChartDataWithMigration(id, variation, version);
|
2023-09-08 17:46:44 -04:00
|
|
|
if (chart == null) continue;
|
|
|
|
applyChartData(chart, variation);
|
2023-07-26 16:52:58 -04:00
|
|
|
}
|
|
|
|
trace('Done caching charts.');
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-07-26 16:52:58 -04:00
|
|
|
function applyChartData(chartData:SongChartData, variation:String):Void
|
|
|
|
{
|
|
|
|
var chartNotes = chartData.notes;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-07-26 16:52:58 -04:00
|
|
|
for (diffId in chartNotes.keys())
|
|
|
|
{
|
|
|
|
// Retrieve the cached difficulty data.
|
2024-02-05 21:35:58 -05:00
|
|
|
var variationSuffix = (variation != Constants.DEFAULT_VARIATION) ? '-$variation' : '';
|
|
|
|
var difficulty:Null<SongDifficulty> = difficulties.get('$diffId$variationSuffix');
|
2023-07-26 16:52:58 -04:00
|
|
|
if (difficulty == null)
|
|
|
|
{
|
|
|
|
trace('Fabricated new difficulty for $diffId.');
|
|
|
|
difficulty = new SongDifficulty(this, diffId, variation);
|
2023-11-16 00:02:42 -05:00
|
|
|
var metadata = _metadata.get(variation);
|
2024-02-05 13:35:30 -05:00
|
|
|
difficulties.set('$diffId$variationSuffix', difficulty);
|
2023-11-16 00:02:42 -05:00
|
|
|
|
|
|
|
if (metadata != null)
|
|
|
|
{
|
|
|
|
difficulty.songName = metadata.songName;
|
|
|
|
difficulty.songArtist = metadata.artist;
|
2024-05-19 01:48:51 -04:00
|
|
|
difficulty.charter = metadata.charter ?? Constants.DEFAULT_CHARTER;
|
2023-11-16 00:02:42 -05:00
|
|
|
difficulty.timeFormat = metadata.timeFormat;
|
|
|
|
difficulty.divisions = metadata.divisions;
|
|
|
|
difficulty.timeChanges = metadata.timeChanges;
|
|
|
|
difficulty.looped = metadata.looped;
|
|
|
|
difficulty.generatedBy = metadata.generatedBy;
|
2024-01-19 23:24:18 -05:00
|
|
|
difficulty.offsets = metadata?.offsets ?? new SongOffsets();
|
2023-11-16 00:02:42 -05:00
|
|
|
|
|
|
|
difficulty.stage = metadata.playData.stage;
|
|
|
|
difficulty.noteStyle = metadata.playData.noteStyle;
|
|
|
|
|
|
|
|
difficulty.characters = metadata.playData.characters;
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
}
|
2023-07-26 16:52:58 -04:00
|
|
|
// Add the chart data to the difficulty.
|
2023-09-08 17:46:44 -04:00
|
|
|
difficulty.notes = chartNotes.get(diffId) ?? [];
|
|
|
|
difficulty.scrollSpeed = chartData.getScrollSpeed(diffId) ?? 1.0;
|
2023-07-26 16:52:58 -04:00
|
|
|
|
|
|
|
difficulty.events = chartData.events;
|
2023-01-22 19:55:30 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the metadata for a specific difficulty, including the chart if it is loaded.
|
2023-02-28 21:06:09 -05:00
|
|
|
* @param diffId The difficulty ID, such as `easy` or `hard`.
|
2024-02-05 21:35:58 -05:00
|
|
|
* @param variation The variation ID to fetch the difficulty for. Or you can use `variations`.
|
|
|
|
* @param variations A list of variations to fetch the difficulty for. Looks for the first variation that exists.
|
2023-02-28 21:06:09 -05:00
|
|
|
* @return The difficulty data.
|
2023-01-22 19:55:30 -05:00
|
|
|
*/
|
2024-02-05 21:35:58 -05:00
|
|
|
public function getDifficulty(?diffId:String, ?variation:String, ?variations:Array<String>):Null<SongDifficulty>
|
2023-01-22 19:55:30 -05:00
|
|
|
{
|
2024-06-05 17:10:53 -04:00
|
|
|
if (diffId == null) diffId = listDifficulties(variation, variations)[0];
|
2024-02-05 13:35:30 -05:00
|
|
|
if (variation == null) variation = Constants.DEFAULT_VARIATION;
|
2024-02-05 21:35:58 -05:00
|
|
|
if (variations == null) variations = [variation];
|
|
|
|
|
|
|
|
for (currentVariation in variations)
|
|
|
|
{
|
|
|
|
var variationSuffix = (currentVariation != Constants.DEFAULT_VARIATION) ? '-$currentVariation' : '';
|
|
|
|
|
|
|
|
if (difficulties.exists('$diffId$variationSuffix'))
|
|
|
|
{
|
|
|
|
return difficulties.get('$diffId$variationSuffix');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2024-06-18 17:56:24 -04:00
|
|
|
public function getFirstValidVariation(?diffId:String, ?currentCharacter:PlayableCharacter, ?possibleVariations:Array<String>):Null<String>
|
2024-02-05 21:35:58 -05:00
|
|
|
{
|
2024-03-22 22:17:34 -04:00
|
|
|
if (possibleVariations == null)
|
|
|
|
{
|
2024-06-18 17:56:24 -04:00
|
|
|
possibleVariations = getVariationsByCharacter(currentCharacter);
|
2024-03-22 22:17:34 -04:00
|
|
|
possibleVariations.sort(SortUtil.defaultsThenAlphabetically.bind(Constants.DEFAULT_VARIATION_LIST));
|
|
|
|
}
|
2024-02-05 21:35:58 -05:00
|
|
|
if (diffId == null) diffId = listDifficulties(null, possibleVariations)[0];
|
2024-02-05 13:35:30 -05:00
|
|
|
|
2024-03-22 22:17:34 -04:00
|
|
|
for (variationId in possibleVariations)
|
2024-02-05 21:35:58 -05:00
|
|
|
{
|
2024-03-22 22:17:34 -04:00
|
|
|
var variationSuffix = (variationId != Constants.DEFAULT_VARIATION) ? '-$variationId' : '';
|
|
|
|
if (difficulties.exists('$diffId$variationSuffix')) return variationId;
|
2024-02-05 21:35:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2023-01-22 19:55:30 -05:00
|
|
|
}
|
|
|
|
|
2024-05-11 01:05:51 -04:00
|
|
|
/**
|
|
|
|
* Given that this character is selected in the Freeplay menu,
|
|
|
|
* which variations should be available?
|
2024-06-18 17:56:24 -04:00
|
|
|
* @param char The playable character to query.
|
2024-05-11 01:05:51 -04:00
|
|
|
* @return An array of available variations.
|
|
|
|
*/
|
2024-06-18 17:56:24 -04:00
|
|
|
public function getVariationsByCharacter(?char:PlayableCharacter):Array<String>
|
2024-05-11 01:05:51 -04:00
|
|
|
{
|
2024-06-18 17:56:24 -04:00
|
|
|
if (char == null) return variations;
|
2024-05-11 01:05:51 -04:00
|
|
|
|
2024-06-18 17:56:24 -04:00
|
|
|
var result = [];
|
|
|
|
trace('Evaluating variations for ${this.id} ${char.id}: ${this.variations}');
|
|
|
|
for (variation in variations)
|
2024-05-11 01:05:51 -04:00
|
|
|
{
|
2024-06-18 17:56:24 -04:00
|
|
|
var metadata = _metadata.get(variation);
|
|
|
|
|
|
|
|
var playerCharId = metadata?.playData?.characters?.player;
|
|
|
|
if (playerCharId == null) continue;
|
|
|
|
|
|
|
|
if (char.shouldShowCharacter(playerCharId))
|
|
|
|
{
|
|
|
|
result.push(variation);
|
|
|
|
}
|
2024-05-11 01:05:51 -04:00
|
|
|
}
|
2024-06-18 17:56:24 -04:00
|
|
|
|
|
|
|
return result;
|
2024-05-11 01:05:51 -04:00
|
|
|
}
|
|
|
|
|
2023-10-11 17:33:55 -04:00
|
|
|
/**
|
|
|
|
* List all the difficulties in this song.
|
2024-03-21 19:44:02 -04:00
|
|
|
*
|
2024-02-05 21:35:58 -05:00
|
|
|
* @param variationId Optionally filter by a single variation.
|
|
|
|
* @param variationIds Optionally filter by multiple variations.
|
2024-04-03 21:57:29 -04:00
|
|
|
* @param showLocked Include charts which are not unlocked
|
2024-03-21 19:44:02 -04:00
|
|
|
* @param showHidden Include charts which are not accessible to the player.
|
|
|
|
*
|
2023-10-11 17:33:55 -04:00
|
|
|
* @return The list of difficulties.
|
|
|
|
*/
|
2024-04-03 21:57:29 -04:00
|
|
|
public function listDifficulties(?variationId:String, ?variationIds:Array<String>, showLocked:Bool = false, showHidden:Bool = false):Array<String>
|
2023-05-16 22:09:53 -04:00
|
|
|
{
|
2024-02-05 21:35:58 -05:00
|
|
|
if (variationIds == null) variationIds = [];
|
|
|
|
if (variationId != null) variationIds.push(variationId);
|
2023-10-11 17:33:55 -04:00
|
|
|
|
2024-06-18 17:56:24 -04:00
|
|
|
if (variationIds.length == 0) return [];
|
|
|
|
|
2024-02-05 13:35:30 -05:00
|
|
|
// 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.
|
|
|
|
|
2024-05-21 04:02:32 -04:00
|
|
|
var diffFiltered:Array<String> = difficulties.keys()
|
|
|
|
.array()
|
|
|
|
.map(function(diffId:String):Null<String> {
|
|
|
|
var difficulty:Null<SongDifficulty> = difficulties.get(diffId);
|
|
|
|
if (difficulty == null) return null;
|
|
|
|
if (variationIds.length > 0 && !variationIds.contains(difficulty.variation)) return null;
|
|
|
|
return difficulty.difficulty;
|
|
|
|
})
|
|
|
|
.filterNull()
|
|
|
|
.distinct();
|
2023-10-17 00:07:36 -04:00
|
|
|
|
2024-03-21 19:44:02 -04:00
|
|
|
diffFiltered = diffFiltered.filter(function(diffId:String):Bool {
|
|
|
|
if (showHidden) return true;
|
|
|
|
for (targetVariation in variationIds)
|
|
|
|
{
|
|
|
|
if (isDifficultyVisible(diffId, targetVariation)) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2023-10-17 17:27:11 -04:00
|
|
|
diffFiltered.sort(SortUtil.defaultsThenAlphabetically.bind(Constants.DEFAULT_DIFFICULTY_LIST));
|
2023-10-17 00:07:36 -04:00
|
|
|
|
|
|
|
return diffFiltered;
|
2023-05-17 16:42:58 -04:00
|
|
|
}
|
|
|
|
|
2024-02-08 02:21:12 -05:00
|
|
|
public function hasDifficulty(diffId:String, ?variationId:String, ?variationIds:Array<String>):Bool
|
2023-05-17 16:42:58 -04:00
|
|
|
{
|
2024-02-08 02:21:12 -05:00
|
|
|
if (variationIds == null) variationIds = [];
|
|
|
|
if (variationId != null) variationIds.push(variationId);
|
|
|
|
|
|
|
|
for (targetVariation in variationIds)
|
|
|
|
{
|
|
|
|
var variationSuffix = (targetVariation != Constants.DEFAULT_VARIATION) ? '-$targetVariation' : '';
|
|
|
|
if (difficulties.exists('$diffId$variationSuffix')) return true;
|
|
|
|
}
|
|
|
|
return false;
|
2023-05-16 22:09:53 -04:00
|
|
|
}
|
|
|
|
|
2024-03-21 19:44:02 -04:00
|
|
|
public function isDifficultyVisible(diffId:String, variationId:String):Bool
|
|
|
|
{
|
|
|
|
var variation = _metadata.get(variationId);
|
|
|
|
if (variation == null) return false;
|
|
|
|
return variation.playData.difficulties.contains(diffId);
|
|
|
|
}
|
|
|
|
|
2023-01-22 19:55:30 -05:00
|
|
|
/**
|
|
|
|
* Purge the cached chart data for each difficulty of this song.
|
|
|
|
*/
|
|
|
|
public function clearCharts():Void
|
|
|
|
{
|
|
|
|
for (diff in difficulties)
|
|
|
|
{
|
|
|
|
diff.clearChart();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toString():String
|
|
|
|
{
|
2023-09-08 17:46:44 -04:00
|
|
|
return 'Song($id)';
|
2023-01-22 19:55:30 -05:00
|
|
|
}
|
2023-05-25 18:33:39 -04:00
|
|
|
|
2023-09-08 17:46:44 -04:00
|
|
|
public function destroy():Void {}
|
|
|
|
|
2023-05-25 18:33:39 -04:00
|
|
|
public function onPause(event:PauseScriptEvent):Void {};
|
|
|
|
|
|
|
|
public function onResume(event:ScriptEvent):Void {};
|
|
|
|
|
|
|
|
public function onSongLoaded(event:SongLoadScriptEvent):Void {};
|
|
|
|
|
|
|
|
public function onSongStart(event:ScriptEvent):Void {};
|
|
|
|
|
|
|
|
public function onSongEnd(event:ScriptEvent):Void {};
|
|
|
|
|
|
|
|
public function onGameOver(event:ScriptEvent):Void {};
|
|
|
|
|
|
|
|
public function onSongRetry(event:ScriptEvent):Void {};
|
|
|
|
|
2024-03-05 21:48:04 -05:00
|
|
|
public function onNoteIncoming(event:NoteScriptEvent) {}
|
|
|
|
|
|
|
|
public function onNoteHit(event:HitNoteScriptEvent) {}
|
2023-05-25 18:33:39 -04:00
|
|
|
|
|
|
|
public function onNoteMiss(event:NoteScriptEvent):Void {};
|
|
|
|
|
|
|
|
public function onNoteGhostMiss(event:GhostMissNoteScriptEvent):Void {};
|
|
|
|
|
|
|
|
public function onSongEvent(event:SongEventScriptEvent):Void {};
|
|
|
|
|
|
|
|
public function onStepHit(event:SongTimeScriptEvent):Void {};
|
|
|
|
|
|
|
|
public function onBeatHit(event:SongTimeScriptEvent):Void {};
|
|
|
|
|
|
|
|
public function onCountdownStart(event:CountdownScriptEvent):Void {};
|
|
|
|
|
|
|
|
public function onCountdownStep(event:CountdownScriptEvent):Void {};
|
|
|
|
|
|
|
|
public function onCountdownEnd(event:CountdownScriptEvent):Void {};
|
|
|
|
|
|
|
|
public function onScriptEvent(event:ScriptEvent):Void {};
|
|
|
|
|
|
|
|
public function onCreate(event:ScriptEvent):Void {};
|
|
|
|
|
|
|
|
public function onDestroy(event:ScriptEvent):Void {};
|
|
|
|
|
|
|
|
public function onUpdate(event:UpdateScriptEvent):Void {};
|
2023-09-08 17:46:44 -04:00
|
|
|
|
|
|
|
static function _fetchData(id:String):Null<SongMetadata>
|
|
|
|
{
|
|
|
|
trace('Fetching song metadata for $id');
|
|
|
|
var version:Null<thx.semver.Version> = SongRegistry.instance.fetchEntryMetadataVersion(id);
|
|
|
|
if (version == null) return null;
|
2023-09-25 23:24:18 -04:00
|
|
|
return SongRegistry.instance.parseEntryMetadataWithMigration(id, Constants.DEFAULT_VARIATION, version);
|
2023-09-08 17:46:44 -04:00
|
|
|
}
|
|
|
|
|
2023-10-21 01:04:50 -04:00
|
|
|
function fetchVariationMetadata(id:String, vari:String):Null<SongMetadata>
|
2023-09-08 17:46:44 -04:00
|
|
|
{
|
2023-10-21 01:04:50 -04:00
|
|
|
var version:Null<thx.semver.Version> = SongRegistry.instance.fetchEntryMetadataVersion(id, vari);
|
|
|
|
if (version == null) return null;
|
|
|
|
var meta:Null<SongMetadata> = SongRegistry.instance.parseEntryMetadataWithMigration(id, vari, version);
|
|
|
|
return meta;
|
2023-09-08 17:46:44 -04:00
|
|
|
}
|
2022-09-06 00:59:54 -04:00
|
|
|
}
|
2022-09-13 01:09:30 -04:00
|
|
|
|
|
|
|
class SongDifficulty
|
|
|
|
{
|
2023-01-22 19:55:30 -05:00
|
|
|
/**
|
|
|
|
* The parent song for this difficulty.
|
|
|
|
*/
|
|
|
|
public final song:Song;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The difficulty ID, such as `easy` or `hard`.
|
|
|
|
*/
|
|
|
|
public final difficulty:String;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The metadata file that contains this difficulty.
|
|
|
|
*/
|
|
|
|
public final variation:String;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The note chart for this difficulty.
|
|
|
|
*/
|
|
|
|
public var notes:Array<SongNoteData>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The event chart for this difficulty.
|
|
|
|
*/
|
|
|
|
public var events:Array<SongEventData>;
|
|
|
|
|
2023-09-25 23:24:07 -04:00
|
|
|
public var songName:String = Constants.DEFAULT_SONGNAME;
|
|
|
|
public var songArtist:String = Constants.DEFAULT_ARTIST;
|
2024-05-19 01:48:51 -04:00
|
|
|
public var charter:String = Constants.DEFAULT_CHARTER;
|
2023-09-25 23:24:07 -04:00
|
|
|
public var timeFormat:SongTimeFormat = Constants.DEFAULT_TIMEFORMAT;
|
|
|
|
public var divisions:Null<Int> = null;
|
|
|
|
public var looped:Bool = false;
|
2023-12-05 02:44:57 -05:00
|
|
|
public var offsets:SongOffsets = new SongOffsets();
|
2023-09-08 17:46:44 -04:00
|
|
|
public var generatedBy:String = SongRegistry.DEFAULT_GENERATEDBY;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
public var timeChanges:Array<SongTimeChange> = [];
|
|
|
|
|
2023-09-25 23:24:07 -04:00
|
|
|
public var stage:String = Constants.DEFAULT_STAGE;
|
|
|
|
public var noteStyle:String = Constants.DEFAULT_NOTE_STYLE;
|
|
|
|
public var characters:SongCharacterData = null;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-09-25 23:24:07 -04:00
|
|
|
public var scrollSpeed:Float = Constants.DEFAULT_SCROLLSPEED;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2024-01-11 00:30:00 -05:00
|
|
|
public var difficultyRating:Int = 0;
|
|
|
|
public var album:Null<String> = null;
|
|
|
|
|
2023-01-22 19:55:30 -05:00
|
|
|
public function new(song:Song, diffId:String, variation:String)
|
|
|
|
{
|
|
|
|
this.song = song;
|
|
|
|
this.difficulty = diffId;
|
|
|
|
this.variation = variation;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function clearChart():Void
|
|
|
|
{
|
|
|
|
notes = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getStartingBPM():Float
|
|
|
|
{
|
|
|
|
if (timeChanges.length == 0)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return timeChanges[0].bpm;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getEvents():Array<SongEventData>
|
|
|
|
{
|
|
|
|
return cast events;
|
|
|
|
}
|
|
|
|
|
2024-04-23 18:32:07 -04:00
|
|
|
public function getInstPath(instrumental = ''):String
|
2023-01-22 19:55:30 -05:00
|
|
|
{
|
2023-09-25 23:24:07 -04:00
|
|
|
if (characters != null)
|
2023-06-22 01:41:01 -04:00
|
|
|
{
|
2023-09-25 23:24:07 -04:00
|
|
|
if (instrumental != '' && characters.altInstrumentals.contains(instrumental))
|
|
|
|
{
|
2024-02-08 02:21:12 -05:00
|
|
|
var instId = '-$instrumental';
|
2024-04-23 18:32:07 -04:00
|
|
|
return Paths.inst(this.song.id, instId);
|
2023-09-25 23:24:07 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Fallback to default instrumental.
|
2024-02-08 02:21:12 -05:00
|
|
|
var instId = (characters.instrumental ?? '') != '' ? '-${characters.instrumental}' : '';
|
2024-04-23 18:32:07 -04:00
|
|
|
return Paths.inst(this.song.id, instId);
|
2023-09-25 23:24:07 -04:00
|
|
|
}
|
2023-06-22 01:41:01 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-04-23 18:32:07 -04:00
|
|
|
return Paths.inst(this.song.id);
|
2023-06-22 01:41:01 -04:00
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
}
|
|
|
|
|
2024-04-23 18:32:07 -04:00
|
|
|
public function cacheInst(instrumental = ''):Void
|
|
|
|
{
|
|
|
|
FlxG.sound.cache(getInstPath(instrumental));
|
|
|
|
}
|
|
|
|
|
2024-06-06 21:38:00 -04:00
|
|
|
public function playInst(volume:Float = 1.0, instId:String = '', looped:Bool = false):Void
|
2023-01-22 19:55:30 -05:00
|
|
|
{
|
2024-06-06 21:38:00 -04:00
|
|
|
var suffix:String = (instId != '') ? '-$instId' : '';
|
2023-12-06 22:03:36 -05:00
|
|
|
|
2024-02-28 03:01:20 -05:00
|
|
|
FlxG.sound.music = FunkinSound.load(Paths.inst(this.song.id, suffix), volume, looped, false, true);
|
2023-12-06 22:03:36 -05:00
|
|
|
|
|
|
|
// Workaround for a bug where FlxG.sound.music.update() was being called twice.
|
|
|
|
FlxG.sound.list.remove(FlxG.sound.music);
|
2023-01-22 19:55:30 -05:00
|
|
|
}
|
|
|
|
|
2023-05-25 18:33:39 -04:00
|
|
|
/**
|
|
|
|
* Cache the vocals for a given character.
|
|
|
|
* @param id The character we are about to play.
|
|
|
|
*/
|
2023-09-25 23:24:07 -04:00
|
|
|
public inline function cacheVocals():Void
|
2023-01-22 19:55:30 -05:00
|
|
|
{
|
2023-09-25 23:24:07 -04:00
|
|
|
for (voice in buildVoiceList())
|
2023-05-25 18:33:39 -04:00
|
|
|
{
|
|
|
|
FlxG.sound.cache(voice);
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
}
|
|
|
|
|
2023-05-25 18:33:39 -04:00
|
|
|
/**
|
|
|
|
* Build a list of vocal files for the given character.
|
|
|
|
* Automatically resolves suffixed character IDs (so bf-car will resolve to bf if needed).
|
2023-06-08 16:30:45 -04:00
|
|
|
*
|
2023-05-25 18:33:39 -04:00
|
|
|
* @param id The character we are about to play.
|
|
|
|
*/
|
2023-09-25 23:24:07 -04:00
|
|
|
public function buildVoiceList():Array<String>
|
2023-01-22 19:55:30 -05:00
|
|
|
{
|
2023-08-28 15:07:51 -04:00
|
|
|
var suffix:String = (variation != null && variation != '' && variation != 'default') ? '-$variation' : '';
|
2023-05-25 18:39:41 -04:00
|
|
|
|
2023-05-25 18:33:39 -04:00
|
|
|
// Automatically resolve voices by removing suffixes.
|
2024-02-05 21:35:58 -05:00
|
|
|
// For example, if `Voices-bf-car-erect.ogg` does not exist, check for `Voices-bf-erect.ogg`.
|
|
|
|
// Then, check for `Voices-bf-car.ogg`, then `Voices-bf.ogg`.
|
2023-05-25 18:33:39 -04:00
|
|
|
|
2023-09-25 23:24:07 -04:00
|
|
|
var playerId:String = characters.player;
|
|
|
|
var voicePlayer:String = Paths.voices(this.song.id, '-$playerId$suffix');
|
2023-05-25 18:33:39 -04:00
|
|
|
while (voicePlayer != null && !Assets.exists(voicePlayer))
|
|
|
|
{
|
|
|
|
// Remove the last suffix.
|
|
|
|
// For example, bf-car becomes bf.
|
|
|
|
playerId = playerId.split('-').slice(0, -1).join('-');
|
|
|
|
// Try again.
|
2023-09-08 17:46:44 -04:00
|
|
|
voicePlayer = playerId == '' ? null : Paths.voices(this.song.id, '-${playerId}$suffix');
|
2023-05-25 18:33:39 -04:00
|
|
|
}
|
2024-02-05 21:35:58 -05:00
|
|
|
if (voicePlayer == null)
|
|
|
|
{
|
|
|
|
// Try again without $suffix.
|
|
|
|
playerId = characters.player;
|
|
|
|
voicePlayer = Paths.voices(this.song.id, '-${playerId}');
|
|
|
|
while (voicePlayer != null && !Assets.exists(voicePlayer))
|
|
|
|
{
|
|
|
|
// Remove the last suffix.
|
|
|
|
playerId = playerId.split('-').slice(0, -1).join('-');
|
|
|
|
// Try again.
|
|
|
|
voicePlayer = playerId == '' ? null : Paths.voices(this.song.id, '-${playerId}$suffix');
|
|
|
|
}
|
|
|
|
}
|
2023-05-25 18:33:39 -04:00
|
|
|
|
2023-09-25 23:24:07 -04:00
|
|
|
var opponentId:String = characters.opponent;
|
2023-09-08 17:46:44 -04:00
|
|
|
var voiceOpponent:String = Paths.voices(this.song.id, '-${opponentId}$suffix');
|
2023-05-25 18:33:39 -04:00
|
|
|
while (voiceOpponent != null && !Assets.exists(voiceOpponent))
|
|
|
|
{
|
|
|
|
// Remove the last suffix.
|
|
|
|
opponentId = opponentId.split('-').slice(0, -1).join('-');
|
|
|
|
// Try again.
|
2023-09-08 17:46:44 -04:00
|
|
|
voiceOpponent = opponentId == '' ? null : Paths.voices(this.song.id, '-${opponentId}$suffix');
|
2023-05-25 18:33:39 -04:00
|
|
|
}
|
2024-02-05 21:35:58 -05:00
|
|
|
if (voiceOpponent == null)
|
|
|
|
{
|
|
|
|
// Try again without $suffix.
|
|
|
|
opponentId = characters.opponent;
|
|
|
|
voiceOpponent = Paths.voices(this.song.id, '-${opponentId}');
|
|
|
|
while (voiceOpponent != null && !Assets.exists(voiceOpponent))
|
|
|
|
{
|
|
|
|
// Remove the last suffix.
|
|
|
|
opponentId = opponentId.split('-').slice(0, -1).join('-');
|
|
|
|
// Try again.
|
|
|
|
voiceOpponent = opponentId == '' ? null : Paths.voices(this.song.id, '-${opponentId}$suffix');
|
|
|
|
}
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
2023-05-25 18:33:39 -04:00
|
|
|
var result:Array<String> = [];
|
|
|
|
if (voicePlayer != null) result.push(voicePlayer);
|
|
|
|
if (voiceOpponent != null) result.push(voiceOpponent);
|
|
|
|
if (voicePlayer == null && voiceOpponent == null)
|
|
|
|
{
|
|
|
|
// Try to use `Voices.ogg` if no other voices are found.
|
2023-09-08 17:46:44 -04:00
|
|
|
if (Assets.exists(Paths.voices(this.song.id, ''))) result.push(Paths.voices(this.song.id, '$suffix'));
|
2023-05-25 18:33:39 -04:00
|
|
|
}
|
|
|
|
return result;
|
2023-01-22 19:55:30 -05:00
|
|
|
}
|
|
|
|
|
2023-05-25 18:33:39 -04:00
|
|
|
/**
|
|
|
|
* Create a VoicesGroup, an audio object that can play the vocals for all characters.
|
|
|
|
* @param charId The player ID.
|
|
|
|
* @return The generated vocal group.
|
|
|
|
*/
|
2023-09-25 23:24:07 -04:00
|
|
|
public function buildVocals():VoicesGroup
|
2023-01-22 19:55:30 -05:00
|
|
|
{
|
2023-05-25 18:33:39 -04:00
|
|
|
var result:VoicesGroup = new VoicesGroup();
|
|
|
|
|
2023-09-25 23:24:07 -04:00
|
|
|
var voiceList:Array<String> = buildVoiceList();
|
2023-05-25 18:33:39 -04:00
|
|
|
|
|
|
|
if (voiceList.length == 0)
|
|
|
|
{
|
2023-09-08 17:46:44 -04:00
|
|
|
trace('Could not find any voices for song ${this.song.id}');
|
2023-05-25 18:33:39 -04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add player vocals.
|
2024-02-28 00:19:08 -05:00
|
|
|
if (voiceList[0] != null) result.addPlayerVoice(FunkinSound.load(voiceList[0]));
|
2023-05-25 18:33:39 -04:00
|
|
|
// Add opponent vocals.
|
2024-02-28 00:19:08 -05:00
|
|
|
if (voiceList[1] != null) result.addOpponentVoice(FunkinSound.load(voiceList[1]));
|
2023-05-25 18:33:39 -04:00
|
|
|
|
|
|
|
// Add additional vocals.
|
|
|
|
if (voiceList.length > 2)
|
|
|
|
{
|
|
|
|
for (i in 2...voiceList.length)
|
|
|
|
{
|
2023-12-06 15:04:24 -05:00
|
|
|
result.add(FunkinSound.load(Assets.getSound(voiceList[i])));
|
2023-05-25 18:33:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-05 02:44:57 -05:00
|
|
|
result.playerVoicesOffset = offsets.getVocalOffset(characters.player);
|
|
|
|
result.opponentVoicesOffset = offsets.getVocalOffset(characters.opponent);
|
|
|
|
|
2023-01-22 19:55:30 -05:00
|
|
|
return result;
|
|
|
|
}
|
2022-09-13 01:09:30 -04:00
|
|
|
}
|