-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upload the first version of powerline_dice.
- Loading branch information
Showing
7 changed files
with
200 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# POWERLINE DICE | ||
|
||
A toy [Powerline](https://powerline.readthedocs.io/en/master/) segment. This segment shows a result of dice combination. | ||
|
||
By [Miguel de Dios Matias](https://github.com/mdtrooper). | ||
|
||
## Installation | ||
|
||
### Using pip | ||
|
||
``` | ||
pip install powerline-dice | ||
``` | ||
|
||
## Configuration | ||
|
||
You can activate the Powerline Slotmachine segment by adding it to your segment configuration, | ||
for example in `.config/powerline/themes/shell/default.json`: | ||
|
||
```json | ||
{ | ||
"function": "powerline_dice.roll", | ||
"priority": 90 | ||
} | ||
``` | ||
|
||
By default shows a roll of d6 (dice of six faces). | ||
|
||
![screenshot roll six faces](https://raw.githubusercontent.com/mdtrooper/powerline_dice/master/powerline_dice_six.jpg "screenshot roll six faces") | ||
|
||
### Arguments | ||
|
||
* **diceCombination (string)**: The combination of dices in [dice notation format](https://github.com/borntyping/python-dice#notation) or [wikipedia: Dice notation](https://en.wikipedia.org/wiki/Dice_notation). | ||
* Default: "d6" | ||
* **preContent (string)**: The string to show before the result. | ||
* Default: "" | ||
* **postContent (string)**: The string to show after the result. | ||
* Default: "🎲" | ||
* **facesDice list(string) or None**: The faces of dice as list of string (can be emojis). | ||
* Default: None | ||
* **critical int or list(int) or None**: The minimum or exact values to critical hit, the background change to critical success. | ||
* Default: None | ||
* **fumble int or list(int) or None**: The maximum or exact values to critical fumble, the background change to critical failture. | ||
* Default: None | ||
|
||
### Examples | ||
|
||
Rolls two dices of twenty faces and get critical hit with 40 and critical fumble with 1. | ||
|
||
```json | ||
{ | ||
"function": "powerline_dice.roll", | ||
"priority": 30, | ||
"args": { | ||
"diceCombination": "2d20", | ||
"critical": 30, | ||
"fumble": 15 | ||
} | ||
}, | ||
``` | ||
|
||
|
||
![screenshot roll d20 critical and fumble](https://raw.githubusercontent.com/mdtrooper/powerline_dice/master/powerline_dice_critical.jpg "screenshot roll d20 critical and fumble") | ||
|
||
Flip a coin with the tail 🙂 and head ️☹️. | ||
|
||
```json | ||
{ | ||
"function": "powerline_dice.roll", | ||
"priority": 30, | ||
"args": { | ||
"diceCombination": "d2", | ||
"facesDice": ["🙂", "☹️"], | ||
"postContent": "" | ||
} | ||
}, | ||
``` | ||
|
||
![screenshot flip a coin](https://raw.githubusercontent.com/mdtrooper/powerline_dice/master/powerline_flip_coin.jpg "screenshot flip a coin") | ||
|
||
|
||
## Thanks | ||
|
||
* [Python Dice](https://github.com/borntyping/python-dice): for great library to parse dice combination. | ||
|
||
## License | ||
|
||
Licensed under [the GPL3 License](https://github.com/mdtrooper/powerline_slotmachine/blob/master/LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# slotmachine_oneline.py | ||
# Copyright (C) 2019 Miguel de Dios Matias | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from .dice import roll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# slotmachine_oneline.py | ||
# Copyright (C) 2019 Miguel de Dios Matias | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import dice | ||
|
||
line = '{preContent}{face}{postContent}' | ||
|
||
def roll(pl, diceCombination='d6', preContent='', postContent='🎲', facesDice=None, critical=None, fumble=None, *args, **kwarg): | ||
result = int(dice.roll(diceCombination)) | ||
""" | ||
Return a segment with the result of roll a dice combination. | ||
Args: | ||
pl (object): The powerline logger. | ||
diceCombination (string): The combination of dices in dice notation format see | ||
https://github.com/borntyping/python-dice | ||
preContent (string): The string to show before the result. | ||
postContent (string): The string to show after the result. | ||
facesDice list(string) or None: The faces of dice as list of string (can be emojis). | ||
critical int or list(int) or None: The minimum or exact values to critical hit, the background | ||
change to critical success. | ||
fumble int or list(int) or None: The maximum or exact values to critical fumble, the background | ||
change to critical failture. | ||
Returns: | ||
segment (list(dict)): The result of roll as powerline segment. | ||
""" | ||
|
||
try: | ||
face = facesDice[result - 1] # The list start with 0 | ||
except (IndexError, TypeError): | ||
face = result | ||
|
||
color = ['information:regular'] | ||
if isinstance(critical, int): | ||
if result >= critical: | ||
color = ['critical:success'] | ||
elif isinstance(critical, list): | ||
if result in critical: | ||
color = ['critical:success'] | ||
if isinstance(fumble, int): | ||
if result <= fumble: | ||
color = ['critical:failure'] | ||
elif isinstance(fumble, list): | ||
if result in fumble: | ||
color = ['critical:failure'] | ||
|
||
return [{ | ||
'contents': line.format(preContent=preContent, face=face, postContent=postContent), | ||
'highlight_groups': color, | ||
'divider_highlight_group': None}] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import setuptools | ||
|
||
with open("README.md", "r") as fh: | ||
long_description = fh.read() | ||
|
||
setuptools.setup( | ||
name="powerline_dice", | ||
version="1.0.0", | ||
license="GPLv3+", | ||
author="Miguel de Dios Matias", | ||
author_email="tres.14159@gmail.com", | ||
description="A toy Powerline segment. This segment shows a result of dice combination.", | ||
long_description=long_description, | ||
long_description_content_type="text/markdown", | ||
url="https://github.com/mdtrooper/powerline_dice", | ||
packages=setuptools.find_packages(), | ||
classifiers=[ | ||
"Programming Language :: Python :: 3", | ||
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", | ||
"Operating System :: OS Independent", | ||
"Environment :: Console", | ||
"Topic :: Games/Entertainment" | ||
], | ||
python_requires='>=3.7', | ||
install_requires=[ | ||
'dice>=2.4.2' | ||
], | ||
platforms=['any'] | ||
) |