diff --git a/docs/README.md b/docs/README.md index 5de5a80..e9f3fcf 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,4 +1,4 @@ -## Chapel's Custom Macro Collection (v2.6.0) +## Chapel's Custom Macro Collection (v2.6.1) - [Try the demo!](https://macros.twinelab.net/demo) ([Sausage](https://github.com/ChapelR/custom-macros-demo)) - [Downloads](./download ':ignore') @@ -8,11 +8,11 @@ ### Documentation - **Gameplay Systems and Mechanics** - [The Simple Inventory System](simple-inventory.md) - - Updated [The Cycles System](cycles-system.md) + - [The Cycles System](cycles-system.md) - [The Playtime System](playtime-system.md) - **Interface and Style** - [The Dialog API Macro Set](dialog-api-macro-set.md) - - New [The Popover Macro](popover.md) + - [The Popover Macro](popover.md) - [The UI Macro](ui-macro.md) - [The Fading Macro Set](fading-macros.md) - [The CSS Macro](css-macro.md) @@ -20,7 +20,7 @@ - [The Meter Macro Set](meter-macros.md) - [The Speech Box System](speech-box-system.md) - **User Interaction and Events** - - [The Event Macros](event-macros.md) + - *Updated!* [The Event Macros](event-macros.md) - [The Continue Macro Set](continue-macro.md) - [The Swap Macro Set](swap-macro-set.md) - [The Mouseover Macro](mouseover-macro.md) @@ -30,7 +30,7 @@ - [The Pronoun Templates](pronoun-templates.md) - [The Articles (A/An) Macros](articles.md) - **Utilities and Other** - - New [The Preload Macro](preload.md) + - [The Preload Macro](preload.md) - [The Done Macro](done-macro.md) - [The File System Macro Set](file-system-macros.md) - [The First Macro](first-macro.md) diff --git a/docs/changelog.md b/docs/changelog.md index d0b7a68..963f107 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,6 +2,14 @@ [Back to the main page](./README.md). +### August 2, 2020 (v2.6.1) + +- **[Update]** Updated the event macro set. + - Added `<>`,`<>`, and `<>`. Deprecated `<>`. + - Support for single-use event handlers. + - Added default namespaces. + - Internal improvements. + ### July 24, 2020 (v2.6.0) - **[New]** New macros. diff --git a/docs/event-macros.md b/docs/event-macros.md index 4286c33..eec1cb2 100644 --- a/docs/event-macros.md +++ b/docs/event-macros.md @@ -2,17 +2,17 @@ [Back to the main readme](./README.md). -This macro set allows Twine authors to create event programming without needing to use JavaScript or jQuery. +This macro set allows Twine authors to create event handlers without needing to use JavaScript or jQuery. **THE CODE:** [Minified](https://github.com/ChapelR/custom-macros-for-sugarcube-2/blob/master/scripts/minified/events.min.js). [Pretty](https://github.com/ChapelR/custom-macros-for-sugarcube-2/blob/master/scripts/events.js). **DEMO:** [Available](http://macros.twinelab.net/demo?macro=event). **GUIDE:** Not available. -### Macro: `<>` +### Macros: `<>` and `<>` **Syntax**: ``` -<> +<> ... <> ... @@ -21,9 +21,14 @@ This macro set allows Twine authors to create event programming without needing <> ``` -This macro set can be used to add more interaction to your game; things like keyboard hotkeys, controls, clickable non-link elements, and more. Once registered, events are essentially permanent (though they can be removed via JavaScript and suppressed via code logic); therefore, **the best place to create events is your StoryInit special passage**. Note that the element the event is tied to does not need to be rendered (or currently on the page or in the passage) in order to attach an event to it. +This macro be used to handle events in your game; things like keyboard hotkeys, controls, clickable non-link elements, and more. Note that the element the event is tied to does not need to be rendered (or currently on the page or in the passage) in order to attach an event to it. -* **type**: a valid jQuery event type. Some events that may be of interest: +This macro has three aliases: `<>` set recurring event handlers, while `<>` creates a single-use event handler. If you want the handler to run each and every time the event occurs, use `<>`. If you want the event to occur only once, the next time the event occurs, use `<>`. + +> [!NOTE] +> The `<>` macro exists as an alias for `<>` for backwards-compatibility with code written for older version of this macro set. The `<>` macro should be considered deprecated going forward. + +* **type**: a valid jQuery event type. You may include a namespace with a dot, e.g., `click.my-namespace`. Some events that may be of interest: * `click`: fires when an element is clicked on. * `dblclick`: fires when an element is double-clicked on. * `keyup`: fires when an key is pressed and released. @@ -31,17 +36,18 @@ This macro set can be used to add more interaction to your game; things like key * `mouseup`: fires when a mouse button is pressed and released. * `mousedown`: fires when a mouse button is pressed. * **selector**: (optional) a valid jQuery/CSS selector. with some events (such as key presses), this checks for focus; with others it checks for the target element of the event (such as mouse clicks). if no selector is provided, the event is bound to the document element. +* **once**: (optional) the keyword `once`. If included, overrides the normal behavior of `<>` (and `<>`) to create a single-use event handler. * **keycode**: an integer. allows you to determine which key or mouse button triggered the event and react accordingly. you can find keycodes [here](http://keycode.info/). **Usage**: ``` /% stow/unstow the ui-bar on double-click %/ -<> +<> <> -<> +<> /% set up some hotkeys %/ -<> +<> <> /% the c key %/ <> /% avoid menu loop %/ <> @@ -52,17 +58,27 @@ This macro set can be used to add more interaction to your game; things like key <> <> /% the m key %/ <> -<> +<> + +/% run one time %/ +<> + <> +<> + +/% the above could also be written: %/ +<> + <> +<> ``` ### Macro: `<>` -**Syntax**:`<>` +**Syntax**:`<>` Allows you to simulate any event on any element. This macro is useful for triggering events you may not otherwise have easy access to. * **type**: a valid jQuery event type -* **selector**: a valid jQuery/CSS selector. if omitted, defaults to the document element +* **selector**: (optional) a valid jQuery/CSS selector. if omitted, defaults to the document element **Usage**: ``` @@ -71,4 +87,27 @@ Allows you to simulate any event on any element. This macro is useful for trigg <> <> <> -``` \ No newline at end of file +``` + +### Macro: `<>` + +**Syntax**:`<>` + +Allows you to remove an event handler. + +* **type**: a valid jQuery event type; may include namespaces +* **selector**: (optional) a valid jQuery/CSS selector. if omitted, defaults to the document element + +**Usage**: + +``` +/% removes all events created through this macro set %/ +<> + +/% remove all `dblclick` handlers from the `#ui-bar` element %/ +<> +``` + +### Setting: `setup.eventMacroNamespace` + +Handlers set up via this macro set are given a namespace automatically. The default value of this name space is `"macro-event"`. You may change this value to change the namespace if you want. Omit the dot. \ No newline at end of file diff --git a/scripts/events.js b/scripts/events.js index bed7bfa..84c2df6 100644 --- a/scripts/events.js +++ b/scripts/events.js @@ -1,65 +1,102 @@ // event macro set, by chapel; for sugarcube 2 -// version 1.1.1 +// version 2.0.0 -// the <> macro -Macro.add('trigger', { - handler : function () { - - // declare vars - var evt, $el; - - // check for errors - if (this.args.length > 2 || this.args.length === 0) { - return this.error('incorrect number of arguments'); - } - if (typeof this.args[0] != 'string') { - return this.error('first argument should be a string and a valid event type'); - } - - // some setup - evt = this.args[0]; - $el = (this.args.length === 1 || - (this.args[1] && typeof this.args[1] === 'string' && - this.args[1].toLowerCase().trim() === 'document')) ? - $(document) : $(this.args[1]); - - // fire the event - $el.trigger(evt); - - } -}); +(function () { + setup.eventMacroNamespace = 'macro-event'; -// the <> macro -Macro.add('event', { - tags : ['which'], - handler : function () { - - var payload = this.payload; - var evt, sel = '', code = '', i; - - if (this.args.length > 2 || this.args.length === 0) { - return this.error('incorrect number of arguments'); - } - if (typeof this.args[0] != 'string') { - return this.error('first argument should be a string and a valid event type'); - } - if (this.args.length === 2 && typeof this.args[1] == 'string') { - sel = this.args[1]; + // the <> macro + Macro.add('trigger', { + handler : function () { + + // declare vars + var evt, $el; + + // check for errors + if (this.args.length > 2 || this.args.length === 0) { + return this.error('incorrect number of arguments'); + } + if (typeof this.args[0] != 'string') { + return this.error('first argument should be a string and a valid event type'); + } + + // some setup + evt = this.args[0]; + $el = (this.args.length === 1 || + (this.args[1] && typeof this.args[1] === 'string' && + this.args[1].toLowerCase().trim() === 'document')) ? + $(document) : $(this.args[1]); + + // fire the event + $el.trigger(evt); + } - - evt = this.args[0]; - - $(document).on(evt, sel, function (e) { - code = payload[0].contents; - if (payload.length > 1) { - for (i = 1; i < payload.length; i++) { - if (payload[i].args.includes(e.which)) { - code = code + payload[i].contents; + }); + + // the <> macro: <> + Macro.add(['event', 'on', 'one'], { + tags : ['which'], + handler : function () { + + var payload = this.payload; + var method = 'on'; + var evt, sel = '', code = '', i; + + if (this.args.length > 3 || this.args.length === 0) { + return this.error('incorrect number of arguments'); + } + if (typeof this.args[0] != 'string') { + return this.error('first argument should be a string and a valid event type'); + } + if (this.args.length === 2 && typeof this.args[1] == 'string' && this.args[1] !== 'once') { + sel = this.args[1]; + } + + if (this.args.includes('once') || this.name === 'one') { + method = 'one'; + } + + evt = this.args[0]; + + $(document)[method](evt + '.' + setup.eventMacroNamespace, sel, function (e) { + code = payload[0].contents; + if (payload.length > 1) { + for (i = 1; i < payload.length; i++) { + if (payload[i].args.includes(e.which)) { + code = code + payload[i].contents; + } } } + new Wikifier(null, code); + }); + + } + }); + + Macro.add('off', { + handler : function () { + + // declare vars + var evt, $el; + + // check for errors + if (this.args.length > 2 || this.args.length === 0) { + return this.error('incorrect number of arguments'); + } + if (typeof this.args[0] != 'string') { + return this.error('first argument should be a string and a valid event type or namespace'); } - new Wikifier(null, code); - }); - - } -}); \ No newline at end of file + + // some setup + evt = this.args[0]; + $el = (this.args.length === 1 || + (this.args[1] && typeof this.args[1] === 'string' && + this.args[1].toLowerCase().trim() === 'document')) ? + $(document) : $(this.args[1]); + + // fire the event + $el.off(evt); + + } + }); + +}()); \ No newline at end of file diff --git a/scripts/minified/articles.min.js b/scripts/minified/articles.min.js index 355fe90..6d83ce6 100644 --- a/scripts/minified/articles.min.js +++ b/scripts/minified/articles.min.js @@ -1,4 +1,4 @@ // articles.min.js, for SugarCube 2, by Chapel -// v1.0.0, 2020-07-06, 92d87a1d979055f318ee94bcad96cb25ae2a23aa +// v1.0.0, 2020-08-02, 1d6b869ee7a4b36293aaf4003bfe47ffdfbdeba8 ;!function(){"use strict";var e=new Map,r=["eunuch","eucalyptus","eugenics","eulogy","euphemism","euphony","euphoria","eureka","european","euphemistic","euphonic","euphoric","euphemistically","euphonically","euphorically","heir","heiress","herb","homage","honesty","honor","honour","hour","honest","honorous","honestly","hourly","one","ouija","once","ubiquitous","ugandan","ukrainian","unanimous","unicameral","unified","unique","unisex","universal","urinal","urological","useful","useless","usurious","usurped","utilitarian","utopic","ubiquitously","unanimously","unicamerally","uniquely","universally","urologically","usefully","uselessly","usuriously"],i=["a","an"],t=/[aeiou8]/i,n=/[A-Z]+$/,u=/[UFHLMNRSX]/,a=/[.,\/#!$%\^&\*;:{}=\-_`~()]/g;function o(e){return"a"===e?"an":"a"}function s(r,t,n){var u;return State.length>0?(u="cannot add article override -> needs to be run in StoryInit special passage or earlier",console.error(u),u):t&&"string"==typeof t?(r&&"string"==typeof r&&(r=r.toLowerCase().trim()),i.includes(r)?(t=t.trim(),void(n?e.set(t,{article:r,caseSensitive:!!n}):e.set(t.toLowerCase(),{article:r,caseSensitive:!!n}))):(u='cannot add article override -> invalid article, must be "a" or "an"',console.error(u),u)):(u="cannot add article override -> invalid word",console.error(u),u)}function l(e){var i;return i=t.test(e.first())?"an":"a",function(e,i){return!!r.includes(e.toLowerCase())&&o(i)}(e,i)||function(e,r){return!(!n.test(e)||!u.test(e.first()))&&o(r)}(e,i)||i}function c(r){if(r&&"string"==typeof r){var i=r.trim().split(" ")[0].trim();return function(r){var i=(r=r.trim()).toLowerCase();if(e.has(i)||e.has(r)){var t=e.get(i)||e.get(r);return t.caseSensitive&&!e.has(r)?null:t.article}return null}(i=i.replace(a,""))||l(i)}}function h(e,r){if(!e||"string"!=typeof e)return e;var i=c(e);return(r?i.toUpperFirst():i)+" "+e}setup.articles={find:c,output:h,override:s},Macro.add("setarticle",{handler:function(){var e=s(this.args[0],this.args[1],this.args[2]);e&&"string"==typeof e&&this.error(e)}}),Macro.add(["a","an","A","An"],{handler:function(){var e=this.name.first()===this.name.first().toUpperCase();this.output.append(h(String(this.args[0]),e))}})}(); // end articles.min.js \ No newline at end of file diff --git a/scripts/minified/continue.min.js b/scripts/minified/continue.min.js index 26cc3e4..eb8bc84 100644 --- a/scripts/minified/continue.min.js +++ b/scripts/minified/continue.min.js @@ -1,4 +1,4 @@ // continue.min.js, for SugarCube 2, by Chapel -// v1.0.1, 2020-07-06, 92d87a1d979055f318ee94bcad96cb25ae2a23aa +// v1.0.1, 2020-08-02, 1d6b869ee7a4b36293aaf4003bfe47ffdfbdeba8 ;!function(){"use strict";var n=["a",":button",'*[role="button"]',".continue-macro-ignore","#ui-bar","#ui-dialog"],t=0;function o(){$(document).on("click.continue-macro keyup.continue-macro",n.join(", "),(function(n){n.stopPropagation()}))}function e(){if(State.length>0)return!1;var t=[].slice.call(arguments).flatten();return n=n.concat(t),!0}function c(n,o){var e=function(){var n="."+Date.now().toString(36)+"-"+t;return t++,n}();if(o&&"function"==typeof o){var c="click.continue-macro"+e;n&&(c=c+" keyup.continue-macro"+e),$(document).one(c,(function(){o.call(),$(document).off(e)}))}}prehistory["%%continue-expiration"]=function(){t=0},$(document).one(":passagerender",(function(){o()})),Macro.add("ignore",{handler:function(){if(!e(this.args))return this.error("the <> macro should only be run from StoryInit or equivalent.")}}),Macro.add("cont",{tags:null,handler:function(){var n,t=this.args.includes("append"),o=this.args.includesAny("key","keypress","press","button"),e=this.payload[0].contents;t&&(n=$(document.createElement("span")).addClass("macro-"+this.name).appendTo(this.output)),c(o,this.createShadowWrapper((function(){t&&n&&n instanceof $?n.wiki(e):$.wiki(e)})))}}),setup.cont=c,setup.cont.ignore=e,setup.cont.reset=function(){var t=[].slice.call(arguments).flatten();n=n.concat(t),$(document).off(".continue-macro"),o()},window.cont=window.cont||setup.cont}(); // end continue.min.js \ No newline at end of file diff --git a/scripts/minified/css-macro.min.js b/scripts/minified/css-macro.min.js index 1fea2b8..86aea31 100644 --- a/scripts/minified/css-macro.min.js +++ b/scripts/minified/css-macro.min.js @@ -1,4 +1,4 @@ // css-macro.min.js, for SugarCube 2, by Chapel -// v1.0.0, 2020-07-06, 92d87a1d979055f318ee94bcad96cb25ae2a23aa +// v1.0.0, 2020-08-02, 1d6b869ee7a4b36293aaf4003bfe47ffdfbdeba8 ;!function(){"use strict";function t(t){if(t.length%2!=0)return"Style rules should be a list of key/value pairs; you've passed an odd number.";var r={};return t.forEach((function(e,n){n%2==0&&(r[e]=t[n+1])})),r}function r(t,r){try{return"string"==typeof r?r:(t instanceof jQuery||(t=$(t)),t.css(r))}catch(t){return t.message}}Macro.add("css",{handler:function(){var e=function(){try{var e,n=[].slice.call(arguments).flatten(),s=n.shift();return"string"==typeof n[0]?e=t(n):"object"==typeof n[0]&&(e=clone(n[0])),r(s,e)}catch(t){return t.message}}(this.args);if("string"==typeof e)return this.error(e)}})}(); // end css-macro.min.js \ No newline at end of file diff --git a/scripts/minified/cycles.min.js b/scripts/minified/cycles.min.js index 34ce989..35d4187 100644 --- a/scripts/minified/cycles.min.js +++ b/scripts/minified/cycles.min.js @@ -1,4 +1,4 @@ // cycles.min.js, for SugarCube 2, by Chapel -// v2.1.1, 2020-07-06, 92d87a1d979055f318ee94bcad96cb25ae2a23aa +// v2.1.1, 2020-08-02, 1d6b869ee7a4b36293aaf4003bfe47ffdfbdeba8 ;!function(){"use strict";var e="%%cycles",t=!0,r="cycles.pause",i="cycles.pause.menu",n="cycles.postdisplay";function s(){return State.variables[e]}function a(e,t){if(!(this instanceof a))return new a(e,t);if(!e||"object"!=typeof e)throw new Error("Cycle() -> invalid definition object");if(!e.name||"string"!=typeof e.name||!e.name.trim())throw new Error("Cycle() -> invalid name");if(this.name=e.name,!e.phases||!Array.isArray(e.phases)||e.phases.length<2)throw new Error("Cycle() -> phases should be an array of at least two strings");if(!e.phases.every((function(e){return e&&"string"==typeof e&&e.trim()})))throw new Error("Cycle() -> each phase should be a valid, non-empty string");this.phases=clone(e.phases),e.period=Number(e.period),(Number.isNaN(e.period)||e.period<1)&&(e.period=1),Number.isInteger(e.period)||(e.period=Math.trunc(e.period)),this.period=e.period,e.increment=Number(e.increment),(Number.isNaN(e.increment)||e.increment<1)&&(e.increment=1),Number.isInteger(e.increment)||(e.increment=Math.trunc(e.increment)),this.increment=e.increment,this.active=void 0===e.active||!!e.active,t=Number(t),(Number.isNaN(t)||t<0)&&(t=0),Number.isInteger(t)||(t=Math.trunc(t)),this.stack=t}State.variables[e]={},Object.assign(a,{is:function(e){return e instanceof a},add:function(e,t){if(!t||"object"!=typeof t)throw new Error("Cycle.add() -> invalid definition object");if(e&&"string"==typeof e&&e.trim())t.name=e;else if(!t.name||"string"!=typeof t.name||!t.name.trim())throw new Error("Cycle.add() -> invalid name");var r=new a(t,0);return s()[t.name]=r,r},has:function(e){var t=s();return t.hasOwnProperty(e)&&a.is(t[e])},get:function(e){return a.has(e)?s()[e]:null},del:function(e){return!!a.has(e)&&(delete s()[e],!0)},check:function(e){if(a.has(e)){var t=[].slice.call(arguments).flatten().slice(1);return a.get(e).check(t)}},clear:function(e){s()},_emit:function(e,t){$(document).trigger({type:":cycle-"+t,cycle:e})},_retrieveCycles:s}),Object.assign(a.prototype,{constructor:a,revive:function(){var e={};return Object.keys(this).forEach((function(t){e[t]=clone(this[t])}),this),e},clone:function(){return new a(this.revive(),this.stack)},toJSON:function(){return JSON.reviveWrapper("new setup.Cycle("+JSON.stringify(this.revive())+", "+this.stack+")")},current:function(){return this.phases[Math.trunc(this.stack/this.period)%this.phases.length]},length:function(){return this.period*this.phases.length},turns:function(){return this.period/this.increment},turnsTotal:function(){return this.length()/this.increment},update:function(e){e=Number(e),Number.isNaN(e)&&(e=this.increment);var t=this.current();return this.stack+=e,this.stack<0&&(this.stack=0),Number.isInteger(this.stack)||(this.stack=Math.trunc(this.stack)),t!==this.current()&&a._emit("change"),this},reset:function(){return this.stack=0,a._emit(this,"reset"),this.update(0)},suspend:function(){var e=this.active;return this.active=!1,e!==this.active&&a._emit(this,"suspend"),this},resume:function(){var e=this.active;return this.active=!0,e!==this.active&&a._emit(this,"resume"),this},toggle:function(){return this.active?this.suspend():this.resume(),this},isSuspended:function(){return!this.active},editIncrement:function(e){return e=Number(e),(!Number.isNaN(e)||e>0)&&(Number.isInteger(e)||(e=Math.trunc(e)),this.increment=e),this.increment},check:function(){var e=[].slice.call(arguments).flatten();return e.includes(this.current())}}),postdisplay[n]=function(){var e;tags().includes(r)||e?e=!1:tags().includes(i)?e=!0:Object.keys(s()).forEach((function(e){var t=a.get(e);t.active&&t.update()}))},setup.Cycle=a,t&&(window.Cycle=window.Cycle||a),Macro.add("newcycle",{tags:["phase"],handler:function(){if(this.args.length<1)return this.error("A cycle must at least be given a name.");if(this.payload.length<2)return this.error("A cycle must be given at least two phases.");var e=this.payload.slice(1).map((function(e){return function(e){if(e.args.length<1)return null;var t=e.args.flatten();return t.every((function(e){return"string"==typeof e}))?t:null}(e)})).flatten();if(e.includes(null))return this.error("Each `<>` tag must be given a valid name.");try{a.add(this.args[0],{phases:e,period:this.args[1],increment:this.args[2],active:this.args[3]&&"string"==typeof this.args[3]&&"suspend"!==this.args[3].trim()})}catch(e){var t=e.message&&e.message.split("->")[1];return t=!!t&&t.trim(),this.error(t||e.message)}}}),Macro.add("editcycle",{handler:function(){if(this.args.length<1||"string"!=typeof this.args[0]||!this.args[0].trim())return this.error("You must name the cycle you wish to act on.");if(this.args.length<2)return this.error("You must provide an action to perform.");var e=a.get(this.args[0]);if(null===e)return this.error('Cannot find a cycle named "'+this.args[0]+'".');if(this.args.includes("suspend")?e.suspend():this.args.includes("toggle")?e.toggle():this.args.includes("resume")&&e.resume(),this.args.includes("increment")){var t=this.args[this.args.indexOf("increment")+1];"number"==typeof t&&e.editIncrement(t)}if(this.args.includesAny("reset","clear")&&e.reset(),this.args.includes("change")){var r=this.args[this.args.indexOf("change")+1];r=Number(r),!Number.isNaN(r)&&Number.isInteger(r)&&e.update(r)}}}),Macro.add("showcycle",{handler:function(){if(this.args.length<1||"string"!=typeof this.args[0]||!this.args[0].trim())return this.error("You must name the cycle you wish to act on.");var e=a.get(this.args[0]);if(null===e)return this.error('Cannot find a cycle named "'+this.args[0]+'".');var t=e.current();this.args.includes("uppercase")?t=t.toUpperCase():this.args.includes("lowercase")?t=t.toLowerCase():this.args.includes("upperfirst")&&(t=t.toUpperFirst()),$(document.createElement("span")).addClass("macro-"+this.name).append(t).appendTo(this.output)}})}(); // end cycles.min.js \ No newline at end of file diff --git a/scripts/minified/dialog-api-macro-set.min.js b/scripts/minified/dialog-api-macro-set.min.js index f2c92b2..5fb74f7 100644 --- a/scripts/minified/dialog-api-macro-set.min.js +++ b/scripts/minified/dialog-api-macro-set.min.js @@ -1,4 +1,4 @@ // dialog-api-macro-set.min.js, for SugarCube 2, by Chapel -// v1.3.0, 2020-07-06, 92d87a1d979055f318ee94bcad96cb25ae2a23aa +// v1.3.0, 2020-08-02, 1d6b869ee7a4b36293aaf4003bfe47ffdfbdeba8 ;Macro.add("dialog",{tags:["onopen","onclose"],handler:function(){var t="",s=null,n=null,o=this.args.length>0?this.args[0]:"",e=this.args.length>1?this.args.slice(1).flatten():[];this.payload.forEach((function(o,e){0===e?t=o.contents:"onopen"===o.name?s=s?s+o.contents:o.contents:n=n?n+o.contents:o.contents})),e.push("macro-"+this.name),Dialog.setup(o,e.join(" ")),Dialog.wiki(t),s&&"string"==typeof s&&s.trim()&&$(document).one(":dialogopened",(function(){$.wiki(s)})),n&&"string"==typeof n&&n.trim()&&$(document).one(":dialogclosed",(function(){$.wiki(n)})),Dialog.open()}}),Macro.add("popup",{handler:function(){if(this.args.length<1)return this.error("need at least one argument; the passage to display");if(!Story.has(this.args[0]))return this.error("the passage "+this.args[0]+"does not exist");var t=this.args[0],s=this.args.length>1?this.args[1]:"",n=this.args.length>2?this.args.slice(2).flatten():[];n.push("macro-"+this.name),Dialog.setup(s,n.join(" ")),Dialog.wiki(Story.get(t).processText()),Dialog.open()}}),Macro.add("dialogclose",{skipArgs:!0,handler:function(){Dialog.close()}}); // end dialog-api-macro-set.min.js \ No newline at end of file diff --git a/scripts/minified/done.min.js b/scripts/minified/done.min.js index 1b04e90..d49d609 100644 --- a/scripts/minified/done.min.js +++ b/scripts/minified/done.min.js @@ -1,4 +1,4 @@ // done.min.js, for SugarCube 2, by Chapel -// v1.0.1, 2020-07-06, 92d87a1d979055f318ee94bcad96cb25ae2a23aa +// v1.0.1, 2020-08-02, 1d6b869ee7a4b36293aaf4003bfe47ffdfbdeba8 ;!function(){var a=1;Macro.add("done",{skipArgs:!0,tags:null,handler:function(){var n=this.payload[0].contents.trim();""!==n&&(postdisplay[":chapel-done-macro-"+a]=function(a){delete postdisplay[a],$.wiki(n)},a++)}})}(); // end done.min.js \ No newline at end of file diff --git a/scripts/minified/events.min.js b/scripts/minified/events.min.js index 72c6a59..3231cc8 100644 --- a/scripts/minified/events.min.js +++ b/scripts/minified/events.min.js @@ -1,4 +1,4 @@ // events.min.js, for SugarCube 2, by Chapel -// v1.1.1, 2020-07-06, 92d87a1d979055f318ee94bcad96cb25ae2a23aa -;Macro.add("trigger",{handler:function(){var t;return this.args.length>2||0===this.args.length?this.error("incorrect number of arguments"):"string"!=typeof this.args[0]?this.error("first argument should be a string and a valid event type"):(t=this.args[0],void(1===this.args.length||this.args[1]&&"string"==typeof this.args[1]&&"document"===this.args[1].toLowerCase().trim()?$(document):$(this.args[1])).trigger(t))}}),Macro.add("event",{tags:["which"],handler:function(){var t,r,s=this.payload,e="",i="";return this.args.length>2||0===this.args.length?this.error("incorrect number of arguments"):"string"!=typeof this.args[0]?this.error("first argument should be a string and a valid event type"):(2===this.args.length&&"string"==typeof this.args[1]&&(e=this.args[1]),t=this.args[0],void $(document).on(t,e,(function(t){if(i=s[0].contents,s.length>1)for(r=1;r2||0===this.args.length?this.error("incorrect number of arguments"):"string"!=typeof this.args[0]?this.error("first argument should be a string and a valid event type"):(t=this.args[0],void(1===this.args.length||this.args[1]&&"string"==typeof this.args[1]&&"document"===this.args[1].toLowerCase().trim()?$(document):$(this.args[1])).trigger(t))}}),Macro.add(["event","on","one"],{tags:["which"],handler:function(){var t,r,s=this.payload,e="on",n="",a="";return this.args.length>3||0===this.args.length?this.error("incorrect number of arguments"):"string"!=typeof this.args[0]?this.error("first argument should be a string and a valid event type"):(2===this.args.length&&"string"==typeof this.args[1]&&"once"!==this.args[1]&&(n=this.args[1]),(this.args.includes("once")||"one"===this.name)&&(e="one"),t=this.args[0],void $(document)[e](t+"."+setup.eventMacroNamespace,n,(function(t){if(a=s[0].contents,s.length>1)for(r=1;r2||0===this.args.length?this.error("incorrect number of arguments"):"string"!=typeof this.args[0]?this.error("first argument should be a string and a valid event type or namespace"):(t=this.args[0],void(1===this.args.length||this.args[1]&&"string"==typeof this.args[1]&&"document"===this.args[1].toLowerCase().trim()?$(document):$(this.args[1])).off(t))}}); // end events.min.js \ No newline at end of file diff --git a/scripts/minified/fading-macro-set.min.js b/scripts/minified/fading-macro-set.min.js index 262ec50..2bf461f 100644 --- a/scripts/minified/fading-macro-set.min.js +++ b/scripts/minified/fading-macro-set.min.js @@ -1,4 +1,4 @@ // fading-macro-set.min.js, for SugarCube 2, by Chapel -// v1.1.0, 2020-07-06, 92d87a1d979055f318ee94bcad96cb25ae2a23aa +// v1.1.0, 2020-08-02, 1d6b869ee7a4b36293aaf4003bfe47ffdfbdeba8 ;Macro.add("fadein",{tags:null,handler:function(){var t,a,s=$(document.createElement("span")),e=this.payload[0].contents;if(0===this.args.length)return this.error("no arguments given");t=Util.fromCssTime(this.args[0]),a=this.args.length>1?Util.fromCssTime(this.args[1]):0,s.wiki(e).addClass("macro-"+this.name).appendTo(this.output).hide().delay(a).fadeIn(t)}}),Macro.add("fadeout",{tags:null,handler:function(){var t,a,s=$(document.createElement("span")),e=this.payload[0].contents;if(0===this.args.length)return this.error("no arguments given");t=Util.fromCssTime(this.args[0]),a=this.args.length>1?Util.fromCssTime(this.args[1]):0,s.wiki(e).addClass("macro-"+this.name).appendTo(this.output).delay(a).fadeOut(t)}}); // end fading-macro-set.min.js \ No newline at end of file diff --git a/scripts/minified/first-macro.min.js b/scripts/minified/first-macro.min.js index a293ad6..1f6ecfe 100644 --- a/scripts/minified/first-macro.min.js +++ b/scripts/minified/first-macro.min.js @@ -1,4 +1,4 @@ // first-macro.min.js, for SugarCube 2, by Chapel -// v1.1.1, 2020-07-06, 92d87a1d979055f318ee94bcad96cb25ae2a23aa +// v1.1.1, 2020-08-02, 1d6b869ee7a4b36293aaf4003bfe47ffdfbdeba8 ;Macro.add("first",{skipArgs:!0,tags:["then","finally"],handler:function(){var a,t=$(document.createElement("span")),n=this.payload[this.payload.length-1],s=visited()-1;a=s0&&"btn"!==this.args[0]?this.args[0]:setup.messageMacro.default).ariaClick(this.createShadowWrapper((function(){a.hasClass("open")?t.css("display","none").empty():t.css("display","block").wiki(e),a.toggleClass("open")}))),a.attr("id","macro-"+this.name+"-"+this.args.join("").replace(/[^A-Za-z0-9]/g,"")).addClass("message-text").append(s).append(t).appendTo(this.output)}}); // end message-macro.min.js \ No newline at end of file diff --git a/scripts/minified/meters.min.js b/scripts/minified/meters.min.js index 72635e3..b5161b3 100644 --- a/scripts/minified/meters.min.js +++ b/scripts/minified/meters.min.js @@ -1,4 +1,4 @@ // meters.min.js, for SugarCube 2, by Chapel -// v1.0.1, 2020-07-06, 92d87a1d979055f318ee94bcad96cb25ae2a23aa +// v1.0.1, 2020-08-02, 1d6b869ee7a4b36293aaf4003bfe47ffdfbdeba8 ;!function(){"use strict";var t=!0,e=!1,s=!1,i={full:"#2ECC40",empty:"#FF4136",back:"#DDDDDD",height:"12px",width:"180px",animate:400,easing:"swing",text:"#111111",label:"",align:"center"},n=["center","left","right"],r=["swing","linear"];function a(t,e){return t&&"string"==typeof t&&(t=t.toLowerCase().trim())?t:e||""}function o(t){return t<.5?2*t*t:(4-2*t)*t-1}function l(t,e){if(!(this instanceof l))return new l(t,e);var s=clone(i);this.settings=Object.assign(s,t),this.settings.align=a(this.settings.align),this.settings.easing=a(this.settings.easing),n.includes(this.settings.align)||(this.settings.align="center"),r.includes(this.settings.easing)||(this.settings.easing="swing"),e=Number(e),Number.isNaN(e)&&(e=1),e=Math.clamp(e,0,1),this.value=e;var h=$(document.createElement("div")).addClass("chapel-meter").attr({"data-val":e,"data-label":this.settings.label}).css({position:"relative","background-color":this.settings.back,height:this.settings.height,width:this.settings.width,overflow:"hidden"}),g=$(document.createElement("div")).addClass("meter-label").css({top:0,right:0,"font-size":this.settings.height,"font-weight":"bold","line-height":"100%",width:"100%",height:"100%","vertical-align":"middle","text-align":this.settings.align,color:this.settings.text,"z-index":1,position:"relative",bottom:"100%"}).wiki(this.settings.label).appendTo(h),u=$(document.createElement("div")).addClass("meter-top").css({"background-color":this.settings.full,opacity:o(this.value),width:"100%",height:"100%","z-index":0}),c=$(document.createElement("div")).addClass("meter-bottom").css({position:"absolute",top:0,left:0,"background-color":this.settings.empty,opacity:1,width:100*this.value+"%",height:"100%","z-index":0}).append(u).appendTo(h);this.$element=h,this.$bars={top:u,bottom:c},this.$label=g,g.css("font-size",parseInt(h.css("height"),10) no valid target"),e&&"object"==typeof e&&(e.classes&&(Array.isArray(e.classes)||"string"==typeof e.classes)&&s.addClass(e.classes),e.attr&&"object"==typeof e.attr&&s.attr(e.attr)),t.append(s.append(this.$element)),this._label(!0),this},on:function(t,e){return"function"!=typeof e?this:t&&"string"==typeof t&&t.trim()?(t=t.split(" ").map((function(t){return(t=t.split(".")[0])+".userland"})).join(" "),this.$element.on(t,e),this):this},one:function(t,e){return"function"!=typeof e?this:t&&"string"==typeof t&&t.trim()?(t=t.split(" ").map((function(t){return(t=t.split(".")[0])+".userland"})).join(" "),this.$element.one(t,e),this):this},off:function(t){return t=t&&"string"==typeof t&&t.trim()?t.split(" ").map((function(t){return(t=t.split(".")[0])+".userland"})).join(" "):".userland",this.$element.off(t),this},click:function(t,e){return this.$element.ariaClick(t,e),this},clone:function(){return new l(this.settings,this.value)},toJSON:function(){return JSON.reviveWrapper("new setup.Meter("+JSON.stringify(this.settings)+", "+this.value+")")}}),setup.Meter=l,t&&(window.Meter=window.Meter||l),Macro.add("newmeter",{tags:["colors","sizing","animation","label"],handler:function(){if(State.length>0&&!s)return this.error("The `<>` macro must be called in your `StoryInit` special passage. Seriously. No excuses. --Love, Chapel");if(this.args.length<1)return this.error("The `<>` macro requires at least one argument: a meter name.");var t=this.args[0],i=null,n=null,r=null,a=null;if("string"!=typeof t)return this.error("Invalid meter name.");if(t=t.trim(),l.has(t)&&!e)return this.error('Cannot clobber the existing meter "'+t+'".');this.payload.length&&(i=this.payload.find((function(t){return"colors"===t.name})),n=this.payload.find((function(t){return"sizing"===t.name})),r=this.payload.find((function(t){return"animation"===t.name})),a=this.payload.find((function(t){return"label"===t.name})));var o={};if(i){if(!i.args.length)return this.error("No arguments passed to the `<>` tag.");switch(i.args.length){case 1:o.empty=i.args[0],o.full="transparent";break;case 2:o.full=i.args[0],o.empty=i.args[1];break;default:o.full=i.args[0],o.empty=i.args[1],o.back=i.args[2]}}if(n){if(!n.args.length)return this.error("No arguments passed to the `<>` tag.");o.width=n.args[0],n.args[1]&&(o.height=n.args[1])}if(r){if(!r.args.length)return this.error("No arguments passed to the `<>` tag.");if("boolean"!=typeof r.args[0]||r.args[0]){if("string"!=typeof r.args[0])return this.error("The argument to the `<>` tag should be `true`, `false`, or a valid CSS time value.");o.animate=Util.fromCssTime(r.args[0])}else o.animate=0;r.args[1]&&["swing","linear"].includes(r.args[1])&&(o.easing=r.args[1])}if(a){var h=a.args[0];if(!h||"string"!=typeof h)return this.error("The labelText argument for the `<