detect recursively required tables

import {UltraLoot} from "ultraloot";

const ultralootDefaultRng = new UltraLoot(); // default RNG
const ultralootCustomRng = new UltraLoot("UL7R4L007"); // seeding the built in RNG
const ultralootCustomRng = new UltraLoot(rngSource); // using a custom RNG

Constructors

Properties

conditions: Record<string, LootTableConditionSignature> = {}

Global conditions that can be used by loot table pools and entries.

The keys in the object are the function identifier used in the table entries/pools

defaultRng: RngInterface

Default RNG source when none is given

functions: Record<string, LootTableFunctionSignature> = {}

Global functions that can be used by loot table entries.

The keys in the object are the function identifier used in the table entries

RNG source given by the end user

rngConstructor?: RngConstructor

RNG Constructor for making new RNGs

throwOnMissingConditions: boolean = true

Whether to throw errors when conditions are missing, otherwise just does console.error

throwOnMissingFunctions: boolean = true

Whether to throw errors when functions are missing, otherwise just does console.error

version: string = CURRENT_VERSION
version: string = CURRENT_VERSION

Methods

  • Parameters

    • str: string
    • ending: string

    Returns string

  • Parameters

    • str: string
    • extension: string

    Returns string

  • Load a table from a file.

    The file can be local or a url. If running in browser, it's always treated as a URL. When run in node, it will only treat it as a URL if it's prefixed with http.

    This function expects a single table to be located in the file, as the base object.

    Parameters

    Returns Promise<LootTable>

  • Load serialized tables from a file.

    This is just a wrapper around unserializing json contents of a file.

    Parameters

    Returns Promise<Record<string, LootTable>>

  • Loads serialized tables from a local file

    Parameters

    Returns Promise<Record<string, LootTable>>

  • Parameters

    • parts: string[]
    • sep: string = '/'

    Returns string

  • Serializes a LootTable ready for converting to text, e.g. JSON

    Returns a key value object, where the keys are the loot table filenames/ids

    Parameters

    • table: LootTable
    • __namedParameters: {
          had?: Set<any>;
          includeRng?: boolean;
          key?: string;
      } = {}
      • Optionalhad?: Set<any>
      • OptionalincludeRng?: boolean
      • Optionalkey?: string

    Returns SerializedTables

    const result = await ultraloot.serialize(table);

    result = {
    kitchen_cupboard: {
    fn: 'kitchen_cupboard',
    pools: [
    {
    entries: [
    {
    type: 'table',
    item: 'vegetables'
    },
    {
    type: 'table',
    item: 'fruit'
    }
    ]
    }
    ]
    },
    fruit_bowl: {
    fn: 'fruit_bowl',
    pools: [
    {
    entries: [
    {
    type: 'table',
    item: 'fruit'
    }
    ]
    }
    ]
    },
    vegetables: {
    fn: 'vegetables',
    pools: [
    {
    entries: [
    {
    id: 'carrot'
    },
    {
    id: 'cabbage'
    },
    ]
    }
    ]
    },
    fruit: {
    fn: 'fruit',
    pools: [
    {
    entries: [
    {
    id: 'apple'
    },
    {
    id: 'pear'
    },
    ]
    }
    ]
    }
    }
  • Convert a LootTable to JSON

    Parameters

    • table: LootTable

      The table to serialize

    • options: {
          includeRng?: boolean;
      } = {}

      Options

      • OptionalincludeRng?: boolean

        Whether to include the RNG seed in the serialized tables

    Returns string

    The resulting LootTable representation in a JSON string

  • Unserializes tables serialized with the "serialize" function

    Parameters

    • tables: SerializedTables

      Record of tables serialized using the "serialize" function

    Returns Record<string, LootTable>

    A key/value pairing of tables