Skip to content

Commit

Permalink
Add option to enable/disable saving data on chat and main window
Browse files Browse the repository at this point in the history
  • Loading branch information
Yosoy-Ed committed Apr 26, 2024
1 parent 6dc45a7 commit aab8205
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 31 deletions.
2 changes: 1 addition & 1 deletion css/sds.css
Expand Up @@ -201,4 +201,4 @@ table td {
font-family: 'Roboto';
text-align: center;
justify-content: center;
}
}
18 changes: 11 additions & 7 deletions module.json
Expand Up @@ -2,20 +2,24 @@
"id": "simple-dice-stats",
"title": "Simple d20 stats",
"description": "A foundryvtt module that shows d20 statitiscs in a bar chart allowing to choose a date range",
"authors": [{"name": "Yosoy-Ed"}],
"version": "0.1.1",
"authors": [
{
"name": "Yosoy-Ed",
"flags": {}
}
],
"version": "0.1.2",
"styles": [
"css/sds.css"
],
"esmodules": [
"scripts/sds.js"
],
"packs": [],
"url": "https://github.com/Yosoy-Ed/simple-d20-stats",
"manifest": "https://github.com/Yosoy-Ed/simple-d20-stats/releases/download/v0.1.1/module.json",
"download": "https://github.com/Yosoy-Ed/simple-d20-stats/releases/download/v0.1.1/module.zip",
"manifest": "https://github.com/Yosoy-Ed/simple-d20-stats/releases/latest/download/module.json",
"download": "https://github.com/Yosoy-Ed/simple-d20-stats/releases/latest/download/module.zip",
"compatibility": {
"minimum": "11",
"verified": "11"
"verified": "11.315"
}
}
}
101 changes: 81 additions & 20 deletions scripts/sds.js
Expand Up @@ -35,7 +35,14 @@ class ChartWindow extends Application {
dicelabels = dicelabels + '<div class="dicenlabel"><div class="bar-label" >' + (i + 1) + '</div></div>';
}

let paus = game.settings.get('simple-dice-stats', 'pausedataacq');

let savingRollData = paus ? 'Disabled' : 'Enabled';

let divSRDContent = `<div><i><b>Saving roll data is <br>${savingRollData}</b></i></div><div id="pause-state-btn" style="margin-left:1em;"></div>`;

