Backward Dice Compatibility

This commit is contained in:
Megastruktur 2020-07-22 13:13:30 +03:00
parent 256f066962
commit 72c5497172
3 changed files with 67 additions and 46 deletions

View file

@ -1,5 +1,5 @@
v0.7.0
v0.7.1
- Fix Dice rolls
- Fix Cohorts
- Get ready for FoundryVTT 0.7.0
- Adds Dice-so-nice support for FoundryVTT <0.7.0
- Adds a proper Dice backward compatibility support (FVTT <0.7.0)
- Refactors Dice functionality a bit

View file

@ -4,6 +4,10 @@
Contact Discord: `megastruktur#5704` in case you find any bugs or if you have any suggestions.
Contributors:
- `megastruktur#5704`
- `Tyronne ISaurus#5415`
## Usage
`"Item" - all classes, crew types, upgrades, items, abilities, upgrades, etc.`
@ -43,10 +47,8 @@ Crew Types:
![alt screen][screenshot_compendium]
## To be done in the nearest future
- Clocks
- Friends/rivals section
- Stress/Harm dynamic values (can be modified by abilities but for now are hardcoded)
- Enhance Dice Rolling (ability modifiers)
## Troubleshooting
- If you can't find the drag-n-dropped item, refer to "All Items" tab on each sheet.

View file

@ -5,26 +5,22 @@
*/
export async function bladesRoll(dice_amount, attribute_name = "") {
// Is Dice So Nice enabled ?
let niceDice = false;
try {
niceDice = game.settings.get('dice-so-nice', 'settings').enabled;
} catch {
console.log("Dice-is-nice! not enabled");
}
// Is Dice So Nice enabled ?
let niceDice = '';
try {
niceDice = true;
game.settings.get('dice-so-nice', 'settings').enabled;
} catch {
niceDice = false;
}
// Is FoundryVTT core version >= 0.7.0 ?
// if using >= 0.7.0 New api calls enabled and DiceSoNice disabled until module update
// if using < 0.7.0 Old Roll API calls used and DiceSoNice enabled
let isBelow070 = isNewerVersion('0.7.0', game.data.version);
if (isBelow070==false) {niceDice=false;}
// Is FoundryVTT core version >= 0.7.0 ?
// if using >= 0.7.0 New api calls enabled and DiceSoNice disabled until module update
// if using < 0.7.0 Old Roll API calls used and DiceSoNice enabled
let isBelow070 = isNewerVersion('0.7.0', game.data.version);
if (isBelow070 == false) { niceDice=false; }
let speaker = ChatMessage.getSpeaker();
// ChatMessage.getSpeaker(controlledToken)
@ -35,32 +31,64 @@ export async function bladesRoll(dice_amount, attribute_name = "") {
let r = new Roll( `${dice_amount}d6`, {} );
r.roll();
// show 3d Dice so Nice if enabled
if (niceDice) {
game.dice3d.showForRoll(r).then(displayed => { });
game.dice3d.showForRoll(r).then(displayed => {});
} else {
r.roll();
}
// r.toMessage();
// Might be better as a DicePool with keep high/keep low intelligence,
// but I want to get my hands into this directly, and I think players
// will want to see all the dice happening.
let rolls='';
let sorted_rolls='';
let rolls = [];
if (isBelow070) {
rolls = (r.parts)[0].rolls;
} else {
rolls = (r.terms)[0].results;
}
if (isBelow070) { rolls = (r.parts)[0].rolls;} else { rolls = (r.terms)[0].results; }
// Retrieve Roll status.
let roll_status = getBladesRollStatus(rolls, zeromode);
let result = await renderTemplate("systems/blades-in-the-dark/templates/blades-roll.html", {rolls: rolls, roll_status: roll_status, attribute_name: attribute_name});
let messageData = {
speaker: speaker,
content: result,
type: CONST.CHAT_MESSAGE_TYPES.OOC,
roll: r
}
CONFIG.ChatMessage.entityClass.create(messageData, {})
return result;
}
/**
* Get status of the Roll.
* - failure
* - partial-success
* - success
* - critical-success
* @param {Array} rolls
* @param {Boolean} zeromode
*/
export function getBladesRollStatus(rolls, zeromode = false) {
// Dice API has changed in 0.7.0 so need to keep that in mind.
let isBelow070 = isNewerVersion('0.7.0', game.data.version);
let sorted_rolls = [];
// Sort roll values from lowest to highest.
if (isBelow070) { sorted_rolls = rolls.map(i => i.roll).sort(); } else { sorted_rolls = rolls.map(i => i.result).sort(); }
if (isBelow070) {
sorted_rolls = rolls.map(i => i.roll).sort();
} else {
sorted_rolls = rolls.map(i => i.result).sort();
}
let roll_status = "failure"
@ -104,20 +132,11 @@ export async function bladesRoll(dice_amount, attribute_name = "") {
}
let result = await renderTemplate("systems/blades-in-the-dark/templates/blades-roll.html", {rolls: rolls, roll_status: roll_status, attribute_name: attribute_name});
return roll_status;
let messageData = {
speaker: speaker,
content: result,
type: CONST.CHAT_MESSAGE_TYPES.OOC,
roll: r
}
CONFIG.ChatMessage.entityClass.create(messageData, {})
return result;
}
/**
* Call a Roll popup.
*/