diff --git a/src/js/utilJS.js b/src/js/utilJS.js index 09ba746be17f9f017f709eb91e6c0ffe0ba0a431..9608cc416109054743c1ad831f7610ca59f9fe6a 100644 --- a/src/js/utilJS.js +++ b/src/js/utilJS.js @@ -2327,6 +2327,46 @@ App.UI.passageLink = function(linkText, passage, setter, elementType = 'a') { return res; }; +App.UI.link = function() { + let counter = 0; + + // reset all handlers for each passage + $(document).on(':passageinit', function() { + State.temporary.linkHandlers = {}; + }); + + return makeLink; + + /** + * Creates a markup for a SugarCube link which executes given function with given arguments + * + * @param {string} linkText link text + * @param {*} handler callable object + * @param {*} args arguments + * @param {string} [passage] the passage name to link to + * @returns {string} link in SC markup + */ + function makeLink(linkText, handler, args = [], passage = '') { + // pack handler and data + State.temporary.linkHandlers[counter] = { + f: handler, + args: Array.isArray(args) ? args : [args] + }; + + // can't say _linkHandlers here becasue SC does not recognize its own notation in "..._varName" + let SCHandlerText = + `State.temporary.linkHandlers[${counter}].f(...State.temporary.linkHandlers[${counter}].args);`; + ++counter; + + if (passage) { + return App.UI.passageLink(linkText, passage, SCHandlerText); + } else { + // data-passage scheme does not work with empty passage name + return `<<link "${linkText}">><<run ${SCHandlerText}>><</link>>`; + } + } +}(); + /** * Replaces contents of the element, identified by the given selector, with wiki'ed new content * diff --git a/src/pregmod/managePersonalAffairs.tw b/src/pregmod/managePersonalAffairs.tw index 250ecc4710ae4bcf293fea6e7ba0805609a292c3..80a589b3a40767b9a26baaae8a829a12a023d5a8 100644 --- a/src/pregmod/managePersonalAffairs.tw +++ b/src/pregmod/managePersonalAffairs.tw @@ -10,7 +10,7 @@ <</if>> You pause for a moment from your busy day to day life to return to <<if $masterSuite != 0>>$masterSuiteName<<else>>your room<</if>> to consider some things about yourself. -<br>You take yourself in a full length mirror. You are <<if $activeSlave.race == "amerindian" || $activeSlave.race == "asian" || $activeSlave.race == "indo-aryan">>an<<else>>a<</if>> $PC.race <<if $PC.dick == 1 && $PC.vagina == 1>>futanari<<elseif $PC.dick == 1>>man<<else>>woman<</if>> with<<if $PC.markings == "freckles">> freckled<<elseif $PC.markings == "heavily freckled">> heavily freckled<</if>> <<print $PC.skin>> skin, $PC.hColor hair, $PC.eyeColor eyes and a perfect $PC.faceShape face. +<br>You take yourself in a full length mirror. You are <<if $PC.race == "amerindian" || $PC.race == "asian" || $PC.race == "indo-aryan">>an<<else>>a<</if>> $PC.race <<if $PC.dick == 1 && $PC.vagina == 1>>futanari<<elseif $PC.dick == 1>>man<<else>>woman<</if>> with<<if $PC.markings == "freckles">> freckled<<elseif $PC.markings == "heavily freckled">> heavily freckled<</if>> <<print $PC.skin>> skin, $PC.hColor hair, $PC.eyeColor eyes and a perfect $PC.faceShape face. <<if $PC.actualAge >= 65>> You're @@.orange;$PC.actualAge@@ and definitely feeling it.<<if $PC.visualAge > $PC.actualAge>> You've taken measures to @@.lime;look an older $PC.visualAge,@@ though perhaps it might be time to undo it.<<elseif $PC.visualAge < $PC.actualAge>> You've taken measures to @@.lime;look a younger $PC.visualAge,@@ now if only your body agreed with your looks.<</if>> <<elseif $PC.actualAge >= 50>>