From 6bbc59cd59df4eb2488ae16e9bdea35e47f689dd Mon Sep 17 00:00:00 2001
From: Arkerthan <arkerthan@gmail.com>
Date: Sat, 23 May 2020 00:44:36 +0200
Subject: [PATCH] Add hidden tag to hide passages but allow history navigation
 to them

---
 src/facilities/farmyard/farmerSelect.tw  |  2 +-
 src/facilities/nursery/matronSelect.tw   |  2 +-
 src/gui/quicklinks.js                    | 37 +++++++++++++++++++-----
 src/uncategorized/attendantSelect.tw     |  2 +-
 src/uncategorized/concubineSelect.tw     |  2 +-
 src/uncategorized/djSelect.tw            |  2 +-
 src/uncategorized/hgSelect.tw            |  2 +-
 src/uncategorized/madamSelect.tw         |  2 +-
 src/uncategorized/milkmaidSelect.tw      |  2 +-
 src/uncategorized/nurseSelect.tw         |  2 +-
 src/uncategorized/schoolteacherSelect.tw |  2 +-
 src/uncategorized/stewardessSelect.tw    |  2 +-
 src/uncategorized/wardenessSelect.tw     |  2 +-
 13 files changed, 42 insertions(+), 19 deletions(-)

diff --git a/src/facilities/farmyard/farmerSelect.tw b/src/facilities/farmyard/farmerSelect.tw
index e94fb005024..8ea91518783 100644
--- a/src/facilities/farmyard/farmerSelect.tw
+++ b/src/facilities/farmyard/farmerSelect.tw
@@ -1,4 +1,4 @@
-:: Farmer Select [nobr jump-from-safe]
+:: Farmer Select [nobr jump-to-safe jump-hidden jump-from-safe]
 
 <<set $nextButton = "Back", $nextLink = "Farmyard", $encyclopedia = "Farmer">>
 <<if ($Farmer != 0)>>
diff --git a/src/facilities/nursery/matronSelect.tw b/src/facilities/nursery/matronSelect.tw
index 334c05b7a23..0b52309d0ff 100644
--- a/src/facilities/nursery/matronSelect.tw
+++ b/src/facilities/nursery/matronSelect.tw
@@ -1,4 +1,4 @@
-:: Matron Select [nobr jump-from-safe]
+:: Matron Select [nobr jump-to-safe jump-hidden jump-from-safe]
 
 <<set $nextButton = "Back", $nextLink = "Nursery", $encyclopedia = "Matron">>
 <<if ($Matron != 0)>>
diff --git a/src/gui/quicklinks.js b/src/gui/quicklinks.js
index 1930c43d792..85418531546 100644
--- a/src/gui/quicklinks.js
+++ b/src/gui/quicklinks.js
@@ -4,14 +4,16 @@
  * Tags are:
  * jump-to-safe: Allow to jump to this passage from anywhere
  * jump-from-safe: Allow to jump from this passage to anywhere
