| @@ -7,14 +7,13 @@ function DialogNode() { | |||||
| this.visit = function() { | this.visit = function() { | ||||
| for (let i=0; i<this.hooks.length; i++) | for (let i=0; i<this.hooks.length; i++) | ||||
| this.hooks[i](); | this.hooks[i](); | ||||
| return this.text; | |||||
| } | |||||
| }; | |||||
| this.choices = []; | this.choices = []; | ||||
| this.addChoice = function(text,node) { | |||||
| this.choices.push({"text": text, "node": node}); | |||||
| } | |||||
| this.addChoice = function(text,node,tests=[]) { | |||||
| this.choices.push({"text": text, "node": node, "tests": []}); | |||||
| }; | |||||
| } | } | ||||
| function EatDude() { | function EatDude() { | ||||
| @@ -35,3 +34,29 @@ function EatDude() { | |||||
| this.addChoice("Eat him lol",eatHim); | this.addChoice("Eat him lol",eatHim); | ||||
| this.addChoice("Actually don't",dontEatHim); | this.addChoice("Actually don't",dontEatHim); | ||||
| } | } | ||||
| function PhoneCall() { | |||||
| DialogNode.call(this); | |||||
| this.text = "You pick up the phone. Who do you want to call?"; | |||||
| { | |||||
| let nodeFen = new DialogNode(); | |||||
| this.addChoice("Fen",nodeFen); | |||||
| nodeFen.text = "You dial Fen's number. Milliseconds later, he kicks open your front door and dabs on you, then runs away."; | |||||
| } | |||||
| { | |||||
| let nodeNerd = new DialogNode(); | |||||
| this.addChoice("Some nerd",nodeNerd); | |||||
| nodeNerd.text = "You dial some nerd. He shows up at your front door."; | |||||
| nodeNerd.hooks.push(function() { startDialog(new EatDude()); }); | |||||
| } | |||||
| { | |||||
| let nodeCrash = new DialogNode(); | |||||
| this.addChoice("Crash the game",nodeCrash); | |||||
| nodeCrash.text = "Oh no oops"; | |||||
| nodeCrash.hooks.push(function() { potato() }); | |||||
| } | |||||
| } | |||||
| @@ -11,13 +11,6 @@ let newline = " "; | |||||
| let player = new Player(); | let player = new Player(); | ||||
| function startDialog(dialog) { | |||||
| mode = "dialog"; | |||||
| currentDialog = dialog; | |||||
| update([currentDialog.visit()]); | |||||
| updateDisplay(); | |||||
| } | |||||
| function updateExploreCompass() { | function updateExploreCompass() { | ||||
| for (let i = 0; i < dirButtons.length; i++) { | for (let i = 0; i < dirButtons.length; i++) { | ||||
| let button = dirButtons[i]; | let button = dirButtons[i]; | ||||
| @@ -168,9 +161,18 @@ function update(lines=[]) { | |||||
| updateDisplay(); | updateDisplay(); | ||||
| } | } | ||||
| function startDialog(dialog) { | |||||
| mode = "dialog"; | |||||
| currentDialog = dialog; | |||||
| update([currentDialog.text]); | |||||
| currentDialog.visit(); | |||||
| updateDisplay(); | |||||
| } | |||||
| function dialogClicked(index) { | function dialogClicked(index) { | ||||
| currentDialog = currentDialog.choices[index].node; | currentDialog = currentDialog.choices[index].node; | ||||
| update([currentDialog.visit()]); | |||||
| update([currentDialog.text]); | |||||
| currentDialog.visit(); | |||||
| if (currentDialog.choices.length == 0) { | if (currentDialog.choices.length == 0) { | ||||
| mode = "explore"; | mode = "explore"; | ||||
| updateDisplay(); | updateDisplay(); | ||||
| @@ -47,7 +47,7 @@ function TV() { | |||||
| function Phone() { | function Phone() { | ||||
| Object.call(this, "Phone"); | Object.call(this, "Phone"); | ||||
| this.actions.push({ | this.actions.push({ | ||||
| "name": "Headbutt phone", | |||||
| "name": "Use phone", | |||||
| "action": function() { | "action": function() { | ||||
| startDialog(new PhoneCall()); | startDialog(new PhoneCall()); | ||||
| } | } | ||||
| @@ -97,13 +97,32 @@ let locationsSrc = [ | |||||
| "name": "Street", | "name": "Street", | ||||
| "dir": EAST, | "dir": EAST, | ||||
| "desc": "You hurry back into the open street." | "desc": "You hurry back into the open street." | ||||
| }, | |||||
| { | |||||
| "name": "Seedy Bar", | |||||
| "dir": NORTH, | |||||
| "desc": "You step into the bar." | |||||
| } | |||||
| ], | |||||
| "objs": [ | |||||
| ] | |||||
| }, | |||||
| { | |||||
| "name": "Seedy Bar", | |||||
| "desc": "God this place is seedy", | |||||
| "conn": [ | |||||
| { | |||||
| "name": "Alley", | |||||
| "dir": SOUTH, | |||||
| "desc": "You step out of the bar." | |||||
| } | } | ||||
| ], | ], | ||||
| "objs": [ | "objs": [ | ||||
| ] | ] | ||||
| } | } | ||||
| ] | |||||
| ]; | |||||
| function Location(name="Nowhere",desc="Nada") { | function Location(name="Nowhere",desc="Nada") { | ||||
| this.name = name; | this.name = name; | ||||