Files
lime/tools/platforms/TizenPlatform.hx
Joseph Cloutier 31af41e69c Unify asset copying code, and standardize asset embedding.
Having eight separate implementations made it harder to maintain. While an asset embedding bug got fixed on desktop targets, it got overlooked on others. This lead to assets being included twice on those other targets: once embedded, and once normally. (#1898) Now, that behavior is controlled from one place, and the bug is fixed for eight targets at once.

This also standardizes the case of `asset.embed == true && asset.type == TEMPLATE`. Previously, some targets would prioritze `embed` over `type`, embedding the template into the app without even processing it as a template. Now, it will always prioritize `type`, processing templates as templates and never trying to embed them.

Three targets are left out since they have more complex asset embedding behavior. I haven't checked if the bug is present on any of those.
2025-08-31 22:07:10 -04:00

257 lines
6.1 KiB
Haxe

package;
import hxp.HXML;
import hxp.Path;
import hxp.System;
import lime.tools.Architecture;
import lime.tools.AssetHelper;
import lime.tools.AssetType;
import lime.tools.CPPHelper;
import lime.tools.DeploymentHelper;
import lime.tools.HXProject;
import lime.tools.Icon;
import lime.tools.IconHelper;
import lime.tools.PlatformTarget;
import lime.tools.ProjectHelper;
import lime.tools.TizenHelper;
import sys.io.File;
import sys.FileSystem;
class TizenPlatform extends PlatformTarget
{
private static var uuid:String = null;
public function new(command:String, _project:HXProject, targetFlags:Map<String, String>)
{
super(command, _project, targetFlags);
var defaults = new HXProject();
defaults.meta =
{
title: "MyApplication",
description: "",
packageName: "com.example.myapp",
version: "1.0.0",
company: "",
companyUrl: "",
buildNumber: null,
companyId: ""
};
defaults.app =
{
main: "Main",
file: "MyApplication",
path: "bin",
preloader: "",
swfVersion: 17,
url: "",
init: null
};
defaults.window =
{
width: 800,
height: 600,
parameters: "{}",
background: 0xFFFFFF,
fps: 30,
hardware: true,
display: 0,
resizable: true,
borderless: false,
orientation: Orientation.AUTO,
vsync: false,
fullscreen: false,
allowHighDPI: true,
alwaysOnTop: false,
antialiasing: 0,
allowShaders: true,
requireShaders: false,
depthBuffer: true,
stencilBuffer: true,
colorDepth: 32,
maximized: false,
minimized: false,
hidden: false,
title: ""
};
defaults.architectures = [Architecture.ARMV6];
defaults.window.width = 0;
defaults.window.height = 0;
defaults.window.fullscreen = true;
defaults.window.requireShaders = true;
= defaults.window.allowHighDPI = false;
for (i in 1...project.windows.length)
{
defaults.windows.push(defaults.window);
}
defaults.merge(project);
project = defaults;
for (excludeArchitecture in project.excludeArchitectures)
{
project.architectures.remove(excludeArchitecture);
}
targetDirectory = Path.combine(project.app.path, project.config.getString("tizen.output-directory", "tizen"));
}
public override function build():Void
{
var destination = targetDirectory + "/bin/";
var arch = "";
if (project.targetFlags.exists("simulator"))
{
arch = "-x86";
}
for (ndll in project.ndlls)
{
ProjectHelper.copyLibrary(project, ndll, "Tizen", "", arch + ".so", destination + "lib/", project.debug, ".so");
}
var hxml = targetDirectory + "/haxe/" + buildType + ".hxml";
System.runCommand("", "haxe", [hxml, "-D", "tizen"]);
if (noOutput) return;
var args = ["-Dtizen", "-DAPP_ID=" + TizenHelper.getUUID(project)];
if (project.targetFlags.exists("simulator"))
{
args.push("-Dsimulator");
}
CPPHelper.compile(project, targetDirectory + "/obj", args);
System.copyIfNewer(targetDirectory
+ "/obj/ApplicationMain"
+ (project.debug ? "-debug" : "")
+ ".exe",
targetDirectory
+ "/bin/CommandLineBuild/"
+ project.app.file
+ ".exe");
TizenHelper.createPackage(project, targetDirectory + "/bin/CommandLineBuild", "");
}
public override function clean():Void
{
if (FileSystem.exists(targetDirectory))
{
System.removeDirectory(targetDirectory);
}
}
public override function deploy():Void
{
DeploymentHelper.deploy(project, targetFlags, targetDirectory, "Tizen");
}
public override function display():Void
{
var path = targetDirectory + "/haxe/" + buildType + ".hxml";
if (FileSystem.exists(path))
{
return File.getContent(path);
}
else
{
var context = project.templateContext;
var hxml = new HXML();
hxml.noOutput = true;
hxml.cpp = "_";
return context.HAXE_FLAGS + "\n" + hxml.toString();
}
}
public override function rebuild():Void
{
var device = (command == "rebuild" || !targetFlags.exists("simulator"));
var simulator = (command == "rebuild" || targetFlags.exists("simulator"));
var commands = [];
if (device) commands.push(["-Dtizen"]);
if (simulator) commands.push(["-Dtizen", "-Dsimulator"]);
CPPHelper.rebuild(project, commands);
}
public override function run():Void
{
TizenHelper.install(project, targetDirectory + "/bin/CommandLineBuild");
TizenHelper.launch(project);
}
public override function trace():Void
{
TizenHelper.trace(project);
}
public override function update():Void
{
AssetHelper.processLibraries(project, targetDirectory);
// project = project.clone ();
var destination = targetDirectory + "/bin/";
System.mkdir(destination);
for (asset in project.assets)
{
asset.resourceName = "../res/" + asset.resourceName;
}
if (project.targetFlags.exists("xml"))
{
project.haxeflags.push("-xml " + targetDirectory + "/types.xml");
}
if (project.targetFlags.exists("json"))
{
project.haxeflags.push("--json " + targetDirectory + "/types.json");
}
var context = project.templateContext;
context.CPP_DIR = targetDirectory + "/obj";
context.OUTPUT_DIR = targetDirectory;
context.APP_PACKAGE = TizenHelper.getUUID(project);
context.SIMULATOR = project.targetFlags.exists("simulator");
System.mkdir(destination + "shared/res/screen-density-xhigh");
var icons = project.icons;
if (icons.length == 0)
{
icons = [new Icon(System.findTemplate(project.templatePaths, "default/icon.svg"))];
}
if (IconHelper.createIcon(icons, 117, 117, Path.combine(destination + "shared/res/screen-density-xhigh", "mainmenu.png")))
{
context.APP_ICON = "mainmenu.png";
}
ProjectHelper.recursiveSmartCopyTemplate(project, "tizen/template", destination, context);
ProjectHelper.recursiveSmartCopyTemplate(project, "haxe", targetDirectory + "/haxe", context);
ProjectHelper.recursiveSmartCopyTemplate(project, "tizen/hxml", targetDirectory + "/haxe", context);
// going to root directory now, but should it be a forced "assets" folder later?
copyProjectAssets(destination + "res/", "");
// copyProjectAssets(destination + "res/", "assets");
}
@ignore public override function install():Void {}
@ignore public override function uninstall():Void {}
}