Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include die type (ie: d20) in the RollResult json output #242

Open
bdc4 opened this issue Feb 16, 2022 · 7 comments
Open

Include die type (ie: d20) in the RollResult json output #242

bdc4 opened this issue Feb 16, 2022 · 7 comments

Comments

@bdc4
Copy link

bdc4 commented Feb 16, 2022

I'm trying to build a UI for the dice output that shows the matching die image (ie: d4, d20, ect) that corresponds to the die roll. However, the RollResult class structure / output doesn't contain that information, just the results after the roll calculation.

I would love an additional property added to the RollResult class that shows the die type used to generate that roll result. ie:
"rolls": [{
"sides": d20, // or even just 20 <-----
"calculationValue": 4,
"initialValue": 4,
"modifierFlags": "",
"modifiers": [],
"type": "result",
"useInTotal": true,
"value": 4
// ... ect
}]

I've tried trying to customize the RollResult class to capture this, but I am having a hard time... Honestly, TypeScript is well out of my wheelhouse... If anyone has a suggestion so I can implement this on my own, I am all ears!

Thanks in advance. Please let me know if you need more info from me :)

@erik-jenkins
Copy link

Yeah, this is actually what I was trying to get at by asking this question (#241). This would be super useful!

@erik-jenkins
Copy link

I put together PR #244 as an attempt to get this implemented. Thanks @GreenImp for making this such an easy and pleasant project to work on!

@bdc4
Copy link
Author

bdc4 commented Feb 23, 2022

Thanks @erik-jenkins! I'll check out your pull request and see if I can leverage that as well if that's alright with you :) I agree, I would love to see both of what we're asking for implemented in the source itself. Good luck with whatever you're working on!

@GreenImp
Copy link
Collaborator

Just thinking about this, and I'm not sure how feasible it would be, but would it make sense to store the actual Dice object against the Result object, rather than just a string side?

@erik-jenkins
Copy link

I just put up PR #252 to try that out, it seems to work pretty well! The one thing I haven't tried yet is to see how serialization of the RollResult is affected.

@jbhaywood
Copy link

I just started using this library and it's great, but one of the first things I tried to do was get the number of sides for a given die being rolled. I was surprised to find that to be not an easy thing to do. Coming here, I see this open issue, which seems to be exactly what I was looking for, but then see that it's been in limbo for almost a year. Are there any plans to get the pull request pushed through?

Alternatively, what's the recommended way of getting the type of die/dice being rolled from a DiceRoll result?

@Artish357
Copy link

Bumping this - I wanted to use it with a deterministic 3d dice roller, which requires knowing both the results and the die types

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants