bugfix for loading deleted mods + safe saves
This commit is contained in:
@@ -51,10 +51,11 @@ class ModsFolder {
|
|||||||
*/
|
*/
|
||||||
private static var __firstTime:Bool = true;
|
private static var __firstTime:Bool = true;
|
||||||
/**
|
/**
|
||||||
* Initialises `mods` folder by adding callbacks and such.
|
* Initialises `mods` folder.
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init() {
|
||||||
|
if(!getModsList().contains(Options.lastLoadedMod))
|
||||||
|
Options.lastLoadedMod = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -89,6 +90,24 @@ class ModsFolder {
|
|||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getModsList():Array<String> {
|
||||||
|
var mods:Array<String> = [];
|
||||||
|
#if MOD_SUPPORT
|
||||||
|
for(modFolder in FileSystem.readDirectory(modsPath)) {
|
||||||
|
if (FileSystem.isDirectory('${modsPath}${modFolder}')) {
|
||||||
|
mods.push(modFolder);
|
||||||
|
} else {
|
||||||
|
var ext = Path.extension(modFolder).toLowerCase();
|
||||||
|
switch(ext) {
|
||||||
|
case 'zip':
|
||||||
|
// is a zip mod!!
|
||||||
|
mods.push(Path.withoutExtension(modFolder));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
return mods;
|
||||||
|
}
|
||||||
public static function getLoadedMods():Array<String> {
|
public static function getLoadedMods():Array<String> {
|
||||||
var libs = [];
|
var libs = [];
|
||||||
for (i in Paths.assetsTree.libraries) {
|
for (i in Paths.assetsTree.libraries) {
|
||||||
|
|||||||
@@ -206,11 +206,11 @@ class Chart {
|
|||||||
var chartPath = '${songFolderPath}/charts/${difficulty.trim()}.json';
|
var chartPath = '${songFolderPath}/charts/${difficulty.trim()}.json';
|
||||||
var metaPath = '${songFolderPath}/meta.json';
|
var metaPath = '${songFolderPath}/meta.json';
|
||||||
|
|
||||||
File.saveContent(chartPath, Json.stringify(filteredChart, null, saveSettings.prettyPrint == true ? "\t" : null));
|
CoolUtil.safeSaveFile(chartPath, Json.stringify(filteredChart, null, saveSettings.prettyPrint == true ? "\t" : null));
|
||||||
|
|
||||||
// idk how null reacts to it so better be sure
|
// idk how null reacts to it so better be sure
|
||||||
if (saveSettings.overrideExistingMeta == true || !FileSystem.exists(metaPath))
|
if (saveSettings.overrideExistingMeta == true || !FileSystem.exists(metaPath))
|
||||||
File.saveContent(metaPath, Json.stringify(meta, null, saveSettings.prettyPrint == true ? "\t" : null));
|
CoolUtil.safeSaveFile(metaPath, Json.stringify(meta, null, saveSettings.prettyPrint == true ? "\t" : null));
|
||||||
#end
|
#end
|
||||||
return filteredChart;
|
return filteredChart;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,7 +120,6 @@ class Main extends Sprite
|
|||||||
ShaderResizeFix.init();
|
ShaderResizeFix.init();
|
||||||
Logs.init();
|
Logs.init();
|
||||||
Paths.init();
|
Paths.init();
|
||||||
ModsFolder.init();
|
|
||||||
DiscordUtil.init();
|
DiscordUtil.init();
|
||||||
#if GLOBAL_SCRIPT
|
#if GLOBAL_SCRIPT
|
||||||
funkin.backend.scripting.GlobalScript.init();
|
funkin.backend.scripting.GlobalScript.init();
|
||||||
@@ -159,6 +158,7 @@ class Main extends Sprite
|
|||||||
|
|
||||||
FlxG.mouse.useSystemCursor = true;
|
FlxG.mouse.useSystemCursor = true;
|
||||||
|
|
||||||
|
ModsFolder.init();
|
||||||
#if MOD_SUPPORT
|
#if MOD_SUPPORT
|
||||||
ModsFolder.switchMod(modToLoad.getDefault(Options.lastLoadedMod));
|
ModsFolder.switchMod(modToLoad.getDefault(Options.lastLoadedMod));
|
||||||
#end
|
#end
|
||||||
|
|||||||
@@ -77,6 +77,22 @@ class CoolUtil
|
|||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Safe saves a file and shows a warning box instead of making the program crash
|
||||||
|
* @param path Path to save the file at.
|
||||||
|
* @param data Content of the file to save.
|
||||||
|
*/
|
||||||
|
@:noUsing public static function safeSaveFile(path:String, content:String, showErrorBox:Bool = true) {
|
||||||
|
#if sys
|
||||||
|
try sys.io.File.saveContent(path, content)
|
||||||
|
catch(e) {
|
||||||
|
var errMsg:String = 'Error while trying to save the file: ${Std.string(e).replace('\n', ' ')}';
|
||||||
|
Logs.traceColored([Logs.logText(errMsg, RED)], ERROR);
|
||||||
|
if(showErrorBox) funkin.backend.utils.NativeAPI.showMessageBox("Codename Engine Warning", errMsg, MSG_WARNING);
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shortcut to parse a JSON string
|
* Shortcut to parse a JSON string
|
||||||
* @param str Path to the JSON string
|
* @param str Path to the JSON string
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
package funkin.editors;
|
package funkin.editors;
|
||||||
|
|
||||||
#if desktop
|
|
||||||
import sys.io.File;
|
|
||||||
#end
|
|
||||||
import haxe.io.Path;
|
import haxe.io.Path;
|
||||||
import lime.ui.FileDialog;
|
import lime.ui.FileDialog;
|
||||||
|
|
||||||
@@ -30,13 +27,9 @@ class SaveSubstate extends MusicBeatSubstate {
|
|||||||
super.create();
|
super.create();
|
||||||
|
|
||||||
var fileDialog = new FileDialog();
|
var fileDialog = new FileDialog();
|
||||||
fileDialog.onCancel.add(function() {
|
fileDialog.onCancel.add(function() close());
|
||||||
close();
|
|
||||||
});
|
|
||||||
fileDialog.onSelect.add(function(str) {
|
fileDialog.onSelect.add(function(str) {
|
||||||
#if desktop
|
CoolUtil.safeSaveFile(str, data);
|
||||||
File.saveContent(str, data);
|
|
||||||
#end
|
|
||||||
close();
|
close();
|
||||||
});
|
});
|
||||||
fileDialog.browse(SAVE, options.saveExt.getDefault(Path.extension(options.defaultSaveFile)), options.defaultSaveFile);
|
fileDialog.browse(SAVE, options.saveExt.getDefault(Path.extension(options.defaultSaveFile)), options.defaultSaveFile);
|
||||||
@@ -46,11 +39,6 @@ class SaveSubstate extends MusicBeatSubstate {
|
|||||||
super.update(elapsed);
|
super.update(elapsed);
|
||||||
parent.persistentUpdate = false;
|
parent.persistentUpdate = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onError(_) {
|
|
||||||
// TODO: error handling
|
|
||||||
close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef SaveSubstateData = {
|
typedef SaveSubstateData = {
|
||||||
|
|||||||
@@ -328,14 +328,14 @@ class CharacterEditor extends UIState {
|
|||||||
|
|
||||||
function _file_save(_) {
|
function _file_save(_) {
|
||||||
#if sys
|
#if sys
|
||||||
sys.io.File.saveContent(
|
CoolUtil.safeSaveFile(
|
||||||
'${Paths.getAssetsRoot()}/data/characters/${character.curCharacter}.xml',
|
'${Paths.getAssetsRoot()}/data/characters/${character.curCharacter}.xml',
|
||||||
buildCharacter()
|
buildCharacter()
|
||||||
);
|
);
|
||||||
undos.save();
|
undos.save();
|
||||||
return;
|
#else
|
||||||
#end
|
|
||||||
_file_saveas(_);
|
_file_saveas(_);
|
||||||
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
function _file_saveas(_) {
|
function _file_saveas(_) {
|
||||||
|
|||||||
@@ -1165,13 +1165,13 @@ class Charter extends UIState {
|
|||||||
|
|
||||||
function _file_meta_save(_) {
|
function _file_meta_save(_) {
|
||||||
#if sys
|
#if sys
|
||||||
sys.io.File.saveContent(
|
CoolUtil.safeSaveFile(
|
||||||
'${Paths.getAssetsRoot()}/songs/${__song.toLowerCase()}/meta.json',
|
'${Paths.getAssetsRoot()}/songs/${__song.toLowerCase()}/meta.json',
|
||||||
Json.stringify(PlayState.SONG.meta == null ? {} : PlayState.SONG.meta, null, "\t")
|
Json.stringify(PlayState.SONG.meta == null ? {} : PlayState.SONG.meta, null, "\t")
|
||||||
);
|
);
|
||||||
return;
|
#else
|
||||||
#end
|
|
||||||
_file_meta_saveas(_);
|
_file_meta_saveas(_);
|
||||||
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
function _file_meta_saveas(_) {
|
function _file_meta_saveas(_) {
|
||||||
@@ -1182,13 +1182,13 @@ class Charter extends UIState {
|
|||||||
|
|
||||||
function _file_events_save(_) {
|
function _file_events_save(_) {
|
||||||
#if sys
|
#if sys
|
||||||
sys.io.File.saveContent(
|
CoolUtil.safeSaveFile(
|
||||||
'${Paths.getAssetsRoot()}/songs/${__song.toLowerCase()}/events.json',
|
'${Paths.getAssetsRoot()}/songs/${__song.toLowerCase()}/events.json',
|
||||||
Json.stringify({events: PlayState.SONG.events == null ? [] : PlayState.SONG.events})
|
Json.stringify({events: PlayState.SONG.events == null ? [] : PlayState.SONG.events})
|
||||||
);
|
);
|
||||||
return;
|
#else
|
||||||
#end
|
|
||||||
_file_events_saveas(_);
|
_file_events_saveas(_);
|
||||||
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
function _file_events_saveas(_) {
|
function _file_events_saveas(_) {
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ class CharterSelection extends EditorTreeMenu {
|
|||||||
sys.FileSystem.createDirectory('$songFolder/charts');
|
sys.FileSystem.createDirectory('$songFolder/charts');
|
||||||
|
|
||||||
// Save Files
|
// 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.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);
|
if (creation.voicesBytes != null) sys.io.File.saveBytes('$songFolder/song/Voices.${Paths.SOUND_EXT}', creation.voicesBytes);
|
||||||
#end
|
#end
|
||||||
@@ -145,9 +145,7 @@ class CharterSelection extends EditorTreeMenu {
|
|||||||
var songFolder:String = '${Paths.getAssetsRoot()}/songs/${curSong.name}';
|
var songFolder:String = '${Paths.getAssetsRoot()}/songs/${curSong.name}';
|
||||||
|
|
||||||
// Save Files
|
// Save Files
|
||||||
#if sys
|
CoolUtil.safeSaveFile('$songFolder/charts/${name}.json', Json.stringify(data, "\t"));
|
||||||
sys.io.File.saveContent('$songFolder/charts/${name}.json', Json.stringify(data, "\t"));
|
|
||||||
#end
|
|
||||||
|
|
||||||
// Add to List
|
// Add to List
|
||||||
curSong.difficulties.push(name);
|
curSong.difficulties.push(name);
|
||||||
@@ -160,7 +158,7 @@ class CharterSelection extends EditorTreeMenu {
|
|||||||
var meta = Json.parse(sys.io.File.getContent('$songFolder/meta.json'));
|
var meta = Json.parse(sys.io.File.getContent('$songFolder/meta.json'));
|
||||||
if (meta.difficulties != null && !meta.difficulties.contains(name)) {
|
if (meta.difficulties != null && !meta.difficulties.contains(name)) {
|
||||||
meta.difficulties.push(name);
|
meta.difficulties.push(name);
|
||||||
sys.io.File.saveContent('$songFolder/meta.json', Json.stringify(meta));
|
CoolUtil.safeSaveFile('$songFolder/meta.json', Json.stringify(meta));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,9 +101,7 @@ class MainMenuState extends MusicBeatState
|
|||||||
if (FlxG.keys.justPressed.SEVEN)
|
if (FlxG.keys.justPressed.SEVEN)
|
||||||
FlxG.switchState(new funkin.desktop.DesktopMain());
|
FlxG.switchState(new funkin.desktop.DesktopMain());
|
||||||
if (FlxG.keys.justPressed.EIGHT) {
|
if (FlxG.keys.justPressed.EIGHT) {
|
||||||
#if sys
|
CoolUtil.safeSaveFile("chart.json", Json.stringify(funkin.backend.chart.Chart.parse("dadbattle", "hard")));
|
||||||
sys.io.File.saveContent("chart.json", Json.stringify(funkin.backend.chart.Chart.parse("dadbattle", "hard")));
|
|
||||||
#end
|
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,19 +22,7 @@ class ModSwitchMenu extends MusicBeatSubstate {
|
|||||||
bg.alpha = 0;
|
bg.alpha = 0;
|
||||||
FlxTween.tween(bg, {alpha: 0.5}, 0.25, {ease: FlxEase.cubeOut});
|
FlxTween.tween(bg, {alpha: 0.5}, 0.25, {ease: FlxEase.cubeOut});
|
||||||
|
|
||||||
for(modFolder in FileSystem.readDirectory(ModsFolder.modsPath)) {
|
mods = ModsFolder.getModsList();
|
||||||
if (FileSystem.isDirectory('${ModsFolder.modsPath}${modFolder}')) {
|
|
||||||
mods.push(modFolder);
|
|
||||||
} else {
|
|
||||||
var ext = Path.extension(modFolder).toLowerCase();
|
|
||||||
switch(ext) {
|
|
||||||
case 'zip':
|
|
||||||
// is a zip mod!!
|
|
||||||
mods.push(Path.withoutExtension(modFolder));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mods.push(null);
|
mods.push(null);
|
||||||
|
|
||||||
alphabets = new FlxTypedGroup<Alphabet>();
|
alphabets = new FlxTypedGroup<Alphabet>();
|
||||||
|
|||||||
Reference in New Issue
Block a user