2022-09-06 04:59:54 +00:00
package funkin . play . song ;
2023-06-16 21:37:56 +00:00
import funkin . modding . events . ScriptEventDispatcher ;
2023-06-08 21:07:35 +00:00
import funkin . modding . events . ScriptEvent ;
2022-09-13 05:09:30 +00:00
import flixel . util . typeLimit . OneOfTwo ;
2023-07-02 20:46:40 +00:00
import funkin . modding . events . ScriptEvent ;
import funkin . modding . events . ScriptEventDispatcher ;
2022-09-13 05:09:30 +00:00
import funkin . play . song . ScriptedSong ;
2022-09-07 23:07:08 +00:00
import funkin . util . assets . DataAssets ;
2022-09-13 05:09:30 +00:00
import haxe . DynamicAccess ;
import haxe . Json ;
2022-09-07 23:07:08 +00:00
import openfl . utils . Assets ;
import thx . semver . Version ;
2022-09-06 04:59:54 +00:00
/ * *
* Contains utilities for l o a d i n g a n d p a r s i n g s t a g e d a t a .
* /
class SongDataParser
{
2023-01-23 00:55:30 +00:00
/ * *
* A list containing all the songs available to the game .
* /
static final songCache : Map < String , Song > = new Map < String , Song > ( ) ;
2023-02-22 01:58:15 +00:00
static final DEFAULT_SONG_ID : String = ' U N K N O W N ' ;
static final SONG_DATA_PATH : String = ' s o n g s / ' ;
2023-07-02 19:34:34 +00:00
static final MUSIC_DATA_PATH : String = ' m u s i c / ' ;
2023-02-22 01:58:15 +00:00
static final SONG_DATA_SUFFIX : String = ' - m e t a d a t a . j s o n ' ;
2023-01-23 00:55:30 +00:00
/ * *
* Parses and preloads the game ' s s o n g m e t a d a t a a n d s c r i p t s w h e n t h e g a m e s t a r t s .
2023-06-08 20:30:45 +00:00
*
2023-01-23 00:55:30 +00:00
* If you want to force song metadata to be reloaded , you can just call this function again .
* /
public static function loadSongCache ( ) : Void
{
clearSongCache ( ) ;
2023-02-22 01:58:15 +00:00
trace ( ' L o a d i n g s o n g c a c h e . . . ' ) ;
2023-01-23 00:55:30 +00:00
//
// SCRIPTED SONGS
//
var scriptedSongClassNames: Array < String > = ScriptedSong . listScriptClasses ( ) ;
trace ( ' I n s t a n t i a t i n g ${ scriptedSongClassNames . length } s c r i p t e d s o n g s . . . ' ) ;
for ( songCls in scriptedSongClassNames )
{
var song: Song = ScriptedSong . init ( songCls , DEFAULT_SONG_ID ) ;
if ( song != null )
{
trace ( ' L o a d e d s c r i p t e d s o n g : ${ song . songId } ' ) ;
songCache . set ( song . songId , song ) ;
}
e lse
{
trace ( ' F a i l e d t o i n s t a n t i a t e s c r i p t e d s o n g c l a s s : ${ songCls } ' ) ;
}
}
//
// UNSCRIPTED SONGS
//
2023-02-22 01:58:15 +00:00
var songIdList: Array < String > = DataAssets . listDataFilesInPath ( SONG_DATA_PATH , SONG_DATA_SUFFIX ) . map ( function ( songDataPath : String ) : String {
2023-01-23 00:55:30 +00:00
return songDataPath . split ( ' / ' ) [ 0 ] ;
} ) ;
2023-02-22 01:58:15 +00:00
var unscriptedSongIds: Array < String > = songIdList . filter ( function ( songId : String ) : Bool {
2023-01-23 00:55:30 +00:00
return ! songCache . exists ( songId ) ;
} ) ;
trace ( ' I n s t a n t i a t i n g ${ unscriptedSongIds . length } n o n - s c r i p t e d s o n g s . . . ' ) ;
for ( songId in unscriptedSongIds )
{
try
{
2023-02-22 01:58:15 +00:00
var song: Song = new Song ( songId ) ;
2023-01-23 00:55:30 +00:00
if ( song != null )
{
trace ( ' L o a d e d s o n g d a t a : ${ song . songId } ' ) ;
songCache . set ( song . songId , song ) ;
}
}
c atch ( e )
{
trace ( ' A n e r r o r o c c u r r e d w h i l e l o a d i n g s o n g d a t a : ${ songId } ' ) ;
trace ( e ) ;
// Assume error was already logged.
continue ;
}
}
trace ( ' S u c c e s s f u l l y l o a d e d ${ Lambda . count ( songCache ) } s t a g e s . ' ) ;
}
/ * *
* Retrieves a particular song from the cache .
2023-02-22 01:58:15 +00:00
* @ param songId The ID of the song to retrieve .
* @ return The song , or null if i t w a s n o t f o u n d .
2023-01-23 00:55:30 +00:00
* /
public static function fetchSong ( songId : String ) : Null < Song >
{
if ( songCache . exists ( songId ) )
{
var song: Song = songCache . get ( songId ) ;
trace ( ' S u c c e s s f u l l y f e t c h s o n g : ${ songId } ' ) ;
2023-07-02 20:46:40 +00:00
var event: ScriptEvent = new ScriptEvent ( ScriptEvent . CREATE , false ) ;
ScriptEventDispatcher . callEvent ( song , event ) ;
2023-01-23 00:55:30 +00:00
return song ;
}
e lse
{
trace ( ' F a i l e d t o f e t c h s o n g , n o t f o u n d i n c a c h e : ${ songId } ' ) ;
return null ;
}
}
static function clearSongCache ( ) : Void
{
if ( songCache != null )
{
songCache . clear ( ) ;
}
}
2023-06-08 21:07:35 +00:00
/ * *
* A list of all the song IDs available to the game .
* @ return The list of song IDs .
* /
2023-01-23 00:55:30 +00:00
public static function listSongIds ( ) : Array < String >
{
return songCache . keys ( ) . array ( ) ;
}
2023-06-08 21:07:35 +00:00
/ * *
* Loads the song metadata for a p a r t i c u l a r s o n g .
* @ param songId The ID of the song to load .
* @ return The song metadata for e a c h v a r i a t i o n , o r a n e m p t y a r r a y i f t h e s o n g w a s n o t f o u n d .
* /
public static function loadSongMetadata ( songId : String ) : Array < SongMetadata >
2023-01-23 00:55:30 +00:00
{
var result: Array < SongMetadata > = [ ] ;
var rawJson: String = loadSongMetadataFile ( songId ) ;
var jsonData: Dynamic = null ;
try
{
jsonData = Json . parse ( rawJson ) ;
}
c atch ( e ) { }
var songMetadata: SongMetadata = SongMigrator . migrateSongMetadata ( jsonData , songId ) ;
songMetadata = SongValidator . validateSongMetadata ( songMetadata , songId ) ;
if ( songMetadata == null )
{
return result ;
}
result . push ( songMetadata ) ;
2023-06-08 21:07:35 +00:00
var variations: Array < String > = songMetadata . playData . songVariations ;
2023-01-23 00:55:30 +00:00
for ( variation in variations )
{
2023-06-08 21:07:35 +00:00
var variationRawJson: String = loadSongMetadataFile ( songId , variation ) ;
var variationSongMetadata: SongMetadata = SongMigrator . migrateSongMetadata ( variationRawJson , ' ${ songId } _ ${ variation } ' ) ;
variationSongMetadata = SongValidator . validateSongMetadata ( variationSongMetadata , ' ${ songId } _ ${ variation } ' ) ;
2023-01-23 00:55:30 +00:00
if ( variationSongMetadata != null )
{
variationSongMetadata . variation = variation ;
result . push ( variationSongMetadata ) ;
}
}
return result ;
}
static function loadSongMetadataFile ( songPath : String , variation : String = ' ' ) : String
{
var songMetadataFilePath: String = ( variation != ' ' ) ? Paths . json ( ' $ SONG_DATA_PATH $ songPath / $ songPath - m e t a d a t a - $ variation ' ) : Paths . json ( ' $ SONG_DATA_PATH $ songPath / $ songPath - m e t a d a t a ' ) ;
var rawJson: String = Assets . getText ( songMetadataFilePath ) . trim ( ) ;
2023-06-08 21:07:35 +00:00
while ( ! rawJson . endsWith ( ' } ' ) && rawJson . length > 0 )
2023-01-23 00:55:30 +00:00
{
rawJson = rawJson . substr ( 0 , rawJson . length - 1 ) ;
}
return rawJson ;
}
2023-07-02 19:34:34 +00:00
public static function parseMusicMetadata ( musicId : String ) : SongMetadata
{
var rawJson: String = loadMusicMetadataFile ( musicId ) ;
var jsonData: Dynamic = null ;
try
{
jsonData = Json . parse ( rawJson ) ;
}
c atch ( e ) { }
var musicMetadata: SongMetadata = SongMigrator . migrateSongMetadata ( jsonData , musicId ) ;
musicMetadata = SongValidator . validateSongMetadata ( musicMetadata , musicId ) ;
return musicMetadata ;
}
static function loadMusicMetadataFile ( musicPath : String , variation : String = ' ' ) : String
{
2023-07-26 20:52:58 +00:00
var musicMetadataFilePath: String = ( variation != ' ' || variation == " d e f a u l t " ) ? Paths . file ( ' $ MUSIC_DATA_PATH $ musicPath / $ musicPath - m e t a d a t a - $ variation . j s o n ' ) : Paths . file ( ' $ MUSIC_DATA_PATH $ musicPath / $ musicPath - m e t a d a t a . j s o n ' ) ;
2023-07-02 19:34:34 +00:00
var rawJson: String = Assets . getText ( musicMetadataFilePath ) . trim ( ) ;
while ( ! rawJson . endsWith ( " } " ) )
{
rawJson = rawJson . substr ( 0 , rawJson . length - 1 ) ;
}
return rawJson ;
}
2023-06-08 21:07:35 +00:00
public static function parseSongChartData ( songId : String , variation : String = ' ' ) : SongChartData
2023-01-23 00:55:30 +00:00
{
var rawJson: String = loadSongChartDataFile ( songId , variation ) ;
var jsonData: Dynamic = null ;
try
{
jsonData = Json . parse ( rawJson ) ;
}
2023-06-08 21:07:35 +00:00
c atch ( e )
{
trace ( ' F a i l e d t o p a r s e s o n g c h a r t d a t a : ${ songId } ( ${ variation } ) ' ) ;
trace ( e ) ;
}
2023-01-23 00:55:30 +00:00
var songChartData: SongChartData = SongMigrator . migrateSongChartData ( jsonData , songId ) ;
songChartData = SongValidator . validateSongChartData ( songChartData , songId ) ;
if ( songChartData == null )
{
trace ( ' F a i l e d t o v a l i d a t e s o n g c h a r t d a t a : ${ songId } ' ) ;
return null ;
}
return songChartData ;
}
static function loadSongChartDataFile ( songPath : String , variation : String = ' ' ) : String
{
2023-07-26 20:52:58 +00:00
var songChartDataFilePath: String = ( variation != ' ' || variation == ' d e f a u l t ' ) ? Paths . json ( ' $ SONG_DATA_PATH $ songPath / $ songPath - c h a r t - $ variation ' ) : Paths . json ( ' $ SONG_DATA_PATH $ songPath / $ songPath - c h a r t ' ) ;
2023-01-23 00:55:30 +00:00
var rawJson: String = Assets . getText ( songChartDataFilePath ) . trim ( ) ;
2023-06-08 21:07:35 +00:00
while ( ! rawJson . endsWith ( ' } ' ) && rawJson . length > 0 )
2023-01-23 00:55:30 +00:00
{
rawJson = rawJson . substr ( 0 , rawJson . length - 1 ) ;
}
return rawJson ;
}
2022-09-06 04:59:54 +00:00
}
2022-09-07 23:07:08 +00:00
2022-10-07 04:37:21 +00:00
typedef RawSongMetadata =
2022-09-07 23:07:08 +00:00
{
2023-01-23 00:55:30 +00:00
/ * *
* A semantic versioning string for t h e s o n g d a t a f o r m a t .
2023-06-08 20:30:45 +00:00
*
2023-01-23 00:55:30 +00:00
* /
var version: Version ;
var songName: String ;
var artist: String ;
var timeFormat: SongTimeFormat ;
var divisions: Int ;
var timeChanges: Array < SongTimeChange > ;
2023-05-25 22:33:39 +00:00
var looped: Bool ;
2023-01-23 00:55:30 +00:00
var playData: SongPlayData ;
var generatedBy: String ;
/ * *
* Defaults to ` d efault ` or ` ' ' ` . Populated later .
* /
var variation: String ;
2022-09-07 23:07:08 +00:00
} ;
2022-10-07 04:37:21 +00:00
@ : forward
abstract SongMetadata ( RawSongMetadata )
{
2023-01-23 00:55:30 +00:00
public function n e w ( songName : String , artist : String , variation : String = ' d e f a u l t ' )
{
2023-01-23 03:25:45 +00:00
this =
{
version : SongMigrator . CHART_VERSION ,
songName : songName ,
artist : artist ,
timeFormat : ' m s ' ,
divisions : 96 ,
timeChanges : [ new SongTimeChange ( - 1 , 0 , 100 , 4 , 4 , [ 4 , 4 , 4 , 4 ] ) ] ,
2023-05-25 22:33:39 +00:00
looped : false ,
2023-01-23 03:25:45 +00:00
playData :
{
songVariations : [ ] ,
difficulties : [ ' n o r m a l ' ] ,
playableChars :
{
bf : new SongPlayableChar ( ' g f ' , ' d a d ' ) ,
} ,
stage : ' m a i n S t a g e ' ,
noteSkin : ' N o r m a l '
} ,
generatedBy : SongValidator . DEFAULT_GENERATEDBY ,
// Variation ID.
variation : variation
} ;
2023-01-23 00:55:30 +00:00
}
public function clone ( ? newVariation : String = null ) : SongMetadata
{
2023-06-08 21:07:35 +00:00
var result: SongMetadata = new SongMetadata ( this . songName , this . artist , newVariation == null ? this . variation : newVariation ) ;
2023-01-23 00:55:30 +00:00
result . version = this . version ;
result . timeFormat = this . timeFormat ;
result . divisions = this . divisions ;
result . timeChanges = this . timeChanges ;
2023-05-25 22:33:39 +00:00
result . looped = this . looped ;
2023-01-23 00:55:30 +00:00
result . playData = this . playData ;
result . generatedBy = this . generatedBy ;
return result ;
}
2022-10-07 04:37:21 +00:00
}
2022-09-13 05:09:30 +00:00
typedef SongPlayData =
{
2023-01-23 00:55:30 +00:00
var songVariations: Array < String > ;
var difficulties: Array < String > ;
2022-09-13 05:09:30 +00:00
2023-01-23 00:55:30 +00:00
/ * *
* Keys are the player characters and the values give info on what opponent / GF / inst to use .
* /
var playableChars: DynamicAccess < SongPlayableChar > ;
2022-09-13 05:09:30 +00:00
2023-01-23 00:55:30 +00:00
var stage: String ;
var noteSkin: String ;
2022-09-13 05:09:30 +00:00
}
typedef RawSongPlayableChar =
{
2023-01-23 00:55:30 +00:00
var g: String ;
var o: String ;
var i: String ;
2022-09-13 05:09:30 +00:00
}
2022-09-16 19:37:00 +00:00
typedef RawSongNoteData =
{
2023-01-23 00:55:30 +00:00
/ * *
* The timestamp of the note . The timestamp is in the format of the song ' s t i m e f o r m a t .
* /
var t: Float ;
/ * *
* Data for t h e n o t e . R e p r e s e n t s t h e i n d e x o n t h e s t r u m l i n e .
* 0 = left , 1 = down , 2 = up , 3 = right
* ` floor ( direction / strumlineSize ) ` specifies which strumline the note is on .
* 0 = player , 1 = opponent , etc .
* /
var d: Int ;
/ * *
* Length of the note , if a p p l i c a b l e .
* Defaults to 0 for s i n g l e n o t e s .
* /
var l: Float ;
/ * *
* The kind of the note .
* This can allow the note to include information used for c u s t o m b e h a v i o r .
* Defaults to blank or ` " n o r m a l " ` .
* /
var k: String ;
2022-09-16 19:37:00 +00:00
}
abstract SongNoteData ( RawSongNoteData )
{
2023-02-22 01:58:15 +00:00
public function n e w ( time : Float , data : Int , length : Float = 0 , kind : String = ' ' )
2023-01-23 00:55:30 +00:00
{
2023-01-23 03:25:45 +00:00
this =
{
t : time ,
d : data ,
l : length ,
k : kind
} ;
2023-01-23 00:55:30 +00:00
}
2023-07-23 00:16:43 +00:00
/ * *
* The timestamp of the note , i n milliseconds .
* /
2023-01-23 00:55:30 +00:00
public var time( get , set ) : Float ;
2023-06-08 21:07:35 +00:00
function get_time ( ) : Float
2023-01-23 00:55:30 +00:00
{
return this . t ;
}
2023-06-08 21:07:35 +00:00
function set_time ( value : Float ) : Float
2023-01-23 00:55:30 +00:00
{
return this . t = value ;
}
2023-07-23 00:16:43 +00:00
/ * *
* The timestamp of the note , i n steps .
* /
2023-01-23 00:55:30 +00:00
public var stepTime( get , never ) : Float ;
2023-06-08 21:07:35 +00:00
function get_stepTime ( ) : Float
2023-01-23 00:55:30 +00:00
{
2023-07-19 05:30:23 +00:00
return Conductor . getTimeInSteps ( a bstract . time ) ;
2023-01-23 00:55:30 +00:00
}
/ * *
* The raw data for t h e n o t e .
* /
public var data( get , set ) : Int ;
2023-06-08 21:07:35 +00:00
function get_data ( ) : Int
2023-01-23 00:55:30 +00:00
{
return this . d ;
}
2023-06-08 21:07:35 +00:00
function set_data ( value : Int ) : Int
2023-01-23 00:55:30 +00:00
{
return this . d = value ;
}
/ * *
* The direction of the note , if a p p l i c a b l e .
* Strips the strumline index from the data .
*
* 0 = left , 1 = down , 2 = up , 3 = right
* /
public inline function getDirection ( strumlineSize : Int = 4 ) : Int
{
2023-07-19 05:30:23 +00:00
return abstract . d a t a % s t r u m l i n e Size ;
2023-01-23 00:55:30 +00:00
}
public function getDirectionName ( strumlineSize : Int = 4 ) : String
{
2023-07-19 05:30:23 +00:00
switch ( a bstract . data % strumlineSize )
2023-01-23 00:55:30 +00:00
{
c ase 0 :
return ' L e f t ' ;
c ase 1 :
return ' D o w n ' ;
c ase 2 :
return ' U p ' ;
c ase 3 :
return ' R i g h t ' ;
d efault :
return ' U n k n o w n ' ;
}
}
/ * *
* The strumline index of the note , if a p p l i c a b l e .
* Strips the direction from the data .
2023-06-08 20:30:45 +00:00
*
2023-01-23 00:55:30 +00:00
* 0 = player , 1 = opponent , etc .
* /
public inline function getStrumlineIndex ( strumlineSize : Int = 4 ) : Int
{
2023-07-19 05:30:23 +00:00
return Math . floor ( a bstract . data / strumlineSize ) ;
2023-01-23 00:55:30 +00:00
}
2023-06-22 05:41:01 +00:00
/ * *
* Returns true if t h e n o t e i s o n e t h a t B o y f r i e n d s h o u l d t r y t o h i t ( i . e . i t ' s o n h i s s i d e ) .
* TODO : The name of this function is a l i t t l e m i s l e a d i n g ; w h a t a b o u t m i n e s ?
* @ param strumlineSize Defaults to 4.
* @ return True if i t ' s B o y f r i e n d ' s n o t e .
* /
2023-01-23 00:55:30 +00:00
public inline function getMustHitNote ( strumlineSize : Int = 4 ) : Bool
{
return getStrumlineIndex ( strumlineSize ) == 0 ;
}
2023-07-23 00:16:43 +00:00
/ * *
* If this is a hold note , this is the length of the hold note in milliseconds .
* @ default 0 ( not a h o l d n o t e )
* /
2023-01-23 00:55:30 +00:00
public var length( get , set ) : Float ;
2023-07-19 05:30:23 +00:00
function get_length ( ) : Float
2023-01-23 00:55:30 +00:00
{
return this . l ;
}
2023-07-19 05:30:23 +00:00
function set_length ( value : Float ) : Float
2023-01-23 00:55:30 +00:00
{
return this . l = value ;
}
2023-07-23 00:16:43 +00:00
/ * *
* If this is a hold note , this is the length of the hold note in steps .
* @ default 0 ( not a h o l d n o t e )
* /
2023-07-19 05:30:23 +00:00
public var stepLength( get , set ) : Float ;
function get_stepLength ( ) : Float
{
return Conductor . getTimeInSteps ( a bstract . time + a bstract . length ) - a bstract . stepTime ;
}
function set_stepLength ( value : Float ) : Float
{
return abstract . l e n g t h = Conductor . g e t S t e p T i m e I n M s ( v a l u e ) - a b s t r a c t . t i m e ;
}
2023-07-04 20:38:10 +00:00
public var isHoldNote( get , never ) : Bool ;
public function get_isHoldNote ( ) : Bool
{
return this . l > 0 ;
}
2023-01-23 00:55:30 +00:00
public var kind( get , set ) : String ;
2023-07-19 05:30:23 +00:00
function get_kind ( ) : String
2023-01-23 00:55:30 +00:00
{
2023-01-23 03:25:45 +00:00
if ( this . k == null || this . k == ' ' ) return ' n o r m a l ' ;
2023-01-23 00:55:30 +00:00
return this . k ;
}
2023-06-08 21:07:35 +00:00
function set_kind ( value : String ) : String
2023-01-23 00:55:30 +00:00
{
2023-01-23 03:25:45 +00:00
if ( value == ' n o r m a l ' || value == ' ' ) value = null ;
2023-01-23 00:55:30 +00:00
return this . k = value ;
}
@ : op ( A == B )
public function op_equals ( other : SongNoteData ) : Bool
{
2023-07-19 05:30:23 +00:00
if ( a bstract . kind == ' ' )
{
if ( other . kind != ' ' && other . kind != ' n o r m a l ' ) return false ;
}
e lse
{
if ( other . kind == ' ' || other . kind != a bstract . kind ) return false ;
}
2023-01-23 00:55:30 +00:00
2023-07-19 05:30:23 +00:00
return abstract . t i m e = = o t h e r . t i m e & & a b s t r a c t . d a t a = = o t h e r . d a t a & & a b s t r a c t . l e n g t h = = o t h e r . l e n g t h ;
2023-01-23 00:55:30 +00:00
}
@ : op ( A != B )
public function op_notEquals ( other : SongNoteData ) : Bool
{
2023-07-19 05:30:23 +00:00
if ( a bstract . kind == ' ' )
{
if ( other . kind != ' ' && other . kind != ' n o r m a l ' ) return true ;
}
e lse
{
if ( other . kind == ' ' || other . kind != a bstract . kind ) return true ;
}
return abstract . t i m e ! = o t h e r . t i m e | | a b s t r a c t . d a t a ! = o t h e r . d a t a | | a b s t r a c t . l e n g t h ! = o t h e r . l e n g t h ;
2023-01-23 00:55:30 +00:00
}
@ : op ( A > B )
public function op_greaterThan ( other : SongNoteData ) : Bool
{
2023-07-19 05:30:23 +00:00
return abstract . t i m e > o t h e r . t i m e ;
2023-01-23 00:55:30 +00:00
}
@ : op ( A < B )
public function op_lessThan ( other : SongNoteData ) : Bool
{
return this . t < other . time ;
}
@ : op ( A >= B )
public function op_greaterThanOrEquals ( other : SongNoteData ) : Bool
{
return this . t >= other . time ;
}
@ : op ( A <= B )
public function op_lessThanOrEquals ( other : SongNoteData ) : Bool
{
return this . t <= other . time ;
}
2022-09-16 19:37:00 +00:00
}
typedef RawSongEventData =
{
2023-01-23 00:55:30 +00:00
/ * *
* The timestamp of the event . The timestamp is in the format of the song ' s t i m e f o r m a t .
* /
var t: Float ;
/ * *
* The kind of the event .
* Examples include " F o c u s C a m e r a " and " P l a y A n i m a t i o n "
* Custom events can be added by scripts with the ` ScriptedSongEvent ` c lass .
* /
var e: String ;
/ * *
* The data for t h e e v e n t .
* This can allow the event to include information used for c u s t o m b e h a v i o r .
* Data type depends on the event kind . It can be anything that ' s J S O N s e r i a l i z a b l e .
* /
var v: DynamicAccess < Dynamic > ;
/ * *
* Whether this event has been activated .
* This is only used internally by the game . It should not be serialized .
* /
@ : optional var a: Bool ;
2022-09-16 19:37:00 +00:00
}
abstract SongEventData ( RawSongEventData )
{
2023-01-23 00:55:30 +00:00
public function n e w ( time : Float , event : String , value : Dynamic = null )
{
2023-01-23 03:25:45 +00:00
this =
{
t : time ,
e : event ,
v : value ,
a : false
} ;
2023-01-23 00:55:30 +00:00
}
public var time( get , set ) : Float ;
2023-06-08 21:07:35 +00:00
function get_time ( ) : Float
2023-01-23 00:55:30 +00:00
{
return this . t ;
}
2023-06-08 21:07:35 +00:00
function set_time ( value : Float ) : Float
2023-01-23 00:55:30 +00:00
{
return this . t = value ;
}
public var stepTime( get , never ) : Float ;
2023-06-08 21:07:35 +00:00
function get_stepTime ( ) : Float
2023-01-23 00:55:30 +00:00
{
2023-07-19 05:30:23 +00:00
return Conductor . getTimeInSteps ( a bstract . time ) ;
2023-01-23 00:55:30 +00:00
}
public var event( get , set ) : String ;
2023-06-08 21:07:35 +00:00
function get_event ( ) : String
2023-01-23 00:55:30 +00:00
{
return this . e ;
}
2023-06-08 21:07:35 +00:00
function set_event ( value : String ) : String
2023-01-23 00:55:30 +00:00
{
return this . e = value ;
}
public var value( get , set ) : Dynamic ;
2023-06-08 21:07:35 +00:00
function get_value ( ) : Dynamic
2023-01-23 00:55:30 +00:00
{
return this . v ;
}
2023-06-08 21:07:35 +00:00
function set_value ( value : Dynamic ) : Dynamic
2023-01-23 00:55:30 +00:00
{
return this . v = value ;
}
public var activated( get , set ) : Bool ;
2023-06-08 21:07:35 +00:00
function get_activated ( ) : Bool
2023-01-23 00:55:30 +00:00
{
return this . a ;
}
2023-06-08 21:07:35 +00:00
function set_activated ( value : Bool ) : Bool
2023-01-23 00:55:30 +00:00
{
return this . a = value ;
}
public inline function getDynamic ( key : String ) : Null < Dynamic >
{
return this . v . get ( key ) ;
}
public inline function getBool ( key : String ) : Null < Bool >
{
return cast this . v . get ( key ) ;
}
public inline function getInt ( key : String ) : Null < Int >
{
return cast this . v . get ( key ) ;
}
public inline function getFloat ( key : String ) : Null < Float >
{
return cast this . v . get ( key ) ;
}
public inline function getString ( key : String ) : String
{
return cast this . v . get ( key ) ;
}
public inline function getArray ( key : String ) : Array < Dynamic >
{
return cast this . v . get ( key ) ;
}
public inline function getBoolArray ( key : String ) : Array < Bool >
{
return cast this . v . get ( key ) ;
}
@ : op ( A == B )
public function op_equals ( other : SongEventData ) : Bool
{
return this . t == other . time && this . e == other . event && this . v == other . value ;
}
@ : op ( A != B )
public function op_notEquals ( other : SongEventData ) : Bool
{
return this . t != other . time || this . e != other . event || this . v != other . value ;
}
@ : op ( A > B )
public function op_greaterThan ( other : SongEventData ) : Bool
{
return this . t > other . time ;
}
@ : op ( A < B )
public function op_lessThan ( other : SongEventData ) : Bool
{
return this . t < other . time ;
}
@ : op ( A >= B )
public function op_greaterThanOrEquals ( other : SongEventData ) : Bool
{
return this . t >= other . time ;
}
@ : op ( A <= B )
public function op_lessThanOrEquals ( other : SongEventData ) : Bool
{
return this . t <= other . time ;
}
2022-09-16 19:37:00 +00:00
}
2022-09-13 05:09:30 +00:00
abstract SongPlayableChar ( RawSongPlayableChar )
{
2023-06-08 21:07:35 +00:00
public function n e w ( girlfriend : String , opponent : String , inst : String = ' ' )
2023-01-23 00:55:30 +00:00
{
2023-01-23 03:25:45 +00:00
this =
{
g : girlfriend ,
o : opponent ,
i : inst
} ;
2023-01-23 00:55:30 +00:00
}
public var girlfriend( get , set ) : String ;
2023-06-08 21:07:35 +00:00
function get_girlfriend ( ) : String
2023-01-23 00:55:30 +00:00
{
return this . g ;
}
2023-06-08 21:07:35 +00:00
function set_girlfriend ( value : String ) : String
2023-01-23 00:55:30 +00:00
{
return this . g = value ;
}
public var opponent( get , set ) : String ;
2023-06-08 21:07:35 +00:00
function get_opponent ( ) : String
2023-01-23 00:55:30 +00:00
{
return this . o ;
}
2023-06-08 21:07:35 +00:00
function set_opponent ( value : String ) : String
2023-01-23 00:55:30 +00:00
{
return this . o = value ;
}
public var inst( get , set ) : String ;
2023-06-08 21:07:35 +00:00
function get_inst ( ) : String
2023-01-23 00:55:30 +00:00
{
return this . i ;
}
2023-06-08 21:07:35 +00:00
function set_inst ( value : String ) : String
2023-01-23 00:55:30 +00:00
{
return this . i = value ;
}
2022-09-13 05:09:30 +00:00
}
2022-09-22 10:34:03 +00:00
typedef RawSongChartData =
2022-09-07 23:07:08 +00:00
{
2023-01-23 00:55:30 +00:00
var version: Version ;
2022-09-16 19:37:00 +00:00
2023-01-23 00:55:30 +00:00
var scrollSpeed: DynamicAccess < Float > ;
var events: Array < SongEventData > ;
var notes: DynamicAccess < Array < SongNoteData > > ;
var generatedBy: String ;
2022-09-07 23:07:08 +00:00
} ;
2022-09-22 10:34:03 +00:00
@ : forward
abstract SongChartData ( RawSongChartData )
{
2023-01-23 00:55:30 +00:00
public function n e w ( scrollSpeed : Float , events : Array < SongEventData > , notes : Array < SongNoteData > )
{
2023-01-23 03:25:45 +00:00
this =
{
version : SongMigrator . CHART_VERSION ,
events : events ,
notes :
{
normal : notes
} ,
scrollSpeed :
{
normal : scrollSpeed
} ,
generatedBy : SongValidator . DEFAULT_GENERATEDBY
}
2023-01-23 00:55:30 +00:00
}
public function getScrollSpeed ( diff : String = ' d e f a u l t ' ) : Float
{
var result: Float = this . scrollSpeed . get ( diff ) ;
2023-01-23 03:25:45 +00:00
if ( result == 0.0 && diff != ' d e f a u l t ' ) return getScrollSpeed ( ' d e f a u l t ' ) ;
2023-01-23 00:55:30 +00:00
return ( result == 0.0 ) ? 1.0 : result ;
}
2023-06-08 21:07:35 +00:00
public function setScrollSpeed ( value : Float , diff : String = ' d e f a u l t ' ) : Float
{
return this . scrollSpeed . set ( diff , value ) ;
}
public function getNotes ( diff : String ) : Array < SongNoteData >
{
var result: Array < SongNoteData > = this . notes . get ( diff ) ;
if ( result == null && diff != ' n o r m a l ' ) return getNotes ( ' n o r m a l ' ) ;
return ( result == null ) ? [ ] : result ;
}
public function setNotes ( value : Array < SongNoteData > , diff : String ) : Array < SongNoteData >
{
return this . notes . set ( diff , value ) ;
}
public function getEvents ( ) : Array < SongEventData >
{
return this . events ;
}
public function setEvents ( value : Array < SongEventData > ) : Array < SongEventData >
{
return this . events = value ;
}
2022-09-22 10:34:03 +00:00
}
2022-09-13 05:09:30 +00:00
typedef RawSongTimeChange =
{
2023-01-23 00:55:30 +00:00
/ * *
* Timestamp in specified ` timeFormat ` .
* /
var t: Float ;
/ * *
* Time in beats ( int ) . The game will calculate further beat values based on this one ,
* so it can do it in a s i m p l e l i n e a r f a s h i o n .
* /
2023-07-02 19:34:34 +00:00
var b: Null < Float > ;
2023-01-23 00:55:30 +00:00
/ * *
* Quarter notes per minute ( float ) . Cannot be empty in the first element of the list ,
* but otherwise it ' s o p t i o n a l , a n d d e f a u l t s t o t h e v a l u e o f t h e p r e v i o u s e l e m e n t .
* /
var bpm: Float ;
/ * *
* Time signature numerator ( int ) . Optional , defaults to 4.
* /
var n: Int ;
/ * *
* Time signature denominator ( int ) . Optional , defaults to 4. Should only ever be a power of two .
* /
var d: Int ;
/ * *
* Beat tuplets ( Array < int > or i n t ) . This defines how many steps each beat is divided into .
* It can either be an array of length ` n ` ( see a b o v e ) or a single integer number .
* Optional , defaults to ` [ 4 ] ` .
* /
var bt: OneOfTwo < Int , Array < Int > > ;
2022-09-13 05:09:30 +00:00
}
/ * *
* Add aliases to the minimalized property names of the typedef ,
* to improve readability .
* /
2023-07-02 19:34:34 +00:00
abstract SongTimeChange ( RawSongTimeChange ) from RawSongTimeChange
2022-09-13 05:09:30 +00:00
{
2023-07-02 19:34:34 +00:00
public function n e w ( timeStamp : Float , beatTime : Null < Float > , bpm : Float , timeSignatureNum : Int = 4 , timeSignatureDen : Int = 4 , beatTuplets : Array < Int > )
2023-01-23 00:55:30 +00:00
{
2023-01-23 03:25:45 +00:00
this =
{
t : timeStamp ,
b : beatTime ,
bpm : bpm ,
n : timeSignatureNum ,
d : timeSignatureDen ,
bt : beatTuplets ,
}
2023-01-23 00:55:30 +00:00
}
public var timeStamp( get , set ) : Float ;
2023-06-08 21:07:35 +00:00
function get_timeStamp ( ) : Float
2023-01-23 00:55:30 +00:00
{
return this . t ;
}
2023-06-08 21:07:35 +00:00
function set_timeStamp ( value : Float ) : Float
2023-01-23 00:55:30 +00:00
{
return this . t = value ;
}
2023-07-02 19:34:34 +00:00
public var beatTime( get , set ) : Null < Float > ;
2023-01-23 00:55:30 +00:00
2023-07-02 19:34:34 +00:00
public function get_beatTime ( ) : Null < Float >
2023-01-23 00:55:30 +00:00
{
return this . b ;
}
2023-07-02 19:34:34 +00:00
public function set_beatTime ( value : Null < Float > ) : Null < Float >
2023-01-23 00:55:30 +00:00
{
return this . b = value ;
}
public var bpm( get , set ) : Float ;
2023-06-08 21:07:35 +00:00
function get_bpm ( ) : Float
2023-01-23 00:55:30 +00:00
{
return this . bpm ;
}
2023-06-08 21:07:35 +00:00
function set_bpm ( value : Float ) : Float
2023-01-23 00:55:30 +00:00
{
return this . bpm = value ;
}
public var timeSignatureNum( get , set ) : Int ;
2023-06-08 21:07:35 +00:00
function get_timeSignatureNum ( ) : Int
2023-01-23 00:55:30 +00:00
{
return this . n ;
}
2023-06-08 21:07:35 +00:00
function set_timeSignatureNum ( value : Int ) : Int
2023-01-23 00:55:30 +00:00
{
return this . n = value ;
}
public var timeSignatureDen( get , set ) : Int ;
2023-06-08 21:07:35 +00:00
function get_timeSignatureDen ( ) : Int
2023-01-23 00:55:30 +00:00
{
return this . d ;
}
2023-06-08 21:07:35 +00:00
function set_timeSignatureDen ( value : Int ) : Int
2023-01-23 00:55:30 +00:00
{
return this . d = value ;
}
public var beatTuplets( get , set ) : Array < Int > ;
2023-06-08 21:07:35 +00:00
function get_beatTuplets ( ) : Array < Int >
2023-01-23 00:55:30 +00:00
{
if ( Std . isOfType ( this . bt , Int ) )
{
return [ this . bt ] ;
}
e lse
{
return this . bt ;
}
}
2023-06-08 21:07:35 +00:00
function set_beatTuplets ( value : Array < Int > ) : Array < Int >
2023-01-23 00:55:30 +00:00
{
return this . bt = value ;
}
2022-09-13 05:09:30 +00:00
}
2022-09-07 23:07:08 +00:00
enum a b s t r a c t SongTimeFormat ( S t r i n g ) f r o m S t r i n g t o S t r i n g
{
2023-06-08 21:07:35 +00:00
var TICKS = ' t i c k s ' ;
var FLOAT = ' f l o a t ' ;
var MILLISECONDS = ' m s ' ;
2022-09-07 23:07:08 +00:00
}