Skip to content

Commit 266161d

Browse files
committed
Updated scripting
1 parent 4719f1f commit 266161d

10 files changed

Lines changed: 438 additions & 237 deletions

File tree

.idea/workspace.xml

Lines changed: 196 additions & 197 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/scripting/build/api/Display.js

Lines changed: 105 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,69 @@
66
var Display;
77
(function (Display) {
88
var Point = (function () {
9-
function Point() {
9+
function Point(x, y) {
10+
if (typeof x === "undefined") { x = 0; }
11+
if (typeof y === "undefined") { y = 0; }
12+
this.x = x;
13+
this.y = y;
1014
}
15+
16+
Object.defineProperty(Point.prototype, "length", {
17+
get: function () {
18+
return Math.sqrt(this.x * this.x + this.y * this.y);
19+
},
20+
set: function (l) {
21+
__trace("Point.length is read-only", "err");
22+
},
23+
enumerable: true,
24+
configurable: true
25+
});
26+
27+
Point.prototype.add = function (p) {
28+
return new Point(p.x + this.x, p.y + this.y);
29+
};
30+
31+
Point.prototype.subtract = function (p) {
32+
return new Point(this.x - p.x, this.y - p.y);
33+
};
34+
35+
Point.interpolate = function (a, b, f) {
36+
return new Point((b.x - a.x) * f + a.x, (b.y - a.y) * f + a.y);
37+
};
38+
39+
Point.prototype.offset = function (dx, dy) {
40+
this.x += dx;
41+
this.y += dy;
42+
};
43+
44+
Point.prototype.normalize = function (thickness) {
45+
var ratio = thickness / this.length;
46+
this.x *= ratio;
47+
this.y *= ratio;
48+
};
49+
50+
Point.polar = function (r, theta) {
51+
return new Point(r * Math.cos(theta), r * Math.sin(theta));
52+
};
53+
54+
Point.prototype.setTo = function (x, y) {
55+
this.x = x;
56+
this.y = y;
57+
};
58+
59+
Point.prototype.equals = function (p) {
60+
if (p.x === this.x && p.y === this.y)
61+
return true;
62+
return false;
63+
};
64+
65+
Point.prototype.toString = function () {
66+
return "(x=" + this.x + ", y=" + this.y + ")";
67+
};
68+
69+
Point.prototype.clone = function () {
70+
return new Point(this.x, this.y);
71+
};
1172
return Point;
1273
})();
1374
Display.Point = Point;
@@ -97,8 +158,10 @@ var Display;
97158
var Matrix3D = (function () {
98159
function Matrix3D(iv) {
99160
if (typeof iv === "undefined") { iv = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]; }
100-
if (iv.length == 16) {
161+
if (iv.length === 16) {
101162
this._data = iv;
163+
} else if (iv.length === 0) {
164+
this.identity();
102165
} else {
103166
__trace("Matrix3D initialization vector invalid", "warn");
104167
this.identity();
@@ -270,8 +333,8 @@ var Display;
270333
})();
271334
Display.Vector3D = Vector3D;
272335

273-
function createMatrix() {
274-
return new Matrix();
336+
function createMatrix(a, b, c, d, tx, ty) {
337+
return new Matrix(a, b, c, d, tx, ty);
275338
}
276339
Display.createMatrix = createMatrix;
277340

@@ -285,8 +348,10 @@ var Display;
285348
}
286349
Display.createColorTransform = createColorTransform;
287350

288-
function createGradientBox() {
289-
return null;
351+
function createGradientBox(width, height, rotation, tX, tY) {
352+
var m = new Matrix();
353+
m.createGradientBox(width, height, rotation, tX, tY);
354+
return m;
290355
}
291356
Display.createGradientBox = createGradientBox;
292357

@@ -300,7 +365,7 @@ var Display;
300365
Display.createVector3D = createVector3D;
301366

302367
function projectVector(matrix, vector) {
303-
return [];
368+
return matrix.transformVector(vector);
304369
}
305370
Display.projectVector = projectVector;
306371

@@ -324,7 +389,7 @@ var Display;
324389
function createPoint(x, y) {
325390
if (typeof x === "undefined") { x = 0; }
326391
if (typeof y === "undefined") { y = 0; }
327-
return new Point();
392+
return new Point(x, y);
328393
}
329394
Display.createPoint = createPoint;
330395

@@ -576,6 +641,7 @@ var Display;
576641
set: function (m) {
577642
this._matrix = null;
578643
this._matrix3d = m;
644+
this.update();
579645
},
580646
enumerable: true,
581647
configurable: true
@@ -588,6 +654,7 @@ var Display;
588654
set: function (m) {
589655
this._matrix3d = null;
590656
this._matrix = m;
657+
this.update();
591658
},
592659
enumerable: true,
593660
configurable: true
@@ -629,6 +696,8 @@ var Display;
629696
};
630697

631698
Transform.prototype.update = function () {
699+
if (this._parent === null)
700+
return;
632701
this._parent.transform = this;
633702
};
634703

@@ -654,12 +723,14 @@ var Display;
654723

655724
/**
656725
* Clones the current transform object
657-
* The new transform still binds to the old DisplayObject
658-
* unless the parent is modifed
726+
* The new transform does not bind to any object until it
727+
* is bound to an object. Before that, updates don't
728+
* take effect.
729+
*
659730
* @returns {Transform} - Clone of transform object
660731
*/
661732
Transform.prototype.clone = function () {
662-
var t = new Transform(this._parent);
733+
var t = new Transform(null);
663734
t._matrix = this._matrix;
664735
t._matrix3d = this._matrix3d;
665736
return t;
@@ -1507,6 +1578,23 @@ var Display;
15071578
return Sprite;
15081579
})(Display.DisplayObject);
15091580
Display.Sprite = Sprite;
1581+
1582+
var RootSprite = (function (_super) {
1583+
__extends(RootSprite, _super);
1584+
function RootSprite() {
1585+
_super.call(this, "__root");
1586+
}
1587+
Object.defineProperty(RootSprite.prototype, "parent", {
1588+
get: function () {
1589+
__trace("SecurityError: No access above root sprite.", "err");
1590+
return null;
1591+
},
1592+
enumerable: true,
1593+
configurable: true
1594+
});
1595+
return RootSprite;
1596+
})(Sprite);
1597+
Display.RootSprite = RootSprite;
15101598
})(Display || (Display = {}));
15111599
/**
15121600
* MotionManager Polyfill for AS3.
@@ -2157,6 +2245,11 @@ var Display;
21572245
return new CommentField(text, params);
21582246
}
21592247
Display.createComment = createComment;
2248+
2249+
function createTextField() {
2250+
return new CommentField("", {});
2251+
}
2252+
Display.createTextField = createTextField;
21602253
})(Display || (Display = {}));
21612254
/**
21622255
* Display Adapter
@@ -2182,7 +2275,7 @@ var Display;
21822275
Display.fullScreenHeight;
21832276
Display.frameRate;
21842277

2185-
var _root = new Display.Sprite("__root");
2278+
var _root = new Display.RootSprite();
21862279
var _width = 0;
21872280
var _height = 0;
21882281
var _fullScreenWidth = 0;

src/scripting/build/api/Tween.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,8 @@ var Tween;
323323
}
324324
Tween.to = to;
325325

326-
function beizer() {
327-
return null;
326+
function beizer(object, dest, src, control) {
327+
return Tween.tween(object, dest, src);
328328
}
329329
Tween.beizer = beizer;
330330

@@ -357,13 +357,21 @@ var Tween;
357357
Tween.reverse = reverse;
358358

359359
function repeat(src, times) {
360-
var clone = src.clone();
361-
clone.repeat = times;
362-
return clone;
360+
var newTween = new ITween(src.target, src.duration * times);
361+
newTween.step = function (target, currentTime, totalTime) {
362+
src.step(target, currentTime % src.duration, src.duration);
363+
};
364+
return newTween;
363365
}
364366
Tween.repeat = repeat;
365367

366368
function slice(src, from, to) {
369+
if (to === null) {
370+
to = src.duration;
371+
}
372+
if (to < from) {
373+
to = from;
374+
}
367375
from *= 1000;
368376
to *= 1000;
369377
var newTween = new ITween(src.target, to - from);

src/scripting/src/api/Display/Bitmap.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@
33
* Author: Jim Chen
44
* Part of the CCLScripter
55
*/
6-
module Bitmap{
7-
export class Bitmap extends Display.DisplayObject {
8-
public bitmapData:Bitmap.BitmapData
6+
module Display{
7+
export class Bitmap extends DisplayObject{
98

109
}
11-
export class IBitmapData{
1210

13-
}
14-
export function createBitmapData(){
11+
export class BitmapData{
1512

1613
}
17-
}
18-
14+
}

src/scripting/src/api/Display/CommentField.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,8 @@ module Display {
9999
return new CommentField(text, params);
100100
}
101101

102+
export function createTextField():any {
103+
return new CommentField("",{});
104+
}
105+
102106
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module Display {
2323
export var fullScreenHeight:number;
2424
export var frameRate:number;
2525

26-
var _root:DisplayObject = new Sprite("__root");
26+
var _root:DisplayObject = new RootSprite();
2727
var _width:number = 0;
2828
var _height:number = 0;
2929
var _fullScreenWidth:number = 0;

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ module Display {
3333
set matrix3D(m:Display.Matrix3D) {
3434
this._matrix = null;
3535
this._matrix3d = m;
36+
this.update();
3637
}
3738

3839
set matrix(m:Display.Matrix) {
3940
this._matrix3d = null;
4041
this._matrix = m;
42+
this.update();
4143
}
4244

4345
get matrix3D():Display.Matrix3D {
@@ -70,6 +72,8 @@ module Display {
7072
}
7173

7274
private update():void {
75+
if(this._parent === null)
76+
return;
7377
this._parent.transform = this;
7478
}
7579

@@ -95,12 +99,14 @@ module Display {
9599

96100
/**
97101
* Clones the current transform object
98-
* The new transform still binds to the old DisplayObject
99-
* unless the parent is modifed
102+
* The new transform does not bind to any object until it
103+
* is bound to an object. Before that, updates don't
104+
* take effect.
105+
*
100106
* @returns {Transform} - Clone of transform object
101107
*/
102108
public clone():Transform {
103-
var t:Transform = new Transform(this._parent);
109+
var t:Transform = new Transform(null);
104110
t._matrix = this._matrix;
105111
t._matrix3d = this._matrix3d;
106112
return t;

0 commit comments

Comments
 (0)