Git Product home page Git Product logo

lobus's Introduction

lobus

Multiple choice input-event library meant to be used with Ranvier.

Tell me more...

Lobus is made to work with RanvierMUD, a relatively unopinionated text-based multiplayer game engine. Lobus also aims to be unopinionated, though right now it functions solely as a library for creating sequenced, multiple-choice menus in conjunction with an EventEmitter-like socket and a say function used for handling output to the client.

That said, this documentation assumes you will be using Lobus with Ranvier, or a fork thereof.

Design/Philosophy

Lobus exposes all of the classes it uses internally, in case you want to compose your own menu system using parts of Lobus. These classes and their uses are as follows:

  • Choices: This is the main class that one needs to import to use Lobus out of the box. It allows you to create a group of scenarios which prompt the user to make a choice, and then run the user through said group of scenarios. See the Example Use section below for usage information. The choices made by the user in each scenario are stored in an internal state, to be used by future scenarios.

  • Scenario: Each scenario has a title and/or description, and a group of choices that the user can make when presented with a description of the scenario. Developers can set a prerequisite to determine if the user is presented with this scenario or not.

  • Choice: Each scenario involves one or more choices that can be made. Each choice made will be recorded in the Choices class' state. Developers can specify a prerequisite for a choice to be shown to the user, and can also specify a side effect for any choices that are made.

Example Use

const Lobus = require('lobus');
const Choices = Lobus.Choices;

// This uses Ranvier's EventUtil class.
const say = EventUtil.genSay(socket);

let startingAttributes = {
  willpower: 5,
  might: 6
};
let startingClass = 'warrior';

// Choices.createScenario takes a scenario ID and
// a config with a title and/or description.
// It returns a Scenario.
// Scenarios use a chaining API to add choices or prerequisites.
const scenario = Choices
  .createScenario('toughChoice', {
    title: 'Make a tough decision',
    description: 'This will have an effect on your character\'s starting equipment or whatever.'
  })
  .addChoices({
    beGood: {
      description: 'Do the right thing',
      effect() {
        startingAttributes.willpower++;
      }
    },
    beBad: {
      description: 'Do the wrong thing via brute force.',
      effect() {
        startingAttributes.might++;
      }
    }
  });

const secondScenario = Choices
  .createScenario('job', {
    title: 'Choose a career path',
    description: 'This will have an effect on your character\'s starting skills or whatever.'
  })
  .addChoices({
    bePaladin: {
      description: 'Become a paladin',
      effect() {
        startingClass = 'paladin';
      },
      prerequisite(choices) {
        return choices.toughChoice !== 'beBad'
      }
    }
  },
  {
    beThief: {
      description: 'Become a thief',
      effect() {
        startingClass = 'thief';
      }
      prerequisite(choices) {
        return choices.toughChoice === 'beBad'
      }
    }
  });

Choices.run({
  // a list of scenarios, ran in the order they are defined
  scenarios: [
    scenario,
    secondScenario
  ],
  // socket to emit input-events to, see also Ranvier's input-events
  socket,
   // function to broadcast to socket or player (or log for testing)
  say
})
.then(() => socket.emit('done'));

Development

If you would like to contribute to Lobus or develop your own fork of it (and please PR improvements!), please clone this repository. Then, in your local repo, use npm link to globally link Lobus. In your Ranvier repository, use npm link lobus. After doing this, require('lobus') should work and the require statement will pull in the code from your local repository.

lobus's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

lobus's Issues

Unit tests and CI

This would be a boon to new contributors and for myself. Untested code doesn't exist, and in its current state, this module is entirely nonexistent. Woops.

Customizable I/O methods

Right now the I/O for lobus is very specific and only customizable by changing the socket or say methods. This means that customizing I/O in any significant way requires a lot of complexity.

There should be a way to provide more custom methods for user input and output.

Before doing this, the methods handling I/O currently will likely need a small refactor.

If no custom method is provided it should fall back to the current methods.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.