Skip to content
27 changes: 17 additions & 10 deletions scripts/Tools.hx
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ class Tools

private static function generateSWFClasses(project:HXProject, output:HXProject, swfAsset:Asset, prefix:String = ""):Array<String>
{
var bitmapDataTemplate = File.getContent(Haxelib.getPath(new Haxelib("swf"), true) + "/templates/swf/BitmapData.mtt");
var movieClipTemplate = File.getContent(Haxelib.getPath(new Haxelib("swf"), true) + "/templates/swf/MovieClip.mtt");
var simpleButtonTemplate = File.getContent(Haxelib.getPath(new Haxelib("swf"), true) + "/templates/swf/SimpleButton.mtt");
var bitmapDataTemplate = File.getContent(Haxelib.getPath(new Haxelib("swf"), true) + "/templates/haxe/BitmapData.mtt");
var movieClipTemplate = File.getContent(Haxelib.getPath(new Haxelib("swf"), true) + "/templates/haxe/MovieClip.mtt");
var simpleButtonTemplate = File.getContent(Haxelib.getPath(new Haxelib("swf"), true) + "/templates/haxe/SimpleButton.mtt");

var bytes = ByteArray.fromBytes(File.getBytes(swfAsset.sourcePath));
bytes = readSWC(bytes);
Expand Down Expand Up @@ -594,10 +594,11 @@ class Tools

var inputPath = words.length > 1 ? words[1] : Sys.getCwd();
var outputPath = words.length > 2 ? words[2] : null;
var language = words.length > 3 ? words[3] : "haxe";

if (words.length < 2 || Path.extension(inputPath) == "swf" || Path.extension(inputPath) == "swc")
if (words.length < 3 || Path.extension(inputPath) == "swf" || Path.extension(inputPath) == "swc")
{
if (words.length > 3)
if (words.length > 4)
{
Log.error("Incorrect number of arguments for command 'process'");
return;
Expand Down Expand Up @@ -638,7 +639,8 @@ class Tools

Log.info("\x1b[1mProcessing file:\x1b[0m " + fileLabel, " - \x1b[1mProcessing file:\x1b[0m " + file + " \x1b[3;37m->\x1b[0m " + output);

processFile(file, output, filePrefix, generate);
var language = "haxe";
processFile(file, output, filePrefix, generate, language);
}
}
else
Expand All @@ -655,7 +657,12 @@ class Tools
outputPath = Path.combine(outputPath, Path.withoutExtension(Path.withoutDirectory(inputPath)) + ".zip");
}

processFile(inputPath, outputPath, filePrefix, generate);
var language = "haxe";
if(words[words.length-1] == "haxe" || words[words.length-1] == "ts" || words[words.length-1] == "as3" || words[words.length-1] == "es5" || words[words.length-1] == "es6")
{
language = words[words.length-1];
}
processFile(inputPath, outputPath, filePrefix, generate, language);
}
}
else if (words.length > 2)
Expand Down Expand Up @@ -749,7 +756,7 @@ class Tools
}
}

