Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including bondage with all npm packages installed. Try it out:

var bondage = require("bondage")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

bondage v0.5.5

Yarn parser for Javascript

bondage.js Build Status

Yarn parser for Javascript, in the same vein as YarnSpinner.

Work in Progress

Some of the base text/option functionality is there but it is not nearly fully feature complete. See the Milestones for what's currently needs to be worked on. Use at your own risk!

Things that don't currently work:

  • Variables
  • If statements
  • Shortcut Options
  • Functions

Usage

As a Web Tool

To run through your yarn files in your browser, go to http://hayley.zone/bondage.js, paste your yarn data in the field, then hit "compile".

As a Command Line Tool

Installation: npm install -g bondage

Now you can use the bondage command to run through Yarn files from the command line. You can load one or multiple files at a time. If you load multiple files and a two nodes are encountered with the same name, the node will be overwritten.

Examples

  • Running a single file from the default start node (named "Start"): bondage yarnfile.json
  • Running a single file from the specified node name: bondage -s StartNode yarnfile.json
  • Running multiple files from the specified node name: bondage -s StartNode yarnfile1.json yarnfile2.json ...

As a Library

Web

Include dist/bondage.min.js somewhere in your html, and the bondage variable will be added to the global scope. You can then access everything in the example below (such as bondage.Dialogue) through that variable.

Node

Installation: npm install bondage

const fs = require('fs');
const bondage = require('bondage');

const dialogue = new bondage.Dialogue();
const yarnData = JSON.parse(fs.readFileSync('yarnFile.json'));

dialogue.load(yarnData);

dialogue.on('start', () => {
  // Called before dialogue is ran
});
dialogue.on('finish', () => {
  // Called after dialogue has finished
});

dialogue.on('line', (result) => {
  // Called when a line of text should be displayed
  console.log(result.text);
});
dialogue.on('options', (result) => {
  // Called when there is a choice to be made
  // result.options is a list of options
  for (const option of result.options) {
    console.log(option);
  }

  // Specify which option is chosen (must be called before the next iteration of the loop)
  result.choose(result.options[0]);
});
dialogue.on('command', (result) => {
  // Called when a command like <<command text>> is encountered
  console.log(result.command);
});
dialogue.on('nodecomplete', (result) => {
  // Called when we finish a node
  console.log(result.nodeName);
});

// Loop over the dialogue from the node titled 'Start'
// The result returned to this loop is the same as the ones passed to the listeners above, but
// the attached event listeners get called before the result is returned to this loop
for (const result of dialogue.run('Start')) {
  // Do something else with the result
}

// Advance the dialogue manually from the node titled 'Start'
const d = dialogue.run('Start')
let result = d.next().value;
let nextResult = d.next().value;
// And so on
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free