Skip to content

Instantly share code, notes, and snippets.

@videlais

videlais/main.js Secret

Created May 29, 2019 16:47
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save videlais/35d6a1fb30b26b31b2a07904815c65df to your computer and use it in GitHub Desktop.
// Use the storyContent to create an Ink story
var story = new inkjs.Story(storyContent);
// Save a reference to the storyContainer where text will be added
var storyContainer = document.getElementById("story");
function continueStory() {
// Check if there is more content in the story
if(story.canContinue) {
// Get ink to generate the next paragraph
var paragraphText = story.Continue();
var speaker = story.currentTags;
// Create paragraph element
var paragraphElement = document.createElement('p');
// Check if speaker is an empty array
if(speaker.length > 0) {
// Add a CSS class matching the speaker
paragraphElement.classList.add(speaker[0]);
// Add a CSS class matching the emotion
paragraphElement.classList.add(speaker[1]);
}
// Add the text to the P-element
paragraphElement.innerHTML = paragraphText;
// Append the P-element to the storyContainer
storyContainer.appendChild(paragraphElement);
}
}
// Call continueStory() to start
continueStory();
// Listen for the "click" event and show text
window.addEventListener("click", continueStory);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment