# Conflicts: # commandline/commands/Compiler.hx # source/funkin/backend/FunkinSprite.hx # source/funkin/backend/MusicBeatState.hx # source/funkin/backend/MusicBeatSubstate.hx # source/funkin/backend/chart/Chart.hx # source/funkin/backend/chart/EventsData.hx # source/funkin/backend/scripting/GlobalScript.hx # source/funkin/backend/system/Controls.hx # source/funkin/backend/system/MainState.hx # source/funkin/backend/utils/AudioAnalyzer.hx # source/funkin/backend/utils/CoolUtil.hx # source/funkin/editors/character/CharacterInfoScreen.hx # source/funkin/editors/charter/Charter.hx # source/funkin/editors/charter/CharterSelection.hx # source/funkin/editors/charter/CharterStrumline.hx # source/funkin/editors/charter/CharterStrumlineButton.hx # source/funkin/editors/charter/SongCreationScreen.hx # source/funkin/editors/ui/UIDropDown.hx # source/funkin/editors/ui/UIFileExplorer.hx # source/funkin/game/Note.hx # source/funkin/game/PlayState.hx # source/funkin/game/SplashGroup.hx # source/funkin/game/Stage.hx # source/funkin/game/Strum.hx # source/funkin/menus/FreeplayState.hx # source/funkin/options/Options.hx # source/funkin/options/keybinds/KeybindsOptions.hx
123 lines
3.0 KiB
Haxe
123 lines
3.0 KiB
Haxe
package funkin.backend.system;
|
|
|
|
#if MOD_SUPPORT
|
|
import sys.FileSystem;
|
|
#end
|
|
import flixel.FlxState;
|
|
import funkin.backend.assets.ModsFolder;
|
|
import funkin.backend.chart.EventsData;
|
|
import funkin.backend.system.framerate.Framerate;
|
|
import funkin.menus.TitleState;
|
|
import haxe.io.Path;
|
|
|
|
@dox(hide)
|
|
typedef AddonInfo = {
|
|
var name:String;
|
|
var path:String;
|
|
}
|
|
|
|
/**
|
|
* Simple state used for loading the game
|
|
*/
|
|
class MainState extends FlxState {
|
|
public static var initiated:Bool = false;
|
|
public override function create() {
|
|
super.create();
|
|
if (!initiated) {
|
|
Main.loadGameSettings();
|
|
}
|
|
|
|
initiated = true;
|
|
|
|
#if sys
|
|
CoolUtil.deleteFolder('./.temp/'); // delete temp folder
|
|
#end
|
|
Options.save();
|
|
|
|
ControlsUtil.resetCustomControls();
|
|
FlxG.bitmap.reset();
|
|
FlxG.sound.destroy(true);
|
|
|
|
Paths.assetsTree.reset();
|
|
|
|
#if MOD_SUPPORT
|
|
inline function isDirectory(path:String):Bool
|
|
return FileSystem.exists(path) && FileSystem.isDirectory(path);
|
|
|
|
inline function ltrim(str:String, prefix:String):String
|
|
return str.substr(prefix.length).ltrim();
|
|
|
|
inline function loadLib(path:String, name:String)
|
|
Paths.assetsTree.addLibrary(ModsFolder.loadModLib(path, name));
|
|
|
|
var _lowPriorityAddons:Array<AddonInfo> = [];
|
|
var _highPriorityAddons:Array<AddonInfo> = [];
|
|
var _noPriorityAddons:Array<AddonInfo> = [];
|
|
|
|
var addonPaths = [
|
|
ModsFolder.addonsPath,
|
|
(
|
|
ModsFolder.currentModFolder != null ?
|
|
ModsFolder.modsPath + ModsFolder.currentModFolder + "/addons/" :
|
|
null
|
|
)
|
|
];
|
|
|
|
for(path in addonPaths) {
|
|
if (path == null) continue;
|
|
if (!isDirectory(path)) continue;
|
|
|
|
for(addon in FileSystem.readDirectory(path)) {
|
|
if(!FileSystem.isDirectory(path + addon)) {
|
|
switch(Path.extension(addon).toLowerCase()) {
|
|
case 'zip':
|
|
addon = Path.withoutExtension(addon);
|
|
default:
|
|
continue;
|
|
}
|
|
}
|
|
|
|
var data:AddonInfo = {
|
|
name: addon,
|
|
path: path + addon
|
|
};
|
|
|
|
if (addon.startsWith("[LOW]")) _lowPriorityAddons.insert(0, data);
|
|
else if (addon.startsWith("[HIGH]")) _highPriorityAddons.insert(0, data);
|
|
else _noPriorityAddons.insert(0, data);
|
|
}
|
|
}
|
|
|
|
for (addon in _lowPriorityAddons)
|
|
loadLib(addon.path, ltrim(addon.name, "[LOW]"));
|
|
|
|
if (ModsFolder.currentModFolder != null)
|
|
loadLib(ModsFolder.modsPath + ModsFolder.currentModFolder, ModsFolder.currentModFolder);
|
|
|
|
for (addon in _noPriorityAddons)
|
|
loadLib(addon.path, addon.name);
|
|
|
|
for (addon in _highPriorityAddons)
|
|
loadLib(addon.path, ltrim(addon.name, "[HIGH]"));
|
|
#end
|
|
|
|
Flags.load();
|
|
ModsFolder.onModSwitch.dispatch(ModsFolder.currentModFolder); // Loads global.hx
|
|
MusicBeatTransition.script = Flags.DEFAULT_TRANSITION_SCRIPT;
|
|
WindowUtils.resetTitle();
|
|
Main.refreshAssets();
|
|
DiscordUtil.init();
|
|
EventsData.reloadEvents();
|
|
ControlsUtil.loadCustomControls();
|
|
TitleState.initialized = false;
|
|
|
|
if (Framerate.isLoaded)
|
|
Framerate.instance.reload();
|
|
|
|
FlxG.switchState(new TitleState());
|
|
|
|
#if sys
|
|
CoolUtil.safeAddAttributes('./.temp/', NativeAPI.FileAttribute.HIDDEN);
|
|
#end
|
|
}
|
|
} |