From 63cab8f11d2144058db5b4684f59f33e77c2cb2a Mon Sep 17 00:00:00 2001 From: Peter Bjerg Lidegaard Date: Fri, 3 Apr 2026 14:31:58 +0200 Subject: [PATCH] Changed the warning box to an auto removal as there is no reason for people to have to do the work manually. --- ADnD_2E_Revised/2ESheet.html | 55 ++++++++++------------ ADnD_2E_Revised/html/changelog.html | 2 +- ADnD_2E_Revised/javascript/sheetWorkers.js | 53 ++++++++++----------- 3 files changed, 50 insertions(+), 60 deletions(-) diff --git a/ADnD_2E_Revised/2ESheet.html b/ADnD_2E_Revised/2ESheet.html index 67684242aa..0ebb44099a 100644 --- a/ADnD_2E_Revised/2ESheet.html +++ b/ADnD_2E_Revised/2ESheet.html @@ -9,7 +9,7 @@

Changes in


@@ -71252,6 +71252,10 @@ const displaySize = function(size) { } } +const unique = function (value, index, array) { + return array.indexOf(value) === index; +} + const sizeToInt = function(size) { if (typeof size !== 'string' || size.length === 0) return ''; @@ -71624,42 +71628,33 @@ on('clicked:hide-toast', function(eventInfo) { }); }); +//#region Text field correction +const SPECIAL_CHARACTER_REGEX = /[(){}\[\]"]/g on('change:character_name', function (eventInfo) { - getAttrs(['character_name'], function (values) { - let characterName = values.character_name.trim() - if (!characterName) - return false; + console.log(eventInfo); + if (isSheetWorkerUpdate(eventInfo)) { + return; + } - let message = `Your character's name contains`; - let suffix = `This can break various buttons and calculations on the sheet.\n\nPlease remove special characters to ensure the sheet functions as expected. Alternatively try using single quotes ' as these has not yet caused any issues.` + if (!eventInfo.newValue) { + return; + } - let parenthesis = (characterName.match(/[()]/g) || []).length - if (parenthesis > 0) { - showToast(ERROR, 'Parenthesis in Character name', `${message} parenthesis '()'. ${suffix}`); - return false; - } + let specialCharacters = eventInfo.newValue.match(SPECIAL_CHARACTER_REGEX) + if (!specialCharacters) { + return; + } - let curlyBracket = (characterName.match(/[{}]/g) || []).length - if (curlyBracket > 0) { - showToast(ERROR, 'Curly brackets in Character name', `${message} curly brackets '{}'. ${suffix}'`); - return false; - } + let message = `@{${eventInfo.sourceAttribute}} had the special characters '${specialCharacters.filter(unique).join(", ")}'. As these can break various buttons, calculations, and functionality on the sheet, they have been removed.\n\nFor flavor names, try using single quotes ' as these has not yet caused any issues. For instance: Thaldrin 'Hawkeye' Ravenflock.` - let squareBrackets = (characterName.match(/[\[\]]/g) || []).length - if (squareBrackets > 0) { - showToast(ERROR, 'Square brackets in Character name', `${message} square brackets '[]'. ${suffix}`); - return false; - } - let doubleQuotes = (characterName.match(/"/g) || []).length - if (doubleQuotes > 0) { - showToast(ERROR, 'Double quotes in Character name', `${message} double quotes '"'. ${suffix}`); - return false; - } + let toast = getToastObject(INFO, "Special characters removed", message); + let newValue = {...toast}; + newValue[eventInfo.sourceAttribute] = eventInfo.newValue.replaceAll(SPECIAL_CHARACTER_REGEX, ''); - return true; - }) + setAttrs(newValue); }) +//#endregion //#region Ability Scores logic // Ability Score Parser function @@ -73912,7 +73907,7 @@ function critEffectExplanations(critEffect, set) { return; injuryMatch = injuryMatch.map(s => s.toLowerCase().replace('internal ', '').trim()) - .filter((v, i, a) => a.indexOf(v) === i); + .filter(unique); injuryMatch.forEach(key => { switch (key) { case 'graze': diff --git a/ADnD_2E_Revised/html/changelog.html b/ADnD_2E_Revised/html/changelog.html index 134829d1df..9f2c63b53c 100644 --- a/ADnD_2E_Revised/html/changelog.html +++ b/ADnD_2E_Revised/html/changelog.html @@ -4,7 +4,7 @@