+ * hidden: Allows to jump to via history, but does not show up in the quick links menu; use together with jump-to-safe
  * no-history: Do not record history for this passage, act as if was never opened; mutually exclusive with the jump tags
  *
  * @returns {DocumentFragment}
  */
 App.UI.quickMenu = (function() {
-	// setup safe passages
+	// setup passage lists
 	const jumpFrom = Story.lookup("tags", "jump-from-safe").map(passage => passage.title);
 	const jumpTo = Story.lookup("tags", "jump-to-safe").map(passage => passage.title);
+	const hidden = Story.lookup("tags", "jump-hidden").map(passage => passage.title);
 	const noHistory = Story.lookup("tags", "no-history").map(passage => passage.title);
 
 	// if property name is a passage name, then it's a link, otherwise only text.
@@ -267,9 +269,9 @@ App.UI.quickMenu = (function() {
 
 	/**
 	 * Add a "Return" link at second position if there is a history.
-	 * @param {HTMLDivElement} container
+	 * @param {Array<HTMLElement>} linkList
 	 */
-	function addBackLink(container) {
+	function addBackLink(linkList) {
 		if (history.length > 0) {
 			const div = document.createElement("div");
 			div.classList.add("menu-link");
@@ -278,7 +280,7 @@ App.UI.quickMenu = (function() {
 			a.onclick = goBack;
 			div.append(a, " ", App.UI.DOM.makeElement("span", "[backspace]", "hotkey"));
 			// insert at second position
-			container.insertBefore(div, container.firstChild.nextSibling);
+			linkList.splice(1, 0, div);
 		}
 	}
 
@@ -300,8 +302,18 @@ App.UI.quickMenu = (function() {
 
 		try {
 			// quick menu
-			div.append(...generateLinkList(layout));
-			addBackLink(div);
+			const links = generateLinkList(layout);
+
+			if (V.debugMode) {
+				addCategory(links, "Hidden", hidden.reduce((acc, cur) => {
+					acc[cur] = true;
+					return acc;
+				}, {}));
+			}
+
+			addBackLink(links);
+			div.append(...links);
+
 
 			// traverse from current passage up to uncollapse.
 			if (currentPassage !== null) {
@@ -449,8 +461,19 @@ App.UI.quickMenu = (function() {
 	 */
 	function addOtherCategory(layout) {
 		const passages = jumpTo.slice();
+
+		// filter out passages used in layout
 		filterPassages(passages, layout);
 
+		// filter out hidden passages
+		for (let i = 0; i < hidden.length; i++) {
+			const index = passages.indexOf(hidden[i]);
+			if (index > -1) {
+				passages.splice(index, 1);
+			}
+		}
+
+		// Other category
 		if (passages.length > 0) {
 			const other = {};
 			for (let i = 0; i < passages.length; i++) {
@@ -469,8 +492,8 @@ App.UI.quickMenu = (function() {
 	 */
 	function filterPassages(passages, layout) {
 		for (const category in layout) {
-			const index = passages.indexOf(category);
 			if (layout[category] === true) {
+				const index = passages.indexOf(category);
 				if (index > -1) {
 					passages.splice(index, 1);
 				}
diff --git a/src/uncategorized/attendantSelect.tw b/src/uncategorized/attendantSelect.tw
index f6d21e712e5..9145c5cb49f 100644
--- a/src/uncategorized/attendantSelect.tw
+++ b/src/uncategorized/attendantSelect.tw
@@ -1,4 +1,4 @@
-:: Attendant Select [nobr jump-from-safe]
+:: Attendant Select [nobr jump-to-safe jump-hidden jump-from-safe]
 
 <<set $nextButton = "Back", $nextLink = "Spa", $encyclopedia = "Attendant">>
 <<if _S.Attendant>>
diff --git a/src/uncategorized/concubineSelect.tw b/src/uncategorized/concubineSelect.tw
index 4911d97db58..9f153e75443 100644
--- a/src/uncategorized/concubineSelect.tw
+++ b/src/uncategorized/concubineSelect.tw
@@ -1,4 +1,4 @@
-:: Concubine Select [nobr jump-from-safe]
+:: Concubine Select [nobr jump-to-safe jump-hidden jump-from-safe]
 
 <<set $nextButton = "Back", $nextLink = "Master Suite", $encyclopedia = "Concubine">>
 <<if ($Concubine != 0)>>
diff --git a/src/uncategorized/djSelect.tw b/src/uncategorized/djSelect.tw
index b96cb766b59..a2c43a88d43 100644
--- a/src/uncategorized/djSelect.tw
+++ b/src/uncategorized/djSelect.tw
@@ -1,4 +1,4 @@
-:: DJ Select [nobr jump-from-safe]
+:: DJ Select [nobr jump-to-safe jump-hidden jump-from-safe]
 
 <<set $nextButton = "Back", $nextLink = "Club", $encyclopedia = "DJ">>
 <<if ($DJ != 0)>>
diff --git a/src/uncategorized/hgSelect.tw b/src/uncategorized/hgSelect.tw
index d84ed190e43..f729326e0e5 100644
--- a/src/uncategorized/hgSelect.tw
+++ b/src/uncategorized/hgSelect.tw
@@ -1,4 +1,4 @@
-:: HG Select [nobr jump-to-safe jump-from-safe]
+:: HG Select [nobr jump-to-safe jump-hidden jump-from-safe]
 
 <<set $nextButton = "Back to Main", $nextLink = "Main", $encyclopedia = "Head Girl">>
 
diff --git a/src/uncategorized/madamSelect.tw b/src/uncategorized/madamSelect.tw
index 9ba7e7ef90c..e72ea4a1018 100644
--- a/src/uncategorized/madamSelect.tw
+++ b/src/uncategorized/madamSelect.tw
@@ -1,4 +1,4 @@
-:: Madam Select [nobr jump-from-safe]
+:: Madam Select [nobr jump-to-safe jump-hidden jump-from-safe]
 
 <<set $nextButton = "Back", $nextLink = "Brothel", $encyclopedia = "Madam">>
 <<if ($Madam != 0)>>
diff --git a/src/uncategorized/milkmaidSelect.tw b/src/uncategorized/milkmaidSelect.tw
index f10c82b5ebe..1123fb3d527 100644
--- a/src/uncategorized/milkmaidSelect.tw
+++ b/src/uncategorized/milkmaidSelect.tw
@@ -1,4 +1,4 @@
-:: Milkmaid Select [nobr jump-from-safe]
+:: Milkmaid Select [nobr jump-to-safe jump-hidden jump-from-safe]
 
 <<set $nextButton = "Back", $nextLink = "Dairy", $encyclopedia = "Milkmaid">>
 <<if ($Milkmaid != 0)>>
diff --git a/src/uncategorized/nurseSelect.tw b/src/uncategorized/nurseSelect.tw
index debce7c0d98..87f88a86f69 100644
--- a/src/uncategorized/nurseSelect.tw
+++ b/src/uncategorized/nurseSelect.tw
@@ -1,4 +1,4 @@
-:: Nurse Select [nobr jump-from-safe]
+:: Nurse Select [nobr jump-to-safe jump-hidden jump-from-safe]
 
 <<set $nextButton = "Back", $nextLink = "Clinic", $encyclopedia = "Nurse">>
 <<if ($Nurse != 0)>>
diff --git a/src/uncategorized/schoolteacherSelect.tw b/src/uncategorized/schoolteacherSelect.tw
index 43cb2333611..745cc48ed9e 100644
--- a/src/uncategorized/schoolteacherSelect.tw
+++ b/src/uncategorized/schoolteacherSelect.tw
@@ -1,4 +1,4 @@
-:: Schoolteacher Select [nobr jump-from-safe]
+:: Schoolteacher Select [nobr jump-to-safe jump-hidden jump-from-safe]
 
 <<set $nextButton = "Back", $nextLink = "Schoolroom", $encyclopedia = "Schoolteacher">>
 <<if ($Schoolteacher != 0)>>
diff --git a/src/uncategorized/stewardessSelect.tw b/src/uncategorized/stewardessSelect.tw
index 8ea988a80db..1c5c4f97b7c 100644
--- a/src/uncategorized/stewardessSelect.tw
+++ b/src/uncategorized/stewardessSelect.tw
@@ -1,4 +1,4 @@
-:: Stewardess Select [nobr jump-from-safe]
+:: Stewardess Select [nobr jump-to-safe jump-hidden jump-from-safe]
 
 <<set $nextButton = "Back", $nextLink = "Servants' Quarters", $encyclopedia = "Stewardess">>
 <<if ($Stewardess != 0)>>
diff --git a/src/uncategorized/wardenessSelect.tw b/src/uncategorized/wardenessSelect.tw
index 7180dd34750..09e2071672a 100644
--- a/src/uncategorized/wardenessSelect.tw
+++ b/src/uncategorized/wardenessSelect.tw
@@ -1,4 +1,4 @@
-:: Wardeness Select [nobr jump-from-safe]
+:: Wardeness Select [nobr jump-to-safe jump-hidden jump-from-safe]
 
 <<set $nextButton = "Back", $nextLink = "Cellblock", $encyclopedia = "Wardeness">>
 <<if ($Wardeness != 0)>>
-- 
GitLab