Options
All
  • Public
  • Public/Protected
  • All
Menu

A type of RollTerm used to enclose a parenthetical expression to be recursively evaluated.

Hierarchy

Index

Constructors

Properties

term: string

The original provided string term used to construct the parenthetical

roll: Roll

Alternatively, an already-evaluated Roll instance may be passed directly

_evaluated: boolean

An internal flag for whether the term has been evaluated

isIntermediate: boolean = true

Is this term intermediate, and should be evaluated first as part of the simplification process?

options: any

An object of additional options which describes and modifies the term.

OPEN_REGEXP: RegExp = ...

The regular expression pattern used to identify the opening of a parenthetical expression. This could also identify the opening of a math function.

CLOSE_REGEXP: RegExp = ...

A regular expression pattern used to identify the closing of a parenthetical expression.

SERIALIZE_ATTRIBUTES: string[] = ...

An array of additional attributes which should be retained when the term is serialized

FLAVOR_REGEXP_STRING: string = "(?:\\[([^\\]]+)\\])"

A regular expression pattern which identifies optional term-level flavor text

FLAVOR_REGEXP: RegExp = ...

A regular expression which identifies term-level flavor text

REGEXP: RegExp = undefined

A regular expression used to match a term of this type

Accessors

  • An array of evaluated DiceTerm instances that should be bubbled up to the parent Roll

    Returns DiceTerm[]

  • get total(): number
  • inheritdoc

    Returns number

  • get expression(): string
  • inheritdoc

    Returns string

  • get isDeterministic(): boolean
  • inheritdoc

    Returns boolean

  • get formula(): string
  • A string representation of the formula, including optional flavor text.

    Returns string

  • get flavor(): string
  • Optional flavor text which modifies and describes this term.

    Returns string

Methods

  • _evaluateSync(__namedParameters?: { minimize: boolean; maximize: boolean }): ParentheticalTerm
  • This method is temporarily factored out in order to provide different behaviors synchronous evaluation. This will be removed in 0.10.x

    Parameters

    • __namedParameters: { minimize: boolean; maximize: boolean } = {}
      • minimize: boolean
      • maximize: boolean

    Returns ParentheticalTerm

  • _evaluate(__namedParameters?: { minimize: boolean; maximize: boolean }): Promise<ParentheticalTerm>
  • Evaluate the term.

    Parameters

    • __namedParameters: { minimize: boolean; maximize: boolean } = {}

      Options which modify how the RollTerm is evaluated, see RollTerm#evaluate

      • minimize: boolean
      • maximize: boolean

    Returns Promise<ParentheticalTerm>

  • evaluate([options={}]?: { minimize: boolean; maximize: boolean; async: boolean }): RollTerm
  • Evaluate the term, processing its inputs and finalizing its total.

    Parameters

    • [options={}]: { minimize: boolean; maximize: boolean; async: boolean } = {}

      Options which modify how the RollTerm is evaluated

      • minimize: boolean
      • maximize: boolean
      • async: boolean

    Returns RollTerm

    The evaluated RollTerm

  • toJSON(): any
  • Serialize the RollTerm to a JSON string which allows it to be saved in the database or embedded in text. This method should return an object suitable for passing to the JSON.stringify function.

    Returns any

  • Construct a ParentheticalTerm from an Array of component terms which should be wrapped inside the parentheses.

    example

    Create a Parenthetical Term from an array of component RollTerm instances

    const d6 = new Die({number: 4, faces: 6});
    const plus = new OperatorTerm({operator: "+"});
    const bonus = new NumericTerm({number: 4});
    t = ParentheticalTerm.fromTerms([d6, plus, bonus]);
    t.formula; // (4d6 + 4)

    Parameters

    • terms: RollTerm[]

      The array of terms to use as internal parts of the parenthetical

    • options: any

    Returns ParentheticalTerm

    The constructed ParentheticalTerm instance

  • Construct a RollTerm from a provided data object

    Parameters

    • data: any

      Provided data from an un-serialized term

    Returns RollTerm

    The constructed RollTerm

  • Reconstruct a RollTerm instance from a provided JSON string

    Parameters

    • json: string

      A serialized JSON representation of a DiceTerm

    Returns RollTerm

    A reconstructed RollTerm from the provided JSON

  • Define term-specific logic for how a de-serialized data object is restored as a functional RollTerm

    Parameters

    • data: any

      The de-serialized term data

    Returns RollTerm

    The re-constructed RollTerm object