2022-03-08 03:13:53 -05:00
package funkin . charting ;
2020-10-09 22:39:52 -04:00
2020-10-10 05:28:44 -04:00
import flixel . FlxSprite ;
2020-10-13 01:18:50 -04:00
import flixel . addons . display . FlxGridOverlay ;
2022-01-25 21:14:31 -05:00
import flixel . addons . transition . FlxTransitionableState ;
2020-10-14 04:18:19 -04:00
import flixel . addons . ui . FlxInputText ;
import flixel . addons . ui . FlxUI ;
2020-10-11 23:52:21 -04:00
import flixel . addons . ui . FlxUICheckBox ;
2020-10-18 20:59:53 -04:00
import flixel . addons . ui . FlxUIDropDownMenu ;
2020-10-14 04:18:19 -04:00
import flixel . addons . ui . FlxUIInputText ;
2020-10-16 00:22:13 -04:00
import flixel . addons . ui . FlxUINumericStepper ;
2020-10-14 04:18:19 -04:00
import flixel . addons . ui . FlxUITabMenu ;
2020-10-11 23:52:21 -04:00
import flixel . group . FlxGroup ;
2020-10-13 01:18:50 -04:00
import flixel . math . FlxMath ;
2022-01-25 23:11:43 -05:00
import flixel . system . FlxSound ;
2020-10-10 05:28:44 -04:00
import flixel . text . FlxText ;
2020-10-09 23:22:07 -04:00
import flixel . ui . FlxButton ;
2020-10-10 00:22:26 -04:00
import flixel . util . FlxColor ;
2022-04-18 19:36:09 -04:00
import funkin . Conductor . BPMChangeEvent ;
import funkin . Section . SwagSection ;
import funkin . SongLoad . SwagSong ;
2022-10-07 00:37:21 -04:00
import funkin . audio . visualize . PolygonSpectogram ;
2022-04-18 19:36:09 -04:00
import funkin . audiovis . ABotVis ;
import funkin . audiovis . SpectogramSprite ;
2022-10-07 00:37:21 -04:00
import funkin . graphics . rendering . MeshRender ;
2022-09-16 01:44:50 -04:00
import funkin . noteStuff . NoteBasic . NoteData ;
2022-04-18 20:39:41 -04:00
import funkin . play . HealthIcon ;
2022-04-18 19:36:09 -04:00
import funkin . play . PlayState ;
2020-10-09 23:22:07 -04:00
import haxe . Json ;
2021-09-06 14:50:04 -04:00
import lime . media . AudioBuffer ;
2021-01-04 18:56:30 -05:00
import lime . utils . Assets ;
2020-10-09 23:22:07 -04:00
import openfl . events . Event ;
import openfl . events . IOErrorEvent ;
import openfl . net . FileReference ;
2020-10-09 22:39:52 -04:00
2021-09-27 22:30:38 -04:00
using Lambda ;
2021-12-06 17:49:05 -05:00
using flixel . util . FlxSpriteUtil ; // add in "compiler save" that saves the JSON directly to the debug json using File.write() stuff on windows / sys
2020-10-13 04:07:04 -04:00
2020-10-09 23:22:07 -04:00
class ChartingState extends MusicBeatState
2020-10-09 22:39:52 -04:00
{
2023-01-22 22:25:45 -05:00
var _file: FileReference ;
2020-10-11 20:24:34 -04:00
2023-01-22 22:25:45 -05:00
var UI_box: FlxUITabMenu ;
var sidePreview: FlxSprite ;
2020-10-11 23:52:21 -04:00
2023-01-22 22:25:45 -05:00
/ * *
* Array of notes showing when each section STARTS in STEPS
* Usually rounded up ? ?
* /
var curSection: Int = 0 ;
2020-10-13 04:07:04 -04:00
2023-01-22 22:25:45 -05:00
public static var lastSection: Int = 0 ;
2021-01-13 22:38:31 -05:00
2023-01-22 22:25:45 -05:00
var bpmTxt: FlxText ;
2020-10-10 05:28:44 -04:00
2023-01-22 22:25:45 -05:00
var strumLine: FlxSprite ;
var curSong: String = ' D a d b a t t l e ' ;
var amountSteps: Int = 0 ;
var bullshitUI: FlxGroup ;
2020-10-11 23:52:21 -04:00
2023-01-22 22:25:45 -05:00
var highlight: FlxSprite ;
2020-10-13 01:18:50 -04:00
2023-01-22 22:25:45 -05:00
var GRID_SIZE: Int = 40 ;
2020-10-13 01:18:50 -04:00
2023-01-22 22:25:45 -05:00
var dummyArrow: FlxSprite ;
2020-10-13 01:18:50 -04:00
2023-01-22 22:25:45 -05:00
var curRenderedNotes: FlxTypedGroup < Note > ;
var curRenderedSustains: FlxTypedGroup < FlxSprite > ;
2020-10-13 04:07:04 -04:00
2023-01-22 22:25:45 -05:00
var gridBG: FlxSprite ;
2020-10-09 23:22:07 -04:00
2023-01-22 22:25:45 -05:00
var _song: SwagSong ;
2020-10-13 21:44:07 -04:00
2023-01-22 22:25:45 -05:00
var typingShit: FlxInputText ;
/ *
* WILL BE THE CURRENT / LAST PLACED NOTE
* * /
var curSelectedNote: NoteData ;
2020-10-16 07:03:10 -04:00
2023-01-22 22:25:45 -05:00
var tempBpm: Float = 0 ;
2020-10-29 23:06:52 -04:00
2023-01-22 22:25:45 -05:00
var vocals: VoicesGroup ;
2020-10-31 00:25:23 -04:00
2023-01-22 22:25:45 -05:00
var leftIcon: HealthIcon ;
var rightIcon: HealthIcon ;
2021-01-16 23:15:29 -05:00
2023-01-22 22:25:45 -05:00
var audioBuf: AudioBuffer = new AudioBuffer ( ) ;
2021-09-06 14:50:04 -04:00
2023-01-22 22:25:45 -05:00
var playheadTest: FlxSprite ;
2021-09-06 14:50:04 -04:00
2023-01-22 22:25:45 -05:00
var staticSpecGrp: FlxTypedGroup < SpectogramSprite > ;
2021-09-20 13:21:25 -04:00
2023-01-22 22:25:45 -05:00
override function create ( )
{
curSection = lastSection ;
2021-01-13 22:38:31 -05:00
2023-01-22 22:25:45 -05:00
// sys.io.File.saveContent('./bitShit.txt', "swag");
2021-09-06 14:50:04 -04:00
2023-01-22 22:25:45 -05:00
// trace(audioBuf.sampleRate);
2021-09-06 14:50:04 -04:00
2023-01-22 22:25:45 -05:00
gridBG = FlxGridOverlay . create ( GRID_SIZE , GRID_SIZE , GRID_SIZE * 8 , GRID_SIZE * 16 ) ;
trace ( " G R D B G : " + gridBG . height ) ;
add ( gridBG ) ;
2020-10-13 01:18:50 -04:00
2023-01-22 22:25:45 -05:00
leftIcon = new HealthIcon ( ' b f ' ) ;
rightIcon = new HealthIcon ( ' d a d ' ) ;
leftIcon . scrollFactor . set ( 1 , 1 ) ;
rightIcon . scrollFactor . set ( 1 , 1 ) ;
2021-01-16 23:15:29 -05:00
2023-01-22 22:25:45 -05:00
leftIcon . setGraphicSize ( 0 , 45 ) ;
rightIcon . setGraphicSize ( 0 , 45 ) ;
2021-01-16 23:15:29 -05:00
2023-01-22 22:25:45 -05:00
leftIcon . autoUpdate = false ;
rightIcon . autoUpdate = false ;
2022-05-03 13:09:02 -04:00
2023-01-22 22:25:45 -05:00
add ( leftIcon ) ;
add ( rightIcon ) ;
2021-01-16 23:15:29 -05:00
2023-01-22 22:25:45 -05:00
leftIcon . setPosition ( 0 , - 100 ) ;
rightIcon . setPosition ( gridBG . width / 2 , - 100 ) ;
2021-01-16 23:15:29 -05:00
2023-01-22 22:25:45 -05:00
var gridBlackLine: FlxSprite = new FlxSprite ( gridBG . x + gridBG . width / 2 ) . makeGraphic ( 2 , Std . int ( gridBG . height ) , FlxColor . BLACK ) ;
add ( gridBlackLine ) ;
2021-01-06 22:38:17 -05:00
2023-01-22 22:25:45 -05:00
curRenderedNotes = new FlxTypedGroup < Note > ( ) ;
curRenderedSustains = new FlxTypedGroup < FlxSprite > ( ) ;
2020-10-13 04:07:04 -04:00
2023-01-22 22:25:45 -05:00
if ( PlayState . currentSong != null )
{
_song = SongLoad . songData = PlayState . currentSong ;
trace ( " L O A D E D A P L A Y S T A T E S O N G F I L E " ) ;
}
e lse
{
_song = SongLoad . songData = SongLoad . getDefaultSwagSong ( ) ;
}
2020-10-13 21:44:07 -04:00
2023-01-22 22:25:45 -05:00
FlxG . mouse . visible = true ;
FlxG . save . bind ( ' f u n k i n ' , ' n i n j a m u f f i n 9 9 ' ) ;
2020-12-25 04:09:14 -05:00
2023-01-22 22:25:45 -05:00
tempBpm = _song . bpm ;
2020-10-29 23:06:52 -04:00
2023-01-22 22:25:45 -05:00
addSection ( ) ;
2020-10-14 04:18:19 -04:00
2023-01-22 22:25:45 -05:00
// sections = SongLoad.getSong();
2020-10-13 21:44:07 -04:00
2023-01-22 22:25:45 -05:00
updateGrid ( ) ;
2020-10-13 21:44:07 -04:00
2023-01-22 22:25:45 -05:00
loadSong ( _song . song ) ;
// Conductor.bpm = _song.bpm;
Conductor . mapBPMChanges ( _song ) ;
2020-10-10 05:28:44 -04:00
2023-01-22 22:25:45 -05:00
bpmTxt = new FlxText ( 1000 , 50 , 0 , " " , 16 ) ;
bpmTxt . scrollFactor . set ( ) ;
add ( bpmTxt ) ;
2020-10-10 05:28:44 -04:00
2023-01-22 22:25:45 -05:00
strumLine = new FlxSprite ( 0 , 50 ) . makeGraphic ( Std . int ( GRID_SIZE * 8 ) , 4 ) ;
add ( strumLine ) ;
2020-10-10 05:28:44 -04:00
2023-01-22 22:25:45 -05:00
dummyArrow = new FlxSprite ( ) . makeGraphic ( GRID_SIZE , GRID_SIZE , 0xFFCC2288 ) ;
dummyArrow . alpha = 0.3 ;
add ( dummyArrow ) ;
2020-10-13 01:18:50 -04:00
2023-01-22 22:25:45 -05:00
var tabs = [
{ name : " S o n g " , label : ' S o n g ' } ,
{ name : " S e c t i o n " , label : ' S e c t i o n ' } ,
{ name : " N o t e " , label : ' N o t e ' }
] ;
2020-10-14 04:18:19 -04:00
2023-01-22 22:25:45 -05:00
UI_box = new FlxUITabMenu ( null , tabs , true ) ;
2020-10-14 04:18:19 -04:00
2023-01-22 22:25:45 -05:00
UI_box . resize ( 300 , 400 ) ;
UI_box . x = ( FlxG . width / 4 ) * 3 ;
UI_box . y = 120 ;
add ( UI_box ) ;
2020-10-14 04:18:19 -04:00
2023-01-22 22:25:45 -05:00
addSongUI ( ) ;
addSectionUI ( ) ;
addNoteUI ( ) ;
2020-10-16 00:22:13 -04:00
2023-01-22 22:25:45 -05:00
add ( curRenderedNotes ) ;
add ( curRenderedSustains ) ;
2020-10-16 00:22:13 -04:00
2023-01-22 22:25:45 -05:00
changeSection ( ) ;
super . create ( ) ;
}
2020-10-16 00:22:13 -04:00
2023-01-22 22:25:45 -05:00
function addSongUI ( ) : Void
{
var UI_songTitle = new FlxUIInputText ( 10 , 10 , 70 , _song . song , 8 ) ;
typingShit = UI_songTitle ;
var check_voices = new FlxUICheckBox ( 10 , 25 , null , null , " H a s v o i c e t r a c k " , 100 ) ;
check_voices . checked = _song . needsVoices ;
// _song.needsVoices = check_voices.checked;
check_voices . callback = function ( )
{
_song . needsVoices = check_voices . checked ;
trace ( ' C H E C K E D ! ' ) ;
} ;
var check_mute_inst = new FlxUICheckBox ( 10 , 200 , null , null , " M u t e I n s t r u m e n t a l ( i n e d i t o r ) " , 100 ) ;
check_mute_inst . checked = false ;
check_mute_inst . callback = function ( )
{
var vol: Float = 1 ;
if ( check_mute_inst . checked ) vol = 0 ;
FlxG . sound . music . volume = vol ;
} ;
var saveButton: FlxButton = new FlxButton ( 110 , 8 , " S a v e " , function ( )
{
saveLevel ( ) ;
} ) ;
var saveCompiler: FlxButton = new FlxButton ( 110 , 30 , " S a v e c o m p i l e " , function ( )
{
saveLevel ( true ) ;
} ) ;
var reloadSong: FlxButton = new FlxButton ( saveButton . x + saveButton . width + 10 , saveButton . y , " R e l o a d A u d i o " , function ( )
{
loadSong ( _song . song ) ;
} ) ;
var reloadSongJson: FlxButton = new FlxButton ( reloadSong . x , saveButton . y + 30 , " R e l o a d J S O N " , function ( )
{
FlxTransitionableState . skipNextTransIn = true ;
FlxTransitionableState . skipNextTransOut = true ;
loadJson ( _song . song . toLowerCase ( ) ) ;
} ) ;
var loadAutosaveBtn: FlxButton = new FlxButton ( reloadSongJson . x , reloadSongJson . y + 30 , ' l o a d a u t o s a v e ' , loadAutosave ) ;
var stepperSpeed: FlxUINumericStepper = new FlxUINumericStepper ( 10 , 80 , 0.1 , 1 , 0.1 , 10 , 2 ) ;
stepperSpeed . value = SongLoad . getSpeed ( ) ;
// stepperSpeed.value = _song.speed[SongLoad.curDiff];
stepperSpeed . name = ' s o n g _ s p e e d ' ;
var stepperBPM: FlxUINumericStepper = new FlxUINumericStepper ( 10 , 65 , 1 , 100 , 1 , 999 , 3 ) ;
stepperBPM . value = Conductor . bpm ;
stepperBPM . name = ' s o n g _ b p m ' ;
var characters: Array < String > = CoolUtil . coolTextFile ( Paths . txt ( ' c h a r a c t e r L i s t ' ) ) ;
var player1DropDown = new FlxUIDropDownMenu ( 10 , 100 , FlxUIDropDownMenu . makeStrIdLabelArray ( characters , true ) , function ( character : String )
{
_song . player1 = characters [ Std . parseInt ( character ) ] ;
updateHeads ( ) ;
} ) ;
player1DropDown . selectedLabel = _song . player1 ;
var player2DropDown = new FlxUIDropDownMenu ( 140 , 100 , FlxUIDropDownMenu . makeStrIdLabelArray ( characters , true ) , function ( character : String )
{
_song . player2 = characters [ Std . parseInt ( character ) ] ;
updateHeads ( ) ;
} ) ;
player2DropDown . selectedLabel = _song . player2 ;
var difficultyDropDown = new FlxUIDropDownMenu ( 10 , 230 , FlxUIDropDownMenu . makeStrIdLabelArray ( _song . difficulties , true ) , function ( diff : String )
{
SongLoad . curDiff = _song . difficulties [ Std . parseInt ( diff ) ] ;
SongLoad . checkAndCreateNotemap ( SongLoad . curDiff ) ;
while ( SongLoad . getSong ( ) [ curSection ] == null )
addSection ( ) ;
updateGrid ( ) ;
} ) ;
difficultyDropDown . selectedLabel = SongLoad . curDiff ;
var difficultyAdder = new FlxUIInputText ( 130 , 230 , 100 , " " , 12 ) ;
var addDiff: FlxButton = new FlxButton ( 130 , 250 , " A d d D i f f i c u l t y " , function ( )
{
difficultyAdder . text = " " ;
// something to regenerate difficulties
} ) ;
var tab_group_song = new FlxUI ( null , UI_box ) ;
tab_group_song . name = " S o n g " ;
tab_group_song . add ( UI_songTitle ) ;
tab_group_song . add ( check_voices ) ;
tab_group_song . add ( check_mute_inst ) ;
tab_group_song . add ( saveButton ) ;
tab_group_song . add ( saveCompiler ) ;
tab_group_song . add ( reloadSong ) ;
tab_group_song . add ( reloadSongJson ) ;
tab_group_song . add ( loadAutosaveBtn ) ;
tab_group_song . add ( stepperBPM ) ;
tab_group_song . add ( stepperSpeed ) ;
tab_group_song . add ( player1DropDown ) ;
tab_group_song . add ( player2DropDown ) ;
tab_group_song . add ( difficultyDropDown ) ;
tab_group_song . add ( difficultyAdder ) ;
tab_group_song . add ( addDiff ) ;
UI_box . addGroup ( tab_group_song ) ;
UI_box . scrollFactor . set ( ) ;
FlxG . camera . focusOn ( gridBG . getGraphicMidpoint ( ) ) ;
}
var stepperLength: FlxUINumericStepper ;
var check_mustHitSection: FlxUICheckBox ;
var check_changeBPM: FlxUICheckBox ;
var stepperSectionBPM: FlxUINumericStepper ;
var check_altAnim: FlxUICheckBox ;
function addSectionUI ( ) : Void
{
var tab_group_section = new FlxUI ( null , UI_box ) ;
tab_group_section . name = ' S e c t i o n ' ;
stepperLength = new FlxUINumericStepper ( 10 , 10 , 4 , 0 , 0 , 999 , 0 ) ;
stepperLength . value = SongLoad . getSong ( ) [ curSection ] . lengthInSteps ;
stepperLength . name = " s e c t i o n _ l e n g t h " ;
stepperSectionBPM = new FlxUINumericStepper ( 10 , 80 , 1 , Conductor . bpm , 1 , 999 , 3 ) ;
stepperSectionBPM . value = Conductor . bpm ;
stepperSectionBPM . name = ' s e c t i o n _ b p m ' ;
var stepperCopy: FlxUINumericStepper = new FlxUINumericStepper ( 110 , 130 , 1 , 1 , - 999 , 999 , 0 ) ;
var copyButton: FlxButton = new FlxButton ( 10 , 130 , " C o p y l a s t s e c t i o n " , function ( )
{
copySection ( Std . int ( stepperCopy . value ) ) ;
} ) ;
var clearSectionButton: FlxButton = new FlxButton ( 10 , 150 , " C l e a r " , clearSection ) ;
var swapSection: FlxButton = new FlxButton ( 10 , 170 , " S w a p s e c t i o n " , function ( )
{
for ( i in 0 ... SongLoad . getSong ( ) [ curSection ] . sectionNotes . length )
{
var note: Note = new Note ( 0 , 0 ) ;
note . data = SongLoad . getSong ( ) [ curSection ] . sectionNotes [ i ] ;
note . data . noteData = ( note . data . noteData + 4 ) % 8 ;
SongLoad . getSong ( ) [ curSection ] . sectionNotes [ i ] = note . data ;
updateGrid ( ) ;
}
} ) ;
check_mustHitSection = new FlxUICheckBox ( 10 , 30 , null , null , " M u s t h i t s e c t i o n " , 100 ) ;
check_mustHitSection . name = ' c h e c k _ m u s t H i t ' ;
check_mustHitSection . checked = true ;
// _song.needsVoices = check_mustHit.checked;
check_altAnim = new FlxUICheckBox ( 10 , 400 , null , null , " A l t A n i m a t i o n " , 100 ) ;
check_altAnim . name = ' c h e c k _ a l t A n i m ' ;
check_changeBPM = new FlxUICheckBox ( 10 , 60 , null , null , ' C h a n g e B P M ' , 100 ) ;
check_changeBPM . name = ' c h e c k _ c h a n g e B P M ' ;
tab_group_section . add ( stepperLength ) ;
tab_group_section . add ( stepperSectionBPM ) ;
tab_group_section . add ( stepperCopy ) ;
tab_group_section . add ( check_mustHitSection ) ;
tab_group_section . add ( check_altAnim ) ;
tab_group_section . add ( check_changeBPM ) ;
tab_group_section . add ( copyButton ) ;
tab_group_section . add ( clearSectionButton ) ;
tab_group_section . add ( swapSection ) ;
UI_box . addGroup ( tab_group_section ) ;
}
var stepperSusLength: FlxUINumericStepper ;
var stepperPerNoteSpeed: FlxUINumericStepper ;
function addNoteUI ( ) : Void
{
var tab_group_note = new FlxUI ( null , UI_box ) ;
tab_group_note . name = ' N o t e ' ;
stepperSusLength = new FlxUINumericStepper ( 10 , 10 , Conductor . stepCrochet / 2 , 0 , 0 , Conductor . stepCrochet * 16 ) ;
stepperSusLength . value = 0 ;
stepperSusLength . name = ' n o t e _ s u s L e n g t h ' ;
stepperPerNoteSpeed = new FlxUINumericStepper ( 10 , 40 , 0.1 , 1 , 0.01 , 100 , 2 ) ;
stepperPerNoteSpeed . value = 1 ;
stepperPerNoteSpeed . name = " n o t e _ P e r N o t e S p e e d " ;
var noteSpeedName: FlxText = new FlxText ( 40 , stepperPerNoteSpeed . y , 0 , " N o t e S p e e d M u l t i p l i e r " ) ;
var applyLength: FlxButton = new FlxButton ( 100 , 10 , ' A p p l y ' ) ;
tab_group_note . add ( stepperSusLength ) ;
tab_group_note . add ( stepperPerNoteSpeed ) ;
tab_group_note . add ( noteSpeedName ) ;
tab_group_note . add ( applyLength ) ;
UI_box . addGroup ( tab_group_note ) ;
}
// var spec:SpectogramSprite;
function loadSong ( daSong : String ) : Void
{
if ( FlxG . sound . music != null )
{
FlxG . sound . music . stop ( ) ;
// vocals.stop();
}
var pathShit = Paths . inst ( daSong ) ;
if ( ! openfl . utils . Assets . cache . hasSound ( pathShit ) )
{
var library = Assets . getLibrary ( " s o n g s " ) ;
var symbolPath = pathShit . split ( " : " ) . pop ( ) ;
// @:privateAccess
// library.types.set(symbolPath, SOUND);
// @:privateAccess
// library.pathGroups.set(symbolPath, [library.__cacheBreak(symbolPath)]);
// var callback = callbacks.add("song:" + pathShit);
openfl . utils . Assets . loadSound ( pathShit ) . onComplete ( function ( _ )
{
// callback();
} ) ;
}
FlxG . sound . playMusic ( Paths . inst ( daSong ) , 0.6 ) ;
var musSpec: PolygonSpectogram = new PolygonSpectogram ( FlxG . sound . music , FlxColor . RED , FlxG . height / 2 , Math . floor ( FlxG . height / 2 ) ) ;
musSpec . x += 170 ;
musSpec . scrollFactor . set ( ) ;
musSpec . waveAmplitude = 50 ;
// musSpec.visType = FREQUENCIES;
add ( musSpec ) ;
sidePreview = new FlxSprite ( 0 , 0 ) . makeGraphic ( 40 , FlxG . height , FlxColor . GRAY ) ;
sidePreview . scrollFactor . set ( ) ;
add ( sidePreview ) ;
// trace(audioBuf.data.length);
playheadTest = new FlxSprite ( 0 , 0 ) . makeGraphic ( 30 , 2 , FlxColor . RED ) ;
playheadTest . scrollFactor . set ( ) ;
playheadTest . alpha = 0.5 ;
add ( playheadTest ) ;
// WONT WORK FOR TUTORIAL OR TEST SONG!!! REDO LATER
vocals = VoicesGroup . build ( daSong , _song . voiceList ) ;
// vocals = new FlxSound().loadEmbedded(Paths.voices(daSong));
// FlxG.sound.list.add(vocals);
staticSpecGrp = new FlxTypedGroup < SpectogramSprite > ( ) ;
add ( staticSpecGrp ) ;
var aBoy: ABotVis = new ABotVis ( FlxG . sound . music ) ;
// add(aBoy);
for ( index => voc in vocals . members )
{
var vocalSpec: SpectogramSprite = new SpectogramSprite ( voc , FlxG . random . color ( 0xFFAAAAAA , FlxColor . WHITE , 100 ) , musSpec . daHeight ,
Math . floor ( FlxG . height / 2 ) ) ;
vocalSpec . x = 70 - ( 50 * index ) ;
// vocalSpec.visType = FREQUENCIES;
vocalSpec . daHeight = musSpec . daHeight ;
vocalSpec . y = vocalSpec . daHeight ;
vocalSpec . scrollFactor . set ( ) ;
add ( vocalSpec ) ;
var staticVocal: SpectogramSprite = new SpectogramSprite ( voc , FlxG . random . color ( 0xFFAAAAAA , FlxColor . WHITE , 100 ) , GRID_SIZE * 16 , GRID_SIZE * 8 ) ;
if ( index == 0 ) staticVocal . x -= 150 ;
if ( index == 1 ) staticVocal . x = gridBG . width ;
staticVocal . visType = STATIC ;
staticSpecGrp . add ( staticVocal ) ;
}
FlxG . sound . music . pause ( ) ;
vocals . pause ( ) ;
FlxG . sound . music . onComplete = function ( )
{
vocals . pause ( ) ;
vocals . time = 0 ;
FlxG . sound . music . pause ( ) ;
FlxG . sound . music . time = 0 ;
changeSection ( ) ;
} ;
}
function generateUI ( ) : Void
{
while ( bullshitUI . members . length > 0 )
{
bullshitUI . remove ( bullshitUI . members [ 0 ] , true ) ;
}
// general shit
var title: FlxText = new FlxText ( UI_box . x + 20 , UI_box . y + 20 , 0 ) ;
bullshitUI . add ( title ) ;
/ *
var loopCheck = new FlxUICheckBox ( UI_box . x + 10 , UI_box . y + 50 , null , null , " L o o p s " , 100 , [ ' l o o p c h e c k ' ] ) ;
loopCheck . checked = notes [ 0 ] elected . doesLoop ;
tooltips . add ( loopCheck , { title : ' S e c t i o n l o o p i n g ' , body : " W h e t h e r o r n o t i t ' s a s i m o n s a y s s t y l e s e c t i o n " , style : tooltipType } ) ;
bullshitUI . add ( loopCheck ) ;
* /
}
override function getEvent ( id : String , sender : Dynamic , data : Dynamic , ? params : Array < Dynamic > )
{
if ( id == FlxUICheckBox . CLICK_EVENT )
{
var check: FlxUICheckBox = cast sender ;
var label = check . getLabel ( ) . text ;
switch ( label )
{
c ase ' M u s t h i t s e c t i o n ' :
SongLoad . getSong ( ) [ curSection ] . mustHitSection = check . checked ;
updateHeads ( ) ;
c ase ' C h a n g e B P M ' :
SongLoad . getSong ( ) [ curSection ] . changeBPM = check . checked ;
FlxG . log . add ( ' c h a n g e d b p m s h i t ' ) ;
c ase " A l t A n i m a t i o n " :
SongLoad . getSong ( ) [ curSection ] . altAnim = check . checked ;
}
}
e lse if ( id == FlxUINumericStepper . CHANGE_EVENT && ( sender i s F l x U I N u m e r i c S t e p p e r ) )
{
var nums: FlxUINumericStepper = cast sender ;
var wname = nums . name ;
FlxG . log . add ( wname ) ;
if ( wname == ' s e c t i o n _ l e n g t h ' )
{
SongLoad . getSong ( ) [ curSection ] . lengthInSteps = Std . int ( nums . value ) ;
updateGrid ( ) ;
}
e lse if ( wname == ' s o n g _ s p e e d ' )
{
// _song.speed[SongLoad.curDiff] = nums.value;
_song . speed . normal = nums . value ;
}
e lse if ( wname == ' s o n g _ b p m ' )
{
tempBpm = nums . value ;
Conductor . mapBPMChanges ( _song ) ;
Conductor . forceBPM ( nums . value ) ;
}
e lse if ( wname == ' n o t e _ s u s L e n g t h ' )
{
curSelectedNote . sustainLength = nums . value ;
updateGrid ( ) ;
}
e lse if ( wname == ' s e c t i o n _ b p m ' )
{
SongLoad . getSong ( ) [ curSection ] . bpm = nums . value ;
updateGrid ( ) ;
}
}
// FlxG.log.add(id + " WEED " + sender + " WEED " + data + " WEED " + params);
}
var updatedSection: Bool = false ;
/ * this function got o w n e d L O L
function lengthBpmBullshit ( ) : Float
{
if ( SongLoad . getSong ( ) [ curSection ] . changeBPM )
return SongLoad . getSong ( ) [ curSection ] . lengthInSteps * ( SongLoad . getSong ( ) [ curSection ] . bpm / _song . bpm ) ;
e lse
return SongLoad . getSong ( ) [ curSection ] . lengthInSteps ;
} * /
/ * *
* Gets the start time of section , defaults to the curSection
* @ param section
* @ return position of the song in . . . either seconds or milliseconds ... . woops
* /
function sectionStartTime ( ? funnySection : Int ) : Float
{
if ( funnySection == null ) funnySection = curSection ;
var daBPM: Float = _song . bpm ;
var daPos: Float = 0 ;
for ( i in 0 ... funnySection )
{
if ( SongLoad . getSong ( ) [ i ] . changeBPM )
{
daBPM = SongLoad . getSong ( ) [ i ] . bpm ;
}
daPos += 4 * sectionCalc ( daBPM ) ;
}
return daPos ;
}
function measureStartTime ( ) : Float
{
var daBPM: Float = _song . bpm ;
var daPos: Float = sectionStartTime ( ) ;
daPos = Math . floor ( FlxG . sound . music . time / sectionCalc ( daBPM ) ) * sectionCalc ( daBPM ) ;
return daPos ;
}
function sectionCalc ( bpm : Float )
{
return ( 1000 * 60 / bpm ) ;
}
var p1Muted: Bool = false ;
var p2Muted: Bool = false ;
override function update ( elapsed : Float )
{
// FlxG.camera.followLerp = CoolUtil.camLerpShit(0.05);
FlxG . sound . music . pan = FlxMath . remapToRange ( FlxG . mouse . screenX , 0 , FlxG . width , - 1 , 1 ) * 10 ;
// curStep = recalculateSteps();
Conductor . songPosition = FlxG . sound . music . time ;
_song . song = typingShit . text ;
playheadTest . y = CoolUtil . coolLerp ( playheadTest . y , FlxMath . remapToRange ( Conductor . songPosition , 0 , FlxG . sound . music . length , 0 , FlxG . height ) , 0.5 ) ;
var strumLinePos: Float = getYfromStrum ( ( Conductor . songPosition - sectionStartTime ( ) ) % ( Conductor . stepCrochet * SongLoad . getSong ( ) [ curSection ] . lengthInSteps ) ) ;
if ( FlxG . sound . music != null )
{
if ( FlxG . sound . music . playing ) strumLine . y = strumLinePos ;
e lse
strumLine . y = CoolUtil . coolLerp ( strumLine . y , strumLinePos , 0.5 ) ;
}
/ * if ( FlxG . sound . music . playing )
{
var normalizedShitIDK: Int = Std . int ( FlxMath . remapToRange ( Conductor . songPosition , 0 , FlxG . sound . music . length , 0 , audioBuf . data . length ) ) ;
FlxG . watch . addQuick ( ' W E I R D A U D I O S H I T L O L ' , audioBuf . data [ normalizedShitIDK ] ) ;
// leftIcon.scale.x = FlxMath.remapToRange(audioBuf.data[normalizedShitIDK], 0, 255, 1, 2);
} * /
if ( FlxG . keys . justPressed . X ) toggleAltAnimNote ( ) ;
if ( false ) // (curBeat % 4 == 0 && curStep >= 16 * (curSection + 1))
{
// trace(curStep);
// trace((SongLoad.getSong()[curSection].lengthInSteps) * (curSection + 1));
trace ( ' D U M B S H I T ' ) ;
if ( SongLoad . getSong ( ) [ curSection + 1 ] == null )
{
addSection ( ) ;
}
changeSection ( curSection + 1 , false ) ;
}
FlxG . watch . addQuick ( ' d a B e a t ' , Conductor . currentBeat ) ;
FlxG . watch . addQuick ( ' d a S t e p ' , Conductor . currentStep ) ;
if ( FlxG . mouse . pressedMiddle && FlxG . mouse . overlaps ( gridBG ) )
{
if ( FlxG . sound . music . playing )
{
FlxG . sound . music . pause ( ) ;
vocals . pause ( ) ;
}
FlxG . sound . music . time = CoolUtil . coolLerp ( FlxG . sound . music . time , getStrumTime ( FlxG . mouse . y ) + sectionStartTime ( ) , 0.5 ) ;
vocals . time = FlxG . sound . music . time ;
}
if ( FlxG . mouse . pressed )
{
if ( FlxG . keys . pressed . ALT && FlxG . mouse . overlaps ( gridBG ) ) // same shit as middle click / hold on grid
{
if ( FlxG . sound . music . playing )
{
FlxG . sound . music . pause ( ) ;
vocals . pause ( ) ;
}
FlxG . sound . music . time = getStrumTime ( FlxG . mouse . y ) + sectionStartTime ( ) ;
vocals . time = FlxG . sound . music . time ;
}
e lse
{
if ( FlxG . mouse . screenX <= 30 && FlxMath . inBounds ( FlxG . mouse . screenY , 0 , FlxG . height ) )
{
if ( FlxG . sound . music . playing )
{
FlxG . sound . music . pause ( ) ;
vocals . pause ( ) ;
}
FlxG . sound . music . time = CoolUtil . coolLerp ( FlxG . sound . music . time ,
FlxMath . remapToRange ( FlxG . mouse . screenY , 0 , FlxG . height , 0 , FlxG . sound . music . length ) , 0.5 ) ;
vocals . time = FlxG . sound . music . time ;
}
if ( FlxG . mouse . justPressed )
{
if ( FlxG . mouse . overlaps ( leftIcon ) )
{
if ( leftIcon . characterId == _song . player1 )
{
p1Muted = ! p1Muted ;
leftIcon . animation . curAnim . curFrame = p1Muted ? 1 : 0 ;
}
e lse
{
p2Muted = ! p2Muted ;
leftIcon . animation . curAnim . curFrame = p2Muted ? 1 : 0 ;
}
vocals . members [ 0 ] . volume = p1Muted ? 0 : 1 ;
// null check jus in case using old shit?
if ( vocals . members [ 1 ] != null ) vocals . members [ 1 ] . volume = p2Muted ? 0 : 1 ;
}
// sloppy copypaste lol deal with it!
if ( FlxG . mouse . overlaps ( rightIcon ) )
{
if ( rightIcon . characterId == _song . player1 )
{
p1Muted = ! p1Muted ;
rightIcon . animation . curAnim . curFrame = p1Muted ? 1 : 0 ;
}
e lse
{
rightIcon . animation . curAnim . curFrame = p2Muted ? 1 : 0 ;
p2Muted = ! p2Muted ;
}
vocals . members [ 0 ] . volume = p1Muted ? 0 : 1 ;
// null check jus in case using old shit?
if ( vocals . members [ 1 ] != null ) vocals . members [ 1 ] . volume = p2Muted ? 0 : 1 ;
}
if ( FlxG . mouse . overlaps ( curRenderedNotes ) )
{
curRenderedNotes . forEach ( function ( note : Note )
{
if ( FlxG . mouse . overlaps ( note ) )
{
selectNote ( note ) ;
}
} ) ;
}
e lse
{
if ( FlxG . mouse . overlaps ( gridBG ) )
{
FlxG . log . add ( ' a d d e d n o t e ' ) ;
addNote ( ) ;
}
}
}
}
}
if ( FlxG . mouse . pressedRight )
{
if ( FlxG . mouse . overlaps ( curRenderedNotes ) )
{
curRenderedNotes . forEach ( function ( note : Note )
{
if ( FlxG . mouse . overlaps ( note ) )
{
trace ( ' t r y i n t o d e l e t e n o t e . . . ' ) ;
deleteNote ( note ) ;
}
} ) ;
}
}
if ( FlxG . mouse . justReleased ) justPlacedNote = false ;
if ( FlxG . mouse . overlaps ( gridBG ) )
{
if ( justPlacedNote && FlxG . mouse . pressed && FlxG . mouse . y > getYfromStrum ( curSelectedNote . strumTime ) )
{
var minusStuff: Float = FlxG . mouse . y - getYfromStrum ( curSelectedNote . strumTime ) ;
minusStuff -= GRID_SIZE ;
minusStuff += GRID_SIZE / 2 ;
minusStuff = Math . floor ( minusStuff / GRID_SIZE ) * GRID_SIZE ;
minusStuff = FlxMath . remapToRange ( minusStuff , 0 , 40 , 0 , Conductor . stepCrochet ) ;
curSelectedNote . sustainLength = minusStuff ;
updateNoteUI ( ) ;
updateGrid ( ) ;
}
dummyArrow . x = Math . floor ( FlxG . mouse . x / GRID_SIZE ) * GRID_SIZE ;
if ( FlxG . keys . pressed . SHIFT ) dummyArrow . y = FlxG . mouse . y ;
e lse
dummyArrow . y = Math . floor ( FlxG . mouse . y / GRID_SIZE ) * GRID_SIZE ;
}
if ( FlxG . keys . justPressed . ENTER )
{
autosaveSong ( ) ;
lastSection = curSection ;
PlayState . currentSong = _song ;
// JUST FOR DEBUG DARNELL STUFF, GENERALIZE THIS FOR BETTER LOADING ELSEWHERE TOO!
PlayState . storyWeek = 8 ;
FlxG . sound . music . stop ( ) ;
vocals . stop ( ) ;
LoadingState . loadAndSwitchState ( new PlayState ( ) ) ;
// FlxG.switchState(new PlayState());
}
if ( FlxG . keys . justPressed . E )
{
changeNoteSustain ( Conductor . stepCrochet ) ;
}
if ( FlxG . keys . justPressed . Q )
{
changeNoteSustain ( - Conductor . stepCrochet ) ;
}
if ( FlxG . keys . justPressed . TAB )
{
if ( FlxG . keys . pressed . SHIFT )
{
UI_box . selected_tab -= 1 ;
if ( UI_box . selected_tab < 0 ) UI_box . selected_tab = 2 ;
}
e lse
{
UI_box . selected_tab += 1 ;
if ( UI_box . selected_tab >= 3 ) UI_box . selected_tab = 0 ;
}
}
if ( ! typingShit . hasFocus )
{
if ( FlxG . keys . justPressed . SPACE )
{
if ( FlxG . sound . music . playing )
{
FlxG . sound . music . pause ( ) ;
vocals . pause ( ) ;
}
e lse
{
vocals . play ( ) ;
FlxG . sound . music . play ( ) ;
}
}
if ( FlxG . keys . justPressed . R )
{
if ( FlxG . keys . pressed . CONTROL ) resetSection ( BEGINNING ) ;
e lse if ( FlxG . keys . pressed . SHIFT ) resetSection ( MEASURE ) ;
e lse
resetSection ( SECTION ) ;
}
if ( FlxG . mouse . wheel != 0 )
{
FlxG . sound . music . pause ( ) ;
vocals . pause ( ) ;
var ctrlMod: Float = FlxG . keys . pressed . CONTROL ? 0.1 : 1 ;
var shiftMod: Float = FlxG . keys . pressed . SHIFT ? 2 : 1 ;
FlxG . sound . music . time -= ( FlxG . mouse . wheel * Conductor . stepCrochet * 0.4 * ctrlMod * shiftMod ) ;
vocals . time = FlxG . sound . music . time ;
}
if ( FlxG . keys . justReleased . S )
{
FlxG . sound . music . pause ( ) ;
vocals . pause ( ) ;
#if HAS_PITCH
FlxG . sound . music . pitch = 1 ;
vocals . pitch = 1 ;
#end
}
if ( ! FlxG . keys . pressed . SHIFT )
{
if ( FlxG . keys . pressed . W || FlxG . keys . pressed . S )
{
var daTime: Float = 700 * elapsed ;
if ( FlxG . keys . pressed . CONTROL ) daTime *= 0.2 ;
if ( FlxG . keys . pressed . W )
{
FlxG . sound . music . pause ( ) ;
vocals . pause ( ) ;
FlxG . sound . music . time -= daTime ;
vocals . time = FlxG . sound . music . time ;
}
e lse
{
if ( FlxG . keys . justPressed . S )
{
FlxG . sound . music . play ( ) ;
vocals . play ( ) ;
#if HAS_PITCH
FlxG . sound . music . pitch = 0.5 ;
vocals . pitch = 0.5 ;
#end
}
}
// FlxG.sound.music.time += daTime;
// vocals.time = FlxG.sound.music.time;
}
}
e lse
{
if ( FlxG . keys . justPressed . W || FlxG . keys . justPressed . S )
{
var daTime: Float = Conductor . stepCrochet * 2 ;
if ( FlxG . keys . justPressed . W )
{
FlxG . sound . music . pause ( ) ;
vocals . pause ( ) ;
FlxG . sound . music . time -= daTime ;
vocals . time = FlxG . sound . music . time ;
}
e lse
{
if ( FlxG . keys . justPressed . S )
{
// FlxG.sound.music.time += daTime;
FlxG . sound . music . pause ( ) ;
vocals . pause ( ) ;
FlxG . sound . music . time += daTime ;
vocals . time = FlxG . sound . music . time ;
// FlxG.sound.music.play();
// vocals.play();
#if HAS_PITCH
FlxG . sound . music . pitch = 0.2 ;
vocals . pitch = 0.2 ;
#end
}
}
}
}
}
_song . bpm = tempBpm ;
/ * if ( FlxG . keys . justPressed . UP )
Conductor . bpm = Conductor . bpm + 1 ;
if ( FlxG . keys . justPressed . DOWN )
Conductor . bpm = Conductor . bpm - 1 ; * /
var shiftThing: Int = 1 ;
if ( FlxG . keys . pressed . SHIFT ) shiftThing = 4 ;
if ( FlxG . keys . justPressed . RIGHT || FlxG . keys . justPressed . D ) changeSection ( curSection + shiftThing ) ;
if ( FlxG . keys . justPressed . LEFT || FlxG . keys . justPressed . A ) changeSection ( curSection - shiftThing ) ;
bpmTxt . text = bpmTxt . text = Std . string ( FlxMath . roundDecimal ( Conductor . songPosition / 1000 , 3 ) )
+ " / "
+ Std . string ( FlxMath . roundDecimal ( FlxG . sound . music . length / 1000 , 3 ) )
+ " \n S e c t i o n : "
+ curSection ;
super . update ( elapsed ) ;
}
function changeNoteSustain ( value : Float ) : Void
{
if ( curSelectedNote != null )
{
curSelectedNote . sustainLength += value ;
curSelectedNote . sustainLength = Math . max ( curSelectedNote . sustainLength , 0 ) ;
}
updateNoteUI ( ) ;
updateGrid ( ) ;
}
function toggleAltAnimNote ( ) : Void
{
if ( curSelectedNote != null )
{
trace ( ' A L T N O T E S H I T ' ) ;
curSelectedNote . noteKind = ( curSelectedNote . noteKind == " a l t " ) ? " " : " a l t " ;
trace ( curSelectedNote . noteKind ) ;
}
}
function recalculateSteps ( ) : Float
{
var lastChange: BPMChangeEvent =
{
stepTime : 0 ,
songTime : 0 ,
bpm : 0
}
for ( i in 0 ... Conductor . bpmChangeMap . length )
{
if ( FlxG . sound . music . time > Conductor . bpmChangeMap [ i ] . songTime ) lastChange = Conductor . bpmChangeMap [ i ] ;
}
// curStep = lastChange.stepTime + Math.floor((FlxG.sound.music.time - lastChange.songTime) / Conductor.stepCrochet);
// updateBeat();
return Conductor . currentStep ;
}
function resetSection ( songBeginning : SongResetType = SECTION ) : Void
{
updateGrid ( ) ;
FlxG . sound . music . pause ( ) ;
vocals . pause ( ) ;
switch ( songBeginning )
{
c ase SECTION :
// Basically old shit from changeSection???
FlxG . sound . music . time = sectionStartTime ( ) ;
c ase BEGINNING :
FlxG . sound . music . time = 0 ;
curSection = 0 ;
c ase MEASURE :
FlxG . sound . music . time = measureStartTime ( ) ; // Math.floor(FlxG.mouse.y / GRID_SIZE) * GRID_SIZE
d efault :
}
vocals . time = FlxG . sound . music . time ;
// updateCurStep();
updateGrid ( ) ;
updateSectionUI ( ) ;
}
function changeSection ( sec : Int = 0 , ? updateMusic : Bool = true ) : Void
{
// trace('changing section' + sec);
if ( SongLoad . getSong ( ) [ sec ] != null )
{
curSection = sec ;
updateGrid ( ) ;
if ( updateMusic )
{
FlxG . sound . music . pause ( ) ;
vocals . pause ( ) ;
/ * var daNum: Int = 0 ;
var daLength: Float = 0 ;
while ( daNum <= sec )
{
daLength += lengthBpmBullshit ( ) ;
daNum ++ ;
} * /
FlxG . sound . music . time = sectionStartTime ( ) ;
vocals . time = FlxG . sound . music . time ;
// updateCurStep();
}
updateGrid ( ) ;
updateSectionUI ( ) ;
}
}
function copySection ( ? sectionNum : Int = 1 )
{
var daSec = FlxMath . maxInt ( curSection , sectionNum ) ;
for ( noteShit in SongLoad . getSong ( ) [ daSec - sectionNum ] . sectionNotes )
{
var strum = noteShit . strumTime + Conductor . stepCrochet * ( SongLoad . getSong ( ) [ daSec ] . lengthInSteps * sectionNum ) ;
var copiedNote: Note = new Note ( strum , noteShit . noteData ) ;
copiedNote . data . sustainLength = noteShit . sustainLength ;
SongLoad . getSong ( ) [ daSec ] . sectionNotes . push ( copiedNote . data ) ;
}
updateGrid ( ) ;
}
function updateSectionUI ( ) : Void
{
var sec = SongLoad . getSong ( ) [ curSection ] ;
stepperLength . value = sec . lengthInSteps ;
check_mustHitSection . checked = sec . mustHitSection ;
check_altAnim . checked = sec . altAnim ;
check_changeBPM . checked = sec . changeBPM ;
stepperSectionBPM . value = sec . bpm ;
updateHeads ( ) ;
}
function updateHeads ( ) : Void
{
if ( check_mustHitSection . checked )
{
leftIcon . characterId = ( _song . player1 ) ;
rightIcon . characterId = ( _song . player2 ) ;
// leftIcon.animation.curAnim.curFrame = p1Muted ? 1 : 0;
// rightIcon.animation.curAnim.curFrame = p2Muted ? 1 : 0;
leftIcon . playAnimation ( p1Muted ? LOSING : IDLE ) ;
rightIcon . playAnimation ( p2Muted ? LOSING : IDLE ) ;
}
e lse
{
leftIcon . characterId = ( _song . player2 ) ;
rightIcon . characterId = ( _song . player1 ) ;
leftIcon . playAnimation ( p2Muted ? LOSING : IDLE ) ;
rightIcon . playAnimation ( p1Muted ? LOSING : IDLE ) ;
// leftIcon.animation.curAnim.curFrame = p2Muted ? 1 : 0;
// rightIcon.animation.curAnim.curFrame = p1Muted ? 1 : 0;
}
leftIcon . setGraphicSize ( 0 , 45 ) ;
rightIcon . setGraphicSize ( 0 , 45 ) ;
leftIcon . height *= 0.6 ;
rightIcon . height *= 0.6 ;
}
function updateNoteUI ( ) : Void
{
if ( curSelectedNote != null ) stepperSusLength . value = curSelectedNote . sustainLength ;
}
function updateGrid ( ) : Void
{
// null if checks jus cuz i put updateGrid() in some weird places!
if ( staticSpecGrp != null )
{
staticSpecGrp . forEach ( function ( spec )
{
if ( spec != null ) spec . generateSection ( sectionStartTime ( ) , ( Conductor . stepCrochet * 32 ) / 1000 ) ;
} ) ;
}
while ( curRenderedNotes . members . length > 0 )
{
curRenderedNotes . remove ( curRenderedNotes . members [ 0 ] , true ) ;
}
while ( curRenderedSustains . members . length > 0 )
{
curRenderedSustains . remove ( curRenderedSustains . members [ 0 ] , true ) ;
}
// generates the cool sidebar shit
if ( sidePreview != null && sidePreview . active )
{
sidePreview . drawRect ( 0 , 0 , 40 , FlxG . height , 0xFF444444 ) ;
/ *
var sectionsNeeded: Int = Std . int ( FlxG . sound . music . length / ( sectionCalc ( _song . bpm ) * 4 ) ) ;
while ( sectionsNeeded > 0 )
{
sidePreview . drawRect ( 0 , sectionsNeeded * ( FlxG . height / sectionsNeeded ) , 40 , FlxG . height / sectionsNeeded ,
( sectionsNeeded % 2 == 0 ? 0xFF000000 : 0xFFFFFFFF ) ) ;
sectionsNeeded -- ;
}
* /
for ( secIndex => sideSection in SongLoad . getSong ( ) )
{
for ( notes in sideSection . sectionNotes )
{
var col: Int = Note . codeColors [ notes . noteData % 4 ] ;
var noteFlip: Int = ( sideSection . mustHitSection ? 1 : - 1 ) ;
var noteX: Float = 5 * ( ( ( notes . noteData - 4 ) * noteFlip ) + 4 ) ;
sidePreview . drawRect ( noteX , FlxMath . remapToRange ( notes . strumTime , 0 , FlxG . sound . music . length , 0 , FlxG . height ) , 5 , 1 , col ) ;
}
}
}
var sectionInfo: Array < NoteData > = SongLoad . getSong ( ) [ curSection ] . sectionNotes ;
if ( SongLoad . getSong ( ) [ curSection ] . changeBPM && SongLoad . getSong ( ) [ curSection ] . bpm > 0 )
{
Conductor . forceBPM ( SongLoad . getSong ( ) [ curSection ] . bpm ) ;
FlxG . log . add ( ' C H A N G E D B P M ! ' ) ;
}
e lse
{
// get last bpm
var daBPM: Float = _song . bpm ;
for ( i in 0 ... curSection )
if ( SongLoad . getSong ( ) [ i ] . changeBPM ) daBPM = SongLoad . getSong ( ) [ i ] . bpm ;
Conductor . forceBPM ( daBPM ) ;
}
/ * // PORT BULLSHIT, INCASE THERE'S NO SUSTAIN DATA FOR A NOTE
for ( sec in 0 ... SongLoad . getSong ( ) . length )
{
for ( notesse in 0 ... SongLoad . getSong ( ) [ sec ] . sectionNotes . length )
{
if ( SongLoad . getSong ( ) [ sec ] . sectionNotes [ notesse ] [ 2 ] == null )
{
trace ( ' S U S N U L L ' ) ;
SongLoad . getSong ( ) [ sec ] . sectionNotes [ notesse ] [ 2 ] = 0 ;
}
}
}
* /
for ( i in sectionInfo )
{
var daNoteInfo = i . noteData ;
var daStrumTime = i . strumTime ;
var daSus = i . sustainLength ;
var note: Note = new Note ( daStrumTime , daNoteInfo % 4 ) ;
note . data . sustainLength = daSus ;
note . setGraphicSize ( GRID_SIZE , GRID_SIZE ) ;
note . updateHitbox ( ) ;
note . x = Math . floor ( daNoteInfo * GRID_SIZE ) ;
note . y = Math . floor ( getYfromStrum ( ( daStrumTime - sectionStartTime ( ) ) % ( Conductor . stepCrochet * SongLoad . getSong ( ) [ curSection ] . lengthInSteps ) ) ) ;
curRenderedNotes . add ( note ) ;
if ( daSus > 0 )
{
var sustainVis: FlxSprite = new FlxSprite ( note . x + ( GRID_SIZE / 2 ) ,
note . y + GRID_SIZE ) . makeGraphic ( 8 , Math . floor ( FlxMath . remapToRange ( daSus , 0 , Conductor . stepCrochet * 16 , 0 , gridBG . height ) ) ) ;
sustainVis . x -= sustainVis . width / 2 ;
sustainVis . color = Note . codeColors [ note . data . noteData % 4 ] ;
curRenderedSustains . add ( sustainVis ) ;
}
}
}
function addSection ( lengthInSteps : Int = 16 ) : Void
{
var sec: SwagSection =
{
lengthInSteps : lengthInSteps ,
bpm : _song . bpm ,
changeBPM : false ,
mustHitSection : true ,
sectionNotes : [ ] ,
typeOfSection : 0 ,
altAnim : false
} ;
SongLoad . getSong ( ) . push ( sec ) ;
}
function selectNote ( note : Note ) : Void
{
var swagNum: Int = 0 ;
for ( i in SongLoad . getSong ( ) [ curSection ] . sectionNotes )
{
if ( i . strumTime == note . data . strumTime && i . noteData % 4 == note . data . noteData )
{
curSelectedNote = SongLoad . getSong ( ) [ curSection ] . sectionNotes [ swagNum ] ;
}
swagNum += 1 ;
}
updateGrid ( ) ;
updateNoteUI ( ) ;
}
function deleteNote ( note : Note ) : Void
{
for ( i in SongLoad . getSong ( ) [ curSection ] . sectionNotes )
{
if ( i . strumTime == note . data . strumTime && i . noteData % 4 == note . data . noteData )
{
var placeIDK: Int = Std . int ( ( ( Math . floor ( dummyArrow . y / GRID_SIZE ) * GRID_SIZE ) ) / 40 ) ;
placeIDK = Std . int ( Math . min ( placeIDK , 15 ) ) ;
placeIDK = Std . int ( Math . max ( placeIDK , 1 ) ) ;
trace ( placeIDK ) ;
FlxG . sound . play ( Paths . sound ( ' f u n n y N o i s e / f u n n y N o i s e - 0 ' + placeIDK ) ) ;
FlxG . log . add ( ' F O U N D E V I L N U M B E R ' ) ;
SongLoad . getSong ( ) [ curSection ] . sectionNotes . remove ( i ) ;
}
}
updateGrid ( ) ;
}
function clearSection ( ) : Void
{
SongLoad . getSong ( ) [ curSection ] . sectionNotes = [ ] ;
updateGrid ( ) ;
}
function clearSong ( ) : Void
{
for ( daSection in 0 ... SongLoad . getSong ( ) . length )
{
SongLoad . getSong ( ) [ daSection ] . sectionNotes = [ ] ;
}
updateGrid ( ) ;
}
/ * *
* Is true if c l i c k e d a n d p l a c e d a n o t e , s e t r e s e t t o f a l s e w h e n r e l e a s i n g m o u s e b u t t o n !
* /
var justPlacedNote: Bool = false ;
function addNote ( ) : Void
{
var noteStrum = getStrumTime ( dummyArrow . y ) + sectionStartTime ( ) ;
var noteData = Math . floor ( FlxG . mouse . x / GRID_SIZE ) ;
var noteSus = 0 ;
var noteKind = " " ;
justPlacedNote = true ;
// FlxG.sound.play(Paths.sound('pianoStuff/piano-00' + FlxG.random.int(1, 9)), FlxG.random.float(0.01, 0.3));
function makeAndPlayChord ( soundsToPlay : Array < String > )
{
var bullshit: Int = Std . int ( ( Math . floor ( dummyArrow . y / GRID_SIZE ) * GRID_SIZE ) / 40 ) ;
soundsToPlay . push ( ' 0 0 ' + Std . string ( ( bullshit % 8 ) + 1 ) ) ;
for ( key in soundsToPlay )
{
var snd: FlxSound = FlxG . sound . list . recycle ( FlxSound ) . loadEmbedded ( FlxG . sound . cache ( Paths . sound ( " p i a n o S t u f f / p i a n o - " + key ) ) ) ;
snd . autoDestroy = true ;
FlxG . sound . list . add ( snd ) ;
snd . volume = FlxG . random . float ( 0.05 , 0.7 ) ;
snd . pan = noteData - 2 ; // .... idk why tf panning doesnt work? (as of 2022/01/25) busted ass bullshit. I only went thru this fuss of creating FlxSound just for the panning!
// snd.proximity(FlxG.mouse.x, FlxG.mouse.y, gridBG, gridBG.width / 2);
snd . play ( ) ;
}
}
switch ( noteData )
{
c ase 0 :
makeAndPlayChord ( [ " 0 1 5 " , " 0 1 3 " , " 0 0 9 " ] ) ;
c ase 1 :
makeAndPlayChord ( [ " 0 1 5 " , " 0 1 2 " , " 0 0 9 " ] ) ;
c ase 2 :
makeAndPlayChord ( [ " 0 1 5 " , " 0 1 1 " , " 0 0 9 " ] ) ;
c ase 3 :
makeAndPlayChord ( [ " 0 1 4 " , " 0 1 1 " , " 0 1 0 " ] ) ;
}
// trace('bullshit $bullshit'); // trace(Math.floor(dummyArrow.y / GRID_SIZE) * GRID_SIZE);
var daNewNote: Note = new Note ( noteStrum , noteData ) ;
daNewNote . data . sustainLength = noteSus ;
daNewNote . data . noteKind = noteKind ;
SongLoad . getSong ( ) [ curSection ] . sectionNotes . push ( daNewNote . data ) ;
curSelectedNote = SongLoad . getSong ( ) [ curSection ] . sectionNotes [ SongLoad . getSong ( ) [ curSection ] . sectionNotes . length - 1 ] ;
if ( FlxG . keys . pressed . CONTROL )
{
// SongLoad.getSong()[curSection].sectionNotes.push([noteStrum, (noteData + 4) % 8, noteSus, noteAlt]);
}
trace ( noteStrum ) ;
trace ( curSection ) ;
updateGrid ( ) ;
updateNoteUI ( ) ;
autosaveSong ( ) ;
}
function getStrumTime ( yPos : Float ) : Float
{
return FlxMath . remapToRange ( yPos , gridBG . y , gridBG . y + gridBG . height , 0 , 16 * Conductor . stepCrochet ) ;
}
function getYfromStrum ( strumTime : Float ) : Float
{
return FlxMath . remapToRange ( strumTime , 0 , 16 * Conductor . stepCrochet , gridBG . y , gridBG . y + gridBG . height ) ;
}
/ *
function calculateSectionLengths ( ? sec : SwagSection ) : Int
{
var daLength: Int = 0 ;
for ( i in SongLoad . getSong ( ) )
{
var swagLength = i . lengthInSteps ;
if ( i . typeOfSection == Section . COPYCAT )
swagLength * 2 ;
daLength += swagLength ;
if ( sec != null && sec == i )
{
trace ( ' s w a g l o o p ? ? ' ) ;
break ;
}
}
return daLength ;
} * /
var daSpacing: Float = 0.3 ;
function loadLevel ( ) : Void
{
trace ( SongLoad . getSong ( ) ) ;
}
function getNotes ( ) : Array < Dynamic >
{
var noteData: Array < Dynamic > = [ ] ;
for ( i in SongLoad . getSong ( ) )
{
noteData . push ( i . sectionNotes ) ;
}
return noteData ;
}
function loadJson ( song : String ) : Void
{
PlayState . currentSong = SongLoad . loadFromJson ( song . toLowerCase ( ) , song . toLowerCase ( ) ) ;
LoadingState . loadAndSwitchState ( new ChartingState ( ) ) ;
}
function loadAutosave ( ) : Void
{
PlayState . currentSong = FlxG . save . data . autosave ;
FlxG . resetState ( ) ;
}
function autosaveSong ( ) : Void
{
FlxG . save . data . autosave = _song ;
// trace(FlxG.save.data.autosave);
FlxG . save . flush ( ) ;
}
function saveLevel ( ? debugSavepath : Bool = false )
{
// Right now the note data is saved as a Note.NoteData typedef / object or whatev
// we want to format it to an ARRAY. We turn it back into the typedef / object at the end of this function hehe
for ( key in _song . noteMap . keys ( ) )
SongLoad . castNoteDataToArray ( _song . noteMap [ key ] ) ;
// SongLoad.castNoteDataToArray(_song.notes.easy);
// SongLoad.castNoteDataToArray(_song.notes.normal);
// SongLoad.castNoteDataToArray(_song.notes.hard);
var json = { " s o n g " : _song } ;
var data: String = Json . stringify ( json , null , " \t " ) ;
#if sys
// quick workaround, since it easier to load into hashlink, thus quicker/nicer to test?
// should get this auto-saved into a file or somethin
var filename = _song . song . toLowerCase ( ) ;
if ( debugSavepath )
{
// file path to assumingly your assets folder in your SOURCE CODE assets folder!!!
// update this later so the save button ONLY appears when you compile in debug mode!
sys . io . File . saveContent ( ' . . / . . / . . / . . / a s s e t s / p r e l o a d / d a t a / $ filename / $ filename . j s o n ' , data ) ;
}
e lse
sys . io . File . saveContent ( ' . / $ filename . j s o n ' , data ) ;
#else
if ( ( data != null ) && ( data . length > 0 ) )
{
_file = new FileReference ( ) ;
_file . addEventListener ( Event . COMPLETE , onSaveComplete ) ;
_file . addEventListener ( Event . CANCEL , onSaveCancel ) ;
_file . addEventListener ( IOErrorEvent . IO_ERROR , onSaveError ) ;
_file . save ( data . trim ( ) , _song . song . toLowerCase ( ) + " . j s o n " ) ;
}
#end
for ( key in _song . noteMap . keys ( ) )
SongLoad . castArrayToNoteData ( _song . noteMap [ key ] ) ;
// turn the array data back to Note.NoteData typedef
// SongLoad.castArrayToNoteData(_song.notes.easy);
// SongLoad.castArrayToNoteData(_song.notes.normal);
// SongLoad.castArrayToNoteData(_song.notes.hard);
}
function onSaveComplete ( _ ) : Void
{
_file . removeEventListener ( Event . COMPLETE , onSaveComplete ) ;
_file . removeEventListener ( Event . CANCEL , onSaveCancel ) ;
_file . removeEventListener ( IOErrorEvent . IO_ERROR , onSaveError ) ;
_file = null ;
FlxG . log . notice ( " S u c c e s s f u l l y s a v e d L E V E L D A T A . " ) ;
}
/ * *
* Called when the save file dialog is cancelled .
* /
function onSaveCancel ( _ ) : Void
{
_file . removeEventListener ( Event . COMPLETE , onSaveComplete ) ;
_file . removeEventListener ( Event . CANCEL , onSaveCancel ) ;
_file . removeEventListener ( IOErrorEvent . IO_ERROR , onSaveError ) ;
_file = null ;
}
/ * *
* Called if t h e r e i s a n e r r o r w h i l e s a v i n g t h e g a m e p l a y r e c o r d i n g .
* /
function onSaveError ( _ ) : Void
{
_file . removeEventListener ( Event . COMPLETE , onSaveComplete ) ;
_file . removeEventListener ( Event . CANCEL , onSaveCancel ) ;
_file . removeEventListener ( IOErrorEvent . IO_ERROR , onSaveError ) ;
_file = null ;
FlxG . log . error ( " P r o b l e m s a v i n g L e v e l d a t a " ) ;
}
2020-10-09 22:39:52 -04:00
}
2022-01-20 23:33:51 -05:00
enum SongResetType
{
2023-01-22 22:25:45 -05:00
BEGINNING ;
MEASURE ; // not sure if measure is 1/4 of a "SECTION" which is definitely a... bar.. right? its nerd shit whatever
SECTION ;
2022-01-20 23:33:51 -05:00
}