display %modifier in rolls if applicable
This commit is contained in:
@@ -583,18 +583,6 @@ export class DeltaGreenActorSheet extends ActorSheet {
|
||||
return this.actor.createEmbeddedDocuments("Item", [itemData]);
|
||||
}
|
||||
|
||||
_formatStringWithLeadingPlus(number){
|
||||
let s = "";
|
||||
|
||||
if(number > 0){
|
||||
s += "+"
|
||||
}
|
||||
|
||||
s += number.toString();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle clickable rolls.
|
||||
*
|
||||
|
||||
@@ -9,7 +9,7 @@ import * as DGRolls from "./roll/roll.js";
|
||||
import { registerSystemSettings } from "./settings.js"
|
||||
import { preloadHandlebarsTemplates } from "./templates.js";
|
||||
import { ParseDeltaGreenStatBlock } from "./other/stat-parser-macro.js";
|
||||
import { localizeWithFallback } from "./other/utility-functions.js";
|
||||
import DGUtils from "./other/utility-functions.js";
|
||||
|
||||
Hooks.once('init', async function() {
|
||||
|
||||
@@ -52,7 +52,7 @@ Hooks.once('init', async function() {
|
||||
|
||||
// Add Handlebars helpers
|
||||
Handlebars.registerHelper('localizeWithFallback', function(value, fallbackValue) {
|
||||
return localizeWithFallback(value, fallbackValue);
|
||||
return DGUtils.localizeWithFallback(value, fallbackValue);
|
||||
});
|
||||
|
||||
Handlebars.registerHelper('concat', function() {
|
||||
|
||||
@@ -1,24 +1,40 @@
|
||||
// Attempt to localize a keyword, and gracefully fallback to something else if the key does not exist.
|
||||
// This way people using incomplete translations will not as many crashes or bugs when playing against a newly updated system.
|
||||
export function localizeWithFallback(key, fallback){
|
||||
try{
|
||||
let translatedValue = game.i18n.localize(key);
|
||||
/* globals game */
|
||||
|
||||
if(translatedValue != key){
|
||||
return translatedValue;
|
||||
}
|
||||
else{
|
||||
|
||||
console.warn(`Untranslated localization key '${key}'.`);
|
||||
|
||||
// can't have single quotes in a handlebars string literal input, so sort of hack in an escape character for them.
|
||||
fallback = fallback.replace("'", "'");
|
||||
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
catch(ex){
|
||||
console.warn(ex);
|
||||
return fallback;
|
||||
export default class DGUtils {
|
||||
/**
|
||||
* Attempt to localize a keyword, and gracefully fallback to something else if the key does not exist.
|
||||
* This way people using incomplete translations will not as many crashes or bugs when playing against a newly updated system.
|
||||
*
|
||||
* @param {String} key - localization key
|
||||
* @param {String} fallback - string to fall back to if translation does not exist for key
|
||||
* @returns
|
||||
*/
|
||||
static localizeWithFallback(key, fallback){
|
||||
try {
|
||||
let translatedValue = game.i18n.localize(key);
|
||||
if (translatedValue != key) {
|
||||
return translatedValue;
|
||||
} else {
|
||||
console.warn(`Untranslated localization key '${key}'.`);
|
||||
// can't have single quotes in a handlebars string literal input, so sort of hack in an escape character for them.
|
||||
fallback = fallback.replace("'", "'");
|
||||
return fallback;
|
||||
}
|
||||
} catch(ex) {
|
||||
console.warn(ex);
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a number with a leading plus.
|
||||
*
|
||||
* @param {Number} number
|
||||
* @returns {String} - the stringified number with a leading plus if applicable
|
||||
*
|
||||
*/
|
||||
static formatStringWithLeadingPlus(number){
|
||||
return number > 0 ? `+${number}` : number.toString();
|
||||
}
|
||||
}
|
||||
+13
-8
@@ -1,6 +1,6 @@
|
||||
/* globals game Roll ChatMessage AudioHelper renderTemplate Dialog */
|
||||
|
||||
import { localizeWithFallback } from "../other/utility-functions.js"
|
||||
import DGUtils from "../other/utility-functions.js"
|
||||
|
||||
export class DGRoll extends Roll {
|
||||
/**
|
||||
@@ -150,11 +150,11 @@ export class DGPercentileRoll extends DGRoll {
|
||||
return new Promise((resolve, reject) => {
|
||||
new Dialog({
|
||||
content: html,
|
||||
title: localizeWithFallback("DG.ModifySkillRollDialogue.Title", "Modify Roll"),
|
||||
title: DGUtils.localizeWithFallback("DG.ModifySkillRollDialogue.Title", "Modify Roll"),
|
||||
default: "roll",
|
||||
buttons: {
|
||||
roll:{
|
||||
label: localizeWithFallback("DG.Roll.Roll", "Roll"),
|
||||
label: DGUtils.localizeWithFallback("DG.Roll.Roll", "Roll"),
|
||||
callback: html => {
|
||||
try {
|
||||
let targetModifier = html.find("[name='targetModifier']").val(); // this is text as a heads up
|
||||
@@ -198,12 +198,13 @@ export class DGPercentileRoll extends DGRoll {
|
||||
rollMode = 'blindroll';
|
||||
}
|
||||
|
||||
let label = '';
|
||||
let label = `${game.i18n.localize("DG.Roll.Rolling")} <b>${this.localizedKey}</b> ${game.i18n.localize("DG.Roll.Target")} ${this.target + this.modifier}`;
|
||||
// "Inhuman" stat being rolled. See function for details.
|
||||
if (this.isInhuman) {
|
||||
label = `${game.i18n.localize("DG.Roll.Rolling")} <b>${this.localizedKey} [${game.i18n.localize("DG.Roll.Inhuman").toUpperCase()}]</b> ${game.i18n.localize("DG.Roll.Target")} ${this.target + this.modifier}`;
|
||||
} else {
|
||||
label = `${game.i18n.localize("DG.Roll.Rolling")} <b>${this.localizedKey}</b> ${game.i18n.localize("DG.Roll.Target")} ${this.target + this.modifier}`;
|
||||
}
|
||||
if (this.modifier) {
|
||||
label += ` (${DGUtils.formatStringWithLeadingPlus(this.modifier)}%)`
|
||||
}
|
||||
|
||||
let resultString = '', styleOverride = '';
|
||||
@@ -356,7 +357,11 @@ export class DGLethalityRoll extends DGPercentileRoll {
|
||||
}
|
||||
|
||||
const { nonLethalDamage } = this;
|
||||
let label = `${game.i18n.localize("DG.Roll.Rolling")} <b>${game.i18n.localize("DG.Roll.Lethality").toUpperCase()}</b> ${game.i18n.localize("DG.Roll.For")} <b>${this.item.name.toUpperCase()}</b> ${game.i18n.localize("DG.Roll.Target")} ${this.target}`;
|
||||
let label = `${game.i18n.localize("DG.Roll.Rolling")} <b>${game.i18n.localize("DG.Roll.Lethality").toUpperCase()}</b> ${game.i18n.localize("DG.Roll.For")} <b>${this.item.name.toUpperCase()}</b> ${game.i18n.localize("DG.Roll.Target")} ${this.target + this.modifier}`;
|
||||
if (this.modifier) {
|
||||
label += ` (${DGUtils.formatStringWithLeadingPlus(this.modifier)}%)`
|
||||
}
|
||||
|
||||
let html = '';
|
||||
html += `<div class="dice-roll">`;
|
||||
html += ` <div class="dice-result">`;
|
||||
@@ -528,7 +533,7 @@ export class DGSanityDamageRoll extends DGRoll {
|
||||
|
||||
const [lowResult, highResult] = this.damageResults;
|
||||
|
||||
const flavor = `Rolling <b>${localizeWithFallback('DG.Generic.SanDamage', 'SAN DAMAGE')}</b> For <b>${lowDie.formula} / ${highDie.formula}</b>`;
|
||||
const flavor = `Rolling <b>${DGUtils.localizeWithFallback('DG.Generic.SanDamage', 'SAN DAMAGE')}</b> For <b>${lowDie.formula} / ${highDie.formula}</b>`;
|
||||
|
||||
let html = '';
|
||||
html += `<div class="dice-roll">`;
|
||||
|
||||
Reference in New Issue
Block a user