Skip to content

Commit

Permalink
Add changes to scripting environment and incorporate bugfix in compil…
Browse files Browse the repository at this point in the history
…ed version
  • Loading branch information
jabbany committed May 30, 2018
1 parent 536bc52 commit e8e551d
Show file tree
Hide file tree
Showing 40 changed files with 1,260 additions and 685 deletions.
2 changes: 1 addition & 1 deletion dist/CommentCoreLibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,7 @@ var CommentManager = (function() {
try {
this._listeners[event][i](data);
} catch (e) {
console.err(e.stack);
console.error(e.stack);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/CommentCoreLibrary.min.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion dist/scripting/Host.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ var CCLScripting = function(workerUrl){
this.resetWorker = function(){
try{
worker.terminate();
}catch(e){}
} catch(e) {

}
worker = scripter.getWorker();
if(!worker){
throw new Error("SANDBOX: Worker pool exhausted.");
Expand Down
338 changes: 247 additions & 91 deletions dist/scripting/api/Display.js

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion dist/scripting/api/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,18 @@ var Player;
__trace('Your environment does not support player triggers.', 'warn');
return;
}
__trace('Comment trigger: not implemented', 'warn');
}
Player.commentTrigger = commentTrigger;
function keyTrigger(callback, timeout) {
if (!Runtime.hasObject('__player')) {
__trace('Your environment does not support key triggers.', 'warn');
return;
}
var player = Runtime.getObject('__player');
player.addEventListener('keydown', function (key) {
callback(key.keyCode);
});
}
Player.keyTrigger = keyTrigger;
function setMask(mask) {
Expand All @@ -194,7 +203,7 @@ var Player;
return '[player Player]';
}
Player.toString = toString;
__schannel("Update:DimensionUpdate", function (payload) {
__schannel('Update:DimensionUpdate', function (payload) {
_width = payload["stageWidth"];
_height = payload["stageHeight"];
if (payload.hasOwnProperty("videoWidth") &&
Expand Down
131 changes: 112 additions & 19 deletions dist/scripting/api/Runtime.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,83 @@
var Runtime;
(function (Runtime) {
var NotCrypto;
(function (NotCrypto) {
var _rngState = [
Math.floor(Date.now() / 1024) % 1024,
Date.now() % 1024
];
var Rc4 = (function () {
function Rc4(key) {
this._s = [];
for (var i = 0; i < 256; i++) {
this._s[i] = i;
}
var j = 0;
for (var i = 0; i < 256; i++) {
j = j + this._s[i] + key[i % key.length] % 256;
var m = this._s[i];
this._s[i] = this._s[j];
this._s[j] = m;
}
}
return Rc4;
}());
function random(bits) {
if (bits === void 0) { bits = 16; }
if (bits > 32) {
throw new Error('NotCrypto.random expects 32 bits or less');
}
if (Math && Math.random) {
var value = 0;
for (var i = 0; i < bits; i++) {
value = (value << 1) + (Math.random() < 0.5 ? 0 : 1);
}
return value;
}
else {
return Runtime.NotCrypto.fallbackRandom(Date.now() % 1024, bits);
}
}
NotCrypto.random = random;
function xorshift128p() {
var s0 = _rngState[1], s1 = _rngState[0];
_rngState[0] = s0;
s1 ^= s1 << 23;
s1 ^= s1 >> 17;
s1 ^= s0;
s1 ^= s0 >> 26;
_rngState[1] = s1;
}
function fallbackRandom(seed, bits) {
if (bits === void 0) { bits = 16; }
if (bits > 32) {
throw new Error('NotCrypto.fallbackRandom expects 32 bits or less');
}
for (var i = 0; i < seed; i++) {
xorshift128p();
}
var mask = 0;
for (var i = 0; i < bits; i++) {
mask = (mask << 1) + 1;
}
return (_rngState[0] + _rngState[1]) & mask;
}
NotCrypto.fallbackRandom = fallbackRandom;
function toHex(value, length) {
if (length === void 0) { length = 0; }
if (length <= 0) {
return value.toString(16);
}
var base = value.toString(16);
while (base.length < length) {
base = '0' + base;
}
return base;
}
NotCrypto.toHex = toHex;
})(NotCrypto = Runtime.NotCrypto || (Runtime.NotCrypto = {}));
})(Runtime || (Runtime = {}));
var Runtime;
(function (Runtime) {
var RuntimeTimer = (function () {
function RuntimeTimer(type, dur, key, callback) {
Expand Down Expand Up @@ -414,6 +493,9 @@ var Runtime;
var MetaObject = (function () {
function MetaObject(name) {
this._listeners = {};
if (name.slice(0, 2) !== '__') {
throw new Error('MetaObject names must start with two underscores.');
}
this._name = name;
}
MetaObject.prototype.addEventListener = function (event, listener, useCapture, priority) {
Expand Down Expand Up @@ -491,55 +573,66 @@ var Runtime;
Runtime.getObject = getObject;
function registerObject(object) {
if (!object.getId) {
__trace("Attempted to register unnamed object", "warn");
__trace('Cannot register object without getId method.', 'warn');
return;
}
if (!Runtime.hasObject(object.getId())) {
_registeredObjects[object.getId()] = object;
__pchannel("Runtime:RegisterObject", {
"id": object.getId(),
"data": object.serialize()
__pchannel('Runtime:RegisterObject', {
'id': object.getId(),
'data': object.serialize()
});
__schannel("object::(" + object.getId() + ")", function (payload) {
if (payload.hasOwnProperty("type") &&
payload.type === "event") {
if (payload.hasOwnProperty('type') &&
payload.type === 'event') {
_dispatchEvent(object.getId(), payload.event, payload.data);
}
});
objCount++;
return;
}
else {
__trace('Attempted to re-register object or id collision', 'warn');
__trace('Attempted to re-register object or id collision @ ' +
object.getId(), 'warn');
return;
}
}
Runtime.registerObject = registerObject;
function deregisterObject(objectId) {
function deregisterObject(object) {
var objectId = object.getId();
deregisterObjectById(objectId);
}
Runtime.deregisterObject = deregisterObject;
function deregisterObjectById(objectId) {
if (Runtime.hasObject(objectId)) {
if (objectId.substr(0, 2) === "__") {
__trace("Runtime.deregisterObject cannot de-register a MetaObject", "warn");
if (objectId.substr(0, 2) === '__') {
__trace('Runtime.deregisterObject cannot de-register a MetaObject', 'warn');
return;
}
__pchannel("Runtime:DeregisterObject", {
"id": objectId
__pchannel('Runtime:DeregisterObject', {
'id': objectId
});
if (typeof _registeredObjects[objectId].unload === "function") {
_registeredObjects[objectId].unload();
}
_registeredObjects[objectId] = null;
delete _registeredObjects[objectId];
objCount--;
}
}
Runtime.deregisterObject = deregisterObject;
function _getId(type, container) {
if (type === void 0) { type = 'obj'; }
if (container === void 0) { container = 'rt'; }
var randomSeed = Math.random();
var randomSegment = '';
return;
}
function generateId(type) {
if (type === void 0) { type = "obj"; }
var id = type + ":" + (new Date()).getTime() + "|" +
Math.round(Math.random() * 4096) + ":" + objCount;
var id = [type, ':', Date.now(), '|',
Runtime.NotCrypto.random(16), ':', objCount].join();
while (Runtime.hasObject(id)) {
id = type + ":" + (new Date()).getTime() + "|" +
Math.round(Math.random() * 4096) + ":" + objCount;
id = type + ":" + Date.now() + "|" +
Runtime.NotCrypto.random(16) + ":" + objCount;
}
return id;
}
Expand All @@ -548,7 +641,7 @@ var Runtime;
function reset() {
for (var i in _registeredObjects) {
if (i.substr(0, 2) !== "__") {
Runtime.deregisterObject(i);
deregisterObjectById(i);
}
}
}
Expand Down
21 changes: 4 additions & 17 deletions dist/scripting/api/Tween.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ var Tween;
return c / 2 * (t * t * t * t * t + 2) + b;
}
Tween.quintic = quintic;
function circuar(t, b, c, d) {
function circular(t, b, c, d) {
t /= d / 2;
if (t < 1)
return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
t -= 2;
return c / 2 * (Math.sqrt(1 - t * t) + 1) + b;
}
Tween.circuar = circuar;
Tween.circular = circular;
function sine(t, b, c, d) {
return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b;
}
Expand All @@ -61,7 +61,7 @@ var Tween;
linear: Tween.linear,
back: null,
bounce: null,
circular: Tween.circuar,
circular: Tween.circular,
cubic: Tween.cubic,
elastic: null,
exponential: Tween.exponential,
Expand All @@ -84,7 +84,7 @@ var Tween;
case "exponential":
return Tween.exponential;
case "circular":
return Tween.circuar;
return Tween.circular;
case "quadratic":
return Tween.quadratic;
case "cubic":
Expand Down Expand Up @@ -248,19 +248,6 @@ var Tween;
}
};
}
function choose(n, k) {
if (n < 0 || k < 0) {
throw new Error('Cannot compute n-choose-k with negative inputs.');
}
if (k > n / 2) {
return choose(n, n - k);
}
var value = 1;
for (var i = 1; i <= k; i++) {
value *= (n + 1 - i) / i;
}
return value;
}
function tween(object, dest, src, duration, easing) {
if (dest === void 0) { dest = {}; }
if (src === void 0) { src = {}; }
Expand Down
2 changes: 1 addition & 1 deletion dist/scripting/api/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var Utils;
}
Utils.hue = hue;
function formatTimes(time) {
return Math.floor(time / 60) + ":" + (time % 60 > 9 ? time % 60 + "" : "0" + (time % 60));
return Math.floor(time / 60) + ":" + (time % 60 > 9 ? "" : "0") + time % 60;
}
Utils.formatTimes = formatTimes;
function distance(x1, y1, x2, y2) {
Expand Down
Loading

0 comments on commit e8e551d

Please sign in to comment.