-
Notifications
You must be signed in to change notification settings - Fork 56
Adding Tables
Tables are plain JavaScript data. Adding one means editing a list, not writing code. There is no build step: save the file and reload the page.
Two files are involved for every table.
- A data file (
js/roll_*.js) holding the results. - The menu file (
js/roll_menu.js) saying which table appears where, and what it rolls.
Data files export an array. js/roll_plots.js starts with top.plots = [ and
ends with // end of plots. Each entry is one rollable list:
{
title: "d8 Roadside Shrines",
id: "d8roadsideshrines_travel",
roll: [
"A cairn of river stones, each painted with an eye.",
"A weathered post with a rusted bell that no longer rings.",
// ...
],
},-
titleis what appears next to the result. By convention it opens with the die size, which is decorative: a roll always picks uniformly from the array, so the list can be any length. -
idmust be unique within its file. The convention is the die size, the slugified title, then an underscore and a group suffix. -
rollis the list of results.
Pick the file by subject: roll_npcs.js, roll_monsters.js, roll_dungeons.js,
roll_settlements.js, roll_wilderness.js, roll_objects.js, roll_magic.js,
roll_food.js, roll_factions.js, roll_plots.js.
js/roll_menu.js holds top.menu, an array of sections. Each section has an
id and a list of items. An item is one entry in the left-hand list:
{
title: "Roadside Shrines",
use: "Roll when the party passes a wayside marker.",
main_rolls: ["plots/d8roadsideshrines_travel"],
sub_rolls: [],
},-
titleis the name in the list. Prefix it with"- "to show it indented as a variant of the entry above. -
useis the suggested-use line shown with the result. -
main_rollsis a list of"file/id"references. Every one of them is rolled, in order, which is how a single click produces a whole scene. -
sub_rollsis for rolling a quantity of something. Leave it[]unless you need it.
The file part of a reference is the data file's short name: plots,
npcs, monsters, dungeons, settlements, wilderness, objects, magic,
food, factions, subrolls.
Add the item twice. Once in the All section and once in its category section. All is a full copy, not a generated view, so a table only added to one will be missing from the other.
Items appear in the order they are listed. There is no sorting at display time.
main_rolls names one or more lists, all of which are rolled.
pick_rolls names several lists; one is chosen at random and only that one
is rolled. The list it landed on is named alongside the result.
{
title: "Random Plot Hook",
use: "One roll picks an environment, a second draws a hook from it.",
main_rolls: [],
sub_rolls: [],
pick_rolls: [
"plots/d50arctic_plothooks",
"plots/d50coastal_plothooks",
// ...
],
},Use it when the lists are alternatives rather than parts of one result.
sub_rolls references entries in js/roll_subrolls.js, which roll a quantity
and then that many results:
{
title: "5d6 Castle Rooms",
singular: "Castle Room",
id: "castle5d6rooms",
roll_type: "amount", // "amount" lists results, "type" counts by kind
number: "5d6", // how many
percent_to: "100", // chance this sub-roll happens at all
percent_of: "100", // percentage of the rolled number actually used
roll: castle_rooms,
},Any result string can contain a sub-roll that is resolved before display:
"A guard on the gate (d4): 1. bored; 2. drunk; 3. suspicious; 4. asleep"
Write the die in parentheses followed by a colon, then numbered options
separated by ; or ,. Only the first inline roll in a string is resolved.
- Results added to a
js/roll_*.jsfile with a uniqueid - Menu item added to the All section
- Menu item added to its category section
-
node --check js/roll_whatever.jspasses - Rolled it in the browser and the results look right
Favorites are stored by table name. Renaming a table's title orphans it for
anyone who starred it, and the table stops appearing in their Favorites until the
old name comes back.
Adding tables is always safe. If a rename is genuinely needed, raise it in the pull request so an alias can be added.