2020-10-03 02:50:15 -04:00
|
|
|
package;
|
|
|
|
|
|
|
|
import flixel.FlxGame;
|
2021-02-16 01:53:25 -05:00
|
|
|
import flixel.FlxState;
|
2024-05-24 19:11:34 -04:00
|
|
|
import funkin.Preferences;
|
2023-08-28 15:03:29 -04:00
|
|
|
import funkin.util.logging.CrashHandler;
|
2023-11-07 04:04:22 -05:00
|
|
|
import funkin.ui.debug.MemoryCounter;
|
2023-10-17 00:38:28 -04:00
|
|
|
import funkin.save.Save;
|
2022-09-07 19:07:08 -04:00
|
|
|
import haxe.ui.Toolkit;
|
2020-10-04 02:42:58 -04:00
|
|
|
import openfl.display.FPS;
|
2020-10-03 02:50:15 -04:00
|
|
|
import openfl.display.Sprite;
|
2021-02-16 01:53:25 -05:00
|
|
|
import openfl.events.Event;
|
2023-08-28 15:03:29 -04:00
|
|
|
import openfl.Lib;
|
2021-03-04 19:36:56 -05:00
|
|
|
import openfl.media.Video;
|
|
|
|
import openfl.net.NetStream;
|
2020-10-03 02:50:15 -04:00
|
|
|
|
2024-03-16 22:20:22 -04:00
|
|
|
/**
|
|
|
|
* The main class which initializes HaxeFlixel and starts the game in its initial state.
|
|
|
|
*/
|
2020-10-03 02:50:15 -04:00
|
|
|
class Main extends Sprite
|
|
|
|
{
|
2023-01-22 22:25:45 -05:00
|
|
|
var gameWidth:Int = 1280; // Width of the game in pixels (might be less / more in actual pixels depending on your zoom).
|
|
|
|
var gameHeight:Int = 720; // Height of the game in pixels (might be less / more in actual pixels depending on your zoom).
|
|
|
|
var initialState:Class<FlxState> = funkin.InitState; // The FlxState the game starts with.
|
|
|
|
var zoom:Float = -1; // If -1, zoom is automatically calculated to fit the window dimensions.
|
|
|
|
var skipSplash:Bool = true; // Whether to skip the flixel splash screen that appears in release mode.
|
|
|
|
var startFullscreen:Bool = false; // Whether to start the game in fullscreen on desktop targets
|
|
|
|
|
|
|
|
// You can pretty much ignore everything from here on - your code should go in your states.
|
|
|
|
|
|
|
|
public static function main():Void
|
|
|
|
{
|
2024-02-12 18:09:36 -05:00
|
|
|
// We need to make the crash handler LITERALLY FIRST so nothing EVER gets past it.
|
|
|
|
CrashHandler.initialize();
|
|
|
|
CrashHandler.queryStatus();
|
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
Lib.current.addChild(new Main());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function new()
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
|
2024-02-12 18:09:36 -05:00
|
|
|
// Initialize custom logging.
|
|
|
|
haxe.Log.trace = funkin.util.logging.AnsiTrace.trace;
|
|
|
|
funkin.util.logging.AnsiTrace.traceBF();
|
|
|
|
|
|
|
|
// Load mods to override assets.
|
|
|
|
// TODO: Replace with loadEnabledMods() once the user can configure the mod list.
|
2023-01-22 22:25:45 -05:00
|
|
|
funkin.modding.PolymodHandler.loadAllMods();
|
|
|
|
|
|
|
|
if (stage != null)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
addEventListener(Event.ADDED_TO_STAGE, init);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function init(?event:Event):Void
|
|
|
|
{
|
2024-07-15 23:10:08 -04:00
|
|
|
#if web
|
2024-09-12 15:38:44 -04:00
|
|
|
// set this variable (which is a function) from the lime version at lime/_internal/backend/html5/HTML5Application.hx
|
|
|
|
// The framerate cap will more thoroughly initialize via Preferences in InitState.hx
|
|
|
|
funkin.Preferences.lockedFramerateFunction = untyped js.Syntax.code("window.requestAnimationFrame");
|
2024-07-15 23:10:08 -04:00
|
|
|
#end
|
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
if (hasEventListener(Event.ADDED_TO_STAGE))
|
|
|
|
{
|
|
|
|
removeEventListener(Event.ADDED_TO_STAGE, init);
|
|
|
|
}
|
|
|
|
|
|
|
|
setupGame();
|
|
|
|
}
|
|
|
|
|
|
|
|
var video:Video;
|
|
|
|
var netStream:NetStream;
|
|
|
|
var overlay:Sprite;
|
|
|
|
|
2024-03-16 22:20:22 -04:00
|
|
|
/**
|
|
|
|
* A frame counter displayed at the top left.
|
|
|
|
*/
|
2023-01-22 22:25:45 -05:00
|
|
|
public static var fpsCounter:FPS;
|
2024-03-16 22:20:22 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A RAM counter displayed at the top left.
|
|
|
|
*/
|
2023-01-22 22:25:45 -05:00
|
|
|
public static var memoryCounter:MemoryCounter;
|
|
|
|
|
|
|
|
function setupGame():Void
|
|
|
|
{
|
|
|
|
initHaxeUI();
|
|
|
|
|
2024-03-16 22:20:22 -04:00
|
|
|
// addChild gets called by the user settings code.
|
2023-01-22 22:25:45 -05:00
|
|
|
fpsCounter = new FPS(10, 3, 0xFFFFFF);
|
2024-03-16 22:20:22 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
#if !html5
|
2024-03-16 22:20:22 -04:00
|
|
|
// addChild gets called by the user settings code.
|
|
|
|
// TODO: disabled on HTML5 (todo: find another method that works?)
|
2023-01-22 22:25:45 -05:00
|
|
|
memoryCounter = new MemoryCounter(10, 13, 0xFFFFFF);
|
|
|
|
#end
|
2023-10-17 00:38:28 -04:00
|
|
|
|
|
|
|
// George recommends binding the save before FlxGame is created.
|
|
|
|
Save.load();
|
2024-05-24 19:11:34 -04:00
|
|
|
var game:FlxGame = new FlxGame(gameWidth, gameHeight, initialState, Preferences.framerate, Preferences.framerate, skipSplash, startFullscreen);
|
2023-10-17 00:38:28 -04:00
|
|
|
|
2024-03-14 22:27:07 -04:00
|
|
|
// FlxG.game._customSoundTray wants just the class, it calls new from
|
|
|
|
// create() in there, which gets called when it's added to stage
|
|
|
|
// which is why it needs to be added before addChild(game) here
|
|
|
|
@:privateAccess
|
|
|
|
game._customSoundTray = funkin.ui.options.FunkinSoundTray;
|
|
|
|
|
|
|
|
addChild(game);
|
2023-10-17 00:38:28 -04:00
|
|
|
|
2024-08-26 18:01:36 -04:00
|
|
|
#if FEATURE_DEBUG_FUNCTIONS
|
2024-04-27 01:17:15 -04:00
|
|
|
game.debugger.interaction.addTool(new funkin.util.TrackerToolButtonUtil());
|
2024-04-29 18:31:20 -04:00
|
|
|
#end
|
2024-04-27 01:17:15 -04:00
|
|
|
|
2023-10-17 00:38:28 -04:00
|
|
|
#if hxcpp_debug_server
|
|
|
|
trace('hxcpp_debug_server is enabled! You can now connect to the game with a debugger.');
|
2024-03-16 22:20:22 -04:00
|
|
|
#else
|
|
|
|
trace('hxcpp_debug_server is disabled! This build does not support debugging.');
|
2023-01-22 22:25:45 -05:00
|
|
|
#end
|
|
|
|
}
|
|
|
|
|
|
|
|
function initHaxeUI():Void
|
|
|
|
{
|
|
|
|
// Calling this before any HaxeUI components get used is important:
|
|
|
|
// - It initializes the theme styles.
|
|
|
|
// - It scans the class path and registers any HaxeUI components.
|
|
|
|
Toolkit.init();
|
|
|
|
Toolkit.theme = 'dark'; // don't be cringe
|
2024-04-27 01:17:15 -04:00
|
|
|
// Toolkit.theme = 'light'; // embrace cringe
|
2023-08-01 13:07:16 -04:00
|
|
|
Toolkit.autoScale = false;
|
2024-01-08 21:26:24 -05:00
|
|
|
// Don't focus on UI elements when they first appear.
|
|
|
|
haxe.ui.focus.FocusManager.instance.autoFocus = false;
|
2023-10-31 14:43:01 -04:00
|
|
|
funkin.input.Cursor.registerHaxeUICursors();
|
2024-01-05 02:35:41 -05:00
|
|
|
haxe.ui.tooltips.ToolTipManager.defaultDelay = 200;
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
2020-10-03 02:50:15 -04:00
|
|
|
}
|