From 427ca3cb03197e6ca4a0d5c726b45ac574a01a5b Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Fri, 9 Oct 2020 20:22:07 -0700 Subject: [PATCH] save data bullshit --- source/ChartingState.hx | 68 +++++++++++++++++++++++++++++++++++++++- source/Main.hx | 2 +- source/MusicBeatState.hx | 19 +++++------ source/PlayState.hx | 16 ++++++++-- 4 files changed, 92 insertions(+), 13 deletions(-) diff --git a/source/ChartingState.hx b/source/ChartingState.hx index 766622f91..d0187e333 100644 --- a/source/ChartingState.hx +++ b/source/ChartingState.hx @@ -1,11 +1,77 @@ package; +import flixel.FlxG; import flixel.FlxState; +import flixel.ui.FlxButton; +import haxe.Json; +import openfl.events.Event; +import openfl.events.IOErrorEvent; +import openfl.events.IOErrorEvent; +import openfl.events.IOErrorEvent; +import openfl.net.FileReference; -class ChartingState extends FlxState +class ChartingState extends MusicBeatState { + var _file:FileReference; + override function create() { + var saveButton:FlxButton = new FlxButton(0, 0, "Save", function() + { + // bullshit + + var json = { + "song": "Bopeebo", + "bpm": 100, + "sections": 15 + }; + + var data:String = Json.stringify(json); + + 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, "swag.json"); + } + }); + saveButton.screenCenter(); + add(saveButton); + super.create(); } + + function onSaveComplete(_):Void + { + _file.removeEventListener(Event.COMPLETE, onSaveComplete); + _file.removeEventListener(Event.CANCEL, onSaveCancel); + _file.removeEventListener(IOErrorEvent.IO_ERROR, onSaveError); + _file = null; + FlxG.log.notice("Successfully saved LEVEL DATA."); + } + + /** + * 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 there is an error while saving the gameplay recording. + */ + function onSaveError(_):Void + { + _file.removeEventListener(Event.COMPLETE, onSaveComplete); + _file.removeEventListener(Event.CANCEL, onSaveCancel); + _file.removeEventListener(IOErrorEvent.IO_ERROR, onSaveError); + _file = null; + FlxG.log.error("Problem saving Level data"); + } } diff --git a/source/Main.hx b/source/Main.hx index 13376db44..d4bd9a4a7 100644 --- a/source/Main.hx +++ b/source/Main.hx @@ -9,7 +9,7 @@ class Main extends Sprite public function new() { super(); - addChild(new FlxGame(0, 0, TitleState)); + addChild(new FlxGame(0, 0, ChartingState)); #if !mobile addChild(new FPS(10, 3, 0xFFFFFF)); diff --git a/source/MusicBeatState.hx b/source/MusicBeatState.hx index f09fad7ea..9b96609eb 100644 --- a/source/MusicBeatState.hx +++ b/source/MusicBeatState.hx @@ -15,18 +15,16 @@ class MusicBeatState extends FlxTransitionableState super.create(); } - private function everyBeat():Void + override function update(elapsed:Float) { - if (Conductor.songPosition > lastBeat + Conductor.crochet - Conductor.safeZoneOffset - || Conductor.songPosition < lastBeat + Conductor.safeZoneOffset) - { - if (Conductor.songPosition > lastBeat + Conductor.crochet) - { - beatHit(); - } - } + everyStep(); + + super.update(elapsed); } + /** + * CHECKS EVERY FRAME + */ private function everyStep():Void { if (Conductor.songPosition > lastStep + Conductor.stepCrochet - Conductor.safeZoneOffset @@ -43,6 +41,9 @@ class MusicBeatState extends FlxTransitionableState { totalSteps += 1; lastStep += Conductor.stepCrochet; + + if (totalSteps % 4 == 0) + beatHit(); } public function beatHit():Void diff --git a/source/PlayState.hx b/source/PlayState.hx index 12ef5c76a..bcab2c832 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -424,6 +424,9 @@ class PlayState extends MusicBeatState openSubState(new PauseSubState()); } + FlxG.watch.addQuick('VOL', vocals.amplitudeLeft); + FlxG.watch.addQuick('VOLRight', vocals.amplitudeRight); + healthHeads.setGraphicSize(Std.int(FlxMath.lerp(100, healthHeads.width, 0.98))); healthHeads.x = healthBar.x + (healthBar.width * (FlxMath.remapToRange(healthBar.percent, 0, 100, 100, 0) * 0.01)) - (healthHeads.width / 2); @@ -512,8 +515,6 @@ class PlayState extends MusicBeatState FlxG.switchState(new PlayState()); } } - everyBeat(); - everyStep(); // better streaming of shit if (health <= 0) @@ -1021,6 +1022,17 @@ class PlayState extends MusicBeatState } } + override function stepHit() + { + if (vocals.time > Conductor.songPosition + Conductor.stepCrochet || vocals.time < Conductor.songPosition - Conductor.stepCrochet) + { + vocals.pause(); + vocals.time = Conductor.songPosition; + vocals.play(); + } + super.stepHit(); + } + override function beatHit() { super.beatHit();