notes and comments
This commit is contained in:
parent
1f7a3da0d9
commit
e587cd126c
|
@ -21,11 +21,9 @@ If you need a lighter template without any console commands: [inkjs-boilerplate.
|
||||||
* Keyboard support (press 1-9 to select 1th-9th choices, 0 to choose 10th)
|
* Keyboard support (press 1-9 to select 1th-9th choices, 0 to choose 10th)
|
||||||
* Great game performance (all JS is ~200Kb in size with Inkjs runtime)
|
* Great game performance (all JS is ~200Kb in size with Inkjs runtime)
|
||||||
* For authors: `npm watch` will auto-recompile the game on changes to JS or JSON
|
* For authors: `npm watch` will auto-recompile the game on changes to JS or JSON
|
||||||
|
* Auto-recompiling from ink to JSON is not included, though
|
||||||
|
* Mobile-ready layout
|
||||||
|
* Editable color scheme
|
||||||
|
|
||||||
### Compatibility
|
### Compatibility
|
||||||
Compatible browsers: Chrome >= 60, Firefox >= 60, iOS >= 12, Safari >= 12.
|
Compatible browsers: Chrome >= 60, Firefox >= 60, iOS >= 12, Safari >= 12.
|
||||||
|
|
||||||
If you want to support older browsers (released before 2018),
|
|
||||||
you'll have to rewrite the CSS.
|
|
||||||
I use Bootstrap 5 because it's a good framework but it's also very modern.
|
|
||||||
Other than that, the code depends only on inkJS and jQuery so it should comfortably support IE9+
|
|
||||||
|
|
23
js/script.js
23
js/script.js
|
@ -1,9 +1,26 @@
|
||||||
import jQuery from 'jquery'
|
import jQuery from 'jquery'
|
||||||
const inkjs = require('inkjs').Story;
|
const inkjs = require('inkjs').Story;
|
||||||
|
/**
|
||||||
|
* Path to your game's compiled JSON.
|
||||||
|
* It is relative to index.html file.
|
||||||
|
*/
|
||||||
const entryPoint = 'game/fogg.ink.json';
|
const entryPoint = 'game/fogg.ink.json';
|
||||||
|
|
||||||
let continueToNextChoice, displayText, loadGame, saveChoice, s;
|
let continueToNextChoice, displayText, loadGame, saveChoice, s;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* You can change this function.
|
||||||
|
* It's an easy way to define your own tags and text transformations.
|
||||||
|
*/
|
||||||
|
transform = function(text) {
|
||||||
|
text = text.replace('<st>', '<span class="subtitle">');
|
||||||
|
text = text.replace('</st>', '</span>');
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* You don't need to change anything past this point.
|
||||||
|
*/
|
||||||
saveChoice = function(index) {
|
saveChoice = function(index) {
|
||||||
window.progress.push(index);
|
window.progress.push(index);
|
||||||
return localStorage.setItem("progress", JSON.stringify(window.progress));
|
return localStorage.setItem("progress", JSON.stringify(window.progress));
|
||||||
|
@ -23,8 +40,7 @@ displayText = function(s, interactive = true) {
|
||||||
for (j = 0, len = paragraphs.length; j < len; j++) {
|
for (j = 0, len = paragraphs.length; j < len; j++) {
|
||||||
i = paragraphs[j];
|
i = paragraphs[j];
|
||||||
if (i !== "") {
|
if (i !== "") {
|
||||||
i = i.replace('<st>', '<span class="subtitle">');
|
i = transform(i);
|
||||||
i = i.replace('</st>', '</span>');
|
|
||||||
html = jQuery.parseHTML(i);
|
html = jQuery.parseHTML(i);
|
||||||
block = jQuery('<p>').html(html);
|
block = jQuery('<p>').html(html);
|
||||||
if (interactive) {
|
if (interactive) {
|
||||||
|
@ -56,8 +72,7 @@ continueToNextChoice = function(s) {
|
||||||
ref = s.currentChoices;
|
ref = s.currentChoices;
|
||||||
for (j = 0, len = ref.length; j < len; j++) {
|
for (j = 0, len = ref.length; j < len; j++) {
|
||||||
choice = ref[j];
|
choice = ref[j];
|
||||||
let text = choice.text.replace('<st>', '<span class="subtitle">');
|
let text = transform(choice.text)
|
||||||
text = text.replace('</st>', '</span>')
|
|
||||||
jQuery("#options").append(`<li><a href='#' id='choice-${choice.index}' data-index=${choice.index}>${text}</a></li>`);
|
jQuery("#options").append(`<li><a href='#' id='choice-${choice.index}' data-index=${choice.index}>${text}</a></li>`);
|
||||||
}
|
}
|
||||||
jQuery("#options").fadeIn(500);
|
jQuery("#options").fadeIn(500);
|
||||||
|
|
Loading…
Reference in a new issue