From eef58effae61d5771811af210d2f2f2dc0e6e855 Mon Sep 17 00:00:00 2001 From: Hugh Sanderson Date: Thu, 19 Sep 2024 14:20:11 +0800 Subject: [PATCH] Draw distinction between assets forceEmbed and defaultEmbed. Assume URL loads from web targets are with http protocol by default --- src/nme/net/URLLoader.hx | 5 ++-- src/nme/net/URLRequest.hx | 6 +++++ tools/nme/src/platforms/EmscriptenPlatform.hx | 3 ++- tools/nme/src/project/NMEProject.hx | 22 ++++++++--------- tools/nme/src/project/NMMLParser.hx | 24 ++++++++++++------- 5 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/nme/net/URLLoader.hx b/src/nme/net/URLLoader.hx index cb2c13c32..d6188043d 100644 --- a/src/nme/net/URLLoader.hx +++ b/src/nme/net/URLLoader.hx @@ -97,8 +97,9 @@ class URLLoader extends EventDispatcher state = urlInit; var pref = request.url.substr(0, 7); - if (pref != "http://" && pref != "https:/") { // local file - + if (request.allowFile && (pref != "http://" && pref != "https:/")) + { + // local file try { var bytes = ByteArray.readFile(request.url); diff --git a/src/nme/net/URLRequest.hx b/src/nme/net/URLRequest.hx index 7380a4ad8..909e5d87e 100644 --- a/src/nme/net/URLRequest.hx +++ b/src/nme/net/URLRequest.hx @@ -25,6 +25,7 @@ class URLRequest public var data:Dynamic; public var credentials:String; public var followRedirects:Bool; + public var allowFile:Bool; /** @private */ public var __bytes:ByteArray; /** @private */ public var nmeBytes(get, set):ByteArray; @@ -41,6 +42,11 @@ class URLRequest verbose = false; cookieString = ""; authType = 0; + #if web + allowFile = false; + #else + allowFile = true; + #end contentType = "application/x-www-form-urlencoded"; credentials = ""; followRedirects = true; diff --git a/tools/nme/src/platforms/EmscriptenPlatform.hx b/tools/nme/src/platforms/EmscriptenPlatform.hx index 11afbbfe3..f715ae3f7 100644 --- a/tools/nme/src/platforms/EmscriptenPlatform.hx +++ b/tools/nme/src/platforms/EmscriptenPlatform.hx @@ -103,9 +103,10 @@ class EmscriptenPlatform extends DesktopPlatform } else { + var verbose = true; var server = new nme.net.http.Server( new nme.net.http.FileServer([FileSystem.fullPath(applicationDirectory) ], - new nme.net.http.StdioHandler( Sys.println ), + new nme.net.http.StdioHandler( Sys.println ), verbose ).onRequest ); var port = 2323; diff --git a/tools/nme/src/project/NMEProject.hx b/tools/nme/src/project/NMEProject.hx index 0842b5002..50bab2219 100644 --- a/tools/nme/src/project/NMEProject.hx +++ b/tools/nme/src/project/NMEProject.hx @@ -181,7 +181,8 @@ class NMEProject public var certificate:Keystore; // Flags - public var embedAssets:Bool; + public var forceEmbedAssets:Bool; + public var defaultEmbedAssets:Bool; public var skipAssets:Bool; public var openflCompat:Bool; public var debug:Bool; @@ -203,7 +204,8 @@ class NMEProject public function new() { baseTemplateContext = {}; - embedAssets = false; + forceEmbedAssets = false; + defaultEmbedAssets = false; skipAssets = false; openflCompat = true; iosConfig = new IOSConfig(); @@ -441,31 +443,29 @@ class NMEProject { case Platform.FLASH: platformType = Platform.TYPE_WEB; - embedAssets = true; + forceEmbedAssets = true; case Platform.CPPIA: platformType = Platform.TYPE_SCRIPT; - embedAssets = false; case Platform.JS: platformType = Platform.TYPE_WEB; - embedAssets = false; case Platform.EMSCRIPTEN, Platform.WASM: platformType = Platform.TYPE_WEB; - embedAssets = true; + defaultEmbedAssets = true; case Platform.JSPRIME, Platform.HTML5: platformType = Platform.TYPE_WEB; - embedAssets = false; + defaultEmbedAssets = true; case Platform.ANDROID, Platform.IOS, Platform.IOSVIEW, Platform.ANDROIDVIEW: platformType = Platform.TYPE_MOBILE; - if (target==Platform.IOSVIEW || target==Platform.ANDROIDVIEW) - embedAssets = true; + if (target==Platform.IOSVIEW || target==Platform.ANDROIDVIEW) + forceEmbedAssets = true; window.width = 0; window.height = 0; @@ -857,7 +857,7 @@ class NMEProject } context.BUILD_DIR = app.binDir; - context.EMBED_ASSETS = embedAssets ? "true" : "false"; + context.EMBED_ASSETS = forceEmbedAssets ? "true" : "false"; context.OPENFL_COMPAT = openflCompat ? "true" : "false"; if (openflCompat) { @@ -945,7 +945,7 @@ class NMEProject asset.alphaMode = defaultMode; asset.preprocess(convertDir); - if ( (embedAssets || asset.embed) && target!=Platform.FLASH && target!=Platform.JSPRIME && target!=Platform.CPPIA) + if ( asset.embed && target!=Platform.FLASH && target!=Platform.JSPRIME && target!=Platform.CPPIA) { asset.resourceName = asset.flatName; //var relPath = PathHelper.relocatePath(asset.sourcePath, inBuildDir); diff --git a/tools/nme/src/project/NMMLParser.hx b/tools/nme/src/project/NMMLParser.hx index 976b6067e..413538d79 100644 --- a/tools/nme/src/project/NMMLParser.hx +++ b/tools/nme/src/project/NMMLParser.hx @@ -298,7 +298,6 @@ class NMMLParser private function parseAssetsElement(element:Access, basePath:String = ""):Void { var path = basePath; - var embed = project.embedAssets; var targetPath = ""; var glyphs = null; var type = null; @@ -328,8 +327,11 @@ class NMMLParser path = project.relocatePath(path); - if (element.has.embed) - embed = embed || parseBool(substitute(element.att.embed)); + var embed = project.defaultEmbedAssets; + if (project.forceEmbedAssets) + embed = true; + else if (element.has.embed) + embed = parseBool(substitute(element.att.embed)); if (element.has.glyphs) glyphs = substitute(element.att.glyphs); @@ -436,7 +438,6 @@ class NMMLParser { var childPath = substitute(childElement.has.name ? childElement.att.name : childElement.att.path); var childTargetPath = childPath; - var childEmbed = embed; var childType = type; var childGlyphs = glyphs; @@ -445,8 +446,11 @@ class NMMLParser if (childElement.has.rename) childTargetPath = childElement.att.rename; - if (childElement.has.embed) - childEmbed = parseBool(substitute(childElement.att.embed)) || project.embedAssets; + var childEmbed = embed; + if (project.forceEmbedAssets) + childEmbed = true; + else if (childElement.has.embed) + childEmbed = parseBool(substitute(childElement.att.embed)); if (childElement.has.glyphs) childGlyphs = substitute(childElement.att.glyphs); @@ -1007,9 +1011,11 @@ class NMMLParser var name = substitute(element.att.path); var id = element.has.id ? substitute(element.att.id) : new Path(name).file; var path = project.relocatePath(name); - var embed = project.embedAssets; - if (element.has.embed) - embed = embed || parseBool(substitute(element.att.embed)); + var embed = project.defaultEmbedAssets; + if (project.forceEmbedAssets) + embed = true; + else if (element.has.embed) + embed = parseBool(substitute(element.att.embed)); var asset = new Asset(path, id, null, embed); //asset.id = id;