Created
April 29, 2020 23:16
-
-
Save jacobmakarsky/fc1098be194a0727a870083442623538 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function showTextNode(textNodeIndex) { | |
const textNode = textNodes.find(textNode => textNode.id === textNodeIndex) | |
textElement.innerText = textNode.text | |
while (optionButtonsElement.firstChild) { | |
optionButtonsElement.removeChild(optionButtonsElement.firstChild) | |
} | |
textNode.options.forEach(option => { | |
if (showOption(option)) { | |
const button = document.createElement('button') | |
button.innerText = option.text | |
button.classList.add('btn') | |
button.addEventListener('click', () => selectOption(option)) | |
optionButtonsElement.appendChild(button) | |
} | |
}) | |
} | |
function showOption(option) { | |
return option.requiredState == null || option.requiredState(state) | |
} | |
function selectOption(option) { | |
const nextTextNodeId = option.nextText | |
if (nextTextNodeId <= 0) { | |
return startGame() | |
} | |
state = Object.assign(state, option.setState) | |
showTextNode(nextTextNodeId) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment