Skip to content

Commit

Permalink
update pronouns.js / docs
Browse files Browse the repository at this point in the history
closes #26
closes #25
  • Loading branch information
ChapelR committed Jun 28, 2019
1 parent 53a9b23 commit ba8e210
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
6 changes: 3 additions & 3 deletions docs/demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
// end fs.min.js
/* twine-user-script #11: "fullscreen.min.js" */
// fullscreen.min.js, for SugarCube 2, by Chapel
;setup.fullscreen=function(e){e.requestFullScreen?e.requestFullScreen():e.mozRequestFullScreen?e.mozRequestFullScreen():e.webkitRequestFullScreen&&e.webkitRequestFullScreen()},Macro.add("fullscreen",{handler:function(){var e=$("body").css("background-color");$("html").css("background-color",e),setup.fullscreen(document.documentElement)}}),Macro.add("fullscreenlink",{handler:function(){var e,n,r=$(document.createElement("span")),c=$(document.createElement("a")),t="macro-"+this.name;if(1!==this.args.length)return this.error("incorrect number of arguments");n=this.args[0],c.wiki(n).attr("id","fullscreen-macro-link").ariaClick(function(){e=$("body").css("background-color"),$("html").css("background-color",e),setup.fullscreen(document.documentElement)}),r.append(c).addClass(t).appendTo(this.output)}});
;!function(){"use strict";var n=document.body;function t(){return!!(document.fullscreenElement||document.webkitFullscreenElement||document.mozFullScreenElement||document.msFullscreenElement)}function u(e){t()||(e.requestFullScreen?e.requestFullScreen():e.mozRequestFullScreen?e.mozRequestFullScreen():e.webkitRequestFullScreen?e.webkitRequestFullScreen():e.msRequestFullscreen&&e.msRequestFullscreen())}function l(){t()&&(document.exitFullscreen?document.exitFullscreen():document.webkitExitFullscreen?document.webkitExitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.msExitFullscreen&&document.msExitFullscreen())}function c(e){t()?l():u(n)}Macro.add("fullscreen",{handler:function(){c()}}),Macro.add("fullscreenlink",{handler:function(){var e,n=$(document.createElement("span")),t=$(document.createElement("a")),u="macro-"+this.name;if(1!==this.args.length)return this.error("incorrect number of arguments");e=this.args[0],t.wiki(e).attr("id","fullscreen-macro-link").ariaClick(function(){c()}),n.append(t).addClass(u).appendTo(this.output)}}),setup.fullscreen=function(e){void 0===e?c():e?u(n):l()},setup.isFullscreen=t}();
// end fullscreen.min.js
/* twine-user-script #12: "message-macro.min.js" */
// message-macro.min.js, for SugarCube 2, by Chapel
Expand All @@ -211,15 +211,15 @@
// end notify.min.js
/* twine-user-script #16: "operations.min.js" */
// operations.min.js, for SugarCube 2, by Chapel
;setup.operations={tryGlobal:!0,nicknames:!0,fmRange:[0,100]},setup.dice={processDice:function(e,r){var t,i=[],o=0;if("string"==typeof e)i=e.split("d");else if("number"==typeof e&&r)i=[e,r];else{if(!(Array.isArray(e)&&2<=e.length))throw new TypeError("setup.dice.processDice(): could not process arguments...");e.length=2,i=e}for(t=0;t<i[0];t++){o+=Math.floor(Math.random()*i[1])+1}return o},processString:function(e){var r;return[(r=(e=e.trim().replace(/\s/g,"")).match(/(\d*d\d*)(.*)/))[1],Number(r[2])]},roll:function(e,r){if("string"==typeof e){var t=setup.dice.processString(e);return setup.dice.processDice(t[0])+t[1]}return setup.dice.processDice(e,r)}},setup.operations.tryGlobal&&(window.dice=window.dice||setup.dice.roll),Number.prototype.dice||Object.defineProperty(Number.prototype,"dice",{configurable:!0,writable:!0,value:function(e){if(0===this)return 0;if(this<0)throw new TypeError("Number.prototype.dice: cannot roll a negative number of dice!");if(null==e||"number"!=typeof e||e<=0||arguments.length<1)throw new TypeError("Number.prototype.dice: error in argument");if(!Number.isInteger(this)||!Number.isInteger(e))throw new TypeError("Number.prototype.dice: cannot roll partial dice!");return setup.dice.processDice(this,e)}}),Number.prototype.fairmath||Object.defineProperty(Number.prototype,"fairmath",{configurable:!0,writable:!0,value:function(e){var r=setup.operations.fmRange;if(this<r[0]||this>r[1])throw new TypeError("Number.prototype.fairmath called on a number that is out of the defined range (the number was "+this+").");if(null==e||"number"!=typeof e||100<e||e<-100||arguments.length<1)throw new TypeError("Number.prototype.fairmath given incorrect argument or an argument that is out of the valid 0-100 range.");if(0===e)return Math.clamp(Math.trunc(this),r[0],r[1]);if(e<0)return e*=-1,Math.clamp(Math.trunc(this-(this-r[0])*(e/r[1])),r[0],r[1]);if(0<e)return Math.clamp(Math.trunc(this+(r[1]-this)*(e/r[1])),r[0],r[1]);throw new Error("Number.prototype.fairmath encountered an unspecified error.")}}),Math.fairmath||Object.defineProperty(Math,"fairmath",{configurable:!0,writable:!0,value:function(e,r){return e.fairmath(r)}}),setup.operations.nicknames&&(Math.fm||Object.defineProperty(Math,"fm",{configurable:!0,writable:!0,value:function(e,r){return e.fairmath(r)}}),Number.prototype.fm||Object.defineProperty(Number.prototype,"fm",{configurable:!0,writable:!0,value:function(e){return this.fairmath(e)}}),Number.prototype.d||Object.defineProperty(Number.prototype,"d",{configurable:!0,writable:!0,value:function(e){return this.dice(e)}}));
;!function(){"use strict";var r=r||{},e=!0,t=!0,i=[0,100];function o(r,e){var t,i=[],o=0,n=1;if("string"==typeof r)i=r.split("d");else if("number"==typeof r&&e)i=[r,e];else{if(!(Array.isArray(r)&&2<=r.length))throw new TypeError("dice(): could not process arguments...");r.length=2,i=r}if(i[0]=Number(i[0]),"string"==typeof i[1]&&"F"===i[1].trim().toUpperCase()?(i[1]=3,n=-1):i[1]=Number(i[1]),i.some(function(r){return Number.isNaN(r)}))throw new TypeError("dice(): could not process arguments...");for(t=0;t<i[0];t++){o+=Math.floor(State.random()*i[1])+n}return o}function n(r,e){if("string"==typeof r){var t=[(i=r.trim().replace(/\s/g,"").match(/(\d+[d][\df]d*)(.*)/i))[1],Number(i[2])];return o(t[0])+t[1]}return o(r,e);var i}r.dice={roll:n},e&&(window.dice=window.dice||n),Number.prototype.dice||Object.defineProperty(Number.prototype,"dice",{configurable:!0,writable:!0,value:function(r){if(0===this)return 0;if(this<0)throw new TypeError("Number.prototype.dice: cannot roll a negative number of dice!");if("string"!=typeof r&&"F"!==r.trim().toUpperCase()&&(null==r||"number"!=typeof r||r<=0||!Number.isInteger(r)))throw new TypeError("Number.prototype.dice: error in argument");if(!Number.isInteger(this))throw new TypeError("Number.prototype.dice: cannot roll partial dice!");return n(this,r)}}),Number.prototype.fairmath||Object.defineProperty(Number.prototype,"fairmath",{configurable:!0,writable:!0,value:function(r){var e=i;if(this<e[0]||this>e[1])throw new TypeError("Number.prototype.fairmath called on a number that is out of the defined range (the number was "+this+").");if(null==r||"number"!=typeof r||100<r||r<-100||arguments.length<1)throw new TypeError("Number.prototype.fairmath given incorrect argument or an argument that is out of the valid 0-100 range.");if(0===r)return Math.clamp(Math.trunc(this),e[0],e[1]);if(r<0)return r*=-1,Math.clamp(Math.trunc(this-(this-e[0])*(r/e[1])),e[0],e[1]);if(0<r)return Math.clamp(Math.trunc(this+(e[1]-this)*(r/e[1])),e[0],e[1]);throw new Error("Number.prototype.fairmath encountered an unspecified error.")}}),Math.fairmath||Object.defineProperty(Math,"fairmath",{configurable:!0,writable:!0,value:function(r,e){return r.fairmath(e)}}),t&&(Math.fm||Object.defineProperty(Math,"fm",{configurable:!0,writable:!0,value:function(r,e){return r.fairmath(e)}}),Number.prototype.fm||Object.defineProperty(Number.prototype,"fm",{configurable:!0,writable:!0,value:function(r){return this.fairmath(r)}}),Number.prototype.d||Object.defineProperty(Number.prototype,"d",{configurable:!0,writable:!0,value:function(r){return this.dice(r)}}))}();
// end operations.min.js
/* twine-user-script #17: "playtime.min.js" */
// playtime.min.js, for SugarCube 2, by Chapel
;!function(){"use strict";var e={tryGlobal:!0,storyVar:"playtime",pauseTag:"pausetimer"};function n(){return Date.now()-State.variables[e.storyVar]}function s(t){if(t&&!(t<0)&&"number"==typeof t){var e=[];return e.push(Math.floor(t/1e3)%60),e.push(Math.floor(t/6e4)%60),e.push(Math.floor(t/36e5)),e}}State.variables[e.storyVar]=Date.now(),predisplay["start-playtime"]=function(t){delete predisplay[t],State.variables[e.storyVar]||(State.variables[e.storyVar]=Date.now())},prehistory["pause-playtime"]=function(t){tags().includes(e.pauseTag)&&(State.variables[e.storyVar]+=time())};var i=["h","hr","hrs","hour","hours"],o=["m","min","mins","minute","minutes"],u=["s","sec","secs","second","seconds"];function l(t){return function(t,e){if(t&&Array.isArray(t)&&!(t.length<3)){var a=t[2]<10?"0"+t[2]:""+t[2],r=t[1]<10?"0"+t[1]:""+t[1],n=t[0]<10?"0"+t[0]:""+t[0];return e?"<b>"+a+":"+r+"</b>:"+n:a+":"+r+":"+n}}(s(n()),t)}setup.playTime=function(t){return"string"==typeof t?(e=t,a=n(),r=s(a),i.includes(e)?r[2]:o.includes(e)?r[1]:u.includes(e)?r[0]:a):l(t);var e,a,r},e.tryGlobal&&(window.playTime=window.playTime||setup.playTime),Macro.add("playtime",{handler:function(){var t=this.args.map(function(t){return String(t).trim().toLowerCase()}),e=$(document.createElement("span")),a=l(t.includesAny(["format","f","fmt","b","bold","true"]));e.wiki(a).addClass("macro-"+this.name).appendTo(this.output)}})}();
// end playtime.min.js
/* twine-user-script #18: "pronouns.min.js" */
// pronouns.min.js, for SugarCube 2, by Chapel
;!function(){"use strict";if(Template&&Template.add&&"function"==typeof Template.add){var m={name:"gender",showSetting:!0,label:"Gender",desc:"",storyVar:"%%gender",default:"female"},e="#setting-control-"+m.name,c={subjective:["she","he","they"],objective:["her","him","them"],possessive:["hers","his","theirs"],determiner:["her","his","their"],reflexive:["herself","himself","themself"],noun:["woman","man","person"]};m.showSetting&&(Setting.addToggle(m.name,{label:m.label,desc:m.desc&&"string"==typeof m.desc&&m.desc.trim()?m.desc.trim():void 0}),$(document).on(":dialogopen :dialogopened",function(){$("#ui-dialog-body").hasClass("settings")&&$(e).parent("div").empty().append($(document.createElement("button")).append("Configure...").ariaClick(function(){t()}))})),Template.add(["he","she","they","He","She","They"],function(){return n(this.name,a().subjective)}),Template.add(["him","her","them","Him","Her","Them"],function(){return n(this.name,a().objective)}),Template.add(["his","hers","theirs","His","Hers","Theirs"],function(){return n(this.name,a().possessive)}),Template.add(["his_","her_","their","His_","Her_","Their"],function(){return n(this.name,a().determiner)}),Template.add(["himself","herself","themself","Himself","Herself","Themself"],function(){return n(this.name,a().reflexive)}),Template.add(["man","woman","person","Man","Woman","Person"],function(){return n(this.name,a().noun)}),Macro.add("pronouns",{skipArgs:!0,handler:function(){t()}}),setup.gender={pronouns:a,dialog:t},window.gender=window.gender||setup.gender}else alert("Warning, this version of SugarCube does not include the Template API. Please upgrade to v2.29.0 or higher.");function r(){var e=$(document.createElement("div"));var t,a,n,r,i=Object.keys(c).map(function(e){var t=2;"male"===m.default?t=1:"female"===m.default&&(t=0);var a,n,r,i=State.variables,s=c[e][t];return i[m.storyVar]&&i[m.storyVar][e]&&(s=i[m.storyVar][e]),a=e.toUpperFirst()+": ",n="gender-"+e,r=s,$(document.createElement("label")).append(a).css("display","block").append($(document.createElement("input")).attr({type:"text",name:n}).css({float:"right","margin-left":"0.2em"}).val(r))}),s=(t="Presets: ",a="gender-preset",n=["She/Her","He/Him","They/Them"],r=$(document.createElement("select")).attr("name",a).css("float","right"),n.forEach(function(e,t){console.log(t),$(document.createElement("option")).attr("value",String(t)).append(e).appendTo(r)}),$(document.createElement("label")).css("display","block").append(t,r)).on("change",function(){var n=Number($(this).find("select").val());Number.isNaN(n)||i.forEach(function(e){var t=e.find("input"),a=t.attr("name").split("-")[1];t.val(c[a][n])})}),o=s.find("select");State.variables[m.storyVar]?o.val(""):"male"===m.default?o.val("1"):"female"===m.default?o.val("0"):o.val("2");var l,d=$(document.createElement("button")).wiki("Confirm").addClass("gender-confirm").ariaClick({label:"Confirm pronoun selection."},function(){var n=State.variables;n[m.storyVar]={},i.forEach(function(e){var t=e.find("input"),a=t.attr("name").split("-")[1];n[m.storyVar][a]=t.val().trim().toLowerCase()}),$("#ui-dialog-body").hasClass("reopen")&&UI.settings(),Dialog.close()}),u=(l=[s,"<br>"],i.forEach(function(e){l.push(e),l.push("<br>")}),l.push(d),l);return e.append(u)}function t(){var e,t,a,n;e="Customize Gender",t=r(),n=!(a="custom-gender"),Dialog.isOpen()&&$("#ui-dialog-body").hasClass("settings")&&(n=!0),Dialog.close(),Dialog.setup(e,n?a+" reopen":a),Dialog.append(t),Dialog.open()}function a(){if(State.variables[m.storyVar]&&State.variables[m.storyVar].subjective)return State.variables[m.storyVar];var t=2;"male"===m.default?t=1:"female"===m.default&&(t=0);var a={};return Object.keys(c).forEach(function(e){a[e]=c[e][t]}),a}function n(e,t){return e[0]===e[0].toUpperCase()?t.toUpperFirst():t}}();
;!function(){"use strict";if(Template&&Template.add&&"function"==typeof Template.add){var m={name:"gender",showSetting:!0,label:"Gender",desc:"",storyVar:"%%gender",default:"female"},e="#setting-control-"+m.name,c={subjective:["she","he","they"],objective:["her","him","them"],possessive:["hers","his","theirs"],determiner:["her","his","their"],reflexive:["herself","himself","themself"],noun:["woman","man","person"]};m.showSetting&&(Setting.addToggle(m.name,{label:m.label,desc:m.desc&&"string"==typeof m.desc&&m.desc.trim()?m.desc.trim():void 0}),$(document).on(":dialogopen :dialogopened",function(){$("#ui-dialog-body").hasClass("settings")&&$(e).parent("div").empty().append($(document.createElement("button")).append("Configure...").ariaClick(function(){t()}))})),Template.add(["he","she","they","He","She","They"],function(){return n(this.name,a().subjective)}),Template.add(["him","her","them","Him","Her","Them"],function(){return n(this.name,a().objective)}),Template.add(["his","hers","theirs","His","Hers","Theirs"],function(){return n(this.name,a().possessive)}),Template.add(["his_","her_","their","His_","Her_","Their"],function(){return n(this.name,a().determiner)}),Template.add(["himself","herself","themself","Himself","Herself","Themself"],function(){return n(this.name,a().reflexive)}),Template.add(["man","woman","person","Man","Woman","Person"],function(){return n(this.name,a().noun)}),Macro.add("pronouns",{skipArgs:!0,handler:function(){t()}}),setup.gender={pronouns:a,dialog:t},window.gender=window.gender||setup.gender}else alert("Warning, this version of SugarCube does not include the Template API. Please upgrade to v2.29.0 or higher.");function r(){var e=$(document.createElement("div"));var t,a,n,r,i=Object.keys(c).map(function(e){var t=2;"male"===m.default?t=1:"female"===m.default&&(t=0);var a,n,r,i=State.variables,s=c[e][t];return i[m.storyVar]&&i[m.storyVar][e]&&(s=i[m.storyVar][e]),a=e.toUpperFirst()+": ",n="gender-"+e,r=s,$(document.createElement("label")).append(a).css("display","block").append($(document.createElement("input")).attr({type:"text",name:n}).css({float:"right","margin-left":"0.2em"}).val(r))}),s=(t="Presets: ",a="gender-preset",n=["She/Her","He/Him","They/Them"],r=$(document.createElement("select")).attr("name",a).css("float","right"),n.forEach(function(e,t){console.log(t),$(document.createElement("option")).attr("value",String(t)).append(e).appendTo(r)}),$(document.createElement("label")).css("display","block").append(t,r)).on("change",function(){var n=Number($(this).find("select").val());Number.isNaN(n)||i.forEach(function(e){var t=e.find("input"),a=t.attr("name").split("-")[1];t.val(c[a][n])})}),o=s.find("select");State.variables[m.storyVar]?o.val(""):"male"===m.default?o.val("1"):"female"===m.default?o.val("0"):o.val("2");var l,d=$(document.createElement("button")).wiki("Confirm").addClass("gender-confirm").ariaClick({label:"Confirm pronoun selection."},function(){var n=State.variables;n[m.storyVar]={},i.forEach(function(e){var t=e.find("input"),a=t.attr("name").split("-")[1];n[m.storyVar][a]=t.val().trim().toLowerCase()}),$("#ui-dialog-body").hasClass("reopen")&&UI.settings(),Dialog.close()}),u=(l=[s,"<br>"],i.forEach(function(e){l.push(e),l.push("<br>")}),l.push(d),l);return e.append(u)}function t(){var e,t,a,n;e="Customize Gender",t=r(),n=!(a="custom-gender"),Dialog.isOpen()&&$("#ui-dialog-body").hasClass("settings")&&(n=!0),Dialog.close(),Dialog.setup(e,n?a+" reopen":a),Dialog.append(t),Dialog.open()}function a(){if(State.variables[m.storyVar]&&State.variables[m.storyVar].subjective)return State.variables[m.storyVar];var t=2;"male"===m.default?t=1:"female"===m.default&&(t=0);var a={};return Object.keys(c).forEach(function(e){a[e]=c[e][t]}),a}function n(e,t){return e.first()===e.first().toUpperCase()?t.toUpperFirst():t}}();
// end pronouns.min.js
/* twine-user-script #19: "simple-inventory.min.js" */
// simple-inventory.min.js, for SugarCube 2, by Chapel
Expand Down
6 changes: 2 additions & 4 deletions docs/pronoun-templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[Back to the main readme](./README.md).

