Changing API from NarrativeManager to StoryManager
This commit is contained in:
+2
-2
@@ -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
@@ -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>>
|
||||
<</widget>></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's palace.
|
||||
<<set _possibleStories = window.NM.getNStorylets(3)>>
|
||||
<<set _possibleStories = window.SM.getNStorylets(3)>>
|
||||
<<ShowStorylets _possibleStories>></tw-passagedata><tw-passagedata pid="3" name="Conversation" tags="" position="350,100" size="100,100"><<set $talkingTo = $payload.character>>
|
||||
You make polite conversation with $talkingTo.name. <br>
|
||||
[[Keep circulating | Start]]</tw-passagedata></tw-storydata>
|
||||
|
||||
@@ -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>>
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
<<set $gossip = 0>>
|
||||
You can go to the [[Ballroom]] or the [[Library]].</tw-passagedata><tw-passagedata pid="3" name="Ballroom" tags="" position="350,100" size="100,100"><<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]]</tw-passagedata><tw-passagedata pid="4" name="DancingRoot" tags="" position="475,100" size="100,100"><<set $partner = $payload["character"]>>
|
||||
You take <<print $partner.firstname>>'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't heard y
|
||||
[[Return | Library]]
|
||||
<</if>></tw-passagedata><tw-passagedata pid="9" name="Library" tags="" position="1100,100" size="100,100"><<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]]</tw-passagedata><tw-passagedata pid="10" name="ConversationRoot" tags="" position="1225,100" size="100,100"><<set $partner = $payload["character"]>>
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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
@@ -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;
|
||||
Reference in New Issue
Block a user