Browse Source

Added enums support. Did some cleanup. Module folder will be automatically created if it needs.

rsredsq 10 years ago
parent
commit
8e07d97789

File diff suppressed because it is too large
+ 1257 - 1421
Script/Haxe/Atomic.hx


+ 20 - 24
Script/Haxe/Editor.hx

@@ -1,34 +1,30 @@
 package atomic;
 package atomic;
 
 
-
-   // enum EditMode
-typedef EditMode = Int;
-
-   // enum AxisMode
-typedef AxisMode = Int;
+@:native("Atomic")
+extern enum EditMode {
+    EDIT_SELECT;
+    EDIT_MOVE;
+    EDIT_ROTATE;
+    EDIT_SCALE;
+}
+@:native("Atomic")
+extern enum AxisMode {
+    AXIS_WORLD;
+    AXIS_LOCAL;
+}
 //Atomic Haxe Definitions
 //Atomic Haxe Definitions
 
 
 extern class Editor {
 extern class Editor {
 
 
 
 
-   // enum EditMode
-    public static var EDIT_SELECT:EditMode;
-    public static var EDIT_MOVE:EditMode;
-    public static var EDIT_ROTATE:EditMode;
-    public static var EDIT_SCALE:EditMode;
-
-   // enum AxisMode
-    public static var AXIS_WORLD:AxisMode;
-    public static var AXIS_LOCAL:AxisMode;
-
-   public static var FINDTEXT_FLAG_NONE: Int;
-   public static var FINDTEXT_FLAG_CASESENSITIVE: Int;
-   public static var FINDTEXT_FLAG_WHOLEWORD: Int;
-   public static var FINDTEXT_FLAG_WRAP: Int;
-   public static var FINDTEXT_FLAG_NEXT: Int;
-   public static var FINDTEXT_FLAG_PREV: Int;
-   public static var EDITOR_MODALERROR: Int;
-   public static var EDITOR_MODALINFO: Int;
+    public static var FINDTEXT_FLAG_NONE: Int;
+    public static var FINDTEXT_FLAG_CASESENSITIVE: Int;
+    public static var FINDTEXT_FLAG_WHOLEWORD: Int;
+    public static var FINDTEXT_FLAG_WRAP: Int;
+    public static var FINDTEXT_FLAG_NEXT: Int;
+    public static var FINDTEXT_FLAG_PREV: Int;
+    public static var EDITOR_MODALERROR: Int;
+    public static var EDITOR_MODALINFO: Int;
 
 
 
 
 }
 }

+ 7 - 0
Script/Haxe/HaxeTest/Resources/Components/Color.js.asset

@@ -0,0 +1,7 @@
+{
+	"version": 1,
+	"guid": "3e361e9464ebd64db3310628649fc16c",
+	"JavascriptImporter": {
+		"IsComponentFile": false
+	}
+}

+ 30 - 0
Script/Haxe/HaxeTest/Resources/Components/Player.hx

@@ -0,0 +1,30 @@
+package components;
+
+import atomic.Atomic;
+
+class Player extends JSComponent {
+	
+	var pos:Vector2;
+	var speed:Float = 0.05;
+	var c:Float->Float;
+	var time:Float;
+	
+	function start() {
+		pos = node.position2D;
+	}
+	
+	function update(time:Float) {
+		this.time += time;
+        onKeyDown();
+		trace(c(this.time));
+		node.position2D = pos;
+    }
+
+    function onKeyDown():Void {
+        if (Atomic.input.getKeyDown(Atomic.KEY_LEFT)) {
+			//pos.x -= speed
+			pos[0] -= speed;
+        }
+    }
+	
+}

+ 28 - 0
Script/Haxe/HaxeTest/Resources/Components/Player.js

@@ -0,0 +1,28 @@
+"atomic component";
+var __extends = (this && this.__extends) || function (d, b) {for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];function __() { this.constructor = d; };__.prototype = b.prototype;d.prototype = new __();};
+var Player = (function(_super) {
+__extends(Player, _super);
+function Player () {
+	this.speed = 0.05;
+	Atomic.JSComponent.call(this);
+};
+Player.prototype.pos = null;
+Player.prototype.speed = null;
+Player.prototype.c = null;
+Player.prototype.time = null;
+Player.prototype.start = function() {
+	this.pos = this.node.position2D;
+};
+Player.prototype.update = function(time) {
+	this.time += time;
+	this.onKeyDown();
+	console.log(this.c(this.time));
+	this.node.position2D = this.pos;
+};
+Player.prototype.onKeyDown = function() {
+	if(Atomic.input.getKeyDown(Atomic.KEY_LEFT)) this.pos[0] -= this.speed;
+};
+;
+return Player;
+})(Atomic.JSComponent);
+module.exports = Player;

