initialize standalone OpenFL application structure with essential files and configurations
This commit is contained in:
parent
d533ffd7a8
commit
8c36316409
2
standalone-openfl-app/.gitignore
vendored
Normal file
2
standalone-openfl-app/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
bin
|
||||
Export
|
||||
49
standalone-openfl-app/README.md
Normal file
49
standalone-openfl-app/README.md
Normal file
@ -0,0 +1,49 @@
|
||||
# Standalone OpenFL Application
|
||||
|
||||
This project is a standalone OpenFL application that serves as a template for building your own applications using the OpenFL framework. Below are the details regarding the structure and usage of the project.
|
||||
|
||||
## Project Structure
|
||||
|
||||
- **src/**: Contains the source code for the application.
|
||||
- **Main.hx**: Entry point for the application. Initializes the application and sets up the main logic.
|
||||
- **ApplicationMain.hx**: Manages the application lifecycle, creates the application instance, and handles preloader functionality.
|
||||
- **DocumentClass.hx**: Extends the main application class, managing display and event handling.
|
||||
- **ManifestResources.hx**: Manages application resources, including asset loading and preloader resources.
|
||||
|
||||
- **assets/**: Contains asset files for the application.
|
||||
- **img/**: Directory for image assets. Currently contains a placeholder file.
|
||||
- **placeholder.txt**: Placeholder file that can be replaced with actual image files.
|
||||
|
||||
- **build.hxml**: Build configuration file for the Haxe compiler. Specifies source files, output directory, and additional compiler flags or libraries.
|
||||
|
||||
- **compile.sh**: Shell script to automate the build process. Runs the Haxe compiler with the specified build.hxml configuration.
|
||||
|
||||
- **project.xml**: Project configuration file for OpenFL, containing metadata such as title, version, and dependencies.
|
||||
|
||||
- **README.md**: Documentation for the project, including setup instructions and usage information.
|
||||
|
||||
## Setup Instructions
|
||||
|
||||
1. **Install Haxe and OpenFL**: Ensure you have Haxe and OpenFL installed on your system. You can find installation instructions on the [Haxe website](https://haxe.org/download/) and the [OpenFL website](https://openfl.org/download/).
|
||||
|
||||
2. **Replace Placeholders**: Open the `src/ApplicationMain.hx` file and replace the `::` placeholders with actual values relevant to your application:
|
||||
- `::APP_FILE::`: Path to your main application file (e.g., "src/Main.hx").
|
||||
- `::meta.buildNumber::`: Build number of your application.
|
||||
- `::meta.company::`: Your company name.
|
||||
- `::meta.title::`: Title of your application.
|
||||
- `::meta.packageName::`: Package name of your application.
|
||||
- `::meta.version::`: Version of your application.
|
||||
- `::WIN_WIDTH::` and `::WIN_HEIGHT::`: Desired window dimensions.
|
||||
- Other boolean values like `::allowHighDPI::`, `::alwaysOnTop::`, etc., with appropriate settings.
|
||||
|
||||
3. **Adjust Build Configuration**: Modify the `build.hxml` file to include necessary libraries and source files for your application.
|
||||
|
||||
4. **Build the Application**: Run the `compile.sh` script to build your OpenFL application. This will compile the source files and generate the executable.
|
||||
|
||||
5. **Run the Application**: After building, you can run the generated executable to see your application in action.
|
||||
|
||||
## Usage Information
|
||||
|
||||
This template provides a solid foundation for developing OpenFL applications. You can expand upon the provided classes and resources to create your own unique application. Be sure to refer to the OpenFL documentation for additional guidance on using the framework effectively.
|
||||
|
||||
Happy coding!
|
||||
1
standalone-openfl-app/assets/img/placeholder.txt
Normal file
1
standalone-openfl-app/assets/img/placeholder.txt
Normal file
@ -0,0 +1 @@
|
||||
This file is intentionally left blank.
|
||||
37
standalone-openfl-app/build.hxml
Normal file
37
standalone-openfl-app/build.hxml
Normal file
@ -0,0 +1,37 @@
|
||||
-main ApplicationMain
|
||||
|
||||
-lib openfl
|
||||
-lib lime
|
||||
-lib hxcpp
|
||||
-lib actuate
|
||||
-lib hxp
|
||||
|
||||
-cp src
|
||||
|
||||
-cp assets
|
||||
-D openfl=8.9.5
|
||||
-D lime=7.9.0
|
||||
-D app_file=src/Main.hx
|
||||
-D meta.buildNumber="1.0.0"
|
||||
-D meta.company="YourCompanyName"
|
||||
-D meta.title="YourApplicationTitle"
|
||||
-D meta.packageName="com.yourcompany.yourapp"
|
||||
-D meta.version="1.0.0"
|
||||
-D WIN_WIDTH=800
|
||||
-D WIN_HEIGHT=600
|
||||
-D allowHighDPI=true
|
||||
-D alwaysOnTop=false
|
||||
-D borderless=false
|
||||
-D fullscreen=false
|
||||
-D hidden=false
|
||||
-D resizable=true
|
||||
-D fps=60
|
||||
-D background=0xFFFFFF
|
||||
-D antialiasing=true
|
||||
-D hardware=true
|
||||
-D vsync=true
|
||||
-D depthBuffer=true
|
||||
-D stencilBuffer=false
|
||||
-D parameters="{}"
|
||||
|
||||
--cpp bin/cpp
|
||||
14
standalone-openfl-app/compile.sh
Normal file
14
standalone-openfl-app/compile.sh
Normal file
@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Navigate to the project directory
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
# Compile the project using the Haxe compiler with the specified build.hxml configuration
|
||||
haxe build.hxml
|
||||
|
||||
# Check if the compilation was successful
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Compilation successful!"
|
||||
else
|
||||
echo "Compilation failed!"
|
||||
fi
|
||||
35
standalone-openfl-app/project.xml
Normal file
35
standalone-openfl-app/project.xml
Normal file
@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- <project>
|
||||
<meta>
|
||||
<title>Your Application Title</title>
|
||||
<version>1.0.0</version>
|
||||
<company>Your Company Name</company>
|
||||
<package>com.yourcompany.yourapp</package>
|
||||
<buildNumber>1</buildNumber>
|
||||
</meta>
|
||||
<source>
|
||||
<path>src/Main.hx</path>
|
||||
<path>src/ApplicationMain.hx</path>
|
||||
<path>src/DocumentClass.hx</path>
|
||||
<path>src/ManifestResources.hx</path>
|
||||
</source>
|
||||
<assets>
|
||||
<path>assets/img/</path>
|
||||
</assets>
|
||||
<dependencies>
|
||||
<dependency>openfl</dependency>
|
||||
<dependency>lime</dependency>
|
||||
</dependencies>
|
||||
</project> -->
|
||||
<project>
|
||||
|
||||
<meta title="MinimalApplication" package="com.sample.minimalapplication" version="1.0.0" company="Company Name" />
|
||||
<app main="Main" path="Export" file="MinimalApplication" />
|
||||
|
||||
<source path="src" />
|
||||
|
||||
<haxelib name="openfl" />
|
||||
|
||||
<assets path="assets" rename="assets" />
|
||||
|
||||
</project>
|
||||
136
standalone-openfl-app/src/ApplicationMain.hx
Normal file
136
standalone-openfl-app/src/ApplicationMain.hx
Normal file
@ -0,0 +1,136 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
32
standalone-openfl-app/src/Assets.hx
Normal file
32
standalone-openfl-app/src/Assets.hx
Normal file
@ -0,0 +1,32 @@
|
||||
package;
|
||||
|
||||
import openfl.display.BitmapData;
|
||||
import openfl.media.Sound;
|
||||
import openfl.text.Font;
|
||||
import openfl.utils.ByteArray;
|
||||
|
||||
@:build(macros.AssetMacro.buildAssets())
|
||||
class Assets {
|
||||
// The @:build macro will inject the initializeAssets method
|
||||
|
||||
// Helper methods for convenience
|
||||
public static function getBitmapData(id:String):BitmapData {
|
||||
return openfl.Assets.getBitmapData(id);
|
||||
}
|
||||
|
||||
public static function getSound(id:String):Sound {
|
||||
return openfl.Assets.getSound(id);
|
||||
}
|
||||
|
||||
public static function getFont(id:String):Font {
|
||||
return openfl.Assets.getFont(id);
|
||||
}
|
||||
|
||||
public static function getText(id:String):String {
|
||||
return openfl.Assets.getText(id);
|
||||
}
|
||||
|
||||
public static function getBytes(id:String):ByteArray {
|
||||
return openfl.Assets.getBytes(id);
|
||||
}
|
||||
}
|
||||
19
standalone-openfl-app/src/DocumentClass.hx
Normal file
19
standalone-openfl-app/src/DocumentClass.hx
Normal file
@ -0,0 +1,19 @@
|
||||
package;
|
||||
|
||||
import openfl.events.EventDispatcher;
|
||||
import openfl.display.Sprite;
|
||||
import openfl.events.Event;
|
||||
import openfl.display.DisplayObjectContainer;
|
||||
import openfl.events.MouseEvent;
|
||||
|
||||
class DocumentClass extends Sprite
|
||||
{
|
||||
public function new()
|
||||
{
|
||||
super();
|
||||
dispatchEvent(new openfl.events.Event(openfl.events.Event.ADDED_TO_STAGE, false, false));
|
||||
graphics.beginFill(0xFFF00F, 1);
|
||||
graphics.drawRect(0, 0, 800, 600);
|
||||
graphics.endFill();
|
||||
}
|
||||
}
|
||||
19
standalone-openfl-app/src/Main.hx
Normal file
19
standalone-openfl-app/src/Main.hx
Normal file
@ -0,0 +1,19 @@
|
||||
package;
|
||||
|
||||
import openfl.events.EventDispatcher;
|
||||
import openfl.display.Sprite;
|
||||
import openfl.events.Event;
|
||||
import openfl.display.DisplayObjectContainer;
|
||||
import openfl.events.MouseEvent;
|
||||
|
||||
class Main extends Sprite
|
||||
{
|
||||
public function new()
|
||||
{
|
||||
super();
|
||||
dispatchEvent(new openfl.events.Event(openfl.events.Event.ADDED_TO_STAGE, false, false));
|
||||
graphics.beginFill(0xFFF00F, 1);
|
||||
graphics.drawRect(0, 0, 800, 600);
|
||||
graphics.endFill();
|
||||
}
|
||||
}
|
||||
15
standalone-openfl-app/src/ManifestResources.hx
Normal file
15
standalone-openfl-app/src/ManifestResources.hx
Normal file
@ -0,0 +1,15 @@
|
||||
// filepath: /standalone-openfl-app/standalone-openfl-app/src/ManifestResources.hx
|
||||
package;
|
||||
|
||||
class ManifestResources
|
||||
{
|
||||
public static var preloadLibraries:Array<String> = [];
|
||||
public static var preloadLibraryNames:Array<String> = [];
|
||||
|
||||
public static function init(config:Dynamic):Void
|
||||
{
|
||||
// Load assets and resources here
|
||||
// Example: preloadLibraries.push("path/to/library");
|
||||
// Example: preloadLibraryNames.push("LibraryName");
|
||||
}
|
||||
}
|
||||
112
standalone-openfl-app/src/macros/AssetMacro.hx
Normal file
112
standalone-openfl-app/src/macros/AssetMacro.hx
Normal file
@ -0,0 +1,112 @@
|
||||
package macros;
|
||||
|
||||
import haxe.macro.Context;
|
||||
import haxe.macro.Expr;
|
||||
import sys.FileSystem;
|
||||
import sys.io.File;
|
||||
import haxe.Json;
|
||||
|
||||
class AssetMacro {
|
||||
public static macro function buildAssets():Array<Field> {
|
||||
var fields = Context.getBuildFields();
|
||||
|
||||
// Define assets directory
|
||||
var assetsDir = "assets";
|
||||
|
||||
// Check if directory exists
|
||||
if (!FileSystem.exists(assetsDir) || !FileSystem.isDirectory(assetsDir)) {
|
||||
Context.warning('Assets directory "$assetsDir" not found', Context.currentPos());
|
||||
return fields;
|
||||
}
|
||||
|
||||
// Generate manifest in the format OpenFL expects
|
||||
var manifest = {
|
||||
name: "default",
|
||||
rootPath: "",
|
||||
assets: []
|
||||
};
|
||||
|
||||
// Scan assets
|
||||
scanDirectory(assetsDir, manifest.assets);
|
||||
|
||||
// Create manifest file (for runtime use)
|
||||
var manifestPath = "bin/manifest.json";
|
||||
try {
|
||||
// Make sure directory exists
|
||||
var dir = manifestPath.split("/")[0];
|
||||
if (!FileSystem.exists(dir)) {
|
||||
FileSystem.createDirectory(dir);
|
||||
}
|
||||
File.saveContent(manifestPath, Json.stringify(manifest, null, " "));
|
||||
} catch (e) {
|
||||
Context.warning('Could not save manifest file: $e', Context.currentPos());
|
||||
}
|
||||
|
||||
// Generate expression to register the assets
|
||||
var registerExpr = macro {
|
||||
// Create an AssetManifest from our generated file
|
||||
var manifestPath = "bin/manifest.json";
|
||||
if (sys.FileSystem.exists(manifestPath)) {
|
||||
var manifest = lime.utils.AssetManifest.fromFile(manifestPath);
|
||||
if (manifest != null) {
|
||||
// Register the library with OpenFL
|
||||
var library = openfl.utils.AssetLibrary.fromManifest(manifest);
|
||||
if (library != null) {
|
||||
openfl.Assets.registerLibrary("default", library);
|
||||
trace("Asset library registered successfully");
|
||||
} else {
|
||||
trace("Failed to create library from manifest");
|
||||
}
|
||||
} else {
|
||||
trace("Failed to parse manifest file");
|
||||
}
|
||||
} else {
|
||||
trace("Manifest file not found at: " + manifestPath);
|
||||
}
|
||||
};
|
||||
|
||||
// Add initialization method
|
||||
fields.push({
|
||||
name: "initializeAssets",
|
||||
access: [Access.APublic, Access.AStatic],
|
||||
kind: FieldType.FFun({
|
||||
args: [],
|
||||
ret: macro:Void,
|
||||
expr: registerExpr
|
||||
}),
|
||||
pos: Context.currentPos()
|
||||
});
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
||||
private static function scanDirectory(dir:String, assets:Array<Dynamic>, ?prefix:String = ""):Void {
|
||||
for (file in FileSystem.readDirectory(dir)) {
|
||||
var path = dir + "/" + file;
|
||||
var id = prefix + file;
|
||||
|
||||
if (FileSystem.isDirectory(path)) {
|
||||
scanDirectory(path, assets, id + "/");
|
||||
} else {
|
||||
var type = getAssetType(file);
|
||||
assets.push({
|
||||
id: id,
|
||||
path: path,
|
||||
type: type
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function getAssetType(file:String):String {
|
||||
var ext = file.substr(file.lastIndexOf(".") + 1).toLowerCase();
|
||||
|
||||
return switch (ext) {
|
||||
case "jpg", "jpeg", "png", "gif", "bmp": "image";
|
||||
case "mp3", "ogg", "wav": "sound";
|
||||
case "ttf", "otf": "font";
|
||||
case "txt", "json", "xml", "csv": "text";
|
||||
default: "binary";
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user