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() {
// setup safe passages
const jumpFrom = Story.lookup("tags", "jump-from-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({
Main: "m",
"Manage Personal Affairs": "x"
......@@ -24,14 +29,13 @@ App.UI.quickMenu = (function() {
let history = [];
let currentPassage;
let historyNavigation = false;
$(document).on(':passageend', function() {
if (currentPassage === State.passage) {
// only reloaded page
return;
}
$(document).on(':passageinit', event => {
// if navigated here normally, add passage to history, otherwise remove last entry from history
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 (jumpTo.includes(currentPassage)) {
history.push(currentPassage);
......@@ -42,15 +46,19 @@ App.UI.quickMenu = (function() {
historyNavigation = false;
history.shift();
}
currentPassage = State.passage;
currentPassage = event.passage.title;
});
Mousetrap.bind("backspace", () => {
// jump back in history
goBack();
});
function goBack() {
if (history.length > 0 && jumpFrom.includes(State.passage)) {
historyNavigation = true;
Engine.play(history[0]);
}
});
}
function generateMenu() {
if (!jumpFrom.includes(State.passage)) {
......@@ -60,6 +68,15 @@ App.UI.quickMenu = (function() {
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++) {
if (jumpTo[i] !== State.passage) {
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