Skip to content

Commit

Permalink
Initial Implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoColman committed Jun 5, 2021
1 parent 1a09388 commit f3263c3
Show file tree
Hide file tree
Showing 27 changed files with 1,018 additions and 52 deletions.
11 changes: 0 additions & 11 deletions .idea/aws.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/copyright/Colman_Apache2.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions .idea/modules/colman-oss-template.iml

This file was deleted.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 42 additions & 6 deletions README.md
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 :)
51 changes: 32 additions & 19 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 Leonardo Colman Lopes
* 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.
Expand All @@ -9,7 +9,7 @@
*
* 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 press or implied.
* 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.
*/
Expand All @@ -22,24 +22,41 @@ plugins {
`maven-publish`
signing
id("org.jetbrains.dokka") version "1.4.32"
id("io.gitlab.arturbosch.detekt").version("1.15.0-RC1")
id("io.gitlab.arturbosch.detekt").version("1.17.1")
antlr
}

// FIXME Replace with group
group = "br.com.colman."
group = "br.com.colman"
version = getenv("RELEASE_VERSION") ?: "local"

repositories {
mavenCentral()
jcenter()
}

kotlin {
explicitApi()
}

sourceSets {
main {
java.srcDir("src/main/gen")
}
}

dependencies {
// Antlr
antlr("org.antlr:antlr4:4.9.2")

// Math evaluation
implementation("net.objecthunter:exp4j:0.4.8")

// Kotest
testImplementation("io.kotest:kotest-runner-junit5:4.6.0")

// Mockk
testImplementation("io.mockk:mockk:1.11.0")
testImplementation("io.kotest:kotest-property:4.6.0")
}

tasks.generateGrammarSource {
outputDirectory = file("src/main/gen")
}

tasks.withType<KotlinCompile> {
Expand All @@ -50,10 +67,6 @@ tasks.withType<Test> {
useJUnitPlatform()
}

kotlin {
explicitApi()
}

val sourcesJar by tasks.registering(Jar::class) {
archiveClassifier.set("sources")
from(sourceSets.getByName("main").allSource)
Expand Down Expand Up @@ -85,15 +98,15 @@ publishing {
artifact(javadocJar.get())

pom {
name.set("NAME") // FIXME change name
description.set("DESCRIPTION") //FIXME change description
url.set("https://www.github.com/LeoColman/repo") // FIXME change URL
name.set("dice-helper")
description.set("Dice Helper")
url.set("https://www.github.com/LeoColman/dice-helper")


scm {
connection.set("scm:git:http://www.github.com/LeoColman/repo") // FIXME change URL
developerConnection.set("scm:git:http://github.com/LeoColman/repo") // FIXME change URL
url.set("https://www.github.com/LeoColman/repo") // FIXME change URL
connection.set("scm:git:http://www.github.com/LeoColman/dice-helper")
developerConnection.set("scm:git:http://github.com/LeoColman/dice-helper")
url.set("https://www.github.com/LeoColman/dice-helper")
}

licenses {
Expand Down
6 changes: 3 additions & 3 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 Leonardo Colman Lopes
* 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.
Expand All @@ -9,9 +9,9 @@
*
* 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 press or implied.
* 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.
*/

rootProject.name = "colman-oss-template" // FIXME change root project name
rootProject.name = "dice-helper"
26 changes: 26 additions & 0 deletions src/main/antlr/br/com/colman/dicehelper/DiceNotation.g4
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 ;
24 changes: 24 additions & 0 deletions src/main/gen/br/com/colman/dicehelper/DiceNotation.interp
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]
7 changes: 7 additions & 0 deletions src/main/gen/br/com/colman/dicehelper/DiceNotation.tokens
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

0 comments on commit f3263c3

Please sign in to comment.