Coder Social home page Coder Social logo

thomascgray / fantasy-content-generator Goto Github PK

View Code? Open in Web Editor NEW
59.0 4.0 12.0 2.11 MB

Generate D&D 5E-flavoured fantasy content for your app, video game, website, etc.

Home Page: https://www.npmjs.com/package/fantasy-content-generator

License: MIT License

JavaScript 1.04% TypeScript 98.96%
dnd5e dnd dnd-tools rpg rpg-tool

fantasy-content-generator's Introduction

Fantasy Content Generator

npm

Simple API for generating flavourful and interesting fantasy gaming content. Need an NPC? A name? A magic item? You came to the right place.

Top Features Include:

  • Interesting, flavoursome, and narrative-focused content, designed for roleplaying and inspiration for DMs
  • Easy to understand API
  • A single dependency (https://www.npmjs.com/package/seedrandom)
  • Can be used in both Node & browser
  • Optional seeding for deterministic generation
  • Ties-in to D&D 5E mechanics (weapon stats, magic effects, etc.)

Using this library in a project? Please let me know!


Installing

Node/Webpack

npm install --save fantasy-content-generator

import FCG from "fantasy-content-generator";

Browser/Direct <script> Include

Download fantasy_content_generator.js direct from Github and include in a script tag.

<script src="./fantasy_content_generator.js" type="text/javascript"></script>

<script>
  // API available on window.FantasyContentGenerator
</script>

Usage

import FCG from "fantasy-content-generator";

FCG.Names.generate();
/*
{
  seed: <uuid>,
  name: 'Sutha Chernin',
  race: 'halfOrc',
  gender: 'female',
  formattedData: {
    name: 'Sutha Chernin',
    race: 'Half-Orc',
    gender: 'Female'
  }
}
*/

FCG.Storyhooks.npcActs();
/*
{
  seed: <uuid>,
  storyhook: 'An NPC takes a liking to a PC'
}
*/

FCG.NPCs.generate();
/*
{
  seed: <uuid>,
  name: 'Biri Drachedandion',
  gender: 'female',
  race: 'dragonborn',
  traits: [
    'I am unusually tall for my race.',
    'I\'m very clumsy.'
  ],
  desires: [
    'I want to prove myself in combat, so I\'m going to win a tournament.'
  ]
}
*/

FCG.Settlements.generate();
/*
{
  seed: <uuid>,
  type: 'large_city',
  population: '45,760'
}
*/

FCG.MagicItems.generate();
/*
{
  seed: <uuid>,
  type: 'weapon',
  subtype: 'Battleaxe',
  powerLevel: 'minor',
  schoolOfMagic: 'necromancy',
  effects: [
    'On a successful attack, target must make a DC 12 CON save or take an extra 1d2 of Necrotic damage. This effect occurs once per day.'
  ],
  formattedData: {
    title: 'Battleaxe of Minor Necromancy'
  }
}
*/

API

API Reference

There are a number of "sets" available. These are

  • Names - generates names based on race and gender
  • NPCs - generates full NPCs
  • Loots - generates loot and treasure
  • MagicItems - generates magic items
  • Storyhooks - generates storyhooks
  • Settlements - generates settlement information

and can all be found on the base Fantasy Content Generator object.

Sets expose a generate() function, some expose others unique to that set.

Many of the sets are currently WIP and quite limited. More content to come soon! Follow me on Twitter for release and update details.

Tests

npm test

If you want to run a specific test file manually, ensure you set ENVIRONMENT=test

Contributing

Development

If you're wanting to quickly test some changes, the best way is to

  • npm run build:node && node to get a Node build locally and run a node instance locally
  • const FCG = require('./dist/index.js'); to load FCG into memory
  • FCG.NPCs.generate(); you can then start running generators, and seeing the JSON output in your console

Open Sourcery

Open up a PR!

Please make sure your PR includes;

  • a thorough description, including what you're changing and why
  • tests
    • if you're touching utils stuff, tests to ensure behaviour is correct
    • if you're adding/amending sets, tests to ensure that the final returned object doesn't contain any undefined's, etc.

If you want to use content taken from other sources, please check with their licensing first. For example, D&D 5E content is OK, as long its from the SRD.

Releasing

With permission to release, simply run any one of;

  • npm run publish:patch
  • npm run publish:minor
  • npm run publish:major

from your CLI and follow the steps. Requires NPM to be installed locally on your machine.

Credits

d100 Community - Endless Inspiration

tmcgry - Code & Content

SkyD1vingNun - Additional Content

https://github.com/davidbau/seedrandom - Random seeding code, huge thank you

fantasy-content-generator's People

Contributors

dependabot[bot] avatar kayac-chang avatar thomascgray avatar tomcgray avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fantasy-content-generator's Issues

NPCs that generate with a relation now get caught in an infinite loop

Because we fixed a bug re. the seeding for NPCs

The seed now persists the whole way through the generation process.

This means that if seed X will generate with the correct desires to generate relation Y, generation Y will also generate with the desires to generate with the same relation Y, etc. causing an infinite loop.

We need to find some way to generate relations with a deliberate different seed.

Error thrown when calling Storyhooks.generate()

When calling fcg.Storyhooks.generate(), the following error is thrown.
Am I missing something?
TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))

Stack:

  at Function.from (<anonymous>)
   at Object.exports.pickMany (fantasy-content-generator\dist\utils\index.js:24:27)
   at Object.exports.pick (fantasy-content-generator\dist\utils\index.js:14:20)
   at fantasy-content-generator\dist\storyhooks\index.js:25:50
   at Object.exports.withSeed (fantasy-content-generator\dist\utils\index.js:153:23)
   at Object.generate (fantasy-content-generator\dist\storyhooks\index.js:22:18)

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.