+ 7 - 0
Script/Haxe/HaxeTest/Resources/Components/Player.js.asset

@@ -0,0 +1,7 @@
+{
+	"version": 1,
+	"guid": "7684e34c8c3b09091020d329cb7e0757",
+	"JavascriptImporter": {
+		"IsComponentFile": true
+	}
+}

+ 19 - 9
Script/Haxe/HaxeTest/Resources/Components/Star.hx

@@ -9,19 +9,29 @@ class Star extends JSComponent {
 	function new() {
 	function new() {
 		super();
 		super();
 		speed = 1;
 		speed = 1;
-		var type:Stars = Stars.RandomStar;
-	}
+		var color = getColor();
+		switch (color) {
+		  case Red: trace("Color was red");
+		  case Green: trace("Color was green");
+		  case Blue: trace("Color was blue");
+		  case Rgb(r, g, b): trace('r: $r, g: $g, b: $b');
+		}
+	  }
+
+	  static function getColor():Color {
+		return Color.Rgb(255, 0, 255);
+	  }
 
 
 	function update(timeStep:Float):Void {
 	function update(timeStep:Float):Void {
 		this.node.rotate2D(speed);
 		this.node.rotate2D(speed);
-		this.node.rotateAround2D([1, 1], timeStep * 50, Atomic.TS_WORLD);
+		this.node.rotateAround2D([1, 1], timeStep * 50, TransformSpace.TS_WORLD);
 	}
 	}
 }
 }
 
 
-//Enums are not working yet
-enum Stars {
-	RandomStar;
-	JustAStar;
-	SimpleStar;
-	NotAStar;
+//Just a test of enums
+enum Color {
+  Red;
+  Green;
+  Blue;
+  Rgb(r:Int, g:Int, b:Int);
 }
 }

+ 23 - 2
Script/Haxe/HaxeTest/Resources/Components/Star.js

