Selaa lähdekoodia

Redid dialog so it shows text before calling hooks. Added a phone!

tags/v0.2.8
Fen Dweller 7 vuotta sitten
vanhempi
commit
2d487c6024
4 muutettua tiedostoa jossa 61 lisäystä ja 15 poistoa
  1. +30
    -5
      dialog.js
  2. +10
    -8
      feast.js
  3. +1
    -1
      objects.js
  4. +20
    -1
      world.js

+ 30
- 5
dialog.js Näytä tiedosto

@@ -7,14 +7,13 @@ function DialogNode() {
this.visit = function() {
for (let i=0; i<this.hooks.length; i++)
this.hooks[i]();
return this.text;
}
};

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() {
@@ -35,3 +34,29 @@ function EatDude() {
this.addChoice("Eat him lol",eatHim);
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() });
}
}

+ 10
- 8
feast.js Näytä tiedosto

@@ -11,13 +11,6 @@ let newline = "&nbsp;";

let player = new Player();

function startDialog(dialog) {
mode = "dialog";
currentDialog = dialog;
update([currentDialog.visit()]);
updateDisplay();
}

function updateExploreCompass() {
for (let i = 0; i < dirButtons.length; i++) {
let button = dirButtons[i];
@@ -168,9 +161,18 @@ function update(lines=[]) {
updateDisplay();
}

function startDialog(dialog) {
mode = "dialog";
currentDialog = dialog;
update([currentDialog.text]);
currentDialog.visit();
updateDisplay();
}

function dialogClicked(index) {
currentDialog = currentDialog.choices[index].node;
update([currentDialog.visit()]);
update([currentDialog.text]);
currentDialog.visit();
if (currentDialog.choices.length == 0) {
mode = "explore";
updateDisplay();


+ 1
- 1
objects.js Näytä tiedosto

@@ -47,7 +47,7 @@ function TV() {
function Phone() {
Object.call(this, "Phone");
this.actions.push({
"name": "Headbutt phone",
"name": "Use phone",
"action": function() {
startDialog(new PhoneCall());
}


+ 20
- 1
world.js Näytä tiedosto

@@ -97,13 +97,32 @@ let locationsSrc = [
"name": "Street",
"dir": EAST,
"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": [

]
}
]
];

function Location(name="Nowhere",desc="Nada") {
this.name = name;


Loading…
Peruuta
Tallenna