-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,48 @@ | ||
# FIXME TITLE | ||
# Dice Helper | ||
|
||
FIXME badges | ||
[![Build](https://github.com/LeoColman/dice-helper/actions/workflows/build.yml/badge.svg)](https://github.com/LeoColman/dice-helper/actions/workflows/build.yml) | ||
[![GitHub](https://img.shields.io/github/license/LeoColman/dice-helper)](https://github.com/LeoColman/dice-helper/blob/master/LICENSE) | ||
[![Maven Central](https://img.shields.io/maven-central/v/group/dicee-helper.svg)](https://search.maven.org/search?q=g:group) | ||
|
||
![Build](https://github.com/LeoColman/) | ||
[![GitHub](https://img.shields.io/github/license/LeoColman/)](https://github.com/LeoColman/SimpleCpfValidator/blob/master/LICENSE) [![Maven Central](https://img.shields.io/maven-central/v/group/simple-cpf-validator.svg)](https://search.maven.org/search?q=g:group) | ||
A Kotlin library to help you parse DiceNotations and roll dice for your RPG games. | ||
|
||
# Using | ||
Adding this library to your project is pretty simple, just add it to your gradle `dependencies`: | ||
|
||
SHORT DESCRIPTION | ||
```kotlin | ||
repositories { | ||
mavenCentral() | ||
} | ||
dependencies { | ||
implementation("br.com.colman:dice-helper:version") | ||
} | ||
``` | ||
|
||
# Usage | ||
# Dice Notation | ||
This library tries to implement a Dice Notation as it's commonly used. More use cases will be added as they're needed. | ||
|
||
You can understand a little bit more of Dice Notation by reading [this Wikipedia article](https://en.wikipedia.org/wiki/Dice_notation). | ||
|
||
# Features | ||
|
||
Parse dice notation (currently only supports `+` and `-`) | ||
```kotlin | ||
val diceNotation: DiceNotation = "5d6 + 12 - 3d5".diceNotation() | ||
``` | ||
|
||
Roll all dice/fixed values in a dice notation | ||
```kotlin | ||
val result: NotationRollResult = diceNotation.roll() | ||
val total = result.total | ||
val individualResults: List<DiceRollResult> = result.results | ||
``` | ||
|
||
Roll a group of dice | ||
```kotlin | ||
// 15d10 | ||
val rollResult: List<Int> = RandomDice(amount = 15, maxFaceValue = 10).roll() | ||
val total = rollResult.sum() | ||
``` | ||
|
||
# Contributing | ||
Please, feel free to create an issue or to open a pull request! I'll be glad to have your help :) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright 2021 Leonardo Colman Lopes | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
grammar DiceNotation ; | ||
@header { | ||
package br.com.colman.dicehelper; | ||
} | ||
notation: dice (operator notation)? EOF; | ||
dice: (amount=DIGIT? D face=DIGIT) | (fixed=DIGIT) ; | ||
operator: '+' | '-' ; | ||
|
||
D: 'd' | 'D' ; | ||
DIGIT: [0-9]+ ; | ||
WS: (' ' | [\t\r\n]) -> skip ; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
token literal names: | ||
null | ||
'+' | ||
'-' | ||
null | ||
null | ||
null | ||
|
||
token symbolic names: | ||
null | ||
null | ||
null | ||
D | ||
DIGIT | ||
WS | ||
|
||
rule names: | ||
notation | ||
dice | ||
operator | ||
|
||
|
||
atn: | ||
[3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 3, 7, 27, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 3, 2, 3, 2, 3, 2, 3, 2, 5, 2, 13, 10, 2, 3, 2, 3, 2, 3, 3, 5, 3, 18, 10, 3, 3, 3, 3, 3, 3, 3, 5, 3, 23, 10, 3, 3, 4, 3, 4, 3, 4, 2, 2, 5, 2, 4, 6, 2, 3, 3, 2, 3, 4, 2, 26, 2, 8, 3, 2, 2, 2, 4, 22, 3, 2, 2, 2, 6, 24, 3, 2, 2, 2, 8, 12, 5, 4, 3, 2, 9, 10, 5, 6, 4, 2, 10, 11, 5, 2, 2, 2, 11, 13, 3, 2, 2, 2, 12, 9, 3, 2, 2, 2, 12, 13, 3, 2, 2, 2, 13, 14, 3, 2, 2, 2, 14, 15, 7, 2, 2, 3, 15, 3, 3, 2, 2, 2, 16, 18, 7, 6, 2, 2, 17, 16, 3, 2, 2, 2, 17, 18, 3, 2, 2, 2, 18, 19, 3, 2, 2, 2, 19, 20, 7, 5, 2, 2, 20, 23, 7, 6, 2, 2, 21, 23, 7, 6, 2, 2, 22, 17, 3, 2, 2, 2, 22, 21, 3, 2, 2, 2, 23, 5, 3, 2, 2, 2, 24, 25, 9, 2, 2, 2, 25, 7, 3, 2, 2, 2, 5, 12, 17, 22] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
T__0=1 | ||
T__1=2 | ||
D=3 | ||
DIGIT=4 | ||
WS=5 | ||
'+'=1 | ||
'-'=2 |