DSTEngine/standalone-openfl-app/src/ApplicationMain.hx

137 lines
4.5 KiB
Haxe

package;
import openfl.Lib;
import lime.utils.AssetType;
import lime.tools.Asset;
import lime.ui.WindowAttributes;
import openfl.system.System;
import openfl.display.Application;
import openfl.display.Stage;
import openfl.events.Event;
import openfl.events.FullScreenEvent;
@:access(lime.app.Application)
@:access(lime.system.System)
@:access(openfl.display.Stage)
@:access(openfl.events.UncaughtErrorEvents)
class ApplicationMain {
public static function main() {
lime.system.System.__registerEntryPoint("src/DocumentClass.hx", create);
create(null);
}
// public static function create(config):Void {
// try {
// trace("Creating minimal application");
// var app = new Application();
// // Initialize assets via macro-generated code
// Assets.initializeAssets();
// trace("Assets initialized");
// // Minimal metadata
// app.meta["name"] = "Debug Application";
// // Simple window
// var attributes:WindowAttributes = {
// height: 600,
// width: 800,
// title: "Debug Window"
// };
// app.createWindow(attributes);
// // Skip preloader, just call start directly
// start(app.window.stage);
// var result = app.exec();
// lime.system.System.exit(result);
// } catch (e:Dynamic) {
// trace("Error: " + e);
// }
// }
public static function create(config):Void
{
var app = new Application();
app.meta["build"] = "1.0.0"; // Replace with actual build number
app.meta["company"] = "Your Company"; // Replace with your company name
app.meta["file"] = "src/Main.hx"; // Path to your main application file
app.meta["name"] = "Your Application"; // Replace with your application title
app.meta["packageName"] = "com.yourcompany.yourapp"; // Replace with your package name
app.meta["version"] = "1.0.0"; // Replace with your application version
// var asset = new Asset();
// asset.sourcePath = "src/assets"; // Path to your assets
// asset.targetPath = "assets"; // Target path for assets
// asset.type = AssetType.IMAGE; // Type of asset
if (config.hxtelemetry != null)
{
app.meta["hxtelemetry-allocations"] = config.hxtelemetry.allocations;
app.meta["hxtelemetry-host"] = config.hxtelemetry.host;
}
var attributes:WindowAttributes = {
allowHighDPI: true, // Set to true or false as needed
alwaysOnTop: false, // Set to true or false as needed
borderless: false, // Set to true or false as needed
frameRate: 60, // Set your desired frame rate
height: 600, // Set your desired window height
hidden: false, // Set to true or false as needed
maximized: false, // Set to true or false as needed
minimized: false, // Set to true or false as needed
resizable: true, // Set to true or false as needed
title: "Your Application", // Replace with your application title
width: 800, // Set your desired window width
x: 100, // Set your desired x position
y: 100 // Set your desired y position
};
app.createWindow(attributes);
var preloader = getPreloader();
app.preloader.onProgress.add(function(loaded, total)
{
@:privateAccess preloader.update(loaded, total);
});
app.preloader.onComplete.add(function()
{
@:privateAccess preloader.start();
});
preloader.onComplete.add(start.bind(app.window.stage));
app.preloader.load();
var result = app.exec();
lime.system.System.exit(result);
}
public static function start(stage:Stage):Void {
if (stage.__uncaughtErrorEvents.__enabled) {
try {
// Instantiate and add DocumentClass
var documentClass = new DocumentClass();
Lib.current.addChild(documentClass);
// Then dispatch events
stage.dispatchEvent(new Event(Event.RESIZE, false, false));
if (stage.window.fullscreen) {
stage.dispatchEvent(new FullScreenEvent(FullScreenEvent.FULL_SCREEN, false, false, true, true));
}
} catch (e:Dynamic) {
stage.__handleError(e);
}
} else {
// Instantiate and add DocumentClass
var documentClass = new DocumentClass();
Lib.current.addChild(documentClass);
// Then dispatch events
stage.dispatchEvent(new Event(Event.RESIZE, false, false));
if (stage.window.fullscreen) {
stage.dispatchEvent(new FullScreenEvent(FullScreenEvent.FULL_SCREEN, false, false, true, true));
}
}
}
public static function getPreloader() {
return new openfl.display.Preloader();
}
}