Redoing Dice Reroll functionality

Attempting something new
This commit is contained in:
Nikhil Nagarajan 2025-07-18 11:22:02 -04:00
parent 65e010caf8
commit 29d7a3e597
2 changed files with 43 additions and 61 deletions

View file

@ -303,61 +303,41 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
//Reroll Functionality //Reroll Functionality
rerollEvent = async(event,message)=> { rerollEvent = async(event,message)=> {
let originalMessage = message; let DieTerm=foundry.dice.terms.Die;
let dicetype = "str"; let dicetype = event.target.value;
let originalobject=originalMessage.rolls.map(roll => JSON.parse(roll)); let originalRoll=message.rolls.map(roll => JSON.parse(roll))[0];
let fear,hope; let diceIndex;
console.log("Dice to reroll is:",dicetype,", and the message id is:",message._id)
if (originalMessage.rolls.length) { console.log("Original Roll Terms:",originalRoll.terms);
console.log("Reroll button clicked for message:", originalMessage._id,originalMessage,originalobject); switch(dicetype){
if (originalobject[0].class==='DualityRoll') { case "hope": {
new foundry.applications.api.DialogV2({ diceIndex=0; //Hope Die
window: { title: 'Reroll' }, break;
content: '<p>Select which die/dice to reroll:</p><label><input type="radio" name="choice" value="fear" checked> Fear</label><label><input type="radio" name="choice" value="hope"> Hope</label><label><input type="radio" name="choice" value="both"> Both</label><p>Confirm option?</p>', };
buttons:[{ case "fear" :{
action: "choice", diceIndex=2 //Fear Die
label: "Confirm Choice", break;
default: true, };
callback: (event, button, dialog) => button.form.elements.choice.value default:
}, ui.notifications.warn("Invalid Dice type selected.");
{ break;
action: "cancel",
label:"Discard Reroll"
}],
submit: result =>{
if (result==="cancel") return;
else dicetype = result;
},
}).render({ force: true });
console.log('User picked:',dicetype);
switch(dicetype) {
case "fear":
console.log('Rerolling fear for user.');
fear=new Roll("1d12");
await fear.evaluate();
console.log('Dice rerolled to',fear.result);
case "hope":
console.log('Rerolling hope for user.');
hope=new Roll("1d12");
await hope.evaluate();
console.log('Dice rerolled to',hope.result);
case "both":
console.log('Rerolling both fear and hope for user.');
await hope.evaluate();
await fear.evaluate();
console.log('Dice rerolled to',hope.result,' in hope and ',fear.result,' in fear');
} }
let rollClone=originalRoll;
/* const confirm = await foundry.applications.api.DialogV2.confirm({ let rerolledTerm=rollClone.terms[diceIndex];
if (!(rerolledTerm instanceof DieTerm)) {
ui.notifications.error("Selected term is not a die.");
return;
}
/*
await rerolledTerm.reroll();
await rollClone.evaluate();
const confirm = await foundry.applications.api.DialogV2.confirm({
window: { title: 'Confirm Reroll' }, window: { title: 'Confirm Reroll' },
content: `<p>You have rerolled your ${dicetype} to ${r.result}</p><p>Apply new roll?</p>` content: `<p>You have rerolled your <strong>${dicetype}</strong> die to <strong>${rerolledTerm.results[0].result}</strong>.</p><p>Apply this new roll?</p>`
}); });
if (!confirm) return; if (!confirm) return;
else{ rollClone.toMessage({flavor: 'Selective reroll applied for ${dicetype}.'});
originalobject[0].; console.log("Updated Roll",rollClone);
} */ */
}
}
} }
} }

View file

@ -37,10 +37,12 @@
<div class="dice-container"> <div class="dice-container">
<div class="dice-title">{{localize "DAGGERHEART.GENERAL.hope"}}</div> <div class="dice-title">{{localize "DAGGERHEART.GENERAL.hope"}}</div>
<div class="dice-inner-container hope" title="{{localize "DAGGERHEART.GENERAL.hope"}}"> <div class="dice-inner-container hope" title="{{localize "DAGGERHEART.GENERAL.hope"}}">
<button type="checkbox" class="reroll-button" id="reroll-dice" value="hope">
<div class="dice-wrapper"> <div class="dice-wrapper">
<img class="dice" src="../icons/svg/d12-grey.svg"/> <img class="dice" src="../icons/svg/d12-grey.svg"/>
</div> </div>
<div class="dice-value">{{roll.hope.value}}</div> <div class="dice-value">{{roll.hope.value}}</div>
</button>
</div> </div>
</div> </div>
</li> </li>
@ -152,6 +154,6 @@
</div> </div>
</div> </div>
</div> </div>
<div class="reroll-div"> <!-- <div class="reroll-div">
<button class="reroll-button"><i class="fas fa-dice"></i><span>Reroll</span></button> <button class="reroll-button"><i class="fas fa-dice"></i><span>Reroll</span></button>
</div> </div> -->