Changes in

    -
  • Show warning box when character name contains special characters as these tend to break buttons and calculations.
  • +
  • Automatically removing the following characters (){}[]" from character names as these break sheet functionality.

diff --git a/ADnD_2E_Revised/javascript/sheetWorkers.js b/ADnD_2E_Revised/javascript/sheetWorkers.js index f192f6b201..3223b6aa58 100644 --- a/ADnD_2E_Revised/javascript/sheetWorkers.js +++ b/ADnD_2E_Revised/javascript/sheetWorkers.js @@ -117,6 +117,10 @@ const displaySize = function(size) { } } +const unique = function (value, index, array) { + return array.indexOf(value) === index; +} + const sizeToInt = function(size) { if (typeof size !== 'string' || size.length === 0) return ''; @@ -489,42 +493,33 @@ on('clicked:hide-toast', function(eventInfo) { }); }); +//#region Text field correction +const SPECIAL_CHARACTER_REGEX = /[(){}\[\]"]/g on('change:character_name', function (eventInfo) { - getAttrs(['character_name'], function (values) { - let characterName = values.character_name.trim() - if (!characterName) - return false; + console.log(eventInfo); + if (isSheetWorkerUpdate(eventInfo)) { + return; + } - let message = `Your character's name contains`; - let suffix = `This can break various buttons and calculations on the sheet.\n\nPlease remove special characters to ensure the sheet functions as expected. Alternatively try using single quotes ' as these has not yet caused any issues.` + if (!eventInfo.newValue) { + return; + } - let parenthesis = (characterName.match(/[()]/g) || []).length - if (parenthesis > 0) { - showToast(ERROR, 'Parenthesis in Character name', `${message} parenthesis '()'. ${suffix}`); - return false; - } + let specialCharacters = eventInfo.newValue.match(SPECIAL_CHARACTER_REGEX) + if (!specialCharacters) { + return; + } - let curlyBracket = (characterName.match(/[{}]/g) || []).length - if (curlyBracket > 0) { - showToast(ERROR, 'Curly brackets in Character name', `${message} curly brackets '{}'. ${suffix}'`); - return false; - } + let message = `@{${eventInfo.sourceAttribute}} had the special characters '${specialCharacters.filter(unique).join(", ")}'. As these can break various buttons, calculations, and functionality on the sheet, they have been removed.\n\nFor flavor names, try using single quotes ' as these has not yet caused any issues. For instance: Thaldrin 'Hawkeye' Ravenflock.` - let squareBrackets = (characterName.match(/[\[\]]/g) || []).length - if (squareBrackets > 0) { - showToast(ERROR, 'Square brackets in Character name', `${message} square brackets '[]'. ${suffix}`); - return false; - } - let doubleQuotes = (characterName.match(/"/g) || []).length - if (doubleQuotes > 0) { - showToast(ERROR, 'Double quotes in Character name', `${message} double quotes '"'. ${suffix}`); - return false; - } + let toast = getToastObject(INFO, "Special characters removed", message); + let newValue = {...toast}; + newValue[eventInfo.sourceAttribute] = eventInfo.newValue.replaceAll(SPECIAL_CHARACTER_REGEX, ''); - return true; - }) + setAttrs(newValue); }) +//#endregion //#region Ability Scores logic // Ability Score Parser function @@ -2777,7 +2772,7 @@ function critEffectExplanations(critEffect, set) { return; injuryMatch = injuryMatch.map(s => s.toLowerCase().replace('internal ', '').trim()) - .filter((v, i, a) => a.indexOf(v) === i); + .filter(unique); injuryMatch.forEach(key => { switch (key) { case 'graze':