Skip to content
Snippets Groups Projects
Commit 473d78b0 authored by Arkerthan's avatar Arkerthan
Browse files

add back link to quick menu

parent 4686bbf6
No related branches found
No related tags found
1 merge request!6816basic implementation for history and auto generated quick links
/**
* Generate a list of links the player can safely jump to.
*
* @returns {DocumentFragment}
*/
App.UI.quickMenu = (function() { App.UI.quickMenu = (function() {
// setup safe passages // setup safe passages
const jumpFrom = Story.lookup("tags", "jump-from-safe").map(passage => passage.title); 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 jumpTo = Story.lookup("tags", "jump-to-safe").map(passage => passage.title);
// setup hotkeys list // setup hotkeys list, upper/lower case is important!
const hotkeys = cleanHotkeys({ const hotkeys = cleanHotkeys({
Main: "m", Main: "m",
"Manage Personal Affairs": "x" "Manage Personal Affairs": "x"
...@@ -24,14 +29,13 @@ App.UI.quickMenu = (function() { ...@@ -24,14 +29,13 @@ App.UI.quickMenu = (function() {
let history = []; let history = [];
let currentPassage; let currentPassage;
let historyNavigation = false; let historyNavigation = false;
$(document).on(':passageend', function() { $(document).on(':passageinit', event => {
if (currentPassage === State.passage) {
// only reloaded page
return;
}
// if navigated here normally, add passage to history, otherwise remove last entry from history // if navigated here normally, add passage to history, otherwise remove last entry from history
if (!historyNavigation) { if (!historyNavigation) {
if (currentPassage === event.passage.title) {
// only reloaded passage
return;
}
// if last passage can be jumped to add passage to history, otherwise clear history // if last passage can be jumped to add passage to history, otherwise clear history
if (jumpTo.includes(currentPassage)) { if (jumpTo.includes(currentPassage)) {
history.push(currentPassage); history.push(currentPassage);
...@@ -42,15 +46,19 @@ App.UI.quickMenu = (function() { ...@@ -42,15 +46,19 @@ App.UI.quickMenu = (function() {
historyNavigation = false; historyNavigation = false;
history.shift(); history.shift();
} }
currentPassage = State.passage; currentPassage = event.passage.title;
}); });
Mousetrap.bind("backspace", () => { Mousetrap.bind("backspace", () => {
// jump back in history // jump back in history
goBack();
});
function goBack() {
if (history.length > 0 && jumpFrom.includes(State.passage)) { if (history.length > 0 && jumpFrom.includes(State.passage)) {
historyNavigation = true; historyNavigation = true;
Engine.play(history[0]); Engine.play(history[0]);
} }
}); }
function generateMenu() { function generateMenu() {
if (!jumpFrom.includes(State.passage)) { if (!jumpFrom.includes(State.passage)) {
...@@ -60,6 +68,15 @@ App.UI.quickMenu = (function() { ...@@ -60,6 +68,15 @@ App.UI.quickMenu = (function() {
const fragment = document.createDocumentFragment(); const fragment = document.createDocumentFragment();
if (history.length > 0) {
const div = document.createElement("div");
const a = document.createElement("a");
a.append("Back");
a.onclick = goBack;
div.append(a, " ", App.UI.DOM.makeElement("span", "[delete]", "hotkey"));
fragment.append(div);
}
for (let i = 0; i < jumpTo.length; i++) { for (let i = 0; i < jumpTo.length; i++) {
if (jumpTo[i] !== State.passage) { if (jumpTo[i] !== State.passage) {
fragment.append(generatePassageLink(jumpTo[i])); fragment.append(generatePassageLink(jumpTo[i]));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment