Closed mikelax closed 6 years ago
@nazar as a general question, do you think that we should implement this as a graphql mutation or create a REST endpoint to create a roll? This question might apply to some other functions that aren't totally graphql related and might lend themselves more to a REST Post.
do you think that we should implement this as a graphql mutation or create a REST endpoint to create a roll?
I think graphQL all the way unless there are technical limitations the prohibit us using it - i.e. lack of file graphQL types and the need for a multer for image uploads.
Do keep in mind that we can use the dice rolling library in both the client (to validate and preview roll dice results for example) and in the API to run the actual dice roll when the message is submitted.
I was thinking we'd do this in a modal that is triggered from the editor action toolbar where the user can either type out the dice rolls and get a preview (i.e. 2d6 +2 - sample result: 9) or build a simple interface with drops downs (i.e. no of dice dropdown, dice sides dropdown, bonus numeric input).
Once the user hits Save on the modal, we construct a meta object and save it to game_messages.meta
with a JSON structure with something like:
meta = {
rolls: [
{
input: "3d20 + 5",
label: "attack roll"
result: calculated on the api and saved here
}, {
input: "1d20 - 5",
label: "damage vs orc",
result: calculated on the api and saved here
}
]
}
@nazar that all sounds pretty good. for a reference I think the modal idea is good, we would just need to be "at least" as good as this UI. We would need to support a "label", or description for the roll, especially if they will be displayed as meta attachments. I don't think that we should bother trying to create all the dropdowns, there will just be too many combinations to make that worth it.
This site allows you to preview a post, in our case this would just be displayed in the editor as the user is creating/editing the message. Basically we could display the "syntax" entered for the roll, but only display the result after the message is created.
@nazar after thinking about this a bit more, I think your idea of the meta attachments for the rolls is a good idea. In looking at this more it seems that if we go the route of using the meta column, the work is more related to the editor than not. It makes sense to get the image uploads sorted and finalized before starting this task.
Also, we should try to isolate the "dice roll" logic the best we can, so if we do decide to switch libs, etc. code updates are minimal.
Overview
One of the required features in order to allow users to play games is a dice roller. This will allow the user to create one or more rolls using commonly accepted dice syntax.
Examples
Here is the BGG dice roller guide. You can see it supports a lot of different formats. Some of the commons one are:
Existing Packages
rpg
anddice
rolls are only a really small part of the overall package. Probably not focused enough on just dice rolls.Out of the above libs, I think the roll package is closest to what we are looking for.
Requirements
Future Considerations
Once we have some basic character attributes we can use those values to automatically calculate certain rolls. These rolls will have to be based on the game label. For example for d&d5e, to roll
Initiative
is 1d20 plus the characterDexterity
modifier. So the user could say:/roll Initiative
We will only be able to easily calculate certain rolls. We could also allow the user to create their own roll templates, or bookmarks. For example:
/roll 2d20l+3 save advantage-attack
they could then later use:/roll advantage-attack