Skip to content

Commit e7a84c2

Browse files
committed
Added support for opacity and xy coords for text. Also added KagerouEngine side support for parent/children relationships etc.
1 parent 469138b commit e7a84c2

16 files changed

Lines changed: 317 additions & 159 deletions

File tree

.idea/workspace.xml

Lines changed: 162 additions & 147 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.

experimental/scripting/ccl.htm

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@
1010

1111
<!-- A few helpers to do some decoding/fetching below-->
1212
<script src="../../demo/libxml.js"></script>
13-
13+
<style>
14+
pre{margin:0;}
15+
pre.error{color:#f00;}
16+
pre.warning{color:#FFC500;}
17+
</style>
1418
<!-- Scripting Extensions -->
1519
<script src="../../src/scripting/build/Host.js"></script>
1620

1721
<title>Testrun Sandbox For CCL /w Scripting Enabled</title>
1822
</head>
1923
<body>
24+
<div style="position:absolute;right:0; top:0; width: 45%; overflow:auto; height:384px; padding:3px;" id="debug-console"></div>
2025
<div id="player-unit" style="width:540px;clear:both;">
2126
<div class="m20 abp" id="player" style="height:384px;">
2227
<div id="commentCanvas" class="container"></div>
@@ -78,6 +83,37 @@ <h2>Tests</h2>
7883

7984
var cm = new CommentManager($('commentCanvas'));
8085
var bscripter = new CCLScripting("../../src/scripting/build/Worker.js");
86+
bscripter.logger = new function(){
87+
this.log = function(t){
88+
var pre = document.createElement("pre");
89+
pre.textContent = t.toString();
90+
$("debug-console").appendChild(pre);
91+
while($("debug-console").children.length > 200){
92+
$("debug-console").removeChild($("debug-console").children[0]);
93+
}
94+
$("debug-console").scrollTop = 100000;
95+
};
96+
this.error = function(t){
97+
var pre = document.createElement("pre");
98+
pre.textContent = t.toString();
99+
pre.className = "error";
100+
$("debug-console").appendChild(pre);
101+
while($("debug-console").children.length > 200){
102+
$("debug-console").removeChild($("debug-console").children[0]);
103+
}
104+
$("debug-console").scrollTop = 100000;
105+
};
106+
this.warn = function(t){
107+
var pre = document.createElement("pre");
108+
pre.textContent = t.toString();
109+
pre.className = "warning";
110+
$("debug-console").appendChild(pre);
111+
while($("debug-console").children.length > 200){
112+
$("debug-console").removeChild($("debug-console").children[0]);
113+
}
114+
$("debug-console").scrollTop = 100000;
115+
};
116+
};
81117
cm.scripting = bscripter.getSandbox($("commentCanvas"));
82118
cm.init();
83119

src/CommentCoreLibrary.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ CommentManager.prototype.sendComment = function(data){
203203
this.stage.appendChild(cmt);
204204
cmt.width = cmt.offsetWidth;
205205
cmt.height = cmt.offsetHeight;
206-
cmt.style.width = (cmt.w + 1) + "px";
207-
cmt.style.height = (cmt.h - 3) + "px";
206+
cmt.style.width = (cmt.width + 1) + "px";
207+
cmt.style.height = (cmt.height - 3) + "px";
208208
cmt.style.left = this.stage.width + "px";
209209

210210
if(this.filter != null && !this.filter.beforeSend(cmt)){

src/CommentSpaceAllocator.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ function CommentSpaceAllocator(w,h){
2828
cmt.y = cmt.offsetTop;
2929
cmt.x = cmt.offsetLeft;
3030
cmt.right = cmt.offsetLeft + cmt.offsetWidth;
31-
if(cmt.w && cmt.h){
32-
cmt.width = cmt.w;
33-
cmt.height = cmt.h;
34-
}else{
31+
if(!cmt.width || !cmt.height){
3532
cmt.height = cmt.offsetHeight;
3633
cmt.width = cmt.offsetWidth;
3734
}

src/scripting/build/Host.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ var CCLScripting = function(workerUrl){
234234
CCLScripting.prototype.BridgedSandbox.prototype.init = function(){
235235
var self = this;
236236
/** Post whatever we need to **/
237-
self.send("Update:dimension", self.getContext().getDimensions());
237+
self.send("Update:DimensionUpdate", self.getContext().getDimensions());
238238
/** Hook Listeners **/
239239
this.addListener("Runtime::alert", function(msg){
240240
alert(msg);
@@ -355,6 +355,10 @@ var CCLScripting = function(workerUrl){
355355
data.y = y;
356356
this.DOM.style.top = data.y + "px";
357357
};
358+
this.setAlpha = function(a){
359+
data.alpha = a;
360+
this.DOM.style.opacity = a;
361+
}
358362
/** Load x,y **/
359363
this.setX(data.x);
360364
this.setY(data.y);
@@ -364,6 +368,12 @@ var CCLScripting = function(workerUrl){
364368
this.DOM.innerHTML = "";
365369
this.DOM.appendChild(_("text",text));
366370
};
371+
this.__defineSetter__("alpha", function(f){
372+
this.setAlpha(f);
373+
});
374+
this.__defineGetter__("alpha", function(f){
375+
return data.alpha;
376+
});
367377
this.__defineSetter__("x", function(f){
368378
this.setX(f);
369379
});
@@ -459,12 +469,18 @@ var CCLScripting = function(workerUrl){
459469
this.__defineSetter__("y", function(f){
460470
this.setY(f);
461471
});
472+
this.__defineSetter__("alpha", function(f){
473+
this.setAlpha(f);
474+
});
462475
this.__defineGetter__("x", function(f){
463476
return this._x;
464477
});
465478
this.__defineGetter__("y", function(f){
466479
return this._y;
467480
});
481+
this.__defineGetter__("alpha", function(f){
482+
return this._alpha;
483+
});
468484
/** /PROPS **/
469485

470486
this.line = {
@@ -528,6 +544,14 @@ var CCLScripting = function(workerUrl){
528544
"transform":"translate(" + this._x + "," + this._y + ")"
529545
});
530546
};
547+
this.setAlpha = function(alpha){
548+
if(!alpha)
549+
return;
550+
this._alpha = alpha;
551+
__(defaultGroup,{
552+
"opacity":this._alpha
553+
});
554+
};
531555
this.moveTo = function(params){
532556
var p = __("path",{
533557
"d":"M" + params.join(" ")

src/scripting/build/api/Display.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,9 @@ var Display;
13131313

13141314

13151315
CommentButton.prototype.initStyle = function (style) {
1316+
if (style.hasOwnProperty("parent")) {
1317+
style["parent"].addChild(this);
1318+
}
13161319
};
13171320

13181321
CommentButton.prototype.serialize = function () {
@@ -1357,6 +1360,9 @@ var Display;
13571360

13581361

13591362
CommentCanvas.prototype.initStyle = function (style) {
1363+
if (style.hasOwnProperty("parent")) {
1364+
style["parent"].addChild(this);
1365+
}
13601366
};
13611367
return CommentCanvas;
13621368
})(Display.Sprite);
@@ -1428,6 +1434,9 @@ var Display;
14281434

14291435

14301436
CommentShape.prototype.initStyle = function (style) {
1437+
if (style.hasOwnProperty("parent")) {
1438+
style["parent"].addChild(this);
1439+
}
14311440
if (style["lifeTime"]) {
14321441
this._mM.dur = style["lifeTime"] * 1000;
14331442
}
@@ -1664,6 +1673,9 @@ var Display;
16641673
if (style["bold"]) {
16651674
this.getTextFormat().bold = style["bold"];
16661675
}
1676+
if (style.hasOwnProperty("parent")) {
1677+
style["parent"].addChild(this);
1678+
}
16671679
this._mM.play();
16681680
};
16691681
return CommentField;
@@ -1783,6 +1795,16 @@ var Display;
17831795
return "[display Display]";
17841796
}
17851797
Display.toString = toString;
1798+
1799+
/** Update Listeners **/
1800+
__schannel("Update:DimensionUpdate", function (payload) {
1801+
_width = payload["stageWidth"];
1802+
_height = payload["stageHeight"];
1803+
if (payload.hasOwnProperty("screenWidth") && payload.hasOwnProperty("screenHeight")) {
1804+
_fullScreenWidth = payload["screenWidth"];
1805+
_fullScreenHeight = payload["screenHeight"];
1806+
}
1807+
});
17861808
})(Display || (Display = {}));
17871809

17881810
var $ = Display;

src/scripting/build/api/Player.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,14 @@ var Player;
199199
return "[player Player]";
200200
}
201201
Player.toString = toString;
202+
203+
/** Update Listeners **/
204+
__schannel("Update:DimensionUpdate", function (payload) {
205+
_width = payload["stageWidth"];
206+
_height = payload["stageHeight"];
207+
if (payload.hasOwnProperty("videoWidth") && payload.hasOwnProperty("videoHeight")) {
208+
_videoWidth = payload["videoWidth"];
209+
_videoHeight = payload["videoHeight"];
210+
}
211+
});
202212
})(Player || (Player = {}));

src/scripting/src/Host.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ var CCLScripting = function(workerUrl){
234234
CCLScripting.prototype.BridgedSandbox.prototype.init = function(){
235235
var self = this;
236236
/** Post whatever we need to **/
237-
self.send("Update:dimension", self.getContext().getDimensions());
237+
self.send("Update:DimensionUpdate", self.getContext().getDimensions());
238238
/** Hook Listeners **/
239239
this.addListener("Runtime::alert", function(msg){
240240
alert(msg);

src/scripting/src/Unpacker.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@
7676
data.y = y;
7777
this.DOM.style.top = data.y + "px";
7878
};
79+
this.setAlpha = function(a){
80+
data.alpha = a;
81+
this.DOM.style.opacity = a;
82+
}
7983
/** Load x,y **/
8084
this.setX(data.x);
8185
this.setY(data.y);
@@ -85,6 +89,12 @@
8589
this.DOM.innerHTML = "";
8690
this.DOM.appendChild(_("text",text));
8791
};
92+
this.__defineSetter__("alpha", function(f){
93+
this.setAlpha(f);
94+
});
95+
this.__defineGetter__("alpha", function(f){
96+
return data.alpha;
97+
});
8898
this.__defineSetter__("x", function(f){
8999
this.setX(f);
90100
});
@@ -180,12 +190,18 @@
180190
this.__defineSetter__("y", function(f){
181191
this.setY(f);
182192
});
193+
this.__defineSetter__("alpha", function(f){
194+
this.setAlpha(f);
195+
});
183196
this.__defineGetter__("x", function(f){
184197
return this._x;
185198
});
186199
this.__defineGetter__("y", function(f){
187200
return this._y;
188201
});
202+
this.__defineGetter__("alpha", function(f){
203+
return this._alpha;
204+
});
189205
/** /PROPS **/
190206

191207
this.line = {
@@ -249,6 +265,14 @@
249265
"transform":"translate(" + this._x + "," + this._y + ")"
250266
});
251267
};
268+
this.setAlpha = function(alpha){
269+
if(!alpha)
270+
return;
271+
this._alpha = alpha;
272+
__(defaultGroup,{
273+
"opacity":this._alpha
274+
});
275+
};
252276
this.moveTo = function(params){
253277
var p = __("path",{
254278
"d":"M" + params.join(" ")

0 commit comments

Comments
 (0)