@@ -1,11 +1,32 @@
-var Stars = require("./Stars");
+var Color = require("modules/Color");
+"atomic component";
 var __extends = (this && this.__extends) || function (d, b) {for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];function __() { this.constructor = d; };__.prototype = b.prototype;d.prototype = new __();};
 var __extends = (this && this.__extends) || function (d, b) {for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];function __() { this.constructor = d; };__.prototype = b.prototype;d.prototype = new __();};
 var Star = (function(_super) {
 var Star = (function(_super) {
 __extends(Star, _super);
 __extends(Star, _super);
 function Star () {
 function Star () {
 	Atomic.JSComponent.call(this);
 	Atomic.JSComponent.call(this);
 	this.speed = 1;
 	this.speed = 1;
-	var type = Stars.RandomStar;
+	var color = Star.getColor();
+	switch(color[1]) {
+	case 0:
+		console.log("Color was red");
+		break;
+	case 1:
+		console.log("Color was green");
+		break;
+	case 2:
+		console.log("Color was blue");
+		break;
+	case 3:
+		var b = color[4];
+		var g = color[3];
+		var r = color[2];
+		console.log("r: " + r + ", g: " + g + ", b: " + b);
+		break;
+	}
+};
+Star.getColor = function() {
+	return Color.Rgb(255,0,255);
 };
 };
 Star.prototype.speed = null;
 Star.prototype.speed = null;
 Star.prototype.update = function(timeStep) {
 Star.prototype.update = function(timeStep) {

+ 5 - 0
Script/Haxe/HaxeTest/Resources/Components/SuperStar.hx

@@ -4,6 +4,11 @@ import components.Star;
 
 
 class SuperStar extends Star {
 class SuperStar extends Star {
 	
 	
+	function new(a:Int) {
+		super();
+		trace(a);
+	}
+	
 	function start():Void {
 	function start():Void {
 		node.scale2D = [2, 2];
 		node.scale2D = [2, 2];
 	}
 	}

+ 3 - 1
Script/Haxe/HaxeTest/Resources/Components/SuperStar.js

@@ -1,9 +1,11 @@
 var Star = require("components/Star");
 var Star = require("components/Star");
+"atomic component";
 var __extends = (this && this.__extends) || function (d, b) {for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];function __() { this.constructor = d; };__.prototype = b.prototype;d.prototype = new __();};
 var __extends = (this && this.__extends) || function (d, b) {for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];function __() { this.constructor = d; };__.prototype = b.prototype;d.prototype = new __();};
 var SuperStar = (function(_super) {
 var SuperStar = (function(_super) {
 __extends(SuperStar, _super);
 __extends(SuperStar, _super);
-function SuperStar () {
+function SuperStar (a) {
 	Star.call(this);
 	Star.call(this);
+	console.log(a);
 };
 };
 SuperStar.prototype.start = function() {
 SuperStar.prototype.start = function() {
 	this.node.scale2D = [2,2];
 	this.node.scale2D = [2,2];

+ 7 - 0
Script/Haxe/HaxeTest/Resources/Components/addit/MegaColor.js.asset

@@ -0,0 +1,7 @@
+{
+	"version": 1,
+	"guid": "d3704fbb4ce1f9fcd4831fc65975184c",
+	"JavascriptImporter": {
+		"IsComponentFile": false
+	}
+}

+ 26 - 0
Script/Haxe/HaxeTest/Resources/Components/addit/MegaStar.hx

@@ -1,11 +1,19 @@
 package components.addit;
 package components.addit;
 
 
+import atomic.Atomic;
 import components.SuperStar;
 import components.SuperStar;
 import scripts.utils.Loler;
 import scripts.utils.Loler;
 
 
 class MegaStar extends SuperStar {
 class MegaStar extends SuperStar {
+	
+	var pos:Vector2;
+	
+	function new() {
+		super(0);
+	}
 
 
 	override function start() {
 	override function start() {
+		pos = node.position2D;
 		var lol:Loler = new Loler("lol");
 		var lol:Loler = new Loler("lol");
 		var nlol:Loler = new Loler("foo");
 		var nlol:Loler = new Loler("foo");
 		node.scale2D = [4, 4];
 		node.scale2D = [4, 4];
@@ -13,6 +21,24 @@ class MegaStar extends SuperStar {
 		var str:String = "ReplAce me :)";
 		var str:String = "ReplAce me :)";
 		str = StringTools.replace(str, "Ace", "LOL");
 		str = StringTools.replace(str, "Ace", "LOL");
 		trace(str);
 		trace(str);
+		
+		var c:MegaColor = MegaColor.Supa;
+	}
+	
+	override function update(time:Float) {
+		super.update(time);
+		onKeyDown();
 	}
 	}
+	
+	function onKeyDown():Void {
+		if (Atomic.input.getKeyDown(Atomic.KEY_LEFT)) {
+			pos[0] -= 0.5;
+		}
+		node.position2D = pos;
+	}
+}
 
 
+enum MegaColor {
+	Supa;
+	NotSupa;
 }
 }

+ 15 - 2
Script/Haxe/HaxeTest/Resources/Components/addit/MegaStar.js

@@ -1,19 +1,32 @@
-var StringTools = require("Modules/StringTools");
+var MegaColor = require("modules/MegaColor");
+var StringTools = require("modules/StringTools");
 var Loler = require("scripts/utils/Loler");
 var Loler = require("scripts/utils/Loler");
 var SuperStar = require("components/SuperStar");
 var SuperStar = require("components/SuperStar");
+"atomic component";
 var __extends = (this && this.__extends) || function (d, b) {for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];function __() { this.constructor = d; };__.prototype = b.prototype;d.prototype = new __();};
 var __extends = (this && this.__extends) || function (d, b) {for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];function __() { this.constructor = d; };__.prototype = b.prototype;d.prototype = new __();};
 var MegaStar = (function(_super) {
 var MegaStar = (function(_super) {
 __extends(MegaStar, _super);
 __extends(MegaStar, _super);
 function MegaStar () {
 function MegaStar () {
-	SuperStar.call(this);
+	SuperStar.call(this,0);
 };
 };
+MegaStar.prototype.pos = null;
 MegaStar.prototype.start = function() {
 MegaStar.prototype.start = function() {
+	this.pos = this.node.position2D;
 	var lol = new Loler("lol");
 	var lol = new Loler("lol");
 	var nlol = new Loler("foo");
 	var nlol = new Loler("foo");
 	this.node.scale2D = [4,4];
 	this.node.scale2D = [4,4];
 	var str = "ReplAce me :)";
 	var str = "ReplAce me :)";
 	str = StringTools.replace(str,"Ace","LOL");
 	str = StringTools.replace(str,"Ace","LOL");
 	console.log(str);
 	console.log(str);
+	var c = MegaColor.Supa;
+};
+MegaStar.prototype.update = function(time) {
+	SuperStar.prototype.update.call(this,time);
+	this.onKeyDown();
+};
+MegaStar.prototype.onKeyDown = function() {
+	if(Atomic.input.getKeyDown(Atomic.KEY_LEFT)) this.pos[0] -= 0.5;
+	this.node.position2D = this.pos;
 };
 };
 ;
 ;
 return MegaStar;
 return MegaStar;

+ 1 - 1
Script/Haxe/HaxeTest/Resources/Modules.asset

@@ -1,5 +1,5 @@
 {
 {
 	"version": 1,
 	"version": 1,
-	"guid": "7bde4142bf0ce00d3e9a6b0696ebc0d0",
+	"guid": "ec08de5e80108e4580d497706d9e2571",
 	"FolderImporter": {}
 	"FolderImporter": {}
 }
 }

+ 0 - 76
Script/Haxe/HaxeTest/Resources/Modules/Boot.js

@@ -1,76 +0,0 @@
-var String = require("Modules/String");
-var __extends = (this && this.__extends) || function (d, b) {for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];function __() { this.constructor = d; };__.prototype = b.prototype;d.prototype = new __();};
-var Boot = (function(_super) {
-__extends(Boot, _super);
-function Boot (){};
-Boot.__string_rec = function(o,s) {
-	if(o == null) return "null";
-	if(s.length >= 5) return "<...>";
-	var t = typeof(o);
-	if(t == "function" && (o.__name__ || o.__ename__)) t = "object";
-	switch(t) {
-	case "object":
-		if(o instanceof Array) {
-			if(o.__enum__) {
-				if(o.length == 2) return o[0];
-				var str2 = o[0] + "(";
-				s += "\t";
-				var _g1 = 2;
-				var _g = o.length;
-				while(_g1 < _g) {
-					var i1 = _g1++;
-					if(i1 != 2) str2 += "," + Boot.__string_rec(o[i1],s); else str2 += Boot.__string_rec(o[i1],s);
-				}
-				return str2 + ")";
-			}
-			var l = o.length;
-			var i;
-			var str1 = "[";
-			s += "\t";
-			var _g2 = 0;
-			while(_g2 < l) {
-				var i2 = _g2++;
-				str1 += (i2 > 0?",":"") + Boot.__string_rec(o[i2],s);
-			}
-			str1 += "]";
-			return str1;
-		}
-		var tostr;
-		try {
-			tostr = o.toString;
-		} catch( e ) {
-			return "???";
-		}
-		if(tostr != null && tostr != Object.toString && typeof(tostr) == "function") {
-			var s2 = o.toString();
-			if(s2 != "[object Object]") return s2;
-		}
-		var k = null;
-		var str = "{\n";
-		s += "\t";
-		var hasp = o.hasOwnProperty != null;
-		for( var k in o ) {
-		if(hasp && !o.hasOwnProperty(k)) {
-			continue;
-		}
-		if(k == "prototype" || k == "__class__" || k == "__super__" || k == "__interfaces__" || k == "__properties__") {
-			continue;
-		}
-		if(str.length != 2) str += ", \n";
-		str += s + k + " : " + Boot.__string_rec(o[k],s);
-		}
-		s = s.substring(1);
-		str += "\n" + s + "}";
-		return str;
-	case "function":
-		return "<function>";
-	case "string":
-		return o;
-	default:
-		return String(o);
-	}
-};
-;
-return Boot;
-})(Object);
-module.exports = Boot;

+ 0 - 8
Script/Haxe/HaxeTest/Resources/Modules/Std.js

@@ -1,8 +0,0 @@
-var __extends = (this && this.__extends) || function (d, b) {for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];function __() { this.constructor = d; };__.prototype = b.prototype;d.prototype = new __();};
-var Std = (function(_super) {
-__extends(Std, _super);
-function Std (){};
-;
-return Std;
-})(Object);
-module.exports = Std;

+ 0 - 11
Script/Haxe/HaxeTest/Resources/Modules/StringTools.js

@@ -1,11 +0,0 @@
-var __extends = (this && this.__extends) || function (d, b) {for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];function __() { this.constructor = d; };__.prototype = b.prototype;d.prototype = new __();};
-var StringTools = (function(_super) {
-__extends(StringTools, _super);
-function StringTools (){};
-StringTools.replace = function(s,sub,by) {
-	return s.split(sub).join(by);
-};
-;
-return StringTools;
-})(Object);
-module.exports = StringTools;

+ 3 - 3
Script/Haxe/HaxeTest/Resources/Scenes/Scene.scene

@@ -5,8 +5,8 @@
 	<attribute name="Smoothing Constant" value="50" />
 	<attribute name="Smoothing Constant" value="50" />
 	<attribute name="Snap Threshold" value="5" />
 	<attribute name="Snap Threshold" value="5" />
 	<attribute name="Elapsed Time" value="0" />
 	<attribute name="Elapsed Time" value="0" />
-	<attribute name="Next Replicated Node ID" value="371" />
-	<attribute name="Next Replicated Component ID" value="1985" />
+	<attribute name="Next Replicated Node ID" value="373" />
+	<attribute name="Next Replicated Component ID" value="1987" />
 	<attribute name="Next Local Node ID" value="16778496" />
 	<attribute name="Next Local Node ID" value="16778496" />
 	<attribute name="Next Local Component ID" value="16777216" />
 	<attribute name="Next Local Component ID" value="16777216" />
 	<attribute name="Variables" />
 	<attribute name="Variables" />
@@ -39,7 +39,7 @@
 			<attribute name="Sprite" value="Sprite2D;Sprites/star.png" />
 			<attribute name="Sprite" value="Sprite2D;Sprites/star.png" />
 		</component>
 		</component>
 		<component type="JSComponent" id="1977">
 		<component type="JSComponent" id="1977">
-			<attribute name="ComponentFile" value="JSComponentFile;Components/addit/MegaStar.js" />
+			<attribute name="ComponentFile" value="JSComponentFile;components/Player.js" />
 		</component>
 		</component>
 	</node>
 	</node>
 </scene>
 </scene>

+ 1 - 0
Script/Haxe/HaxeTest/Resources/Scripts/Main.hx

@@ -5,6 +5,7 @@ import atomic.Atomic;
 import components.Star;
 import components.Star;
 import components.SuperStar;
 import components.SuperStar;
 import components.addit.MegaStar;
 import components.addit.MegaStar;
+import components.Player;
 
 
 class Main {
 class Main {
 
 

File diff suppressed because it is too large
+ 1257 - 1421
Script/Haxe/HaxeTest/Resources/atomic/Atomic.hx


+ 63 - 47
Script/Haxe/HaxeTest/Resources/atomic/AtomicBuilder.hx

@@ -1,12 +1,11 @@
 package atomic;
 package atomic;
 
 
 import haxe.macro.Compiler;
 import haxe.macro.Compiler;
-import haxe.macro.Context;
 import haxe.macro.ExampleJSGenerator;
 import haxe.macro.ExampleJSGenerator;
 import haxe.macro.JSGenApi;
 import haxe.macro.JSGenApi;
-import haxe.macro.PositionTools;
 import haxe.macro.Type;
 import haxe.macro.Type;
 import haxe.macro.Expr;
 import haxe.macro.Expr;
+import sys.FileSystem;
 import sys.io.File;
 import sys.io.File;
 
 
 class AtomicBuilder {
 class AtomicBuilder {
@@ -16,8 +15,11 @@ class AtomicBuilder {
 	var statics : List<{ c : ClassType, f : ClassField }>;
 	var statics : List<{ c : ClassType, f : ClassField }>;
 	var requirements: Map<String, Array<String>>;
 	var requirements: Map<String, Array<String>>;
 	var currClass:BaseType;
 	var currClass:BaseType;
+	var isEnum:Bool;
 	var components:List<ClassType>;
 	var components:List<ClassType>;
 	var enums:List<EnumType>;
 	var enums:List<EnumType>;
+	static var reservedWords:Array<String> = ['Math', 'Array', 'Date', 'Enum', 'Class', 'Dynamic', 'Bool', 'Float', 'Int', 'String', 'Error'];
+	
 	
 	
 	function new(api:JSGenApi) {
 	function new(api:JSGenApi) {
 		this.api = api;
 		this.api = api;
@@ -44,7 +46,7 @@ class AtomicBuilder {
 	}
 	}
 	
 	
 	//n is a type, 0 - inst, 1 - enum, 2 - abstract
 	//n is a type, 0 - inst, 1 - enum, 2 - abstract
-	function getPath(t : BaseType, ?n: Int) {
+	function getPath(t : BaseType, ?nt: Int) {
 		var s:Array<String> = t.module.split(".");
 		var s:Array<String> = t.module.split(".");
 		if (s[0].toLowerCase() == "atomic") {
 		if (s[0].toLowerCase() == "atomic") {
 			if (StringTools.startsWith(t.name, "Atomic")) {
 			if (StringTools.startsWith(t.name, "Atomic")) {
@@ -55,22 +57,22 @@ class AtomicBuilder {
 		//skip to do not require itself
 		//skip to do not require itself
 		if (t.name == currClass.name) return t.name;
 		if (t.name == currClass.name) return t.name;
 		var mod = t.module.split(".");
 		var mod = t.module.split(".");
+		var n = "";
 		//it it's enum
 		//it it's enum
-		if (n == 1) {
-			addReq("./" + t.name);
+		//if it's an enum inside of class
+		if (nt == 1) {
+			//var i = 0;
+			//for (i in 0...(mod.length - 1)) {
+			//	n += mod[i] + "/"; 
+			//}
+			
+			addReq("modules/" + t.name);
+			return t.name;
 		}
 		}
-		if (mod[0].toLowerCase() == "scripts") {
-			var n = "";
-			for (pa in mod) {
-				if (mod[0] == pa) {
-					n += pa;
-					continue;
-				}
-				n += "/" + pa;
-			}
-			addReq(n);
-		} else if (mod[0].toLowerCase() == "components") {
-			var n = "";
+		//check if it's a script or a component
+		//probably I should rework it, to make components and scripts works with metadata, such like:
+		//@:AtomicComponent or @:AtomicScript
+		if (mod[0] == "scripts" || mod[0] == "components") {	
 			for (pa in mod) {
 			for (pa in mod) {
 				if (mod[0] == pa) {
 				if (mod[0] == pa) {
 					n += pa;
 					n += pa;
@@ -80,7 +82,7 @@ class AtomicBuilder {
 			}
 			}
 			addReq(n);
 			addReq(n);
 		} else {
 		} else {
-			addReq("Modules/" + t.name);
+			addReq("modules/" + t.name);
 		}
 		}
 		return t.name;
 		return t.name;
 	}
 	}
@@ -159,6 +161,8 @@ class AtomicBuilder {
 			var name = a[a.length - 1];
 			var name = a[a.length - 1];
 			//TODO fix that check
 			//TODO fix that check
 			if (name == currClass.name) continue;
 			if (name == currClass.name) continue;
+			//exclude reservedWords
+			if (reservedWords.indexOf(name) >= 0) continue;
 			prepend("var " + name + " = require(\"" + req + "\");\n");
 			prepend("var " + name + " = require(\"" + req + "\");\n");
 		}
 		}
 	}
 	}
@@ -204,46 +208,39 @@ class AtomicBuilder {
 	
 	
 	function genScript(c: ClassType):Void {
 	function genScript(c: ClassType):Void {
 		genClassBoody(c);
 		genClassBoody(c);
-		var p = "";
-		//script path
-		if (c.pack.length > 0 && c.pack[0].toLowerCase() == "scripts") {
-			for (pa in c.pack) {
-				p += pa + "/";
-			}
-			p += c.name + ".js";
-		} else {
-			p = "Modules/" + c.name + ".js";
-		}
-		File.saveContent(p, buf.toString());
-		buf = new StringBuf();
+		writeFile();
 	}
 	}
 	
 	
 	function genComponent(c: ClassType):Void {
 	function genComponent(c: ClassType):Void {
+		print("\"atomic component\"");
+		newline();
 		genClassBoody(c);
 		genClassBoody(c);
-		var p = "";
-		for (pa in c.pack) {
-			p += pa + "/";
-		}
-		p += c.name + ".js";
-		File.saveContent(p, buf.toString());
-		buf = new StringBuf();
+		writeFile();
 	}
 	}
 	
 	
-	function genEnum( e : EnumType ) {
+	function genEnum(e: EnumType) {
 		currClass = e;
 		currClass = e;
-		//api.setCurrentClass(e);
+		isEnum = true;
+		var p = getPath(e);
 		print('var ${e.name}');
 		print('var ${e.name}');
 		newline();
 		newline();
 		print('(function (${e.name}) {\n');
 		print('(function (${e.name}) {\n');
-		//TODO generate enum statements
-		print('})(${e.name} || (${e.name} = {}));');
-		var p = "";
-		for (pa in e.pack) {
-			p += pa + "/";
+		var constructs = e.names.map(api.quoteString).join(",");
+		for( c in e.constructs.keys() ) {
+			var c = e.constructs.get(c);
+			var f = c.name;
+			print('$p.$f = ');
+			switch( c.type ) {
+			case TFun(args, _):
+				var sargs = args.map(function(a) return a.name).join(",");
+				print('function($sargs) { var $$me = ["${c.name}",${c.index},$sargs]; return $$me; };\n');
+			default:
+				print("[" + api.quoteString(c.name) + "," + c.index + "];\n");
+			}
 		}
 		}
-		p += e.name + ".js";
-		File.saveContent(p, buf.toString());
-		buf = new StringBuf();
+		print('})(${e.name} || (${e.name} = {}));\n');
+		print('module.exports = ${e.name};\n');
+		writeFile();
 	}
 	}
 	
 	
 	function genStaticField(c: ClassType, f: ClassField):Void {
 	function genStaticField(c: ClassType, f: ClassField):Void {
@@ -282,6 +279,25 @@ class AtomicBuilder {
 		newline();
 		newline();
 	}
 	}
 	
 	
+	//saves current buffer to file and then clears buffer
+	function writeFile():Void {
+		var path = "";
+		if (currClass.pack.length > 0 && (currClass.pack[0].toLowerCase() == "scripts" || currClass.pack[0].toLowerCase() == "components") && !isEnum) {
+			for (p in currClass.pack) {
+				path += p + "/";
+			}
+		} else {
+			path = "modules/";
+		}
+		if (!FileSystem.exists(path)) {
+			FileSystem.createDirectory(path);
+		}
+		path += currClass.name + ".js";
+		File.saveContent(path, buf.toString());
+		buf = new StringBuf();
+		isEnum = false;
+	}
+	
 	static function use() {
 	static function use() {
 		Compiler.setCustomJSGenerator(function(_api) {
 		Compiler.setCustomJSGenerator(function(_api) {
 			new AtomicBuilder(_api);
 			new AtomicBuilder(_api);

+ 10 - 12
Script/Haxe/ToolCore.hx

@@ -1,22 +1,20 @@
 package atomic;
 package atomic;
 
 
-
-   // enum PlatformID
-typedef PlatformID = Int;
+@:native("Atomic")
+extern enum PlatformID {
+    PLATFORMID_UNDEFINED;
+    PLATFORMID_WINDOWS;
+    PLATFORMID_MAC;
+    PLATFORMID_ANDROID;
+    PLATFORMID_IOS;
+    PLATFORMID_WEB;
+}
 //Atomic Haxe Definitions
 //Atomic Haxe Definitions
 
 
 extern class ToolCore {
 extern class ToolCore {
 
 
 
 
-   // enum PlatformID
-    public static var PLATFORMID_UNDEFINED:PlatformID;
-    public static var PLATFORMID_WINDOWS:PlatformID;
-    public static var PLATFORMID_MAC:PlatformID;
-    public static var PLATFORMID_ANDROID:PlatformID;
-    public static var PLATFORMID_IOS:PlatformID;
-    public static var PLATFORMID_WEB:PlatformID;
-
-   public static var PROJECTFILE_VERSION: Int;
+    public static var PROJECTFILE_VERSION: Int;
 
 
 
 
 }
 }

+ 9 - 41
Source/ToolCore/JSBind/JSBHaxe.cpp

@@ -66,13 +66,6 @@ namespace ToolCore
     {
     {
         source_ += "//Atomic Haxe Definitions\n\n";
         source_ += "//Atomic Haxe Definitions\n\n";
 
 
-        //if (package_->GetName() != "Atomic")
-        //{
-        //    source_ += "/// <reference path=\"Atomic.d.ts\" />\n\n";
-        //}
-
-        //source_ += "package;\n\n";
-
         source_ += "extern class " + package_->GetName() + " {\n\n";
         source_ += "extern class " + package_->GetName() + " {\n\n";
     }
     }
 
 
@@ -360,7 +353,7 @@ namespace ToolCore
         {
         {
             const String& cname = constants.At(i);
             const String& cname = constants.At(i);
 
 
-            source_ += "   public static var " + cname + ": Int;\n";
+            source_ += "    public static var " + cname + ": Int;\n";
         }
         }
 
 
         source_ += "\n";
         source_ += "\n";
@@ -372,46 +365,21 @@ namespace ToolCore
 
 
         Vector<SharedPtr<JSBEnum>> enums = module->GetEnums();
         Vector<SharedPtr<JSBEnum>> enums = module->GetEnums();
 
 
-        for (unsigned i = 0; i <enums.Size(); i++)
-        {
-            JSBEnum* _enum = enums[i];
-            //TODO: support for enums(for the first need to make support for enums in haxe2js compiler)
-            source_ += "\n   // enum " + _enum->GetName() + "\n";
-            source_ += "typedef " + _enum->GetName() + " = Int;\n";
-
-            //Vector<String>& values = _enum->GetValues();
-
-            //for (unsigned j = 0; j < values.Size(); j++)
-            //{
-            //    source_ += "var " + values[j] + ":" + _enum->GetName() +";\n";
-            //}
-
-            //source_ += "}\n";
-
-        }
-
-    }
-
-    void JSBHaxe::RegisterEnums(JSBModule* module)
-    {
-
-        Vector<SharedPtr<JSBEnum>> enums = module->GetEnums();
-
         for (unsigned i = 0; i <enums.Size(); i++)
         for (unsigned i = 0; i <enums.Size(); i++)
         {
         {
             JSBEnum* _enum = enums[i];
             JSBEnum* _enum = enums[i];
 
 
-            source_ += "\n   // enum " + _enum->GetName() + "\n";
-            //source_ += "    public static var " + _enum->GetName() + ":" + _enum->GetName() + ";\n";
+            source_ += "@:native(\"Atomic\")\n";
+            source_ += "extern enum " + _enum->GetName() + " {\n";
 
 
             Vector<String>& values = _enum->GetValues();
             Vector<String>& values = _enum->GetValues();
 
 
             for (unsigned j = 0; j < values.Size(); j++)
             for (unsigned j = 0; j < values.Size(); j++)
             {
             {
-                source_ += "    public static var " + values[j] + ":" + _enum->GetName() + ";\n";
+                source_ += "    " + values[j] + ";\n";
             }
             }
-            //source_ += "}\n";
 
 
+            source_ += "}\n";
         }
         }
 
 
     }
     }
@@ -442,10 +410,10 @@ namespace ToolCore
 
 
         Begin();
         Begin();
 
 
-        for (unsigned i = 0; i < modules.Size(); i++)
-        {
-            RegisterEnums(modules[i]);
-        }
+        //for (unsigned i = 0; i < modules.Size(); i++)
+        //{
+        //    RegisterEnums(modules[i]);
+        //}
 
 
         for (unsigned i = 0; i < modules.Size(); i++)
         for (unsigned i = 0; i < modules.Size(); i++)
         {
         {

+ 0 - 1
Source/ToolCore/JSBind/JSBHaxe.h

@@ -38,7 +38,6 @@ namespace ToolCore
         JSBFunction* findFunctionInBase(JSBFunction* function);
         JSBFunction* findFunctionInBase(JSBFunction* function);
 
 
         void ExportEnums(JSBModule* moduleName);
         void ExportEnums(JSBModule* moduleName);
-        void RegisterEnums(JSBModule* moduleName);
         void ExportModuleConstants(JSBModule*  moduleName);
         void ExportModuleConstants(JSBModule*  moduleName);
         void ExportModuleClasses(JSBModule*  moduleName);
         void ExportModuleClasses(JSBModule*  moduleName);
 
 

Some files were not shown because too many files changed in this diff