return {
divSRDContent: divSRDContent,
usermostd20: usermostd20,
usermostd1: usermostd1,
nat1s: p['nat1s'],
Expand All @@ -57,7 +64,7 @@ class ChartWindow extends Application {
activateListeners(html) {
super.activateListeners(html);

let theuser = game.user.name;
let theuser = game.user.name;

$("#selectuser option[value='" + theuser + "']").prop("selected", true);
$("#fromdateselect option:first").prop("selected", true);
Expand Down Expand Up @@ -90,7 +97,32 @@ class ChartWindow extends Application {
$('#todateselect').change(ev => {
updatechartonchange();
});

if (game.user.isGM) {
let btn = document.createElement('button');
btn.innerText = "Toggle";

btn.addEventListener('click', () => {

let paus = game.settings.get('simple-dice-stats', 'pausedataacq');
game.settings.set('simple-dice-stats', 'pausedataacq', !paus);
let savingRollData = !paus ? 'Disabled' : 'Enabled';

let divSRDContent = `<div><i><b>Saving roll data is <br>${savingRollData}</b></i></div><div id="pause-state-btn" style="margin-left:1em;"></div>`;

$('#pause-state').html(divSRDContent);
document.getElementById('pause-state-btn').appendChild(btn);

ChatMessage.create({
content: `<div class="sdsdisabled"><b> Saving Roll data ${savingRollData} </b></div>`
});

});
document.getElementById('pause-state-btn').appendChild(btn);
}
}


}

// A class to create list of rolls with methods to update them
Expand Down Expand Up @@ -236,13 +268,42 @@ Hooks.on("ready", function () {

if (game.user.isGM) {

let gmids = game.users.contents.filter(user => user.isGM).map(gm => gm.id);
ChatMessage.create({
content: '<div class="sdsdisabled"><img style="width: 40px; height:40px; border:none;" src="../../../icons/svg/d20-grey.svg"><b><u>Simple d20 statistics:</u> <br> Saving roll data is disabled</b><br></div>',
});

content: '<div class="sdsdisabled"><img style="width: 40px; height:40px; border:none;" src="../../../icons/svg/d20-grey.svg"><b><u>Simple d20 statistics:</u> <br> Saving roll data is disabled</b><br></div><br><div> Enable?<br><button type="button" class="chat-enable-sds">Yes</button><button class="chat-disable-sds">No</button></div><br>', whisper: gmids,
})
}
}

$(document).on('click', '.chat-enable-sds', async function () {
let grandGrandParentDataId = this.parentNode.parentNode.parentNode.getAttribute('data-message-id');
game.messages.get(grandGrandParentDataId).delete();
game.settings.set('simple-dice-stats', 'pausedataacq', false);
ChatMessage.create({
content: '<div class="sdsdisabled"><b> Saving Roll data enabled </b></div>'
});
});

$(document).on('click', '.chat-disable-sds', async function () {
let grandGrandParentDataId = this.parentNode.parentNode.parentNode.getAttribute('data-message-id');
game.messages.get(grandGrandParentDataId).delete();
game.settings.set('simple-dice-stats', 'pausedataacq', true);
ChatMessage.create({
content: '<div class="sdsdisabled"> <b>Saving Roll data disabled</b> </div>'
});
});

if (game.user.isGM) {

const mesgs = document.querySelectorAll('.sdsdisabled');
mesgs.forEach((childElement) => {
const sdsMsg = childElement.parentNode.parentNode.getAttribute('data-message-id');
game.messages.get(sdsMsg).delete();

});
}


});