This script leverages SugarCube 2's new [template markup](.) and [API](.) to create a complete, user configurable pronoun system. Users are free to list their own pronouns by filling out a form, or choose from one of three presets "He/Him", "She/Her", and "They/Them". You can use the provided macro or JavaScript function to give the user access to the pronoun configuration dialog, and you can optionally allow the user to re-configure their pronouns from the Settings dialog at their pleasure.
This script leverages SugarCube 2's new [template markup](http://www.motoslave.net/sugarcube/2/docs/#markup-template) and [API](http://www.motoslave.net/sugarcube/2/docs/#template-api) to create a complete, user configurable pronoun system. Users are free to list their own pronouns by filling out a form, or choose from one of three presets "He/Him", "She/Her", and "They/Them". You can use the provided macro or JavaScript function to give the user access to the pronoun configuration dialog, and you can optionally allow the user to re-configure their pronouns from the Settings dialog at their pleasure.

**THE CODE:** [Minified](https://github.com/ChapelR/custom-macros-for-sugarcube-2/blob/master/scripts/minified/pronouns.min.js). [Pretty](https://github.com/ChapelR/custom-macros-for-sugarcube-2/blob/master/scripts/pronouns.js).
**DEMO:** [Available](http://macros.twinelab.net/demo?macro=pronouns).
Expand All @@ -23,7 +23,7 @@ This macro opens the pronoun configuration dialog, a pop-up style form where the

### Included Templates

See the [documentation](.) for more on template markup.
See the [documentation](http://www.motoslave.net/sugarcube/2/docs/#markup-template) for more on template markup.

#### Determiner warning:

Expand Down Expand Up @@ -126,8 +126,6 @@ Here is the complete list of templates provided by this system.
?He went to the bank to find out what state ?his_ mortgage was in. For ?him, all that mattered was that the house remained ?his.
```

etc...

### JavaScript API

The following functions are available on `window.gender` and on `setup.gender`.
Expand Down
Loading

0 comments on commit ba8e210

Please sign in to comment.