11package states .editors ;
22
3+ import haxe .io .Path ;
4+ import states .editors .content .FileDialogHandler ;
35import mikolka .stages .cutscenes .dialogueBox .DialogueCharacter .DialogueCharacterFile ;
46import mikolka .stages .cutscenes .dialogueBox .DialogueCharacter .DialogueAnimArray ;
57import openfl .net .FileReference ;
@@ -674,34 +676,23 @@ class DialogueCharacterEditorState extends MusicBeatState implements PsychUIEven
674676 else ClientPrefs .toggleVolumeKeys (false );
675677 }
676678
677- var _file : FileReference = null ;
679+ var _file : FileDialogHandler = null ;
678680 function loadCharacter () {
679681 var jsonFilter : FileFilter = new FileFilter (' JSON' , ' json' );
680- _file = new FileReference ();
681- _file .addEventListener (#if desktop Event .SELECT #else Event .COMPLETE #end, onLoadComplete );
682- _file .addEventListener (Event .CANCEL , onLoadCancel );
683- _file .addEventListener (IOErrorEvent .IO_ERROR , onLoadError );
684- _file .browse ([#if !mac jsonFilter #end]);
682+ _file = new FileDialogHandler ();
683+ _file .open (null ," Open dialog portrait character" ,[jsonFilter ],onLoadComplete ,onLoadCancel ,onLoadError );
685684 }
686685
687- function onLoadComplete (_ ): Void
686+ function onLoadComplete (): Void
688687 {
689- _file .removeEventListener (#if desktop Event .SELECT #else Event .COMPLETE #end, onLoadComplete );
690- _file .removeEventListener (Event .CANCEL , onLoadCancel );
691- _file .removeEventListener (IOErrorEvent .IO_ERROR , onLoadError );
692-
693- #if sys
694- var fullPath : String = null ;
695- @:privateAccess
696- if (_file .__path != null ) fullPath = _file .__path ;
697-
698- if (fullPath != null ) {
699- var rawJson : String = NativeFileSystem .getContent (fullPath );
688+ if (_file .data != null ) {
689+ var rawJson : String = _file .data ;
700690 if (rawJson != null ) {
701691 var loadedChar : DialogueCharacterFile = cast Json .parse (rawJson );
702692 if (loadedChar .dialogue_pos != null ) // Make sure it's really a dialogue character
703693 {
704- var cutName : String = _file .name .substr (0 , _file .name .length - 5 );
694+ var cutName : String = Path .withoutDirectory (_file .path );
695+ cutName = cutName .substr (0 , cutName .length - 5 );
705696 trace (" Successfully loaded file: " + cutName );
706697 character .jsonFile = loadedChar ;
707698 reloadCharacter ();
@@ -719,31 +710,22 @@ class DialogueCharacterEditorState extends MusicBeatState implements PsychUIEven
719710 }
720711 }
721712 _file = null ;
722- #else
723- trace (" File couldn't be loaded! You aren't on Desktop, are you?" );
724- #end
725713 }
726714
727715 /**
728716 * Called when the save file dialog is cancelled.
729717 */
730- function onLoadCancel (_ ): Void
718+ function onLoadCancel (): Void
731719 {
732- _file .removeEventListener (#if desktop Event .SELECT #else Event .COMPLETE #end, onLoadComplete );
733- _file .removeEventListener (Event .CANCEL , onLoadCancel );
734- _file .removeEventListener (IOErrorEvent .IO_ERROR , onLoadError );
735720 _file = null ;
736721 trace (" Cancelled file loading." );
737722 }
738723
739724 /**
740725 * Called if there is an error while saving the gameplay recording.
741726 */
742- function onLoadError (_ ): Void
727+ function onLoadError (): Void
743728 {
744- _file .removeEventListener (#if desktop Event .SELECT #else Event .COMPLETE #end, onLoadComplete );
745- _file .removeEventListener (Event .CANCEL , onLoadCancel );
746- _file .removeEventListener (IOErrorEvent .IO_ERROR , onLoadError );
747729 _file = null ;
748730 trace (" Problem loading file" );
749731 }
@@ -759,43 +741,31 @@ class DialogueCharacterEditorState extends MusicBeatState implements PsychUIEven
759741 unsavedProgress = false ;
760742 StorageUtil .saveContent (' $characterName .json' , data );
761743 #else
762- _file = new FileReference ();
763- _file .addEventListener (#if desktop Event .SELECT #else Event .COMPLETE #end, onSaveComplete );
764- _file .addEventListener (Event .CANCEL , onSaveCancel );
765- _file .addEventListener (IOErrorEvent .IO_ERROR , onSaveError );
766- _file .save (data , characterName + " .json" );
744+ _file = new FileDialogHandler ();
745+ _file .save (characterName + " .json" ,data ,onSaveComplete ,onSaveCancel ,onSaveError );
767746 #end
768747 }
769748 }
770749
771- function onSaveComplete (_ ): Void
750+ function onSaveComplete (): Void
772751 {
773- _file .removeEventListener (#if desktop Event .SELECT #else Event .COMPLETE #end, onSaveComplete );
774- _file .removeEventListener (Event .CANCEL , onSaveCancel );
775- _file .removeEventListener (IOErrorEvent .IO_ERROR , onSaveError );
776752 _file = null ;
777753 FlxG .log .notice (" Successfully saved file." );
778754 }
779755
780756 /**
781757 * Called when the save file dialog is cancelled.
782758 */
783- function onSaveCancel (_ ): Void
759+ function onSaveCancel (): Void
784760 {
785- _file .removeEventListener (#if desktop Event .SELECT #else Event .COMPLETE #end, onSaveComplete );
786- _file .removeEventListener (Event .CANCEL , onSaveCancel );
787- _file .removeEventListener (IOErrorEvent .IO_ERROR , onSaveError );
788761 _file = null ;
789762 }
790763
791764 /**
792765 * Called if there is an error while saving the gameplay recording.
793766 */
794- function onSaveError (_ ): Void
767+ function onSaveError (): Void
795768 {
796- _file .removeEventListener (#if desktop Event .SELECT #else Event .COMPLETE #end, onSaveComplete );
797- _file .removeEventListener (Event .CANCEL , onSaveCancel );
798- _file .removeEventListener (IOErrorEvent .IO_ERROR , onSaveError );
799769 _file = null ;
800770 FlxG .log .error (" Problem saving file" );
801771 }
0 commit comments