Skip to content

Commit 760345f

Browse files
committed
Support for experimental tweening.
1 parent a85ed17 commit 760345f

22 files changed

Lines changed: 1189 additions & 247 deletions

src/scripting/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ 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+
tsc -d --target ES5 src/api/Tween/Tween.ts --out src/api/Tween.d.ts
1011

1112
compile: compile-ts compile-host
1213

1314
compile-host:
1415
cp src/*.js build/
1516
cp src/api/*.js build/api/
16-
cp src/api/Tween/Tween.js build/api/
1717
cat build/Host.js build/Unpacker.js > build/_Host.js
1818
rm -f build/Unpacker.js
1919
rm -f build/Host.js
@@ -24,3 +24,4 @@ compile-ts:
2424
tsc --target ES5 src/api/Runtime/Runtime.ts --out build/api/Runtime.js
2525
tsc --target ES5 src/api/Player/Player.ts --out build/api/Player.js
2626
tsc --target ES5 src/api/Utils/Utils.ts --out build/api/Utils.js
27+
tsc --target ES5 src/api/Tween/Tween.ts --out build/api/Tween.js

src/scripting/build/Host.js

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ var CCLScripting = function(workerUrl){
4848
};
4949
this.updateProperty = function(objectId, propName, value){
5050
if(!objects[objectId]){
51-
scripter.logger.error("Object not found.");
51+
scripter.logger.error("Object (" + objectId + ") not found.");
5252
return;
5353
}
5454
if(objects[objectId][propName] === undefined){
@@ -61,7 +61,7 @@ var CCLScripting = function(workerUrl){
6161
};
6262
this.callMethod = function(objectId, methodName, params){
6363
if(!objects[objectId]){
64-
scripter.logger.error("Object not found.");
64+
scripter.logger.error("Object (" + objectId + ") not found.");
6565
return;
6666
}
6767
if(!objects[objectId][methodName]){
@@ -80,7 +80,27 @@ var CCLScripting = function(workerUrl){
8080
};
8181
}
8282
};
83-
83+
this.getObject = function(objectId){
84+
if(!objects.hasOwnProperty(objectId)){
85+
scripter.logger.error("Object (" + objectId + ") not found.");
86+
return objects[objectId];
87+
}
88+
return objects[objectId];
89+
};
90+
this.invokeError = function(msg, mode){
91+
switch(mode){
92+
case "err":
93+
scripter.logger.error(msg);
94+
break;
95+
case "warn":
96+
scripter.logger.warn(msg);
97+
break;
98+
default:
99+
case "log":
100+
scripter.logger.log(msg);
101+
break;
102+
}
103+
};
84104
this.clear = function(){
85105

86106
};
@@ -821,6 +841,19 @@ var CCLScripting = function(workerUrl){
821841
ScriptingContext.prototype.Unpack.Sprite = function(stage, data, ctx){
822842
this.DOM = _("div",{"style":{"position":"absolute"}});
823843

844+
this.__defineSetter__("x", function(f){
845+
this.setX(f);
846+
});
847+
this.__defineSetter__("y", function(f){
848+
this.setY(f);
849+
});
850+
this.__defineGetter__("x", function(f){
851+
return this.DOM.offsetLeft;
852+
});
853+
this.__defineGetter__("y", function(f){
854+
return this.DOM.offsetTop;
855+
});
856+
824857
this.setX = function(x){
825858
this.DOM.style.left = x + "px";
826859
};
@@ -837,6 +870,28 @@ var CCLScripting = function(workerUrl){
837870
this.DOM.style.height = height + "px";
838871
};
839872

873+
this.addChild = function(childitem){
874+
var child = ctx.getObject(childitem);
875+
if(!child)
876+
return;
877+
if(child.DOM){
878+
this.DOM.appendChild(child.DOM);
879+
}else{
880+
ctx.invokeError("Sprite.addChild failed. Attempted to add non object","err");
881+
}
882+
};
883+
884+
this.removeChild = function(childitem){
885+
var child = ctx.getObject(childitem);
886+
if(!child)
887+
return;
888+
try{
889+
this.DOM.removeChild(child.DOM);
890+
}catch(e){
891+
ctx.invokeError(e.stack, "err");
892+
}
893+
};
894+
840895
this.unload = function(){
841896
try{
842897
stage.removeChild(this.DOM);

src/scripting/build/Worker.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ importScripts('api/Runtime.js', 'api/ScriptManager.js', 'api/Player.js', 'api/Di
1616

1717
/** Immediately Hook into the eval channel, blocking future hooks **/
1818
__schannel("::eval", function(msg){
19+
if(Tween && Tween.extendWithEasingFunctions){
20+
Tween.extendWithEasingFunctions(this);
21+
}
1922
eval(msg);
2023
});
2124
__schannel("::debug", function(msg){

0 commit comments

Comments
 (0)