diff --git a/.gitignore b/.gitignore index eb3a634eb..04ae94128 100644 --- a/.gitignore +++ b/.gitignore @@ -1,89 +1,91 @@ -# Mac - -.DS_Store - -# Logs -logs -*.log -npm-debug.log* - -# Runtime data -pids -*.pid -*.seed - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (http://nodejs.org/api/addons.html) -build/Release - -# Dependency directory -# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git -node_modules -bower_components - -temp/ -desktop\.ini -*.png~ -.directory - -# Generated files -src/typedefs/ct.js/types.d.ts -app/examples -app/data/bundle.js -app/data/bundle.css -app/data/node_requires/**/* -app/data/fonts/style/.css -app/data/theme*.css -app/data/typedefs/global.d.ts -app/data/typedefs/pixi.js.d.ts -/app/data/docs -app/index.html -app/preview.html -app/empty.html -app/debuggerToolbar.html -app/qrCodePanel.html -app/exportDesktop -app/temp -/temp -app/data/fonts/style/.css -app/data/patronsCache.csv -builds -build -cache -tempChangelog.md - -# tests -error_screenshots/ -reports/ - -# ct specific -/export -app/zipexport -app/*.ict.zip -app/Screenshot of *.png -app/export.zip -app/export -*.ict.recovery - -# editor-specific -/.vscode - -# docs -docs/db.json -docs/node_modules -docs/public -app/data/icons.svg -export.zip -app/pleaseCtJSLoadWithoutGPUAccelerationMmkay -app/debugger.html +# Mac + +.DS_Store + +# Logs +logs +*.log +npm-debug.log* + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directory +# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git +node_modules +bower_components + +temp/ +desktop\.ini +*.png~ +.directory + +# Generated files +src/typedefs/ct.js/types.d.ts +app/examples +app/data/bundle.js +app/data/bundle.css +app/data/node_requires/**/* +app/data/fonts/style/.css +app/data/theme*.css +app/data/typedefs/global.d.ts +app/data/typedefs/pixi.js.d.ts +/app/data/docs +app/index.html +app/preview.html +app/empty.html +app/debuggerToolbar.html +app/qrCodePanel.html +app/exportDesktop +app/temp +/temp +app/data/fonts/style/.css +app/data/patronsCache.csv +builds +build +cache +tempChangelog.md + +# tests +error_screenshots/ +reports/ + +# ct specific +/export +app/zipexport +app/*.ict.zip +app/Screenshot of *.png +app/export.zip +app/export +*.ict.recovery + +# editor-specific +/.vscode + +# docs +docs/db.json +docs/node_modules +docs/public +app/data/icons.svg +export.zip +app/pleaseCtJSLoadWithoutGPUAccelerationMmkay +app/debugger.html + +**/**/*.orig diff --git a/app/data/ct.libs/flow/DOCS.md b/app/data/ct.libs/flow/DOCS.md index 327654b9c..8b4a46d5f 100644 --- a/app/data/ct.libs/flow/DOCS.md +++ b/app/data/ct.libs/flow/DOCS.md @@ -96,9 +96,12 @@ Similar to `ct.flow.delay`, this method will return a new function that will lim the execution of the `func` to max once in `ms` period. It will call the function first and then block the execution for `ms` time, though. +It takes into account `ct.delta` or `ct.deltaUi`. + **Returns**: `function` - a new triggerable function | Param | Type | Description | | --- | --- | --- | | func | `function` | The function to limit | | ms | `Number` | The period to wait, in milliseconds | +| [useUiDelta=false] | `Boolean` | If true, use `ct.deltaUi` instead of `ct.delta` | diff --git a/app/data/ct.libs/flow/README.md b/app/data/ct.libs/flow/README.md index e37f59986..e7c673d3a 100644 --- a/app/data/ct.libs/flow/README.md +++ b/app/data/ct.libs/flow/README.md @@ -1,3 +1 @@ -A collection of high-level utilities for flow control, that are especially useful while working with asynchronous events. - -Please note that this function **ignores the scaling of `ct.delta`**, meaning that triggers will work even while the game is paused. \ No newline at end of file +A collection of high-level utilities for flow control, that are especially useful while working with asynchronous events. \ No newline at end of file diff --git a/app/data/ct.libs/flow/index.js b/app/data/ct.libs/flow/index.js index b489f849d..83735d46e 100644 --- a/app/data/ct.libs/flow/index.js +++ b/app/data/ct.libs/flow/index.js @@ -140,16 +140,21 @@ * * @param {Function} func The function to limit * @param {Number} ms The period to wait, in milliseconds + * @param {boolean} [useUiDelta=false] If true, use ct.deltaUi instead of ct.delta * @returns {Function} a new triggerable function */ - timer(func, ms) { + timer(func, ms, useUiDelta = false) { // The same may be done with ct.flow.gate + ct.flow. var timer; var delay = function () { if (!timer) { - timer = setTimeout(() => { + timer = true; + ct.u.wait(ms, useUiDelta).then(() => { timer = false; - }, ms); + }); + /*timer = setTimeout(() => { + timer = false; + }, ms);*/ func(); } }; diff --git a/app/data/ct.libs/tween/DOCS.md b/app/data/ct.libs/tween/DOCS.md index 7f1d58bd6..75ae1b946 100644 --- a/app/data/ct.libs/tween/DOCS.md +++ b/app/data/ct.libs/tween/DOCS.md @@ -7,6 +7,7 @@ Creates a new tween effect and adds it to the game loop. * `options.fields` A map with pairs `fieldName: newValue`. Values must be of numerical type. * `options.curve` An interpolating function. You can write your own, or use default ones written below. The default one is `ct.tween.ease`. * `options.duration` The duration of easing, in milliseconds. + * `options.useUiDelta` If true, use `ct.deltaUi` instead of `ct.delta`. The default is `false`. Returns a Promise which is resolved if the effect was fully played, or rejected if it was interrupted manually by code, room switching or Copy kill. diff --git a/app/data/ct.libs/tween/index.js b/app/data/ct.libs/tween/index.js index cf4531cb5..88987dc38 100644 --- a/app/data/ct.libs/tween/index.js +++ b/app/data/ct.libs/tween/index.js @@ -1,17 +1,18 @@ -/* global ct */ +/* global CtTimer */ ct.tween = { /** * Creates a new tween effect and adds it to the game loop - * + * * @param {Object} options An object with options: * @param {Object|Copy} options.obj An object to animate. All objects are supported. * @param {Object} options.fields A map with pairs `fieldName: newValue`. Values must be of numerical type. - * @param {Function} options.curve An interpolating function. You can write your own, - * or use default ones written below. The default one is `ct.tween.ease`. + * @param {Function} options.curve An interpolating function. You can write your own, + * or use default ones (see methods in `ct.tween`). The default one is `ct.tween.ease`. * @param {Number} options.duration The duration of easing, in milliseconds. - * - * @returns {Promise} A promise which is resolved if the effect was fully played, + * @param {Number} options.useUiDelta If true, use ct.deltaUi instead of ct.delta. The default is `false`. + * + * @returns {Promise} A promise which is resolved if the effect was fully played, * or rejected if it was interrupted manually by code, room switching or instance kill. * You can call a `stop()` method on this promise to interrupt it manually. */ @@ -21,7 +22,8 @@ ct.tween = { fields: options.fields || {}, curve: options.curve || ct.tween.ease, duration: options.duration || 1000, - registered: (Number(new Date())) + useUiDelta: options.useUiDelta || false, + timer: new CtTimer('ct.tween', this.duration, this.useUiDelta) }; var promise = new Promise((resolve, reject) => { tween.resolve = resolve; @@ -44,8 +46,8 @@ ct.tween = { /** * Linear interpolation. * Here and below, these parameters are used: - * - * @param {Number} s Starting value + * + * @param {Number} s Starting value * @param {Number} d The change of value to transition to, the Delta * @param {Number} a The current timing state, 0-1 * @returns {Number} Interpolated value @@ -56,61 +58,61 @@ ct.tween = { ease(s, d, a) { a *= 2; if (a < 1) { - return d/2*a*a + s; + return d / 2 * a * a + s; } a--; - return -d/2 * (a*(a-2) - 1) + s; + return -d / 2 * (a * (a - 2) - 1) + s; }, easeInQuad(s, d, a) { - return d*a*a + s; + return d * a * a + s; }, easeOutQuad(s, d, a) { - return -d * a*(a-2) + s; + return -d * a * (a - 2) + s; }, easeInCubic(s, d, a) { - return d*a*a*a + s; + return d * a * a * a + s; }, easeOutCubic(s, d, a) { a--; - return d*(a*a*a + 1) + s; + return d * (a * a * a + 1) + s; }, easeInOutCubic(s, d, a) { a *= 2; if (a < 1) { - return d/2*a*a*a + s; + return d / 2 * a * a * a + s; } a -= 2; - return d/2*(a*a*a + 2) + s; + return d / 2 * (a * a * a + 2) + s; }, easeInOutQuart(s, d, a) { a *= 2; if (a < 1) { - return d/2*a*a*a*a + s; + return d / 2 * a * a * a * a + s; } a -= 2; - return -d/2 * (a*a*a*a - 2) + s; + return -d / 2 * (a * a * a * a - 2) + s; }, easeInQuart(s, d, a) { - return d*a*a*a*a + s; + return d * a * a * a * a + s; }, easeOutQuart(s, d, a) { a--; - return -d * (a*a*a*a - 1) + s; + return -d * (a * a * a * a - 1) + s; }, easeInCirc(s, d, a) { - return -d * (Math.sqrt(1 - a*a) - 1) + s; + return -d * (Math.sqrt(1 - a * a) - 1) + s; }, easeOutCirc(s, d, a) { a--; - return d * Math.sqrt(1 - a*a) + s; + return d * Math.sqrt(1 - a * a) + s; }, easeInOutCirc(s, d, a) { a *= 2; if (a < 1) { - return -d/2 * (Math.sqrt(1 - a*a) - 1) + s; + return -d / 2 * (Math.sqrt(1 - a * a) - 1) + s; } a -= 2; - return d/2 * (Math.sqrt(1 - a*a) + 1) + s; + return d / 2 * (Math.sqrt(1 - a * a) + 1) + s; }, tweens: [], wait: ct.u.wait diff --git a/app/data/ct.libs/tween/injects/beforeroomstep.js b/app/data/ct.libs/tween/injects/beforeroomstep.js index 112ad9b08..3b47e264f 100644 --- a/app/data/ct.libs/tween/injects/beforeroomstep.js +++ b/app/data/ct.libs/tween/injects/beforeroomstep.js @@ -1,7 +1,4 @@ -/* global ct */ - var i = 0; -var newTime = Number(new Date()); while (i < ct.tween.tweens.length) { var tween = ct.tween.tweens[i]; if (tween.obj.kill) { @@ -12,7 +9,7 @@ while (i < ct.tween.tweens.length) { ct.tween.tweens.splice(i, 1); continue; } - var a = (newTime - tween.registered) / tween.duration; + var a = tween.timer.time / tween.duration; if (a > 1) { a = 1; } diff --git a/app/data/ct.release/main.js b/app/data/ct.release/main.js index c39510faa..7cbd3cc89 100644 --- a/app/data/ct.release/main.js +++ b/app/data/ct.release/main.js @@ -1,4 +1,7 @@ /* Made with ct.js http://ctjs.rocks/ */ + +/* global CtTimer */ + const deadPool = []; // a pool of `kill`-ed copies for delaying frequent garbage collection const copyTypeSymbol = Symbol('I am a ct.js copy'); setInterval(function () { @@ -45,9 +48,9 @@ const ct = { * This is a version for UI elements, as it is not affected by time scaling, and thus works well * both with slow-mo effects and game pause. * - * @type {number} - */ - deltaUi: 1, + * @type {number} + */ + deltaUi: 1, /** * The camera that outputs its view to the renderer. * @type {Camera} @@ -147,7 +150,7 @@ try { console.error(e); // eslint-disable-next-line no-console console.warn('[ct.js] Something bad has just happened. This is usually due to hardware problems. I\'ll try to fix them now, but if the game still doesn\'t run, try including a legacy renderer in the project\'s settings.'); - PIXI.settings.SPRITE_MAX_TEXTURES = Math.min(PIXI.settings.SPRITE_MAX_TEXTURES , 16); + PIXI.settings.SPRITE_MAX_TEXTURES = Math.min(PIXI.settings.SPRITE_MAX_TEXTURES, 16); ct.pixiApp = new PIXI.Application(pixiAppSettings); } @@ -289,7 +292,7 @@ ct.u = { * @returns {number} The result of the interpolation */ lerp(a, b, alpha) { - return a + (b-a)*alpha; + return a + (b - a) * alpha; }, /** * Returns the position of a given value in a given range. Opposite to linear interpolation. @@ -361,7 +364,7 @@ ct.u = { * @param {any} [arr] An optional array of properties to copy. If not specified, all the properties will be copied. * @returns {object} The modified destination object */ - ext (o1, o2, arr) { + ext(o1, o2, arr) { if (arr) { for (const i in arr) { if (o2[arr[i]]) { @@ -390,22 +393,26 @@ ct.u = { document.getElementsByTagName('head')[0].appendChild(script); }, /** - * Returns a Promise that resolves after the given time + * Returns a Promise that resolves after the given time. + * This timer is run in gameplay time scale, meaning that it is affected by time stretching. * @param {number} time Time to wait, in milliseconds - * @returns {Promise} The promise with no data + * @returns {CtTimer} The timer, which you can call `.then()` to */ wait(time) { - var room = ct.room.name; - return new Promise((resolve, reject) => setTimeout(() => { - if (ct.room.name === room) { - resolve(); - } else { - reject({ - info: 'Room switch', - from: 'ct.u.wait' - }); - } - }, time)); + const id = ct.timer.counter; + ct.timer.counter++; + return new CtTimer('ct.u.wait' + id, time); + }, + /** + * Returns a Promise that resolves after the given time. + * This timer runs in UI time scale and is not sensitive to time stretching. + * @param {number} time Time to wait, in milliseconds + * @returns {CtTimer} The timer, which you can call `.then()` to + */ + waitUi(time) { + const id = ct.timer.counter; + ct.timer.counter++; + return new CtTimer('ct.u.wait' + id, time, true); } }; ct.u.ext(ct.u, {// make aliases @@ -449,10 +456,11 @@ ct.u.ext(ct.u, {// make aliases } }; - ct.loop = function(delta) { + ct.loop = function (delta) { ct.delta = delta; ct.deltaUi = PIXI.Ticker.shared.elapsedMS / (1000 / (PIXI.Ticker.shared.maxFPS || 60)); ct.inputs.updateActions(); + ct.timer.updateTimers(); for (let i = 0, li = ct.stack.length; i < li; i++) { ct.types.beforeStep.apply(ct.stack[i]); ct.stack[i].onStep.apply(ct.stack[i]); diff --git a/app/data/ct.release/timer.js b/app/data/ct.release/timer.js new file mode 100644 index 000000000..5937c7238 --- /dev/null +++ b/app/data/ct.release/timer.js @@ -0,0 +1,163 @@ +(function () { + const ctTimerTime = Symbol('time'); + const ctTimerRoomName = Symbol('roomName'); + const ctTimerTimeLeftOriginal = Symbol('timeLeftOriginal'); + const promiseResolve = Symbol('promiseResolve'); + const promiseReject = Symbol('promiseReject'); + + /** + * @property {boolean} isUi Whether the timer uses ct.deltaUi or not. + * @property {string|false} name The name of the timer + */ + class CtTimer { + /** + * An object for holding a timer + * + * @param {number} timeMs The length of the timer, **in milliseconds** + * @param {string|false} [name=false] The name of the timer + * @param {boolean} [uiDelta=false] If `true`, it will use `ct.deltaUi` for counting time. if `false`, it will use `ct.delta` for counting time. + */ + constructor(timeMs, name = false, uiDelta = false) { + this[ctTimerRoomName] = ct.room.name || ''; + this.name = name && name.toString(); + this.isUi = uiDelta; + this[ctTimerTime] = 0; + this[ctTimerTimeLeftOriginal] = timeMs; + this.timeLeft = this[ctTimerTimeLeftOriginal]; + this.promise = new Promise((resolve, reject) => { + this[promiseResolve] = resolve; + this[promiseReject] = reject; + }); + this.rejected = false; + this.done = false; + this.settled = false; + ct.timer.timers.add(this); + } + + /** + * Attaches callbacks for the resolution and/or rejection of the Promise. + * + * @param {Function} onfulfilled The callback to execute when the Promise is resolved. + * @param {Function} [onrejected] The callback to execute when the Promise is rejected. + * @returns {Promise} A Promise for the completion of which ever callback is executed. + */ + then(...args) { + return this.promise.then(...args); + } + /** + * Attaches a callback for the rejection of the Promise. + * + * @param {Function} [onrejected] The callback to execute when the Promise is rejected. + * @returns {Promise} A Promise for the completion of which ever callback is executed. + */ + catch(onrejected) { + return this.promise.catch(onrejected); + } + + /** + * The time passed on this timer, in seconds + * @type {number} + */ + get time() { + return this[ctTimerTime] * 1000 / ct.speed; + } + set time(newTime) { + this[ctTimerTime] = newTime / 1000 * ct.speed; + } + + /** + * Updates the timer. **DONT CALL THIS UNLESS YOU KNOW WHAT YOU ARE DOING** + * + * @returns {void} + * @private + */ + update() { + // Not something that would normally happen, + // but do check whether this timer was not automatically removed + if (this.rejected === true || this.done === true) { + this.remove(); + return; + } + this[ctTimerTime] += this.isUi ? ct.deltaUi : ct.delta; + if (ct.room.name !== this[ctTimerRoomName] && this[ctTimerRoomName] !== '') { + this.reject({ + info: 'Room switch', + from: 'ct.timer' + }); // Reject if the room was switched + } + + // If the timer is supposed to end + if (this.timeLeft !== 0) { + this.timeLeft = this[ctTimerTimeLeftOriginal] - this.time; + if (this.timeLeft <= 0) { + this.resolve(); + } + } + } + + /** + * Instantly triggers the timer and calls the callbacks added through `then` method. + * @returns {void} + */ + resolve() { + this.done = true; + this.settled = true; + this[promiseResolve](); + this.remove(); + } + /** + * Stops the timer with a given message by rejecting a Promise object. + * @param {any} message The value to pass to the `catch` callback + * @returns {void} + */ + reject(message) { + this.rejected = true; + this.settled = true; + this[promiseReject](message); + this.remove(); + } + /** + * Removes the timer from ct.js game loop. This timer will not trigger. + * @returns {void} + */ + remove() { + ct.timer.timers.delete(this); + } + } + window.CtTimer = CtTimer; + + /** + * Timer utilities + * @namespace + */ + ct.timer = { + /** + * A set with all the active timers. + * @type Set + */ + timers: new Set(), + counter: 0, + /** + * Adds a new timer with a given name + * + * @param {string|false} name The name of the timer, which you use to access it from `ct.timer.timers`. + * @param {number} [timeMs=0] The length of the timer, **in milliseconds** + * @param {boolean} [uiDelta=false] If `true`, it will use `ct.deltaUi` for counting time. if `false`, it will use `ct.delta` for counting time. + * @returns {CtTimer} The timer + */ + add(name=false, timeMs = 0, uiDelta = false) { + return new CtTimer(name, timeMs, uiDelta, true); + }, + /** + * Updates the timers. **DONT CALL THIS UNLESS YOU KNOW WHAT YOU ARE DOING** + * + * @returns {void} + * @private + */ + updateTimers() { + for (const timer of this.timers) { + timer.update(); + } + } + }; +})(); diff --git a/package-lock.json b/package-lock.json index b87799b3d..2545a9d8b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1692,9 +1692,9 @@ "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" }, "readable-stream": { - "version": "2.3.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", - "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", "requires": { "core-util-is": "~1.0.0", "inherits": "~2.0.3", @@ -3215,9 +3215,9 @@ "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" }, "readable-stream": { - "version": "2.3.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", - "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", "requires": { "core-util-is": "~1.0.0", "inherits": "~2.0.3", @@ -3341,22 +3341,26 @@ "dependencies": { "abbrev": { "version": "1.1.1", - "bundled": true, + "resolved": false, + "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==", "optional": true }, "ansi-regex": { "version": "2.1.1", - "bundled": true, + "resolved": false, + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", "optional": true }, "aproba": { "version": "1.2.0", - "bundled": true, + "resolved": false, + "integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw==", "optional": true }, "are-we-there-yet": { "version": "1.1.5", - "bundled": true, + "resolved": false, + "integrity": "sha512-5hYdAkZlcG8tOLujVDTgCT+uPX0VnpAH28gWsLfzpXYm7wP6mp5Q/gYyR7YQ0cKVJcXJnl3j2kpBan13PtQf6w==", "optional": true, "requires": { "delegates": "^1.0.0", @@ -3365,12 +3369,14 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true, + "resolved": false, + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", "optional": true }, "brace-expansion": { "version": "1.1.11", - "bundled": true, + "resolved": false, + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "optional": true, "requires": { "balanced-match": "^1.0.0", @@ -3384,22 +3390,26 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true, + "resolved": false, + "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=", "optional": true }, "concat-map": { "version": "0.0.1", - "bundled": true, + "resolved": false, + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "optional": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true, + "resolved": false, + "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=", "optional": true }, "core-util-is": { "version": "1.0.2", - "bundled": true, + "resolved": false, + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", "optional": true }, "debug": { @@ -3412,17 +3422,20 @@ }, "deep-extend": { "version": "0.6.0", - "bundled": true, + "resolved": false, + "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==", "optional": true }, "delegates": { "version": "1.0.0", - "bundled": true, + "resolved": false, + "integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=", "optional": true }, "detect-libc": { "version": "1.0.3", - "bundled": true, + "resolved": false, + "integrity": "sha1-+hN8S9aY7fVc1c0CrFWfkaTEups=", "optional": true }, "fs-minipass": { @@ -3435,12 +3448,14 @@ }, "fs.realpath": { "version": "1.0.0", - "bundled": true, + "resolved": false, + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "optional": true }, "gauge": { "version": "2.7.4", - "bundled": true, + "resolved": false, + "integrity": "sha1-LANAXHU4w51+s3sxcCLjJfsBi/c=", "optional": true, "requires": { "aproba": "^1.0.3", @@ -3468,12 +3483,14 @@ }, "has-unicode": { "version": "2.0.1", - "bundled": true, + "resolved": false, + "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=", "optional": true }, "iconv-lite": { "version": "0.4.24", - "bundled": true, + "resolved": false, + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", "optional": true, "requires": { "safer-buffer": ">= 2.1.2 < 3" @@ -3489,7 +3506,8 @@ }, "inflight": { "version": "1.0.6", - "bundled": true, + "resolved": false, + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", "optional": true, "requires": { "once": "^1.3.0", @@ -3503,12 +3521,14 @@ }, "ini": { "version": "1.3.5", - "bundled": true, + "resolved": false, + "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==", "optional": true }, "is-fullwidth-code-point": { "version": "1.0.0", - "bundled": true, + "resolved": false, + "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", "optional": true, "requires": { "number-is-nan": "^1.0.0" @@ -3516,12 +3536,14 @@ }, "isarray": { "version": "1.0.0", - "bundled": true, + "resolved": false, + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", "optional": true }, "minimatch": { "version": "3.0.4", - "bundled": true, + "resolved": false, + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "optional": true, "requires": { "brace-expansion": "^1.1.7" @@ -3623,7 +3645,8 @@ }, "npmlog": { "version": "4.1.2", - "bundled": true, + "resolved": false, + "integrity": "sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==", "optional": true, "requires": { "are-we-there-yet": "~1.1.2", @@ -3634,17 +3657,20 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true, + "resolved": false, + "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=", "optional": true }, "object-assign": { "version": "4.1.1", - "bundled": true, + "resolved": false, + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", "optional": true }, "once": { "version": "1.4.0", - "bundled": true, + "resolved": false, + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", "optional": true, "requires": { "wrappy": "1" @@ -3652,17 +3678,20 @@ }, "os-homedir": { "version": "1.0.2", - "bundled": true, + "resolved": false, + "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=", "optional": true }, "os-tmpdir": { "version": "1.0.2", - "bundled": true, + "resolved": false, + "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", "optional": true }, "osenv": { "version": "0.1.5", - "bundled": true, + "resolved": false, + "integrity": "sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g==", "optional": true, "requires": { "os-homedir": "^1.0.0", @@ -3671,7 +3700,8 @@ }, "path-is-absolute": { "version": "1.0.1", - "bundled": true, + "resolved": false, + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "optional": true }, "process-nextick-args": { @@ -3681,7 +3711,8 @@ }, "rc": { "version": "1.2.8", - "bundled": true, + "resolved": false, + "integrity": "sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==", "optional": true, "requires": { "deep-extend": "^0.6.0", @@ -3714,17 +3745,20 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true, + "resolved": false, + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", "optional": true }, "safer-buffer": { "version": "2.1.2", - "bundled": true, + "resolved": false, + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "optional": true }, "sax": { "version": "1.2.4", - "bundled": true, + "resolved": false, + "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==", "optional": true }, "semver": { @@ -3734,17 +3768,20 @@ }, "set-blocking": { "version": "2.0.0", - "bundled": true, + "resolved": false, + "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", "optional": true }, "signal-exit": { "version": "3.0.2", - "bundled": true, + "resolved": false, + "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", "optional": true }, "string-width": { "version": "1.0.2", - "bundled": true, + "resolved": false, + "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", "optional": true, "requires": { "code-point-at": "^1.0.0", @@ -3754,7 +3791,8 @@ }, "string_decoder": { "version": "1.1.1", - "bundled": true, + "resolved": false, + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", "optional": true, "requires": { "safe-buffer": "~5.1.0" @@ -3762,7 +3800,8 @@ }, "strip-ansi": { "version": "3.0.1", - "bundled": true, + "resolved": false, + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", "optional": true, "requires": { "ansi-regex": "^2.0.0" @@ -3770,7 +3809,8 @@ }, "strip-json-comments": { "version": "2.0.1", - "bundled": true, + "resolved": false, + "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", "optional": true }, "tar": { @@ -3925,9 +3965,9 @@ "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" }, "readable-stream": { - "version": "2.3.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", - "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", "requires": { "core-util-is": "~1.0.0", "inherits": "~2.0.3", @@ -5082,9 +5122,9 @@ } }, "has-symbols": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.0.tgz", - "integrity": "sha1-uhqPGvKg/DllD1yFA2dwQSIGO0Q=" + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.1.tgz", + "integrity": "sha512-PLcsoqu++dmEIZB+6totNFKq/7Do+Z0u4oT0zKOJNl3lYK6vGwwu2hjHs+68OEZbTjiUE9bgOABXbP/GvrS0Kg==" }, "has-value": { "version": "1.0.0", @@ -5938,14 +5978,14 @@ "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" }, "process-nextick-args": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz", - "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==" + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", + "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" }, "readable-stream": { - "version": "2.3.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", - "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", "requires": { "core-util-is": "~1.0.0", "inherits": "~2.0.3", @@ -7219,13 +7259,6 @@ "function-bind": "^1.1.1", "has-symbols": "^1.0.0", "object-keys": "^1.0.11" - }, - "dependencies": { - "function-bind": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" - } } }, "object.defaults": { @@ -7392,9 +7425,9 @@ "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" }, "readable-stream": { - "version": "2.3.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", - "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", "requires": { "core-util-is": "~1.0.0", "inherits": "~2.0.3", @@ -9903,9 +9936,9 @@ "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" }, "readable-stream": { - "version": "2.3.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", - "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", "requires": { "core-util-is": "~1.0.0", "inherits": "~2.0.3", diff --git a/projects/u.wait_delta.ict b/projects/u.wait_delta.ict new file mode 100644 index 000000000..70f3bdc06 --- /dev/null +++ b/projects/u.wait_delta.ict @@ -0,0 +1,194 @@ +ctjsVersion: 1.3.0 +notes: /* empty */ +libs: + place: + gridX: 1024 + gridY: 1024 + fittoscreen: + mode: scaleFit + mouse: {} + keyboard: {} + keyboard.polyfill: {} + sound.howler: {} + flow: {} + tween: {} +textures: + - name: Robot_Idle + untill: 0 + grid: + - 1 + - 1 + axis: + - 0 + - 0 + marginx: 0 + marginy: 0 + imgWidth: 96 + imgHeight: 96 + width: 96 + height: 96 + offx: 0 + offy: 0 + origname: i17142445-0a78-4191-a02d-528bcd40e136.png + source: >- + /Users/aidandj/Library/Mobile + Documents/com~apple~CloudDocs/Code/ct-js/src/examples/Platformer_assets/Robot_Idle.png + shape: rect + left: 0 + right: 96 + top: 0 + bottom: 96 + uid: 17142445-0a78-4191-a02d-528bcd40e136 + padding: 1 +skeletons: [] +types: + - name: test + depth: 0 + oncreate: |- + ct.tween.add({ + obj: this, + fields: { + x: this.x + 100, + y: this.y + 150 + }, + duration: 1000, + curve: ct.tween.easeInOutCirc + }); + onstep: this.move(); + ondraw: '' + ondestroy: '' + uid: 52954eac-7257-4f70-a490-0e46be2914e7 + texture: 17142445-0a78-4191-a02d-528bcd40e136 + extends: {} + lastmod: 1587492564967 +sounds: [] +styles: + - name: default + uid: ff53e951-ccf0-481c-bf41-c8c103bdced8 + origname: sc8c103bdced8 + font: + family: sans-serif + size: 12 + weight: 400 + italic: false + lastmod: 1586047198425 + fill: + type: '0' +rooms: + - name: test + oncreate: |2- + this.text = new PIXI.Text('delta: ' + ct.delta + "\ndeltaUi: " + ct.deltaUi + "\ntimerOn: " + this.timerOn, ct.styles.get('default')); + this.text.x = 32; + this.text.y = 32; + + this.addChild(this.text); + + this.timerOn = false; + this.timerAdded = false; + + this.timer = new CtTimer("a", 5000, true).then(() => { + console.warn("ajshdjakshdjahskjdhjkh +++++++++++++++++++"); + }); + + this.flowTimer = ct.flow.timer(() => { + console.warn("a"); + }, 5000); + onstep: '' + ondraw: |2- + if (ct.actions.Test.down) { + //ct.delta = 0; + //ct.deltaUi = 0; + if (this.timerOn == false) { + this.timerOn = true; + ct.u.wait(1000).then(() => { + this.timerOn = false; + }); + } + if (this.timerAdded == false) { + //ct.timer.addTimer("a"); + this.timerAdded = true; + } + } + console.log(this.timerOn); + console.log(ct.timer.timers["a"]); + if (this.timerOn == false) { + this.timerOn = true; + ct.u.wait(5000).then(() => { + console.warn("done yay"); + //this.timerOn = false; + }); + } + this.flowTimer(); + //console.log(ct.timer._timersInternal["ct.u.wait"] / 60); + + this.text.x = 32; + this.text.y = 32; + this.text.text = 'delta: ' + ct.delta + "\ndeltaUi: " + ct.deltaUi + "\ntimerOn: " + this.timerOn; + onleave: '' + width: 800 + height: 600 + backgrounds: [] + copies: + - x: 128 + 'y': 64 + uid: 52954eac-7257-4f70-a490-0e46be2914e7 + tiles: + - depth: -10 + tiles: [] + uid: ef9f0643-be19-44d7-8ff1-0079a0731f6f + thumbnail: 0079a0731f6f + gridX: 64 + gridY: 64 + lastmod: 1587428032702 + - name: test2 + oncreate: '' + onstep: '' + ondraw: '' + onleave: '' + width: 800 + height: 600 + backgrounds: [] + copies: [] + tiles: + - depth: -10 + tiles: [] + uid: cfcbbd02-8895-4083-885d-318bf434ecf1 + thumbnail: 318bf434ecf1 + gridX: 64 + gridY: 64 + lastmod: 1587428043720 +actions: + - name: Test + methods: + - code: mouse.Left + multiplier: 1 + - code: keyboard.KeyT +emitterTandems: [] +starting: 0 +settings: + minifyhtmlcss: false + minifyjs: false + fps: 60 + version: + - 0 + - 0 + - 0 + versionPostfix: '' + usePixiLegacy: true + export: + windows: true + linux: true + mac: true + branding: + icon: -1 + accent: '#446adb' + invertPreloaderScheme: true + title: u.wait_delta + author: naturecodevoid + site: 'https://ctjs.rocks' + maxFPS: 60 +scripts: [] +fonts: [] +styletick: .nan +palette: [] +startroom: ef9f0643-be19-44d7-8ff1-0079a0731f6f diff --git a/projects/u.wait_delta/img/i17142445-0a78-4191-a02d-528bcd40e136.png b/projects/u.wait_delta/img/i17142445-0a78-4191-a02d-528bcd40e136.png new file mode 100644 index 000000000..fa3723f9c Binary files /dev/null and b/projects/u.wait_delta/img/i17142445-0a78-4191-a02d-528bcd40e136.png differ diff --git a/projects/u.wait_delta/img/i17142445-0a78-4191-a02d-528bcd40e136.png_prev.png b/projects/u.wait_delta/img/i17142445-0a78-4191-a02d-528bcd40e136.png_prev.png new file mode 100644 index 000000000..a187a3947 Binary files /dev/null and b/projects/u.wait_delta/img/i17142445-0a78-4191-a02d-528bcd40e136.png_prev.png differ diff --git a/projects/u.wait_delta/img/i17142445-0a78-4191-a02d-528bcd40e136.png_prev@2.png b/projects/u.wait_delta/img/i17142445-0a78-4191-a02d-528bcd40e136.png_prev@2.png new file mode 100644 index 000000000..614e012d9 Binary files /dev/null and b/projects/u.wait_delta/img/i17142445-0a78-4191-a02d-528bcd40e136.png_prev@2.png differ diff --git a/projects/u.wait_delta/img/r0079a0731f6f.png b/projects/u.wait_delta/img/r0079a0731f6f.png new file mode 100644 index 000000000..22c147ef5 Binary files /dev/null and b/projects/u.wait_delta/img/r0079a0731f6f.png differ diff --git a/projects/u.wait_delta/img/r318bf434ecf1.png b/projects/u.wait_delta/img/r318bf434ecf1.png new file mode 100644 index 000000000..22c147ef5 Binary files /dev/null and b/projects/u.wait_delta/img/r318bf434ecf1.png differ diff --git a/projects/u.wait_delta/img/sc8c103bdced8_prev.png b/projects/u.wait_delta/img/sc8c103bdced8_prev.png new file mode 100644 index 000000000..7109339ca Binary files /dev/null and b/projects/u.wait_delta/img/sc8c103bdced8_prev.png differ diff --git a/projects/u.wait_delta/img/sc8c103bdced8_prev@2.png b/projects/u.wait_delta/img/sc8c103bdced8_prev@2.png new file mode 100644 index 000000000..7109339ca Binary files /dev/null and b/projects/u.wait_delta/img/sc8c103bdced8_prev@2.png differ diff --git a/projects/u.wait_delta/img/splash.png b/projects/u.wait_delta/img/splash.png new file mode 100644 index 000000000..22c147ef5 Binary files /dev/null and b/projects/u.wait_delta/img/splash.png differ diff --git a/src/node_requires/exporter/index.js b/src/node_requires/exporter/index.js index ee1ec454f..44ceac6e0 100644 --- a/src/node_requires/exporter/index.js +++ b/src/node_requires/exporter/index.js @@ -142,7 +142,8 @@ const exportCtProject = async (project, projdir) => { 'rooms.js', 'sound.js', 'styles.js', - 'types.js' + 'types.js', + 'timer.js' ]; for (const file of sourcesList) { sources[file] = fs.readFile(path.join(basePath, 'ct.release', file), { @@ -238,6 +239,9 @@ const exportCtProject = async (project, projdir) => { buffer += (await sources['sound.js']) .replace('/*@sound@*/', sounds); + buffer += (await sources['timer.js']); + buffer += '\n'; + const fonts = await bundleFonts(currentProject, projdir, writeDir); buffer += fonts.js; /* eslint-enable require-atomic-updates */