bugfix for loading deleted mods + safe saves

This commit is contained in:
⍚~Nex
2024-03-17 18:00:18 +01:00
parent c3691c8f08
commit 3de8fcc804
10 changed files with 56 additions and 49 deletions
+2 -14
View File
@@ -1,8 +1,5 @@
package funkin.editors;
#if desktop
import sys.io.File;
#end
import haxe.io.Path;
import lime.ui.FileDialog;
@@ -30,13 +27,9 @@ class SaveSubstate extends MusicBeatSubstate {
super.create();
var fileDialog = new FileDialog();
fileDialog.onCancel.add(function() {
close();
});
fileDialog.onCancel.add(function() close());
fileDialog.onSelect.add(function(str) {
#if desktop
File.saveContent(str, data);
#end
CoolUtil.safeSaveFile(str, data);
close();
});
fileDialog.browse(SAVE, options.saveExt.getDefault(Path.extension(options.defaultSaveFile)), options.defaultSaveFile);
@@ -46,11 +39,6 @@ class SaveSubstate extends MusicBeatSubstate {
super.update(elapsed);
parent.persistentUpdate = false;
}
private function onError(_) {
// TODO: error handling
close();
}
}
typedef SaveSubstateData = {
@@ -328,14 +328,14 @@ class CharacterEditor extends UIState {
function _file_save(_) {
#if sys
sys.io.File.saveContent(
CoolUtil.safeSaveFile(
'${Paths.getAssetsRoot()}/data/characters/${character.curCharacter}.xml',
buildCharacter()
);
undos.save();
return;
#end
#else
_file_saveas(_);
#end
}
function _file_saveas(_) {
+6 -6
View File
@@ -1165,13 +1165,13 @@ class Charter extends UIState {
function _file_meta_save(_) {
#if sys
sys.io.File.saveContent(
CoolUtil.safeSaveFile(
'${Paths.getAssetsRoot()}/songs/${__song.toLowerCase()}/meta.json',
Json.stringify(PlayState.SONG.meta == null ? {} : PlayState.SONG.meta, null, "\t")
);
return;
#end
#else
_file_meta_saveas(_);
#end
}
function _file_meta_saveas(_) {
@@ -1182,13 +1182,13 @@ class Charter extends UIState {
function _file_events_save(_) {
#if sys
sys.io.File.saveContent(
CoolUtil.safeSaveFile(
'${Paths.getAssetsRoot()}/songs/${__song.toLowerCase()}/events.json',
Json.stringify({events: PlayState.SONG.events == null ? [] : PlayState.SONG.events})
);
return;
#end
#else
_file_events_saveas(_);
#end
}
function _file_events_saveas(_) {
@@ -107,7 +107,7 @@ class CharterSelection extends EditorTreeMenu {
sys.FileSystem.createDirectory('$songFolder/charts');
// Save Files
sys.io.File.saveContent('$songFolder/meta.json', Json.stringify(creation.meta, "\t"));
CoolUtil.safeSaveFile('$songFolder/meta.json', Json.stringify(creation.meta, "\t"));
if (creation.instBytes != null) sys.io.File.saveBytes('$songFolder/song/Inst.${Paths.SOUND_EXT}', creation.instBytes);
if (creation.voicesBytes != null) sys.io.File.saveBytes('$songFolder/song/Voices.${Paths.SOUND_EXT}', creation.voicesBytes);
#end
@@ -145,9 +145,7 @@ class CharterSelection extends EditorTreeMenu {
var songFolder:String = '${Paths.getAssetsRoot()}/songs/${curSong.name}';
// Save Files
#if sys
sys.io.File.saveContent('$songFolder/charts/${name}.json', Json.stringify(data, "\t"));
#end
CoolUtil.safeSaveFile('$songFolder/charts/${name}.json', Json.stringify(data, "\t"));
// Add to List
curSong.difficulties.push(name);
@@ -160,7 +158,7 @@ class CharterSelection extends EditorTreeMenu {
var meta = Json.parse(sys.io.File.getContent('$songFolder/meta.json'));
if (meta.difficulties != null && !meta.difficulties.contains(name)) {
meta.difficulties.push(name);
sys.io.File.saveContent('$songFolder/meta.json', Json.stringify(meta));
CoolUtil.safeSaveFile('$songFolder/meta.json', Json.stringify(meta));
}
}
}