Changing API from NarrativeManager to StoryManager

This commit is contained in:
David Masad
2021-01-28 14:33:12 -05:00
parent 0413480900
commit 51dd88d89e
7 changed files with 30 additions and 30 deletions
+2 -2
View File
@@ -24,7 +24,7 @@ We know the `Conversation` passage is going to be an entrypoint into a storylet,
Every realized storylet comes with some data attached that will fill in its specifics (in Max Kreminski's terminology, the storylet is instantiated by binding some data to it). By default, StoryManager passes this data via the $payload variable. Note that this is a global variable, meaning that it holds the payload relevant for the current storylet only.
Now let's create the characters. To make it easier to write more complicated game-world logic in JavaScript later on, we'll do this in pure JavaScript in the `:: Story JavaScript [script]` passage:
Now we need to create some data we'll be able to bind to the storylet: so let's create the characters. To make it easier to write more complicated game-world logic in JavaScript later on, we'll do this in pure JavaScript in the `:: Story JavaScript [script]` passage:
```
:: Story JavaScript [script]
@@ -40,7 +40,7 @@ Finally, we'll create the storylet generator. This is a function returning the l
```javascript
NarrativeManager.storylets["Conversation"] = {
StoryManager.storylets["Conversation"] = {
name: "Conversation",
tags: [],
generate: function() {
+7 -7
View File
@@ -109,10 +109,10 @@ var randomChoice = function(vals) {
// Set up the general narrative manager
// -----------------------------------------------------------------------
var NarrativeManager = {};
NarrativeManager.storylets = {};
var StoryManager = {};
StoryManager.storylets = {};
NarrativeManager.getAllStorylets = function() {
StoryManager.getAllStorylets = function() {
let allStorylets = [];
for (let key in this.storylets) {
let storylets = this.storylets[key].generate();
@@ -121,7 +121,7 @@ NarrativeManager.getAllStorylets = function() {
return allStorylets;
}
NarrativeManager.getNStorylets = function(n) {
StoryManager.getNStorylets = function(n) {
/*
Get N storylets, prioritizing the highest-priority ones first.
For now assume that priorities are integers, but it would be nice
@@ -145,7 +145,7 @@ NarrativeManager.getNStorylets = function(n) {
return selectedStorylets;
}
window.NM = NarrativeManager;
window.SM = StoryManager;
/* twine-user-script #2: "Story JavaScript" */
Config.passages.nobr = true; // Deal with linebreaks.
@@ -155,7 +155,7 @@ State.variables.characters = [
{name: "Claudio Croix"}
]
NarrativeManager.storylets["Conversation"] = {
StoryManager.storylets["Conversation"] = {
name: "Conversation",
tags: [],
generate: function() {
@@ -179,7 +179,7 @@ NarrativeManager.storylets["Conversation"] = {
<</capture>>
<</for>>
&lt;&lt;/widget&gt;&gt;</tw-passagedata><tw-passagedata pid="2" name="Start" tags="" position="225,100" size="100,100">You stand at the edge of the grand ballroom in the Duchess&#39;s palace.
&lt;&lt;set _possibleStories = window.NM.getNStorylets(3)&gt;&gt;
&lt;&lt;set _possibleStories = window.SM.getNStorylets(3)&gt;&gt;
&lt;&lt;ShowStorylets _possibleStories&gt;&gt;</tw-passagedata><tw-passagedata pid="3" name="Conversation" tags="" position="350,100" size="100,100">&lt;&lt;set $talkingTo = $payload.character&gt;&gt;
You make polite conversation with $talkingTo.name. &lt;br&gt;
[[Keep circulating | Start]]</tw-passagedata></tw-storydata>
+3 -3
View File
@@ -15,7 +15,7 @@ State.variables.characters = [
{name: "Claudio Croix"}
]
NarrativeManager.storylets["Conversation"] = {
StoryManager.storylets["Conversation"] = {
name: "Conversation",
tags: [],
generate: function() {
@@ -36,8 +36,8 @@ NarrativeManager.storylets["Conversation"] = {
:: Start
You stand at the edge of the grand ballroom in the Duchess's palace.
<<set _possibleStories = window.NM.getNStorylets(3)>>
You stand at the edge of the grand ballroom in the Duchess's palace.<br>
<<set _possibleStories = window.SM.getNStorylets(3)>>
<<ShowStorylets _possibleStories>>
+9 -9
View File
@@ -109,10 +109,10 @@ var randomChoice = function(vals) {
// Set up the general narrative manager
// -----------------------------------------------------------------------
var NarrativeManager = {};
NarrativeManager.storylets = {};
var StoryManager = {};
StoryManager.storylets = {};
NarrativeManager.getAllStorylets = function() {
StoryManager.getAllStorylets = function() {
let allStorylets = [];
for (let key in this.storylets) {
let storylets = this.storylets[key].generate();
@@ -121,7 +121,7 @@ NarrativeManager.getAllStorylets = function() {
return allStorylets;
}
NarrativeManager.getNStorylets = function(n) {
StoryManager.getNStorylets = function(n) {
/*
Get N storylets, prioritizing the highest-priority ones first.
For now assume that priorities are integers, but it would be nice
@@ -145,7 +145,7 @@ NarrativeManager.getNStorylets = function(n) {
return selectedStorylets;
}
window.NM = NarrativeManager;
window.SM = StoryManager;
/* twine-user-script #2: "ball_game.js" */
// Set up narrative model
// -----------------------------------------------------------------------
@@ -188,7 +188,7 @@ for (let id=0; id<nChars; id++) {
// Set up storylets themselves
// ------------------------------------------
NarrativeManager.storylets["Dance"] = {
StoryManager.storylets["Dance"] = {
name: "Dance",
tags: ["interaction"],
generate: function() {
@@ -211,7 +211,7 @@ NarrativeManager.storylets["Dance"] = {
};
NarrativeManager.storylets["Conversation"] = {
StoryManager.storylets["Conversation"] = {
name: "Conversation",
tags: ["interaction"],
generate: function() {
@@ -243,7 +243,7 @@ Config.passages.nobr = true; // Deal with linebreaks.</script><tw-passagedata pi
&lt;&lt;set $gossip = 0&gt;&gt;
You can go to the [[Ballroom]] or the [[Library]].</tw-passagedata><tw-passagedata pid="3" name="Ballroom" tags="" position="350,100" size="100,100">&lt;&lt;set $location = &quot;Ballroom&quot;&gt;&gt;
You&#39;re in the ballroom.&lt;br&gt;
&lt;&lt;set _possibleStories = window.NM.getNStorylets(3)&gt;&gt;
&lt;&lt;set _possibleStories = window.SM.getNStorylets(3)&gt;&gt;
&lt;&lt;ShowStorylets _possibleStories&gt;&gt;
Or you can go to the [[Library]]</tw-passagedata><tw-passagedata pid="4" name="DancingRoot" tags="" position="475,100" size="100,100">&lt;&lt;set $partner = $payload[&quot;character&quot;]&gt;&gt;
You take &lt;&lt;print $partner.firstname&gt;&gt;&#39;s hand and step onto the dance floor. As you dance, you can
@@ -277,7 +277,7 @@ Fortunately, they reply with a rumor of their own -- one you haven&#39;t heard y
[[Return | Library]]
&lt;&lt;/if&gt;&gt;</tw-passagedata><tw-passagedata pid="9" name="Library" tags="" position="1100,100" size="100,100">&lt;&lt;set $location = &quot;Library&quot;&gt;&gt;
You&#39;re in the library.&lt;br&gt;
&lt;&lt;set _possibleStories = window.NM.getNStorylets(3)&gt;&gt;
&lt;&lt;set _possibleStories = window.SM.getNStorylets(3)&gt;&gt;
&lt;&lt;ShowStorylets _possibleStories&gt;&gt;
Or you can go to the [[Ballroom]]</tw-passagedata><tw-passagedata pid="10" name="ConversationRoot" tags="" position="1225,100" size="100,100">&lt;&lt;set $partner = $payload[&quot;character&quot;]&gt;&gt;
+2 -2
View File
@@ -39,7 +39,7 @@ for (let id=0; id<nChars; id++) {
// Set up storylets themselves
// ------------------------------------------
NarrativeManager.storylets["Dance"] = {
StoryManager.storylets["Dance"] = {
name: "Dance",
tags: ["interaction"],
generate: function() {
@@ -62,7 +62,7 @@ NarrativeManager.storylets["Dance"] = {
};
NarrativeManager.storylets["Conversation"] = {
StoryManager.storylets["Conversation"] = {
name: "Conversation",
tags: ["interaction"],
generate: function() {
+2 -2
View File
@@ -17,7 +17,7 @@ You can go to the [[Ballroom]] or the [[Library]].
:: Ballroom
<<set $location = "Ballroom">>
You're in the ballroom.<br>
<<set _possibleStories = window.NM.getNStorylets(3)>>
<<set _possibleStories = window.SM.getNStorylets(3)>>
<<ShowStorylets _possibleStories>>
Or you can go to the [[Library]]
@@ -71,7 +71,7 @@ Fortunately, they reply with a rumor of their own -- one you haven't heard yet.
:: Library
<<set $location = "Library">>
You're in the library.<br>
<<set _possibleStories = window.NM.getNStorylets(3)>>
<<set _possibleStories = window.SM.getNStorylets(3)>>
<<ShowStorylets _possibleStories>>
Or you can go to the [[Ballroom]]
+5 -5
View File
@@ -6,10 +6,10 @@ var randomChoice = function(vals) {
// Set up the general narrative manager
// -----------------------------------------------------------------------
var NarrativeManager = {};
NarrativeManager.storylets = {};
var StoryManager = {};
StoryManager.storylets = {};
NarrativeManager.getAllStorylets = function() {
StoryManager.getAllStorylets = function() {
let allStorylets = [];
for (let key in this.storylets) {
let storylets = this.storylets[key].generate();
@@ -18,7 +18,7 @@ NarrativeManager.getAllStorylets = function() {
return allStorylets;
}
NarrativeManager.getNStorylets = function(n) {
StoryManager.getNStorylets = function(n) {
/*
Get N storylets, prioritizing the highest-priority ones first.
For now assume that priorities are integers, but it would be nice
@@ -42,4 +42,4 @@ NarrativeManager.getNStorylets = function(n) {
return selectedStorylets;
}
window.NM = NarrativeManager;
window.SM = StoryManager;