Skip to content

Commit 4719f1f

Browse files
committed
Fixed many compat issues. Added scripter tests
1 parent cbafca8 commit 4719f1f

24 files changed

Lines changed: 409 additions & 144 deletions

.idea/workspace.xml

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

demo/scripting/ccl.htm

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,20 @@ <h2>Tests</h2>
130130

131131
var tmr=0;
132132
var start=0;
133-
var playhead = 0;
133+
var playhead = 0, lasthead = 0;
134+
135+
function timeupdate(){
136+
playhead = new Date().getTime() - start;
137+
cm.time(playhead);
138+
if(cm.scripting && playhead - lasthead > 300 ){;
139+
cm.scripting.send("Update:TimeUpdate",{
140+
"state":"playing",
141+
"time":playhead
142+
});
143+
lasthead = playhead;
144+
}
145+
}
146+
134147
function load(dmf,dmfmd){
135148
if(dmfmd == null)
136149
dmfmd = 'bilibili';
@@ -142,10 +155,8 @@ <h2>Tests</h2>
142155
CommentLoader(dmf,cm,dmfmd);
143156
cm.startTimer();
144157
start = new Date().getTime();
145-
tmr = setInterval(function(){
146-
playhead = new Date().getTime() - start;
147-
cm.time(playhead);
148-
},10);
158+
lasthead = playhead;
159+
tmr = setInterval(timeupdate,42);
149160
}
150161
function stop(){
151162
cm.stopTimer();
@@ -160,18 +171,8 @@ <h2>Tests</h2>
160171
function resume(){
161172
cm.startTimer();
162173
start = new Date().getTime() - playhead;
163-
var lasthead = playhead;
164-
tmr = setInterval(function(){
165-
playhead = new Date().getTime() - start;
166-
cm.time(playhead);
167-
if(cm.scripting && playhead - lasthead > 300 ){
168-
cm.scripting.send("Update:TimeUpdate",{
169-
"state":"pause",
170-
"time":playhead
171-
});
172-
lasthead = playhead;
173-
}
174-
},10);
174+
lasthead = playhead;
175+
tmr = setInterval(timeupdate,42);
175176
}
176177
</script>
177178
</body>

src/scripting/build/Host.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,12 @@ var CCLScripting = function(workerUrl){
397397
this.DOM.innerHTML = "";
398398
this.DOM.appendChild(_("text",text));
399399
};
400+
this.__defineSetter__("visible", function(f){
401+
this.DOM.style.visible = f ? "visible" : "hidden";
402+
});
403+
this.__defineGetter__("visible", function(f){
404+
return this.DOM.style.visible === "hidden" ? false : true;
405+
});
400406
this.__defineSetter__("alpha", function(f){
401407
this.setAlpha(f);
402408
});
@@ -518,6 +524,12 @@ var CCLScripting = function(workerUrl){
518524
this.DOM.appendChild(defaultEffects);
519525
this.DOM.appendChild(defaultGroupWithEffects);
520526
/** PROPS **/
527+
this.__defineSetter__("visible", function(f){
528+
this.DOM.style.visible = f ? "visible" : "hidden";
529+
});
530+
this.__defineGetter__("visible", function(f){
531+
return this.DOM.style.visible === "hidden" ? false : true;
532+
});
521533
this.__defineSetter__("x", function(f){
522534
this.setX(f);
523535
});
@@ -949,6 +961,12 @@ var CCLScripting = function(workerUrl){
949961
data.scaleX = 1;
950962
data.scaleY = 1;
951963
data.children = [];
964+
this.__defineSetter__("visible", function(f){
965+
this.DOM.style.visible = f ? "visible" : "hidden";
966+
});
967+
this.__defineGetter__("visible", function(f){
968+
return this.DOM.style.visible === "hidden" ? false : true;
969+
});
952970
this.__defineSetter__("alpha", function(f){
953971
this.DOM.style.opacity = f;
954972
});
@@ -1077,6 +1095,12 @@ var CCLScripting = function(workerUrl){
10771095

10781096
data.scaleX = 1;
10791097
data.scaleY = 1;
1098+
this.__defineSetter__("visible", function(f){
1099+
this.DOM.style.visible = f ? "visible" : "hidden";
1100+
});
1101+
this.__defineGetter__("visible", function(f){
1102+
return this.DOM.style.visible === "hidden" ? false : true;
1103+
});
10801104
this.__defineGetter__("transform", function(f){
10811105
return {};
10821106
});

src/scripting/build/Worker.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ __schannel("::eval", function(msg){
1919
if(Tween && Tween.extendWithEasingFunctions){
2020
Tween.extendWithEasingFunctions(this);
2121
}
22+
var clearTimeout = Utils.clearTimeout;
23+
var clearInterval = Utils.clearInterval;
2224
eval(msg);
2325
});
2426
__schannel("::debug", function(msg){

src/scripting/build/api/Display.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ var Display;
275275
}
276276
Display.createMatrix = createMatrix;
277277

278-
function createMatrix3D() {
279-
return new Matrix3D();
278+
function createMatrix3D(iv) {
279+
return new Matrix3D(iv);
280280
}
281281
Display.createMatrix3D = createMatrix3D;
282282

@@ -603,7 +603,7 @@ var Display;
603603
if (typeof tX === "undefined") { tX = 0; }
604604
if (typeof tY === "undefined") { tY = 0; }
605605
if (typeof tZ === "undefined") { tZ = 0; }
606-
if (this._matrix !== null) {
606+
if (this._matrix !== null || this._matrix3d === null) {
607607
this._matrix = null;
608608
this._matrix3d = new Display.Matrix3D();
609609
}
@@ -980,7 +980,7 @@ var Display;
980980
},
981981
set: function (val) {
982982
this._z = val;
983-
this._updateBox();
983+
this._updateBox("3d");
984984
},
985985
enumerable: true,
986986
configurable: true

src/scripting/build/api/Function.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,30 @@ function load(library, onComplete){
2121
};
2222

2323
function clone(a){
24-
// Shallow copy
24+
if(null === a || "object" != typeof a)
25+
return a;
26+
/** Call method's own clone if possible **/
27+
if(a.hasOwnProperty("clone") || typeof a["clone"] === "function"){
28+
return a.clone();
29+
}
30+
/** Perform a shallow clone */
2531
var b = {};
32+
b.constructor = a.constructor;
33+
b.prototype = a.prototype;
2634
for(var x in a){
2735
b[x] = a[x];
2836
}
2937
return b;
3038
};
3139

3240
function foreach(dtype, f){
41+
if(null === dtype || "object" != typeof dtype)
42+
return;
43+
/** DisplayObjects do not have any enumerable properties **/
44+
if(dtype instanceof Display.DisplayObject){
45+
return;
46+
}
47+
/** Iterates through object **/
3348
for(var x in dtype){
3449
if(dtype.hasOwnProperty(x)){
3550
f(x, dtype[x]);

src/scripting/build/api/Tween.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ var Tween;
341341
if (currentTime <= delay * 1000) {
342342
return;
343343
}
344-
src.step(target, currentTime - delay * 1000, totalTime);
344+
src.step(target, currentTime - delay * 1000, totalTime - delay * 1000);
345345
};
346346
return newTween;
347347
}

src/scripting/build/api/Utils.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,25 @@ var Utils;
166166
return ivl;
167167
}
168168
Utils.interval = interval;
169+
170+
/**
171+
* Clears a scheduled timeout. If timeout id is not recognized no action
172+
* is performed
173+
* @param tid - timeout id, returned by timer
174+
*/
175+
function clearTimeout(tid) {
176+
Runtime.getTimer().clearTimeout(tid);
177+
}
178+
Utils.clearTimeout = clearTimeout;
179+
180+
/**
181+
* Clears an interval timer. If we are in timers mode then do nothing
182+
* @param iid - interval id
183+
*/
184+
function clearInterval(iid) {
185+
Runtime.getTimer().clearInterval(iid);
186+
}
187+
Utils.clearInterval = clearInterval;
169188
})(Utils || (Utils = {}));
170189

171190
var getTimer = Utils.getTimer;

src/scripting/src/Host.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,12 @@ var CCLScripting = function(workerUrl){
169169
};
170170

171171
var WorkerHook = function(event){
172-
var resp = JSON.parse(event.data);
172+
try{
173+
var resp = JSON.parse(event.data);
174+
}catch(e){
175+
console.log(e);
176+
return;
177+
}
173178
if(resp.channel === ""){
174179
switch(resp.mode){
175180
case "log":

src/scripting/src/Unpacker.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@
9797
this.DOM.innerHTML = "";
9898
this.DOM.appendChild(_("text",text));
9999
};
100+
this.__defineSetter__("visible", function(f){
101+
this.DOM.style.visible = f ? "visible" : "hidden";
102+
});
103+
this.__defineGetter__("visible", function(f){
104+
return this.DOM.style.visible === "hidden" ? false : true;
105+
});
100106
this.__defineSetter__("alpha", function(f){
101107
this.setAlpha(f);
102108
});
@@ -218,6 +224,12 @@
218224
this.DOM.appendChild(defaultEffects);
219225
this.DOM.appendChild(defaultGroupWithEffects);
220226
/** PROPS **/
227+
this.__defineSetter__("visible", function(f){
228+
this.DOM.style.visible = f ? "visible" : "hidden";
229+
});
230+
this.__defineGetter__("visible", function(f){
231+
return this.DOM.style.visible === "hidden" ? false : true;
232+
});
221233
this.__defineSetter__("x", function(f){
222234
this.setX(f);
223235
});
@@ -649,6 +661,12 @@
649661
data.scaleX = 1;
650662
data.scaleY = 1;
651663
data.children = [];
664+
this.__defineSetter__("visible", function(f){
665+
this.DOM.style.visible = f ? "visible" : "hidden";
666+
});
667+
this.__defineGetter__("visible", function(f){
668+
return this.DOM.style.visible === "hidden" ? false : true;
669+
});
652670
this.__defineSetter__("alpha", function(f){
653671
this.DOM.style.opacity = f;
654672
});
@@ -777,6 +795,12 @@
777795

778796
data.scaleX = 1;
779797
data.scaleY = 1;
798+
this.__defineSetter__("visible", function(f){
799+
this.DOM.style.visible = f ? "visible" : "hidden";
800+
});
801+
this.__defineGetter__("visible", function(f){
802+
return this.DOM.style.visible === "hidden" ? false : true;
803+
});
780804
this.__defineGetter__("transform", function(f){
781805
return {};
782806
});

0 commit comments

Comments
 (0)