import jQuery from 'jquery' const inkjs = require('inkjs').Story; const entryPoint = 'game/game.ink.json'; let continueToNextChoice, displayText, loadGame, saveChoice, s; saveChoice = function(index) { window.progress.push(index); return localStorage.setItem("progress", JSON.stringify(window.progress)); }; function listCharacters (paragraphs) { const chars = [ { match: "Я:", title: "🙉", }, { match: "ПОЛ:", title: "🙍‍♀️" } ] let output = "

На сцене:

" for (let j = 0; j < chars.length; j++) { const e = chars[j]; if (paragraphs.match(e.match)) { output += "

"+e.title+"

" } } return output.trim() } displayText = function(s, interactive = true) { let block, delay, html, i, paragraphs, results; results = []; while (s.canContinue) { paragraphs = s.Continue().split("\n"); if (interactive) { delay = 1000; } results.push((function() { let j, len, results1; results1 = []; for (j = 0, len = paragraphs.length; j < len; j++) { i = paragraphs[j]; if (i !== "") { i = i.replace('', ''); i = i.replace('', ''); html = jQuery.parseHTML(i); block = jQuery('

').html(html); if (interactive) { block.hide(); } jQuery("#content").append(block); if (interactive) { block.fadeIn(delay); results1.push(delay += 500); } else { results1.push(void 0); } } else { results1.push(void 0); } } return results1; })()); } return results; }; continueToNextChoice = function(s) { let choice, j, len, ref, scrollTo; displayText(s, true); scrollTo = jQuery('#options').offset().top; if (s.currentChoices.length > 0) { const characters = listCharacters(jQuery("#content").text()); if (characters.trim().length > 0) { if (jQuery("#content .portraits").length === 0) { jQuery("#content").prepend('

'+characters.trim()+'
') } else { jQuery(".portraits").html(characters.trim()) } } jQuery("#options").html("").hide(); ref = s.currentChoices; for (j = 0, len = ref.length; j < len; j++) { choice = ref[j]; let text = choice.text.replace('', ''); text = text.replace('', '') text = text.replace('', '⏸️ '); jQuery("#options").append(`
  • ${text}
  • `); } jQuery("#options").fadeIn(500); } else { jQuery("#content").append("

    THE END

    "); jQuery("#options").html(""); } return jQuery('html, body').animate({ scrollTop: scrollTo }, 800); }; loadGame = function(s) { let index, j, ref, results; ref = window.progress; results = []; const len = ref.length; while(s.canContinue) { displayText(s, false); } for (j = 0; j < len; j++) { index = ref[j]; if (!index) { continue } if (!s.currentChoices[index]) { continue } s.ChooseChoiceIndex(index) while(s.canContinue) { displayText(s, false); } } return results; }; jQuery.ajax({ url: entryPoint, dataType: 'text', success: function(data) { let progress; progress = localStorage.getItem("progress"); if (progress != null) { window.progress = JSON.parse(progress); } else { window.progress = []; } s = new inkjs(data); if (window.progress !== []) { loadGame(s); } return continueToNextChoice(s); } }); jQuery(document).on('click', "#restart", function() { localStorage.setItem("progress", '[]'); window.location.reload(); }); jQuery(document).on('click', "#options li a", function() { s.ChooseChoiceIndex(jQuery(this).data("index")); saveChoice(jQuery(this).data("index")); continueToNextChoice(s); return false; }); jQuery(document).on('click', "#options li", function() { s.ChooseChoiceIndex(jQuery(this).find('a').data("index")); saveChoice(jQuery(this).find('a').data("index")); continueToNextChoice(s); return false; });