2020-10-03 02:50:15 -04:00
|
|
|
package;
|
|
|
|
|
|
|
|
import flixel.FlxGame;
|
2021-02-16 01:53:25 -05:00
|
|
|
import flixel.FlxState;
|
2022-04-18 19:36:09 -04:00
|
|
|
import funkin.MemoryCounter;
|
2022-09-07 19:07:08 -04:00
|
|
|
import haxe.ui.Toolkit;
|
2021-02-16 01:53:25 -05:00
|
|
|
import openfl.Lib;
|
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;
|
2021-03-04 19:36:56 -05:00
|
|
|
import openfl.media.Video;
|
|
|
|
import openfl.net.NetStream;
|
2020-10-03 02:50:15 -04:00
|
|
|
|
|
|
|
class Main extends Sprite
|
|
|
|
{
|
2021-02-16 01:53:25 -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).
|
2022-09-07 19:07:08 -04:00
|
|
|
var initialState:Class<FlxState> = funkin.InitState; // The FlxState the game starts with.
|
2021-02-16 01:53:25 -05:00
|
|
|
var zoom:Float = -1; // If -1, zoom is automatically calculated to fit the window dimensions.
|
2021-03-13 13:37:59 -05:00
|
|
|
#if web
|
2021-02-16 01:53:25 -05:00
|
|
|
var framerate:Int = 60; // How many frames per second the game should run at.
|
2021-03-13 13:37:59 -05:00
|
|
|
#else
|
2022-01-26 00:41:14 -05:00
|
|
|
// TODO: This should probably be in the options menu?
|
2022-01-31 14:16:28 -05:00
|
|
|
var framerate:Int = 144; // How many frames per second the game should run at.
|
2021-03-13 13:37:59 -05:00
|
|
|
#end
|
2021-02-16 01:53:25 -05:00
|
|
|
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
|
|
|
|
{
|
|
|
|
Lib.current.addChild(new Main());
|
|
|
|
}
|
|
|
|
|
2020-10-03 02:50:15 -04:00
|
|
|
public function new()
|
|
|
|
{
|
|
|
|
super();
|
2021-02-16 01:53:25 -05:00
|
|
|
|
2022-04-18 19:36:09 -04:00
|
|
|
// TODO: Replace this with loadEnabledMods().
|
2022-03-08 03:13:53 -05:00
|
|
|
funkin.modding.PolymodHandler.loadAllMods();
|
2022-01-26 00:41:14 -05:00
|
|
|
|
2021-02-16 01:53:25 -05:00
|
|
|
if (stage != null)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
addEventListener(Event.ADDED_TO_STAGE, init);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function init(?E:Event):Void
|
|
|
|
{
|
|
|
|
if (hasEventListener(Event.ADDED_TO_STAGE))
|
|
|
|
{
|
|
|
|
removeEventListener(Event.ADDED_TO_STAGE, init);
|
|
|
|
}
|
|
|
|
|
|
|
|
setupGame();
|
|
|
|
}
|
|
|
|
|
2021-03-04 19:36:56 -05:00
|
|
|
var video:Video;
|
|
|
|
var netStream:NetStream;
|
|
|
|
private var overlay:Sprite;
|
|
|
|
|
2021-03-30 23:51:17 -04:00
|
|
|
public static var fpsCounter:FPS;
|
2022-01-27 22:20:38 -05:00
|
|
|
public static var memoryCounter:MemoryCounter;
|
2021-03-30 23:51:17 -04:00
|
|
|
|
2021-02-16 01:53:25 -05:00
|
|
|
private function setupGame():Void
|
|
|
|
{
|
2022-07-14 19:03:42 -04:00
|
|
|
/**
|
|
|
|
* The `zoom` argument of FlxGame was removed in the dev branch of Flixel,
|
|
|
|
* since it was considered confusing and unintuitive.
|
|
|
|
* If you want to change how the game scales when you resize the window,
|
|
|
|
* you can use `FlxG.scaleMode`.
|
|
|
|
* -Eric
|
|
|
|
*/
|
2021-02-16 01:53:25 -05:00
|
|
|
|
|
|
|
#if !debug
|
2022-11-24 19:09:47 -05:00
|
|
|
/**
|
|
|
|
* Someone was like "hey let's make a state that only runs code on debug builds"
|
|
|
|
* then put essential initialization code in it.
|
|
|
|
* The easiest fix is to make it run in all builds.
|
|
|
|
* -Eric
|
|
|
|
*/
|
|
|
|
// initialState = funkin.TitleState;
|
2021-02-16 01:53:25 -05:00
|
|
|
#end
|
|
|
|
|
2022-09-07 19:07:08 -04:00
|
|
|
initHaxeUI();
|
|
|
|
|
2022-07-14 19:03:42 -04:00
|
|
|
addChild(new FlxGame(gameWidth, gameHeight, initialState, framerate, framerate, skipSplash, startFullscreen));
|
2020-10-04 02:42:58 -04:00
|
|
|
|
2022-01-27 22:20:38 -05:00
|
|
|
#if debug
|
2021-03-30 23:51:17 -04:00
|
|
|
fpsCounter = new FPS(10, 3, 0xFFFFFF);
|
|
|
|
addChild(fpsCounter);
|
2022-03-06 02:37:38 -05:00
|
|
|
#if !html5
|
2022-01-27 22:20:38 -05:00
|
|
|
memoryCounter = new MemoryCounter(10, 13, 0xFFFFFF);
|
|
|
|
addChild(memoryCounter);
|
2020-10-04 02:42:58 -04:00
|
|
|
#end
|
2022-03-06 02:37:38 -05:00
|
|
|
#end
|
2020-10-03 02:50:15 -04:00
|
|
|
}
|
2021-03-04 19:36:56 -05:00
|
|
|
|
2022-09-07 19:07:08 -04:00
|
|
|
function initHaxeUI()
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
}
|
2020-10-03 02:50:15 -04:00
|
|
|
}
|