// Boton en el panel izquierdo
Expand All @@ -262,14 +323,14 @@ Hooks.on('getSceneControlButtons', function (controls) {
// If dice so nice is not active
Hooks.on("createChatMessage", (chatMessage) => {

if (game.modules.get("dice-so-nice")?.active){ //If dice so nice is active but the roll is blind and ghost dice is not enabled
if(!game.settings.get("dice-so-nice", "showGhostDice") && chatMessage.blind && !game.settings.get('simple-dice-stats', 'pausedataacq') && chatMessage.isRoll){
if (game.modules.get("dice-so-nice")?.active) { //If dice so nice is active but the roll is blind and ghost dice is not enabled
if (!game.settings.get("dice-so-nice", "showGhostDice") && chatMessage.blind && !game.settings.get('simple-dice-stats', 'pausedataacq') && chatMessage.isRoll) {

detectroll(chatMessage);
detectroll(chatMessage);
}
}

if (!game.modules.get("dice-so-nice")?.active && !game.settings.get('simple-dice-stats', 'pausedataacq') && chatMessage.isRoll ) {
if (!game.modules.get("dice-so-nice")?.active && !game.settings.get('simple-dice-stats', 'pausedataacq') && chatMessage.isRoll) {

detectroll(chatMessage);
}
Expand All @@ -281,9 +342,9 @@ Hooks.on('diceSoNiceRollComplete', (data) => {

let chatMessage = game.messages.get(data);

if (game.settings.get('simple-dice-stats', 'pausedataacq') || (chatMessage.blind && !game.settings.get("dice-so-nice", "showGhostDice"))) {// if the roll is blind it was registered like dice so nice is not installed and evaluated before
if (game.settings.get('simple-dice-stats', 'pausedataacq') || (chatMessage.blind && !game.settings.get("dice-so-nice", "showGhostDice"))) {// if the roll is blind it was registered like dice so nice is not installed and evaluated before
return;
}
}

detectroll(chatMessage);
});
Expand Down Expand Up @@ -314,8 +375,8 @@ function detectroll(chatMessage) {
if (atstring.includes('Attack Roll')) {
isattack = true;
}
}
}

let rolltype = 0; // 0-Public, 1-Blind , 2-PrivateGM, 3-Self

// If the roll is not public it is whisper
Expand All @@ -329,12 +390,12 @@ function detectroll(chatMessage) {
rolltype = 1; // Blind Roll
} else {
//The roll was whispered to the GM
if(whisperdto.length === gmids.length){
if (whisperdto.length === gmids.length) {

const a1fus = whisperdto.sort().join('');
const a2fus = gmids.sort().join('');
if (a1fus === a2fus){

if (a1fus === a2fus) {
rolltype = 2; //Private GM
}
}
Expand All @@ -344,7 +405,7 @@ function detectroll(chatMessage) {
}
}
}

if (rolltype !== 0 && !game.settings.get('simple-dice-stats', 'allowhiddenrolls')) {
return;
}
Expand Down Expand Up @@ -477,7 +538,7 @@ function wus() {

for (let x of gmids) {
let gmname = game.users.get(x).name;
let valuetodelete = '<option value='+gmname+'>'+gmname+'</option>';
let valuetodelete = '<option value=' + gmname + '>' + gmname + '</option>';
whichuser = whichuser.replace(valuetodelete, '');

}
Expand All @@ -489,7 +550,7 @@ function wus() {
// A function to create a d20 svg with the color of the user
function d20icon(theusercolor) {

let usicon = '<svg class="mysvgdice" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 280 320" width="52" height="52" style="transform: rotate(180deg);"><g transform="translate(-246.69456,-375.66745)"> <path fill=' + theusercolor + ' d="M379.93,375.668c-0.57,0.019-1.226,0.228-1.585,0.731l-80.673,96.527 c-1.342,1.681-1.433,2.056,0.366,2.073l161.59-0.427c2.221-0.182,2.23-0.07,0.792-1.951l-79.27-96.527 C380.986,375.84,380.501,375.654,379.93,375.668L379.93,375.668z M395.419,384.266l72.746,88.478 c0.974,1.182,1.212,1.249,2.927,0.427l38.354-17.562c2.513-1.134,2.165-1.366,0.487-2.5L395.419,384.266z M361.454,387.498 c-0.034-0.072-0.625,0.37-1.952,1.281L253.89,458.292l33.05,15.001c1.724,0.568,2.239,0.599,3.354-0.793l69.698-83.234 C360.973,388.129,361.487,387.57,361.454,387.498L361.454,387.498z M515.056,459.756c-0.328,0.023-0.846,0.212-1.646,0.548 l-39.392,17.989c-1.398,0.635-1.311,1.49-0.792,2.561l45.793,116.162l-3.292-135.309 C515.626,460.228,515.604,459.717,515.056,459.756L515.056,459.756z M250.902,463.354l-4.208,131.651l38.782-113.907 c0.573-1.682,0.559-1.767-0.61-2.317L250.902,463.354L250.902,463.354z M461.761,480.427l-165.249,0.427 c-2.361-0.035-2.264-0.033-1.098,1.89l83.905,141.529c1.417,2.159,1.265,2.092,2.744-0.121l80.612-141.772 C463.383,481.253,463.887,480.466,461.761,480.427L461.761,480.427z M468.347,484.147c-0.152,0.064-0.318,0.639-0.793,1.524 l-81.16,142.809c-0.887,1.508-1.097,2.048,1.036,1.708l128.845-17.744c2.044-0.467,1.982-1.197,1.281-3.232l-48.6-123.479 C468.635,484.55,468.5,484.083,468.347,484.147L468.347,484.147z M290.171,485.489c-0.158,0.113-0.3,0.715-0.609,1.585 l-41.16,121.162c-0.701,2.573-0.78,3.541,1.829,4.024l123.113,17.805c2.328,0.351,2.03-0.822,1.463-1.951l-83.783-141.345 C290.498,485.702,290.329,485.375,290.171,485.489L290.171,485.489z M258.158,619.334l120.796,68.538 c1.564,0.949,1.929,0.604,1.707-1.036l-2.561-48.05c-0.07-1.551-0.28-2.183-1.89-2.439L258.158,619.334L258.158,619.334z M507.922,619.455l-122.625,16.952c-1.618,0.238-1.326,1.032-1.342,2.195l2.622,48.903c0.135,1.483,0.091,2.017,1.89,1.098 L507.922,619.455z"/></g></svg>'
let usicon = '<svg class="mysvgdice" id="mysvgdice" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 280 320" width="52" height="52" style="transform: rotate(180deg);"><g transform="translate(-246.69456,-375.66745)"> <path fill=' + theusercolor + ' d="M379.93,375.668c-0.57,0.019-1.226,0.228-1.585,0.731l-80.673,96.527 c-1.342,1.681-1.433,2.056,0.366,2.073l161.59-0.427c2.221-0.182,2.23-0.07,0.792-1.951l-79.27-96.527 C380.986,375.84,380.501,375.654,379.93,375.668L379.93,375.668z M395.419,384.266l72.746,88.478 c0.974,1.182,1.212,1.249,2.927,0.427l38.354-17.562c2.513-1.134,2.165-1.366,0.487-2.5L395.419,384.266z M361.454,387.498 c-0.034-0.072-0.625,0.37-1.952,1.281L253.89,458.292l33.05,15.001c1.724,0.568,2.239,0.599,3.354-0.793l69.698-83.234 C360.973,388.129,361.487,387.57,361.454,387.498L361.454,387.498z M515.056,459.756c-0.328,0.023-0.846,0.212-1.646,0.548 l-39.392,17.989c-1.398,0.635-1.311,1.49-0.792,2.561l45.793,116.162l-3.292-135.309 C515.626,460.228,515.604,459.717,515.056,459.756L515.056,459.756z M250.902,463.354l-4.208,131.651l38.782-113.907 c0.573-1.682,0.559-1.767-0.61-2.317L250.902,463.354L250.902,463.354z M461.761,480.427l-165.249,0.427 c-2.361-0.035-2.264-0.033-1.098,1.89l83.905,141.529c1.417,2.159,1.265,2.092,2.744-0.121l80.612-141.772 C463.383,481.253,463.887,480.466,461.761,480.427L461.761,480.427z M468.347,484.147c-0.152,0.064-0.318,0.639-0.793,1.524 l-81.16,142.809c-0.887,1.508-1.097,2.048,1.036,1.708l128.845-17.744c2.044-0.467,1.982-1.197,1.281-3.232l-48.6-123.479 C468.635,484.55,468.5,484.083,468.347,484.147L468.347,484.147z M290.171,485.489c-0.158,0.113-0.3,0.715-0.609,1.585 l-41.16,121.162c-0.701,2.573-0.78,3.541,1.829,4.024l123.113,17.805c2.328,0.351,2.03-0.822,1.463-1.951l-83.783-141.345 C290.498,485.702,290.329,485.375,290.171,485.489L290.171,485.489z M258.158,619.334l120.796,68.538 c1.564,0.949,1.929,0.604,1.707-1.036l-2.561-48.05c-0.07-1.551-0.28-2.183-1.89-2.439L258.158,619.334L258.158,619.334z M507.922,619.455l-122.625,16.952c-1.618,0.238-1.326,1.032-1.342,2.195l2.622,48.903c0.135,1.483,0.091,2.017,1.89,1.098 L507.922,619.455z"/></g></svg>'

return usicon;

Expand Down Expand Up @@ -637,4 +698,4 @@ function sumInRange(data, startDate, endDate) {
}

return result;
}
}
7 changes: 4 additions & 3 deletions templates/sds.hbs
@@ -1,6 +1,7 @@
<div class="chartdice">
<div class="selections-container">
<div class="divsvgdice">{{{svgicon}}}</div>
<div class="chartdice" id="chartdice">
<div class="selections-container" id="selections-container" >
<div id="pause-state" style="display: flex; margin-right:2em;">{{{divSRDContent}}}</div>
<div class="divsvgdice" id="divsvgdice">{{{svgicon}}}</div>
<div id="d20itex"> ? </div>
<div class="dateselect">
<span class="usertogetdata">Show data of </span>
Expand Down

0 comments on commit aab8205

Please sign in to comment.