Implementing storylet generators as generator functions

This commit is contained in:
David Masad
2021-02-06 07:05:00 -05:00
parent edd66e8da9
commit 82e7c5f403
9 changed files with 90 additions and 103 deletions

View File

@@ -114,11 +114,11 @@ StoryManager.getAllStorylets = function(tag=null) {
storylet = this.storylets[key];
if (tag === null || ("tags" in storylet && storylet.tags.includes(tag))) {
// TODO: If using yield, this part will change
storylets = storylet.generate();
for (let i in storylets) {
boundStorylet = storylets[i];
//storylets = storylet.generate();
for (let boundStorylet of storylet.generate()) {
//boundStorylet = storylets[i];
if (!("priority" in boundStorylet)) boundStorylet.priority = 0;
allStorylets.push(storylets[i]);
allStorylets.push(boundStorylet);
}
}
}
@@ -222,8 +222,7 @@ State.variables.conversationTopics = {
StoryManager.storylets["Conversation"] = {
name: "Conversation",
tags: ["circulating"],
generate: function() {
let storylets = [];
generate: function*() {
for (let i in State.variables.characters) {
let character = State.variables.characters[i];
let storylet = {
@@ -233,24 +232,23 @@ StoryManager.storylets["Conversation"] = {
character: character
}
storylets.push(storylet);
yield storylet;
}
return storylets;
}
};
StoryManager.storylets["Buttonholed"] = {
name: "Buttonholed",
tags: ["circulating"],
generate: function() {
generate: function*() {
if (Math.random() < 0.2) {
let char = randomChoice(State.variables.characters);
return [{
yield {
passage: "Being approached",
description: "You see " + char.name + " approaching you.",
interrupt: true,
character: char
}]
};
}
}
};
@@ -277,13 +275,14 @@ StoryManager.storylets["Conversation topic"] = {
StoryManager.storylets["Asked to leave"] = {
name: "Asked to leave",
tags: ["circulating"],
generate: function() {
generate: function*
() {
if (State.variables.reputation < -1 && Math.random() < 0.5) {
return [{
yield {
passage: "Asked to leave",
description: "You see a footman approaching you.",
interrupt: true
}]
};
}
}
};
@@ -291,13 +290,13 @@ StoryManager.storylets["Asked to leave"] = {
StoryManager.storylets["Seeing the duchess"] = {
name: "Seeing the duchess",
tags: ["circulating"],
generate: function() {
generate: function*() {
if (State.variables.reputation > 6 && Math.random() < 0.5) {
return [{
yield {
passage: "Invited to see the Duchess",
description: "You see a footman approaching you.",
interrupt: true
}]
}
}
}
};