Open GreenImp opened 4 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>
}
output()
method. When called, it calls a method on the Output
class which in turn calls the output()
method on the current output engine - passing in the object to output.before()
and after()
method, or maybe wrap()
which returns an array of two parts - start and end?toString()
method on the object.
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.