private static function processFile(sourcePath:String, targetPath:String, prefix:String = null, generate:Bool = false):Bool
private static function processFile(sourcePath:String, targetPath:String, prefix:String = null, generate:Bool = false, language:String = "haxe"):Bool
{
if (targetPath == null)
{
Expand All @@ -768,7 +775,7 @@ class Tools
var generatePath = Path.tryFullPath(Path.directory(targetPath));

var output = [];
var generatedClasses = exporter.generateClasses("", output, prefix);
var generatedClasses = exporter.generateClasses("", output, language, prefix);

for (asset in output)
{
Expand Down Expand Up @@ -1066,7 +1073,7 @@ class Tools
targetPath = Path.tryFullPath(targetDirectory) + "/haxe/_generated";
}

var generatedClasses = exporter.generateClasses(targetPath, output.assets, library.prefix);
var generatedClasses = exporter.generateClasses(targetPath, output.assets, "haxe", library.prefix);

// for (className in generatedClasses)
// {
Expand Down
20 changes: 12 additions & 8 deletions src/swf/exporters/AnimateLibraryExporter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1133,16 +1133,16 @@ class AnimateLibraryExporter
return;
}

public function generateClasses(targetPath:String, output:Array<Asset>, prefix:String = ""):Array<String>
public function generateClasses(targetPath:String, output:Array<Asset>, language:String = "haxe", prefix:String = ""):Array<String>
{
#if commonjs
var bitmapDataTemplate = File.getContent(Path.combine(js.Node.__dirname, "../templates/animate/BitmapData.mtt"));
var movieClipTemplate = File.getContent(Path.combine(js.Node.__dirname, "../templates/animate/MovieClip.mtt"));
var simpleButtonTemplate = File.getContent(Path.combine(js.Node.__dirname, "../templates/animate/SimpleButton.mtt"));
var bitmapDataTemplate = File.getContent(Path.combine(js.Node.__dirname, "../templates/" + language + "/BitmapData.mtt"));
var movieClipTemplate = File.getContent(Path.combine(js.Node.__dirname, "../templates/" + language + "/MovieClip.mtt"));
var simpleButtonTemplate = File.getContent(Path.combine(js.Node.__dirname, "../templates/" + language + "/SimpleButton.mtt"));
#else
var bitmapDataTemplate = File.getContent(Haxelib.getPath(new Haxelib("swf"), true) + "/templates/animate/BitmapData.mtt");
var movieClipTemplate = File.getContent(Haxelib.getPath(new Haxelib("swf"), true) + "/templates/animate/MovieClip.mtt");
var simpleButtonTemplate = File.getContent(Haxelib.getPath(new Haxelib("swf"), true) + "/templates/animate/SimpleButton.mtt");
var bitmapDataTemplate = File.getContent(Haxelib.getPath(new Haxelib("swf"), true) + "/templates/" + language + "/BitmapData.mtt");
var movieClipTemplate = File.getContent(Haxelib.getPath(new Haxelib("swf"), true) + "/templates/" + language + "/MovieClip.mtt");
var simpleButtonTemplate = File.getContent(Haxelib.getPath(new Haxelib("swf"), true) + "/templates/" + language + "/SimpleButton.mtt");
#end

var generatedClasses = [];
Expand Down Expand Up @@ -1298,9 +1298,13 @@ class AnimateLibraryExporter
context.BASE_CLASS_NAME = baseClassName;
}

var languageExtension:String = ".hx";
if(language == "es5" || language == "es6") languageExtension = ".js";
if(language == "as3") languageExtension = ".as";

var template = new Template(templateData);

var templateFile = new Asset("", Path.combine(Path.combine(targetPath, Path.directory(className.split(".").join("/"))), name + ".hx"),
var templateFile = new Asset("", Path.combine(Path.combine(targetPath, Path.directory(className.split(".").join("/"))), name + languageExtension),
cast AssetType.TEMPLATE);
templateFile.embed = false;
templateFile.data = template.execute(context);
Expand Down
16 changes: 0 additions & 16 deletions templates/animate/BitmapData.mtt

This file was deleted.

18 changes: 0 additions & 18 deletions templates/animate/MovieClip.mtt

This file was deleted.

15 changes: 0 additions & 15 deletions templates/animate/SimpleButton.mtt

This file was deleted.

12 changes: 12 additions & 0 deletions templates/as3/BitmapData.mtt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ::PACKAGE_NAME:: {
import openfl.utils.Assets;
import openfl.display.BitmapData;

public class ::NATIVE_CLASS_NAME:: extends BitmapData {

public function ::NATIVE_CLASS_NAME:: (width:int = 0, height:int = 0, transparent:boolean = false, background:int = 0) {
super (width, height, transparent, background);
}

}
}
15 changes: 15 additions & 0 deletions templates/as3/MovieClip.mtt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ::PACKAGE_NAME:: {
import openfl.utils.Assets;
::if BASE_CLASS_NAME::::else::import openfl.display.MovieClip;::end::

public class ::NATIVE_CLASS_NAME:: extends ::if BASE_CLASS_NAME::::BASE_CLASS_NAME::::else::MovieClip::end:: {

::foreach CLASS_PROPERTIES::public var ::name:::::type::;
::end::

public function ::NATIVE_CLASS_NAME:: () {
super ();
Assets.initBinding("::NATIVE_CLASS_NAME::", this);
}
}
}
12 changes: 12 additions & 0 deletions templates/as3/SimpleButton.mtt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ::PACKAGE_NAME:: {
import openfl.utils.Assets;
::if BASE_CLASS_NAME::::else::import openfl.display.SimpleButton;::end::

public class ::NATIVE_CLASS_NAME:: extends ::if BASE_CLASS_NAME::::BASE_CLASS_NAME::::else::SimpleButton::end:: {

public function ::NATIVE_CLASS_NAME:: () {
super ();
Assets.initBinding("::NATIVE_CLASS_NAME::", this);
}
}
}
18 changes: 18 additions & 0 deletions templates/es5/BitmapData.mtt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use strict"
var Assets = require ("openfl/utils/Assets").default;
var BitmapData = require ("openfl/display/BitmapData").default;

var ::NATIVE_CLASS_NAME:: = (function(width, height, transparent, background) {
width = width || 0;
height = height || 0;
transparent = transparent || false;
background = background || 0;
BitmapData.call (this, width, height, transparent, background);
Assets.initBinding("::NATIVE_CLASS_NAME::", this);
})

::NATIVE_CLASS_NAME::.prototype = Object.create(BitmapData.prototype);
::NATIVE_CLASS_NAME::.prototype.constructor = ::NATIVE_CLASS_NAME::;

module.exports.::NATIVE_CLASS_NAME:: = ::NATIVE_CLASS_NAME::;
module.exports.default = ::NATIVE_CLASS_NAME::;
14 changes: 14 additions & 0 deletions templates/es5/MovieClip.mtt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use strict"
var Assets = require ("openfl/utils/Assets").default;
::if BASE_CLASS_NAME::::else::var MovieClip = require ("openfl/display/MovieClip").default;::end::

var ::NATIVE_CLASS_NAME:: = (function() {
::if BASE_CLASS_NAME::::BASE_CLASS_NAME::::else::MovieClip::end::.call (this);
Assets.initBinding("::NATIVE_CLASS_NAME::", this);
})

::NATIVE_CLASS_NAME::.prototype = Object.create(::if BASE_CLASS_NAME::::BASE_CLASS_NAME::::else::MovieClip::end::.prototype);
::NATIVE_CLASS_NAME::.prototype.constructor = ::NATIVE_CLASS_NAME::;

module.exports.::NATIVE_CLASS_NAME:: = ::NATIVE_CLASS_NAME::;
module.exports.default = ::NATIVE_CLASS_NAME::;
14 changes: 14 additions & 0 deletions templates/es5/SimpleButton.mtt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use strict"
var Assets = require ("openfl/utils/Assets").default;
::if BASE_CLASS_NAME::::else::var SimpleButton = require ("openfl/display/SimpleButton").default;::end::

var ::NATIVE_CLASS_NAME:: = function() {
::if BASE_CLASS_NAME::::BASE_CLASS_NAME::::else::SimpleButton::end::.call (this);
Assets.initBinding("::NATIVE_CLASS_NAME::", this);
}

::NATIVE_CLASS_NAME::.prototype = Object.create(::if BASE_CLASS_NAME::::BASE_CLASS_NAME::::else::SimpleButton::end::.prototype);
::NATIVE_CLASS_NAME::.prototype.constructor = ::NATIVE_CLASS_NAME::;

module.exports.::NATIVE_CLASS_NAME:: = ::NATIVE_CLASS_NAME::;
module.exports.default = ::NATIVE_CLASS_NAME::;
13 changes: 13 additions & 0 deletions templates/es6/BitmapData.mtt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"use strict";
import Assets from "openfl/utils/Assets";
import BitmapData from "openfl/display/BitmapData";

class ::NATIVE_CLASS_NAME:: extends BitmapData {

constructor (width = 0, height = 0, transparent = false, background = 0) {
super (width, height, transparent, background);
Assets.initBinding("::NATIVE_CLASS_NAME::", this);
}

}
export default ::NATIVE_CLASS_NAME::;
17 changes: 17 additions & 0 deletions templates/es6/MovieClip.mtt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict";
import Assets from "openfl/utils/Assets";
::if BASE_CLASS_NAME::::else::import MovieClip from "openfl/display/MovieClip";::end::

class ::NATIVE_CLASS_NAME:: extends ::if BASE_CLASS_NAME::::BASE_CLASS_NAME::::else::MovieClip::end:: {

::foreach CLASS_PROPERTIES::::name::;
::end::

constructor () {
super ();
Assets.initBinding("::NATIVE_CLASS_NAME::", this);
}

}
export default ::NATIVE_CLASS_NAME::;

13 changes: 13 additions & 0 deletions templates/es6/SimpleButton.mtt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"use strict";
import Assets from "openfl/utils/Assets";
::if BASE_CLASS_NAME::::else::import SimpleButton from "openfl/display/SimpleButton";::end::

class ::NATIVE_CLASS_NAME:: extends ::if BASE_CLASS_NAME::::BASE_CLASS_NAME::::else::SimpleButton:: {

constructor () {
super ();
Assets.initBinding("::NATIVE_CLASS_NAME::", this);
}

}
export default ::NATIVE_CLASS_NAME::;
11 changes: 11 additions & 0 deletions templates/haxe/BitmapData.mtt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ::PACKAGE_NAME::;

@:bind @:native("::NATIVE_CLASS_NAME::") class ::CLASS_NAME:: extends openfl.display.BitmapData {

public function new (width:Int = 0, height:Int = 0, transparent:Bool = false, background:Int = 0) {

super (width, height, transparent, background);

}

}
16 changes: 16 additions & 0 deletions templates/haxe/MovieClip.mtt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ::PACKAGE_NAME::;


@:bind @:native("::NATIVE_CLASS_NAME::") class ::CLASS_NAME:: extends ::if BASE_CLASS_NAME::::BASE_CLASS_NAME::::else::#if flash flash.display.MovieClip.MovieClip2 #else openfl.display.MovieClip #end::end::
{

::foreach CLASS_PROPERTIES::@:keep ::if hidden::@:noCompletion @:dox(hide) ::end::public var ::name:: (default, null):::type::;
::end::

public function new () {

super ();

}

}
13 changes: 13 additions & 0 deletions templates/haxe/SimpleButton.mtt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ::PACKAGE_NAME::;

@:bind @:native("::NATIVE_CLASS_NAME::") class ::CLASS_NAME:: extends ::if BASE_CLASS_NAME::::BASE_CLASS_NAME::::else::#if flash flash.display.SimpleButton.SimpleButton2 #else openfl.display.SimpleButton #end::end::
{

public function new () {

super ();

}


}
39 changes: 0 additions & 39 deletions templates/swf/BitmapData.mtt

This file was deleted.

Loading