repl.it
@videlais/

Tracery + Ink

Nodejs

No description

fork
loading
Files
  • index.js
  • InkStory.json
  • tracery.json
  • Packager files
  • package-lock.json
  • package.json
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
var Story = require('inkjs').Story;
var Tracery = require('tracery-grammar');
var fs = require('fs');

var inkJSON = JSON.parse( fs.readFileSync('./InkStory.json', 'UTF-8').replace(/^\uFEFF/, '') );

var inkStory = new Story(inkJSON);

var traceryJSON = JSON.parse(fs.readFileSync('./tracery.json') ); 

var grammar = Tracery.createGrammar(traceryJSON);

var name = grammar.flatten("#name#");
var mood = grammar.flatten("#mood#");
var animal = grammar.flatten("#animal#");

inkStory.variablesState["name"] = name;
inkStory.variablesState["mood"] = mood;
inkStory.variablesState["animal"] = animal;

console.log(inkStory.Continue() );