Rolisteam / DiceParser

Powerful dice Roller is used as discord bot, irc bot, cli tool and inside Rolisteam : 1d20+4, 1L[head,arm,leg,belly,chest], 1d6+1d8, 8+5*3
http://www.rolisteam.org/
GNU General Public License v3.0
125 stars 31 forks source link

[design question] how are stored aliases #10

Closed robinmoussu closed 6 years ago

robinmoussu commented 6 years ago

Hello,

[ I'm not sure where I should post this ]

I try to search both in the code and the documentation, and I didn't found how alias are exactly stored. I think currently they are hard-coded (at least the are two aliases for l5r in cli/main.cpp (l.206), but since it's possible to directly add new one inside from rolisteam, I guess that their are other input ways.

Do you plan to implement a way to give an external text file that as an input of diceparser as one point? That way it would be really easy to import/export/modify/share aliases for rolisteam. I don't use the other channels (like slack and twitter) so I don't know if a text file it's a good universal solution for all the uses cases of diceparser. If you think it could be a good idea I can implement it, I just would like to know what format you prefer. I think it would make the code cleaner by removing all hard-coded aliases.

Since you handle two syntax (regular expression and standard replace, maybe an ini style is the best:

[ replace ]
# A comment.
l5r => D10k      # another comment
L5R => D10K
[ regex ]
(.*)wod(.*) =>\1d10e[=10]c[>=\2]-@c[=1]
[ replace ]
# you can use multiple time the same section
DF => D[-1-1]

Remarks:

obiwankennedy commented 6 years ago

The code of diceparser is designed to be easy to import into a project. It is a black box. It takes a command (string) as input and it gives data structures as output. I implemented some clients of diceparser. Rolisteam is a diceparser client, and cli/main.cpp is another one.

Each client is in charge of its own aliases.

In the cli/main.cpp, I started (but not finished yet) to implement a way to load alias from json file.

In rolisteam, aliases are stored into the preferences manager and they are saved into init file (on linux as any preferences) (in the register database on windows).

To create import/export methods about aliases, I strongly recommend the use of JSON. Qt contains a really easy way to perform input/output operations. Moreover, it could be interesting to offer a way to save all the other game related data (such as Character states).

Moreover the JSON format it is really tolerant to changes.

Exported theme from rolisteam are saved into rSkin file which are JSON file. You can take a look about that as an example to implement the same thing about dice aliases.

robinmoussu commented 6 years ago

Thanks for the precisions.