Skip to content

Commit a31a39f

Browse files
committed
Merged from dev-scripter
2 parents 0a47af3 + 8f5b966 commit a31a39f

11 files changed

Lines changed: 270 additions & 16 deletions

File tree

src/scripting/build/Host.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,40 @@ var CCLScripting = function(workerUrl){
839839
};
840840

841841
ScriptingContext.prototype.Unpack.Sprite = function(stage, data, ctx){
842-
this.DOM = _("div",{"style":{"position":"absolute"}});
842+
this.DOM = _("div",{"style":{
843+
"position":"absolute",
844+
"top": data.y ? data.y + "px" : "0px",
845+
"left": data.x ? data.x + "px" : "0px",
846+
"width":"100%",
847+
"height":"100%",
848+
"overflow":"visible"
849+
}});
850+
851+
data.scaleX = 1;
852+
data.scaleY = 1;
853+
854+
this.__defineSetter__("scaleX", function(f){
855+
if(f > 50)
856+
return;
857+
data.scaleX = f;
858+
for(var i = 0; i < this.DOM.children.length; i++){
859+
this.DOM.children[i].style.transform = "scale(" + data.scaleX + "," + data.scaleY + ")";
860+
}
861+
});
862+
this.__defineSetter__("scaleY", function(f){
863+
if(f > 50)
864+
return;
865+
data.scaleY = f;
866+
for(var i = 0; i < this.DOM.children.length; i++){
867+
this.DOM.children[i].style.transform = "scale(" + data.scaleX + "," + data.scaleY + ")";
868+
}
869+
});
870+
this.__defineGetter__("scaleX", function(f){
871+
return data.scaleX;
872+
});
873+
this.__defineGetter__("scaleY", function(f){
874+
return data.scaleY;
875+
});
843876

844877
this.__defineSetter__("x", function(f){
845878
this.setX(f);
@@ -875,6 +908,12 @@ var CCLScripting = function(workerUrl){
875908
if(!child)
876909
return;
877910
if(child.DOM){
911+
if(child.getClass() === "Shape"){
912+
child.DOM.style.left = -this.x + "px";
913+
child.DOM.style.top = -this.y + "px";
914+
child.setX(this.x);
915+
child.setY(this.y);
916+
}
878917
this.DOM.appendChild(child.DOM);
879918
}else{
880919
ctx.invokeError("Sprite.addChild failed. Attempted to add non object","err");

src/scripting/build/api/Display.js

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ var Display;
7171
this.setTo(1, 0, 0, 1, 0, 0);
7272
};
7373

74+
Matrix.prototype.createGradientBox = function (width, height, rotation, tX, tY) {
75+
this.createBox(width, height, rotation, tX, tY);
76+
};
77+
7478
Matrix.prototype.createBox = function (sX, sY, q, tX, tY) {
7579
this.identity();
7680
this.rotate(q);
@@ -600,6 +604,33 @@ var Display;
600604
return;
601605
}
602606
this._hasSetDefaults = true;
607+
try {
608+
/** Try reading the defaults from motion fields **/
609+
if (defaults.hasOwnProperty("motion")) {
610+
var motion = defaults["motion"];
611+
if (motion.hasOwnProperty("alpha")) {
612+
this._alpha = motion["alpha"]["fromValue"];
613+
}
614+
if (motion.hasOwnProperty("x")) {
615+
this._x = motion["x"]["fromValue"];
616+
}
617+
if (motion.hasOwnProperty("y")) {
618+
this._y = motion["y"]["fromValue"];
619+
}
620+
} else if (defaults.hasOwnProperty("motionGroup") && defaults["motionGroup"] && defaults["motionGroup"].length > 0) {
621+
var motion = defaults["motionGroup"][0];
622+
if (motion.hasOwnProperty("alpha")) {
623+
this._alpha = motion["alpha"]["fromValue"];
624+
}
625+
if (motion.hasOwnProperty("x")) {
626+
this._x = motion["x"]["fromValue"];
627+
}
628+
if (motion.hasOwnProperty("y")) {
629+
this._y = motion["y"]["fromValue"];
630+
}
631+
}
632+
} catch (e) {
633+
}
603634
if (defaults.hasOwnProperty("alpha")) {
604635
this._alpha = defaults["alpha"];
605636
}
@@ -771,6 +802,32 @@ var Display;
771802
});
772803

773804

805+
Object.defineProperty(DisplayObject.prototype, "width", {
806+
get: function () {
807+
return this._width;
808+
},
809+
set: function (w) {
810+
this._width = w;
811+
this.propertyUpdate("width", w);
812+
},
813+
enumerable: true,
814+
configurable: true
815+
});
816+
817+
818+
Object.defineProperty(DisplayObject.prototype, "height", {
819+
get: function () {
820+
return this._height;
821+
},
822+
set: function (h) {
823+
this._height = h;
824+
this.propertyUpdate("height", h);
825+
},
826+
enumerable: true,
827+
configurable: true
828+
});
829+
830+
774831
Object.defineProperty(DisplayObject.prototype, "visible", {
775832
get: function () {
776833
return this._visible;
@@ -1315,8 +1372,6 @@ var Display;
13151372
}
13161373
if (!mProp.hasOwnProperty("lifeTime")) {
13171374
mProp["lifeTime"] = this._dur;
1318-
} else {
1319-
mProp["lifeTime"] *= 1000;
13201375
}
13211376
var src = {}, dst = {};
13221377
src[movingVars] = mProp["fromValue"];
@@ -1429,6 +1484,7 @@ var Display;
14291484
function CommentCanvas(params) {
14301485
_super.call(this);
14311486
this._mM = new Display.MotionManager(this);
1487+
this.setDefaults(params);
14321488
this.initStyle(params);
14331489
Runtime.registerObject(this);
14341490
this.bindParent(params);
@@ -1624,6 +1680,18 @@ var Display;
16241680
});
16251681

16261682

1683+
Object.defineProperty(TextField.prototype, "length", {
1684+
get: function () {
1685+
return this.text.length;
1686+
},
1687+
set: function (l) {
1688+
__trace("TextField.length is read-only.", "warn");
1689+
},
1690+
enumerable: true,
1691+
configurable: true
1692+
});
1693+
1694+
16271695
Object.defineProperty(TextField.prototype, "htmlText", {
16281696
get: function () {
16291697
return this.text;
@@ -1637,6 +1705,32 @@ var Display;
16371705
});
16381706

16391707

1708+
1709+
1710+
Object.defineProperty(TextField.prototype, "textWidth", {
1711+
get: function () {
1712+
/** TODO: Fix this to actually calculate the width **/
1713+
return this._text.length * this._textFormat.size;
1714+
},
1715+
set: function (w) {
1716+
__trace("TextField.textWidth is read-only", "warn");
1717+
},
1718+
enumerable: true,
1719+
configurable: true
1720+
});
1721+
1722+
Object.defineProperty(TextField.prototype, "textHeight", {
1723+
get: function () {
1724+
/** TODO: Fix this to actually calculate the height **/
1725+
return this._textFormat.size;
1726+
},
1727+
set: function (h) {
1728+
__trace("TextField.textHeight is read-only", "warn");
1729+
},
1730+
enumerable: true,
1731+
configurable: true
1732+
});
1733+
16401734
Object.defineProperty(TextField.prototype, "color", {
16411735
get: function () {
16421736
return this._textFormat.color;

src/scripting/build/api/Tween.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ var Tween;
270270
if (typeof src === "undefined") { src = {}; }
271271
if (typeof duration === "undefined") { duration = 0; }
272272
if (typeof easing === "undefined") { easing = null; }
273-
var t = new ITween(object, duration);
273+
var t = new ITween(object, duration * 1000);
274274
t.step = createStepFunction(object, dest, src, t);
275275
if (easing !== null) {
276276
t.easing = easing;
@@ -310,12 +310,12 @@ var Tween;
310310
Tween.scale = scale;
311311

312312
function delay(src, delay) {
313-
var newTween = new ITween(src.target, src.duration + delay);
313+
var newTween = new ITween(src.target, src.duration + delay * 1000);
314314
newTween.step = function (target, currentTime, totalTime) {
315-
if (currentTime <= delay) {
315+
if (currentTime <= delay * 1000) {
316316
return;
317317
}
318-
src.step(target, currentTime - delay, totalTime);
318+
src.step(target, currentTime - delay * 1000, totalTime);
319319
};
320320
return newTween;
321321
}
@@ -338,6 +338,8 @@ var Tween;
338338
Tween.repeat = repeat;
339339

340340
function slice(src, from, to) {
341+
from *= 1000;
342+
to *= 1000;
341343
var newTween = new ITween(src.target, to - from);
342344
newTween.step = function (target, currentTime, totalTime) {
343345
src.step(target, from + currentTime, src.duration);

src/scripting/src/Unpacker.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,40 @@
540540
};
541541

542542
ScriptingContext.prototype.Unpack.Sprite = function(stage, data, ctx){
543-
this.DOM = _("div",{"style":{"position":"absolute"}});
543+
this.DOM = _("div",{"style":{
544+
"position":"absolute",
545+
"top": data.y ? data.y + "px" : "0px",
546+
"left": data.x ? data.x + "px" : "0px",
547+
"width":"100%",
548+
"height":"100%",
549+
"overflow":"visible"
550+
}});
551+
552+
data.scaleX = 1;
553+
data.scaleY = 1;
554+
555+
this.__defineSetter__("scaleX", function(f){
556+
if(f > 50)
557+
return;
558+
data.scaleX = f;
559+
for(var i = 0; i < this.DOM.children.length; i++){
560+
this.DOM.children[i].style.transform = "scale(" + data.scaleX + "," + data.scaleY + ")";
561+
}
562+
});
563+
this.__defineSetter__("scaleY", function(f){
564+
if(f > 50)
565+
return;
566+
data.scaleY = f;
567+
for(var i = 0; i < this.DOM.children.length; i++){
568+
this.DOM.children[i].style.transform = "scale(" + data.scaleX + "," + data.scaleY + ")";
569+
}
570+
});
571+
this.__defineGetter__("scaleX", function(f){
572+
return data.scaleX;
573+
});
574+
this.__defineGetter__("scaleY", function(f){
575+
return data.scaleY;
576+
});
544577

545578
this.__defineSetter__("x", function(f){
546579
this.setX(f);
@@ -576,6 +609,12 @@
576609
if(!child)
577610
return;
578611
if(child.DOM){
612+
if(child.getClass() === "Shape"){
613+
child.DOM.style.left = -this.x + "px";
614+
child.DOM.style.top = -this.y + "px";
615+
child.setX(this.x);
616+
child.setY(this.y);
617+
}
579618
this.DOM.appendChild(child.DOM);
580619
}else{
581620
ctx.invokeError("Sprite.addChild failed. Attempted to add non object","err");

src/scripting/src/api/Display/CommentCanvas.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module Display {
1010

1111
constructor(params:Object) {
1212
super();
13+
this.setDefaults(params);
1314
this.initStyle(params);
1415
Runtime.registerObject(this);
1516
this.bindParent(params);

src/scripting/src/api/Display/DisplayObject.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ module Display {
8080
private _alpha:number = 1;
8181
private _x:number = 0;
8282
private _y:number = 0;
83+
private _width:number;
84+
private _height:number;
8385
private _scaleX:number = 1;
8486
private _scaleY:number = 1;
8587
private _filters:Array<Filter> = [];
@@ -102,6 +104,35 @@ module Display {
102104
return;
103105
}
104106
this._hasSetDefaults = true;
107+
try{
108+
/** Try reading the defaults from motion fields **/
109+
if (defaults.hasOwnProperty("motion")) {
110+
var motion:Object = defaults["motion"];
111+
if (motion.hasOwnProperty("alpha")) {
112+
this._alpha = motion["alpha"]["fromValue"];
113+
}
114+
if (motion.hasOwnProperty("x")) {
115+
this._x = motion["x"]["fromValue"];
116+
}
117+
if (motion.hasOwnProperty("y")) {
118+
this._y = motion["y"]["fromValue"];
119+
}
120+
}else if(defaults.hasOwnProperty("motionGroup") &&
121+
defaults["motionGroup"] && defaults["motionGroup"].length > 0){
122+
var motion:Object = defaults["motionGroup"][0];
123+
if (motion.hasOwnProperty("alpha")) {
124+
this._alpha = motion["alpha"]["fromValue"];
125+
}
126+
if (motion.hasOwnProperty("x")) {
127+
this._x = motion["x"]["fromValue"];
128+
}
129+
if (motion.hasOwnProperty("y")) {
130+
this._y = motion["y"]["fromValue"];
131+
}
132+
}
133+
}catch(e){
134+
135+
}
105136
if (defaults.hasOwnProperty("alpha")) {
106137
this._alpha = defaults["alpha"];
107138
}
@@ -232,6 +263,24 @@ module Display {
232263
return 0;
233264
}
234265

266+
set width(w:number){
267+
this._width = w;
268+
this.propertyUpdate("width", w);
269+
}
270+
271+
get width():number{
272+
return this._width;
273+
}
274+
275+
set height(h:number){
276+
this._height = h;
277+
this.propertyUpdate("height", h);
278+
}
279+
280+
get height():number{
281+
return this._height;
282+
}
283+
235284
set visible(visible:boolean) {
236285
this._visible = visible;
237286
this.propertyUpdate("visible", visible);

src/scripting/src/api/Display/Matrix.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ module Display {
6161
this.setTo(1, 0, 0, 1, 0, 0);
6262
}
6363

64+
public createGradientBox(width:number, height:number, rotation:number, tX:number, tY:number):void{
65+
this.createBox(width, height, rotation, tX, tY);
66+
}
67+
6468
public createBox(sX:number, sY:number, q:number, tX:number, tY:number):void{
6569
this.identity();
6670
this.rotate(q);

src/scripting/src/api/Display/MotionManager.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ module Display {
109109
}
110110
if(!mProp.hasOwnProperty("lifeTime")){
111111
mProp["lifeTime"] = this._dur;
112-
}else{
113-
mProp["lifeTime"] *= 1000;
114112
}
115113
var src:Object = {}, dst:Object = {};
116114
src[movingVars] = mProp["fromValue"];

0 commit comments

Comments
 (0)