dice-roller / rpg-dice-roller

An advanced JS based dice roller that can roll various types of dice and modifiers, along with mathematical equations.
https://dice-roller.github.io/documentation
MIT License
243 stars 58 forks source link

Split output to separate module / library #132

Open GreenImp opened 4 years ago

GreenImp commented 4 years ago

Is your feature request related to a problem? Please describe. The roll output, that returns the string version of the roll log, is currently built in to the individual classes and is not easily changeable. It could be helpful if the output was built as a separate module, so that it can be easily swapped out for a different output type. This would enable easier modification of the output and allow things like HTML output.

Describe the solution you'd like Move the output functionality into it's own set of classes that can handle the various objects that need to be output.

It may be beneficial for this to be it's own library, rather than built in to the dice roller itself. The alternative is to simply build it inside the library as it's own set of modules.

GreenImp commented 2 years ago

Just a note on my thoughts at the moment:

We can probably achieve this in a similar way to the RNG, where we have a separate class that you can call methods on: https://dice-roller.github.io/documentation/guide/customisation.html#random-number-generator

So we'd have a class (e.g. Output that you can pass an engine or similar names object to, that handles the output itself.

The engine will have to have a public method (e.g. output()) that takes the object to output (and probably a context object, which could contain things like the parent, for contextual output / styling):

type ObjectTypes = RollResult | ResultGroup ...;

interface engine {
    output<ReturnType>: (arg: ObjectTypes, context: { parent?: ObjectTypes | undefined }) => <ReturnType>
}