Skip to content

Commit 98cc61d

Browse files
committed
Greatly improved support for matrices and matrix transformations.
1 parent 9e72ee1 commit 98cc61d

11 files changed

Lines changed: 1059 additions & 626 deletions

File tree

.idea/workspace.xml

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

build/CommentCoreLibrary.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/scripting/Makefile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,20 @@ clean:
77
definitions:
88
tsc -d --target ES5 src/api/Runtime/Runtime.ts --out src/api/Runtime.d.ts
99
tsc -d --target ES5 src/api/Player/Player.ts --out src/api/Player.d.ts
10+
11+
compile: compile-ts compile-host
12+
13+
compile-host:
14+
cp src/*.js build/
15+
cp src/api/*.js build/api/
16+
cp src/api/Tween/Tween.js build/api/
17+
cat build/Host.js build/Unpacker.js > build/_Host.js
18+
rm -f build/Unpacker.js
19+
rm -f build/Host.js
20+
mv build/_Host.js build/Host.js
1021

11-
compile:
22+
compile-ts:
1223
tsc --target ES5 src/api/Display/Display.ts --out build/api/Display.js
1324
tsc --target ES5 src/api/Runtime/Runtime.ts --out build/api/Runtime.js
1425
tsc --target ES5 src/api/Player/Player.ts --out build/api/Player.js
1526
tsc --target ES5 src/api/Utils/Utils.ts --out build/api/Utils.js
16-
cp src/*.js build/
17-
cp src/api/*.js build/api/
18-
cp src/api/Tween/Tween.js build/api/

src/scripting/build/Host.js

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ var CCLScripting = function(workerUrl){
5151
scripter.logger.error("Object not found.");
5252
return;
5353
}
54-
if(!objects[objectId][propName]){
54+
if(objects[objectId][propName] === undefined){
5555
scripter.logger.error("Property \"" + propName
5656
+ "\" not defined for object of type " +
5757
objects[objectId].getClass() +".");
@@ -276,6 +276,9 @@ var CCLScripting = function(workerUrl){
276276
self.getContext().updateProperty(pl.id, pl.name, pl.value);
277277
});
278278
};
279+
})();
280+
/** Define some Unpackers **/
281+
(function(){
279282
/** This is the DOM Manipulation Library **/
280283
var _ = function (type, props, children, callback) {
281284
var elem = null;
@@ -308,7 +311,6 @@ var CCLScripting = function(workerUrl){
308311
}
309312
return elem;
310313
};
311-
/** Define some unpackers **/
312314
var ScriptingContext = CCLScripting.prototype.ScriptingContext;
313315
ScriptingContext.prototype.Unpack.TextField = function(stage, data, ctx){
314316
this.DOM = _("div",{
@@ -417,9 +419,9 @@ var CCLScripting = function(workerUrl){
417419
"width":"100%",
418420
"height":"100%"
419421
}});
420-
this.x = data.x ? data.x : 0;
421-
this.y = data.y ? data.y : 0;
422-
this.alpha = data.alpha ? data.alpha : 1;
422+
this._x = data.x ? data.x : 0;
423+
this._y = data.y ? data.y : 0;
424+
this._alpha = data.alpha ? data.alpha : 1;
423425
// Helpers
424426
var __ = function(e, attr){
425427
if(typeof e === "string"){
@@ -437,12 +439,28 @@ var CCLScripting = function(workerUrl){
437439
};
438440
var defaultEffects = __("defs");
439441
var defaultGroup = __("g",{
440-
"transform":"translate(" + this.x + "," + this.y + ")",
441-
"opacity":this.alpha,
442+
"transform":"translate(" + this._x + "," + this._y + ")",
443+
"opacity":this._alpha,
442444
});
445+
var defaultGroupWithEffects = defaultGroup;
443446
this.DOM.appendChild(defaultEffects);
444447
this.DOM.appendChild(defaultGroup);
445448

449+
/** PROPS **/
450+
this.__defineSetter__("x", function(f){
451+
this.setX(f);
452+
});
453+
this.__defineSetter__("y", function(f){
454+
this.setY(f);
455+
});
456+
this.__defineGetter__("x", function(f){
457+
return this._x;
458+
});
459+
this.__defineGetter__("y", function(f){
460+
return this._y;
461+
});
462+
/** /PROPS **/
463+
446464
this.line = {
447465
width:0,
448466
color:"#ffffff",
@@ -489,17 +507,17 @@ var CCLScripting = function(workerUrl){
489507
this.setX = function(x){
490508
if(!x)
491509
return;
492-
this.x = x;
510+
this._x = x;
493511
__(defaultGroup,{
494-
"transform":"translate(" + this.x + "," + this.y + ")"
512+
"transform":"translate(" + this._x + "," + this._y + ")"
495513
});
496514
};
497515
this.setY = function(y){
498516
if(!y)
499517
return;
500-
this.y = y;
518+
this._y = y;
501519
__(defaultGroup,{
502-
"transform":"translate(" + this.x + "," + this.y + ")"
520+
"transform":"translate(" + this._x + "," + this._y + ")"
503521
});
504522
};
505523
this.moveTo = function(params){
@@ -612,6 +630,24 @@ var CCLScripting = function(workerUrl){
612630
defaultGroup.appendChild(e);
613631
};
614632

633+
this.drawTriangles = function(params){
634+
if(params[1].length % 3 !== 0){
635+
throw new Error("Illegal drawTriangles index argument. Indices array size must be a multiple of 3.");
636+
}
637+
for(var i = 0; i < params[1].length / 3; i++){
638+
var a = params[1][3 * i],
639+
b = params[1][3 * i + 1],
640+
c = params[1][3 * i + 2];
641+
var ax = params[0][2 * a], ay = params[0][2 * a + 1];
642+
var bx = params[0][2 * b], by = params[0][2 * b + 1];
643+
var cx = params[0][2 * c], cy = params[0][2 * c + 1];
644+
this.moveTo([ax,ay]);
645+
this.lineTo([bx,by]);
646+
this.lineTo([cx,cy]);
647+
this.lineTo([ax,ay]);
648+
}
649+
};
650+
615651
this.clear = function(){
616652
defaultGroup.innerHTML = "";
617653
};
@@ -653,7 +689,7 @@ var CCLScripting = function(workerUrl){
653689
0,0,0,cR,0,
654690
0,0,0,cG,0,
655691
0,0,0,cB,0,
656-
0,0,0,1,0
692+
0,0,0,0,1,
657693
];
658694
dFilter.appendChild(__("feColorMatrix",{
659695
"type":"matrix",
@@ -679,7 +715,7 @@ var CCLScripting = function(workerUrl){
679715
// Add new filters
680716
this.DOM.appendChild(defaultEffects);
681717
// Apply filters
682-
this.DOM.removeChild(defaultGroup);
718+
this.DOM.removeChild(defaultGroupWithEffects);
683719
var tGroup = defaultGroup;
684720
for(var i = 0; i < filters.length; i++){
685721
var layeredG = __("g",{
@@ -689,6 +725,7 @@ var CCLScripting = function(workerUrl){
689725
tGroup = layeredG;
690726
}
691727
this.DOM.appendChild(tGroup);
728+
defaultGroupWithEffects = tGroup;
692729
};
693730

694731
this.unload = function(){

0 commit comments

Comments
 (0)