diff --git a/.github/workflows/build-samples.yml b/.github/workflows/build-samples.yml new file mode 100644 index 00000000..dd5c80e7 --- /dev/null +++ b/.github/workflows/build-samples.yml @@ -0,0 +1,91 @@ +# Builds the sample projects on multiple targets to check for compiler errors. + +name: Build Samples + +on: + #push: + pull_request: + workflow_dispatch: + +jobs: + build: + strategy: + matrix: + os: [windows-latest, ubuntu-latest, macos-latest] + target: [cpp, html5, hl] + fail-fast: false + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout + uses: actions/checkout@v6.0.2 + + - name: Setup Haxe + uses: FunkinCrew/ci-haxe@v3 + with: + haxe-version: 4.3.7 + + - name: Setup hmm.json for Samples + working-directory: ./samples + run: haxe run.hxml + + - name: Cache Haxelibs + uses: actions/cache@v6 + with: + path: ./samples/.haxelib + key: haxelib-${{ hashFiles('samples/hmm.json') }} + enableCrossOsArchive: true + restore-keys: | + haxelib- + + - name: Setup HMM + run: | + haxelib --global --quiet --never update haxelib + haxelib --global fixrepo + haxelib --global --quiet install hmm + haxelib --global run hmm setup + + - name: Install sample dependencies + working-directory: ./samples + run: | + hmm install --quiet + haxelib fixrepo + + - name: Build Flixel Sample + working-directory: ./samples/flixel + run: haxelib run lime build ${{ matrix.target }} --no-output + + - name: Build ZIP Flixel Sample + working-directory: ./samples/flixel_zip + run: haxelib run lime build ${{ matrix.target }} --no-output + + - name: Build Heaps Sample + if: matrix.target == 'hl' + working-directory: ./samples/heaps + run: haxe hl.hxml + + # The NME target seems to be in a pretty unusable state, so we will ignore errors for now. + - name: Build NME Sample + continue-on-error: true + if: matrix.target != 'hl' && matrix.target != 'html5' + working-directory: ./samples/nme + run: echo y | haxelib run nme build ${{ matrix.target }} --no-output + + - name: Build OpenFL Sample + working-directory: ./samples/openfl + run: haxelib run openfl build ${{ matrix.target }} --no-output + + - name: Build OpenFL (Firetongue) Sample + working-directory: ./samples/openfl_firetongue + run: haxelib run openfl build ${{ matrix.target }} --no-output + + - name: Build OpenFL (HScript) Sample + working-directory: ./samples/openfl_hscript + run: haxelib run openfl build ${{ matrix.target }} --no-output + + - name: Build OpenFL (HScript with Classes) Sample + working-directory: ./samples/openfl_hscript_class + run: haxelib run openfl build ${{ matrix.target }} --no-output + + diff --git a/include.xml b/include.xml index ab2c2bfe..f92b7ef1 100644 --- a/include.xml +++ b/include.xml @@ -1,6 +1,9 @@ + + + diff --git a/polymod/Polymod.hx b/polymod/Polymod.hx index c1ca70a3..8ad5c798 100644 --- a/polymod/Polymod.hx +++ b/polymod/Polymod.hx @@ -279,7 +279,6 @@ class Polymod params.dirs ??= []; params.ignoredFiles ??= []; - var shouldLoadMods:Bool = params.modIds.length == 0 && params.dirs.length == 0; if (params.fileSystemParams == null) params.fileSystemParams = {modRoot: modRoot}; if (params.fileSystemParams.modRoot == null) params.fileSystemParams.modRoot = modRoot; if (params.apiVersionRule == null) params.apiVersionRule = VersionUtil.DEFAULT_VERSION_RULE; @@ -847,7 +846,7 @@ class Polymod #if hscript_typer polymod.hscript._internal.PolymodTyperEx.clearAllModules(); #end - polymod.hscript.HScriptable.ScriptRunner.clearScripts(); + polymod.hscript.ScriptRunner.clearScripts(); } static function prepareRegisterScriptedClasses():Void @@ -965,6 +964,12 @@ class Polymod return lime.app.Future.withValue(results); }); } + #else + public static function registerAllScriptClassesAsync():Array + { + Polymod.error(SCRIPT_PARSE_FAILED, 'Asynchronous script loading is not supported on this platform!'); + return []; + } #end /** diff --git a/polymod/backends/HEAPSBackend.hx b/polymod/backends/HEAPSBackend.hx index 854f66a0..2b5b235b 100644 --- a/polymod/backends/HEAPSBackend.hx +++ b/polymod/backends/HEAPSBackend.hx @@ -99,6 +99,11 @@ class HEAPSBackend implements IBackend throw 'Function not implemented'; } + public function listLibraries():Array + { + throw 'Function not implemented'; + } + public function getPath(id:String):String { throw 'Function not implemented'; @@ -229,7 +234,7 @@ class ModFileEntry extends BytesFileEntry var dirPath = isDir ? path : Util.uPathPop(fullFilePath); var itemPaths = []; - for (id in p.type.keys()) + for (id in p.assetTypes.keys()) { if (id.indexOf(dirPath) != 0) continue; if (Util.isMergeOrAppend(id)) continue; @@ -290,16 +295,16 @@ class ModFileEntry extends BytesFileEntry return super.getBytes(); } - override function readByte():Int + override function readBytes(out:Bytes, outPos:Int, pos:Int, len:Int):Int { initBytes(); - return super.readByte(); + return super.readBytes(out, outPos, pos, len); } - override function read(out:Bytes, pos:Int, size:Int) + override function readFull(bytes:Bytes, pos:Int, len:Int) { initBytes(); - return super.read(out, pos, size); + return super.readFull(bytes, pos, len); } override function loadBitmap(onLoaded:LoadedBitmap->Void):Void diff --git a/polymod/backends/NMEBackend.hx b/polymod/backends/NMEBackend.hx index d1cf0c8e..8fbe8a2d 100644 --- a/polymod/backends/NMEBackend.hx +++ b/polymod/backends/NMEBackend.hx @@ -165,6 +165,11 @@ class NMEBackend implements IBackend throw 'Function not implemented'; } + public function listLibraries():Array + { + throw 'Function not implemented'; + } + public function getPath(id:String):String { throw 'Function not implemented'; diff --git a/polymod/backends/PolymodAssetLibrary.hx b/polymod/backends/PolymodAssetLibrary.hx index f728d6de..574c3f0d 100644 --- a/polymod/backends/PolymodAssetLibrary.hx +++ b/polymod/backends/PolymodAssetLibrary.hx @@ -347,7 +347,7 @@ class PolymodAssetLibrary return (bytes == null) ? null : bytes.getString(0, bytes.length); } - #if openfl + #if (openfl && !nme) /** * Fetch text directly from the file system. * Queries for any modded asset replacements, but ignores merging and appending. @@ -611,6 +611,7 @@ class PolymodAssetLibrary return soundFuture; } #end + #end /** * @return A list of asset libraries for this framework. @@ -619,7 +620,6 @@ class PolymodAssetLibrary { return backend.listLibraries(); } - #end /** * Get the absolute system file path for a given asset ID. @@ -1039,7 +1039,7 @@ class PolymodAssetLibrary typeLibraries.get('default').push(file); } - #if openfl + #if (openfl && !nme) if (assetType == FONT) { var font = Font.fromFile(this.file(file, modDir)); @@ -1103,7 +1103,7 @@ class PolymodAssetLibrary assetTypes.set(f, assetType); if (!typeLibraries.exists(libraryId)) typeLibraries.set(libraryId, []); typeLibraries.get(libraryId).push(f); - #if openfl + #if (openfl && !nme) if (assetType == FONT) { var font = Font.fromFile(file(f, redirectPath)); diff --git a/polymod/fs/BaseFileSystem.hx b/polymod/fs/BaseFileSystem.hx index 9a06953d..6736d5aa 100644 --- a/polymod/fs/BaseFileSystem.hx +++ b/polymod/fs/BaseFileSystem.hx @@ -104,40 +104,38 @@ abstract class BaseFileSystem implements IFileSystem return new Future(performWork, true); } - #end /** - * Get the byte data for a file from a specific mod. + * Load the byte data for a file from a specific mod, asynchronously. * * @param path The path to retrieve byte data from, relative to the asset root. * @param modId A specific mod ID to retrieve an asset from. - * @return The file bytes, or `null` if it couldn't be fetched. + * @return A future which returns the file bytes. */ - public function getFileBytesByModId(path:String, modId:String):Null + public function loadFileBytesByModId(path:String, modId:String):Future { - var modDir:String = scanModDirectoriesForId(modId) ?? return null; - var relativeDir:String = Util.pathJoin(modRoot, modDir); + var modDir:Null = scanModDirectoriesForId(modId); + if (modDir == null) return null; + var relativeDir = Util.pathJoin(modRoot, modDir); - return getFileBytes(Util.pathJoin(relativeDir, path)); + return loadFileBytes(Util.pathJoin(relativeDir, path)); } + #end - #if lime /** - * Load the byte data for a file from a specific mod, asynchronously. + * Get the byte data for a file from a specific mod. * * @param path The path to retrieve byte data from, relative to the asset root. * @param modId A specific mod ID to retrieve an asset from. - * @return A future which returns the file bytes. + * @return The file bytes, or `null` if it couldn't be fetched. */ - public function loadFileBytesByModId(path:String, modId:String):Future + public function getFileBytesByModId(path:String, modId:String):Null { - var modDir:Null = scanModDirectoriesForId(modId); - if (modDir == null) return null; - var relativeDir = Util.pathJoin(modRoot, modDir); + var modDir:String = scanModDirectoriesForId(modId) ?? return null; + var relativeDir:String = Util.pathJoin(modRoot, modDir); - return loadFileBytes(Util.pathJoin(relativeDir, path)); + return getFileBytes(Util.pathJoin(relativeDir, path)); } - #end /** * Provide a list of valid mods for this file system to load. @@ -295,7 +293,6 @@ abstract class BaseFileSystem implements IFileSystem function getModIconPath(modPath:String, ?origin:PolymodErrorOrigin):Null { - var foundIcon = false; for (iconBasePath in PolymodConfig.modIconFile) { var iconFile = Util.pathJoin(modPath, iconBasePath); diff --git a/polymod/fs/StubFileSystem.hx b/polymod/fs/StubFileSystem.hx index e9646b1e..0cbe4432 100644 --- a/polymod/fs/StubFileSystem.hx +++ b/polymod/fs/StubFileSystem.hx @@ -6,6 +6,9 @@ import polymod.Polymod.PolymodErrorOrigin; import thx.semver.VersionRule; import polymod.fs.PolymodFileSystem.IFileSystem; import polymod.fs.PolymodFileSystem.PolymodFileSystemParams; +#if lime +import lime.app.Future; +#end /** * This stub file system returns false for all requests. @@ -16,7 +19,7 @@ import polymod.fs.PolymodFileSystem.PolymodFileSystemParams; @SuppressWarnings('checkstyle:FieldDocComment') class StubFileSystem implements IFileSystem { - public final modRoot:String; + public final modRoot:String = ''; public function new(params:PolymodFileSystemParams) {} public inline function exists(path:String):Bool @@ -49,15 +52,34 @@ class StubFileSystem implements IFileSystem return null; } - public function onLoadMod(id:String):Void {} - - public function onUnloadMod(id:String):Void {} - public inline function getFileBytesByModId(path:String, modId:String):Null { return null; } + #if lime + public inline function loadFileBytes(path:String):Future + { + return cast Future.withError('Cannot load file bytes from stub file system'); + } + + /** + * Load the byte data for a file from a specific mod, asynchronously. + * + * @param path The path to retrieve byte data from, relative to the asset root. + * @param modId A specific mod ID to retrieve an asset from. + * @return A future which returns the file bytes. + */ + public inline function loadFileBytesByModId(path:String, modId:String):Future + { + return cast Future.withError('Cannot load file bytes from stub file system'); + } + #end + + public function onLoadMod(id:String):Void {} + + public function onUnloadMod(id:String):Void {} + public inline function readDirectoryRecursive(path:String):Array { return []; diff --git a/polymod/hscript/HScriptable.hx b/polymod/hscript/HScriptable.hx index 18e9cb78..0c8f2e06 100644 --- a/polymod/hscript/HScriptable.hx +++ b/polymod/hscript/HScriptable.hx @@ -1,9 +1,6 @@ package polymod.hscript; import haxe.Json; -import polymod.hscript._internal.Expr; -import polymod.Polymod; -import polymod.util.Util; /** * This interface triggers the execution of a macro on any elements which use the `@:hscript` annotation. @@ -171,133 +168,3 @@ class HScriptParams return Json.stringify(this); } } - -typedef ScriptOutput = -{ - /** - * The output of the script. Can be any value type. - */ - var script_result:Dynamic; - - /** - * The functions and variables created within the scope of the script. - */ - var script_variables:Map; -} - -class ScriptRunner -{ - /** - * No reason not to make this static! Load a script once instead of 50 times. - */ - private static var scripts:Map = new Map(); - - public function new() {} - - public static function clearScripts():Void - { - scripts.clear(); - } - - public function load(name:String, assetHandler:Dynamic):Null