mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Move dice extension to external repository
This commit is contained in:
@@ -1,88 +0,0 @@
|
|||||||
import { callPopup } from "../../../script.js";
|
|
||||||
import { getContext } from "../../extensions.js";
|
|
||||||
import { registerSlashCommand } from "../../slash-commands.js";
|
|
||||||
export { MODULE_NAME };
|
|
||||||
|
|
||||||
const MODULE_NAME = 'dice';
|
|
||||||
const UPDATE_INTERVAL = 1000;
|
|
||||||
|
|
||||||
async function doDiceRoll(customDiceFormula) {
|
|
||||||
let value = typeof customDiceFormula === 'string' ? customDiceFormula.trim() : $(this).data('value');
|
|
||||||
|
|
||||||
if (value == 'custom') {
|
|
||||||
value = await callPopup('Enter the dice formula:<br><i>(for example, <tt>2d6</tt>)</i>', 'input');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!value) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const isValid = droll.validate(value);
|
|
||||||
|
|
||||||
if (isValid) {
|
|
||||||
const result = droll.roll(value);
|
|
||||||
const context = getContext();
|
|
||||||
context.sendSystemMessage('generic', `${context.name1} rolls a ${value}. The result is: ${result.total} (${result.rolls})`, { isSmallSys: true });
|
|
||||||
} else {
|
|
||||||
toastr.warning('Invalid dice formula');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function addDiceRollButton() {
|
|
||||||
const buttonHtml = `
|
|
||||||
<div id="roll_dice" class="list-group-item flex-container flexGap5">
|
|
||||||
<div class="fa-solid fa-dice extensionsMenuExtensionButton" title="Roll Dice" /></div>
|
|
||||||
Roll Dice
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
const dropdownHtml = `
|
|
||||||
<div id="dice_dropdown">
|
|
||||||
<ul class="list-group">
|
|
||||||
<li class="list-group-item" data-value="d4">d4</li>
|
|
||||||
<li class="list-group-item" data-value="d6">d6</li>
|
|
||||||
<li class="list-group-item" data-value="d8">d8</li>
|
|
||||||
<li class="list-group-item" data-value="d10">d10</li>
|
|
||||||
<li class="list-group-item" data-value="d12">d12</li>
|
|
||||||
<li class="list-group-item" data-value="d20">d20</li>
|
|
||||||
<li class="list-group-item" data-value="d100">d100</li>
|
|
||||||
<li class="list-group-item" data-value="custom">...</li>
|
|
||||||
</ul>
|
|
||||||
</div>`;
|
|
||||||
|
|
||||||
$('#extensionsMenu').prepend(buttonHtml);
|
|
||||||
|
|
||||||
$(document.body).append(dropdownHtml)
|
|
||||||
$('#dice_dropdown li').on('click', doDiceRoll);
|
|
||||||
const button = $('#roll_dice');
|
|
||||||
const dropdown = $('#dice_dropdown');
|
|
||||||
dropdown.hide();
|
|
||||||
button.hide();
|
|
||||||
|
|
||||||
let popper = Popper.createPopper(button.get(0), dropdown.get(0), {
|
|
||||||
placement: 'top',
|
|
||||||
});
|
|
||||||
|
|
||||||
$(document).on('click touchend', function (e) {
|
|
||||||
const target = $(e.target);
|
|
||||||
if (target.is(dropdown)) return;
|
|
||||||
if (target.is(button) && !dropdown.is(":visible")) {
|
|
||||||
e.preventDefault();
|
|
||||||
|
|
||||||
dropdown.fadeIn(250);
|
|
||||||
popper.update();
|
|
||||||
} else {
|
|
||||||
dropdown.fadeOut(250);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function moduleWorker() {
|
|
||||||
$('#roll_dice').toggle(getContext().onlineStatus !== 'no_connection');
|
|
||||||
}
|
|
||||||
|
|
||||||
jQuery(function () {
|
|
||||||
addDiceRollButton();
|
|
||||||
moduleWorker();
|
|
||||||
setInterval(moduleWorker, UPDATE_INTERVAL);
|
|
||||||
registerSlashCommand('roll', (_, value) => doDiceRoll(value), ['r'], "<span class='monospace'>(dice formula)</span> – roll the dice. For example, /roll 2d6", false, true);
|
|
||||||
});
|
|
@@ -1,11 +0,0 @@
|
|||||||
{
|
|
||||||
"display_name": "D&D Dice",
|
|
||||||
"loading_order": 5,
|
|
||||||
"requires": [],
|
|
||||||
"optional": [],
|
|
||||||
"js": "index.js",
|
|
||||||
"css": "style.css",
|
|
||||||
"author": "Cohee#1207",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"homePage": "https://github.com/SillyTavern/SillyTavern"
|
|
||||||
}
|
|
@@ -1,26 +0,0 @@
|
|||||||
#roll_dice {
|
|
||||||
/* order: 100; */
|
|
||||||
/* width: 40px;
|
|
||||||
height: 40px;
|
|
||||||
margin: 0;
|
|
||||||
padding: 1px; */
|
|
||||||
outline: none;
|
|
||||||
border: none;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: 0.3s;
|
|
||||||
opacity: 0.7;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
/* justify-content: center; */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#roll_dice:hover {
|
|
||||||
opacity: 1;
|
|
||||||
filter: brightness(1.2);
|
|
||||||
}
|
|
||||||
|
|
||||||
#dice_dropdown {
|
|
||||||
z-index: 30000;
|
|
||||||
backdrop-filter: blur(--SmartThemeBlurStrength);
|
|
||||||
}
|
|
Reference in New Issue
Block a user