Skip to content

Commit

Permalink
Draw distinction between assets forceEmbed and defaultEmbed. Assume U…
Browse files Browse the repository at this point in the history
…RL loads from web targets are with http protocol by default
  • Loading branch information
hughsando committed Sep 19, 2024
1 parent 0057c6d commit eef58ef
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 23 deletions.
5 changes: 3 additions & 2 deletions src/nme/net/URLLoader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions src/nme/net/URLRequest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion tools/nme/src/platforms/EmscriptenPlatform.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 11 additions & 11 deletions tools/nme/src/project/NMEProject.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -203,7 +204,8 @@ class NMEProject
public function new()
{
baseTemplateContext = {};
embedAssets = false;
forceEmbedAssets = false;
defaultEmbedAssets = false;
skipAssets = false;
openflCompat = true;
iosConfig = new IOSConfig();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down
24 changes: 15 additions & 9 deletions tools/nme/src/project/NMMLParser.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit eef58ef

Please sign in to comment.