From 74edb77ecbc63001348f84353fa7509ee67fbc9f Mon Sep 17 00:00:00 2001 From: nesuprachy <64099419+nesuprachy@users.noreply.github.com> Date: Fri, 15 Nov 2024 10:23:19 +0100 Subject: [PATCH 1/2] DrD2StatusMarkers patch 0.1.3 Token markers for load (encumberance) --- DrD2StatusMarkers/0.1.3/DrD2StatusMarkers.js | 94 ++++++++++++++++++++ DrD2StatusMarkers/DrD2StatusMarkers.js | 54 ++++++----- DrD2StatusMarkers/script.json | 2 +- 3 files changed, 128 insertions(+), 22 deletions(-) create mode 100644 DrD2StatusMarkers/0.1.3/DrD2StatusMarkers.js diff --git a/DrD2StatusMarkers/0.1.3/DrD2StatusMarkers.js b/DrD2StatusMarkers/0.1.3/DrD2StatusMarkers.js new file mode 100644 index 0000000000..3cc07d2599 --- /dev/null +++ b/DrD2StatusMarkers/0.1.3/DrD2StatusMarkers.js @@ -0,0 +1,94 @@ +// Github: TBD +// By: nesuprachy +// Contact: https://app.roll20.net/users/11071738/nesuprachy +// +// This script sets token markers based on relevant sheet attributes. +// Works with the DrD2 token marker set, icons must be named `RED`, `BLU`, `GRN`, `VIO`, `BLK`, `GRY`, `load` followed by corresponding values +// Uses TokenMod to set token markers from chat https://wiki.roll20.net/Script:Token_Mod + +var DrD2StatusMarkers = DrD2StatusMarkers || (function() { + 'use strict'; + + const version = '0.1.3'; + const lastUpdate = 1731662174989; + const markerAttributes = ['body_scarred', 'spirit_scarred', 'influence_scarred', 'danger', 'advantages', 'companion_bond_scarred', 'load']; + + checkInstall = function () { + log(`-=> DrD2StatusMarkers v${version} <=- [${new Date(lastUpdate)}]`); + }, + + handleMarkerAttributes = function (obj, prev) { + var attr = obj.get('name'); + if(markerAttributes.includes(attr)) { + var prevVal, newVal; + if(attr === 'load') { + prevVal = prev.current; + newVal = obj.get('current'); + }else { + prevVal = parseInt(prev.current)||0; + newVal = parseInt(obj.get('current'))||0; + } + var charId = obj.get('_characterid'); + var marker = ''; + //log(`${obj.get('name')} changed`); + //log(`prevVal ${prevVal} -> newVal ${newVal}`); + switch (attr) { + case markerAttributes[0]: + marker = 'RED'; + break; + case markerAttributes[1]: + marker = 'BLU'; + break; + case markerAttributes[2]: + marker = 'GRN'; + break; + case markerAttributes[3]: + marker = 'VIO'; + break; + case markerAttributes[4]: + marker = 'BLK'; + break; + case markerAttributes[5]: + marker = 'GRY'; + break; + case markerAttributes[6]: + marker= 'load'; + break; + default: + break; + } + if(marker){ + if(attr === 'load'){ + sendChat('API', `!token-mod --ignore-selected --ids ${charId} --set statusmarkers|-loadL|-loadS|-loadT|load${newVal}`, null, {noarchive:true}); + //log(`!token-mod --ignore-selected --ids ${charId} --set statusmarkers|-loadL|-loadS|-loadT|load${newVal}`); + } else if(newVal > 0 && newVal < 10) { + sendChat('API', `!token-mod --ignore-selected --ids ${charId} --set statusmarkers|-${marker}1|-${marker}2|-${marker}3|-${marker}4|-${marker}5|-${marker}6|-${marker}7|-${marker}8|-${marker}9|-${marker}9plus|${marker}${newVal}`, null, {noarchive:true} ); + //log(`!token-mod --ignore-selected --ids ${charId} --set statusmarkers|-${marker}1|-${marker}2|-${marker}3|-${marker}4|-${marker}5|-${marker}6|-${marker}7|-${marker}8|-${marker}9|-${marker}9plus|${marker}${newVal}`); + } else if(newVal >= 10) { + sendChat('API', `!token-mod --ignore-selected --ids ${charId} --set statusmarkers|-${marker}1|-${marker}2|-${marker}3|-${marker}4|-${marker}5|-${marker}6|-${marker}7|-${marker}8|-${marker}9|${marker}9plus`, null, {noarchive:true} ); + //log(`!token-mod --ignore-selected --ids ${charId} --set statusmarkers|-${marker}1|-${marker}2|-${marker}3|-${marker}4|-${marker}5|-${marker}6|-${marker}7|-${marker}8|-${marker}9|${marker}9plus`); + } else { + sendChat('API', `!token-mod --ignore-selected --ids ${charId} --set statusmarkers|-${marker}1|-${marker}2|-${marker}3|-${marker}4|-${marker}5|-${marker}6|-${marker}7|-${marker}8|-${marker}9|-${marker}9plus`, null, {noarchive:true} ); + //log(`!token-mod --ignore-selected --ids ${charId} --set statusmarkers|-${marker}1|-${marker}2|-${marker}3|-${marker}4|-${marker}5|-${marker}6|-${marker}7|-${marker}8|-${marker}9|-${marker}9plus`); + } + } + } + }, + + registerEventHandlers = function () { + on('change:attribute:current', function(obj, prev){handleMarkerAttributes(obj, prev)}); + }; + + return { + CheckInstall: checkInstall, + RegisterEventHandlers: registerEventHandlers + }; + +}()); + +on('ready', () => { + 'use strict'; + + DrD2StatusMarkers.CheckInstall(); + DrD2StatusMarkers.RegisterEventHandlers(); +}); \ No newline at end of file diff --git a/DrD2StatusMarkers/DrD2StatusMarkers.js b/DrD2StatusMarkers/DrD2StatusMarkers.js index 6df9106a8a..3cc07d2599 100644 --- a/DrD2StatusMarkers/DrD2StatusMarkers.js +++ b/DrD2StatusMarkers/DrD2StatusMarkers.js @@ -3,15 +3,15 @@ // Contact: https://app.roll20.net/users/11071738/nesuprachy // // This script sets token markers based on relevant sheet attributes. -// Works with the DrD2 token marker set, icons must be named `RED`, `BLU`, `GRN`, `VIO`, `BLK` +// Works with the DrD2 token marker set, icons must be named `RED`, `BLU`, `GRN`, `VIO`, `BLK`, `GRY`, `load` followed by corresponding values // Uses TokenMod to set token markers from chat https://wiki.roll20.net/Script:Token_Mod var DrD2StatusMarkers = DrD2StatusMarkers || (function() { 'use strict'; - const version = '0.1.2'; - const lastUpdate = 1725975609706; - const markerAttributes = ['body_scarred', 'spirit_scarred', 'influence_scarred', 'danger', 'advantages', 'companion_bond_scarred']; + const version = '0.1.3'; + const lastUpdate = 1731662174989; + const markerAttributes = ['body_scarred', 'spirit_scarred', 'influence_scarred', 'danger', 'advantages', 'companion_bond_scarred', 'load']; checkInstall = function () { log(`-=> DrD2StatusMarkers v${version} <=- [${new Date(lastUpdate)}]`); @@ -20,44 +20,56 @@ var DrD2StatusMarkers = DrD2StatusMarkers || (function() { handleMarkerAttributes = function (obj, prev) { var attr = obj.get('name'); if(markerAttributes.includes(attr)) { - var prevVal = parseInt(prev.current)||0; - var newVal = parseInt(obj.get('current'))||0; + var prevVal, newVal; + if(attr === 'load') { + prevVal = prev.current; + newVal = obj.get('current'); + }else { + prevVal = parseInt(prev.current)||0; + newVal = parseInt(obj.get('current'))||0; + } var charId = obj.get('_characterid'); - var color = ''; + var marker = ''; //log(`${obj.get('name')} changed`); //log(`prevVal ${prevVal} -> newVal ${newVal}`); switch (attr) { case markerAttributes[0]: - color = 'RED'; + marker = 'RED'; break; case markerAttributes[1]: - color = 'BLU'; + marker = 'BLU'; break; case markerAttributes[2]: - color = 'GRN'; + marker = 'GRN'; break; case markerAttributes[3]: - color = 'VIO'; + marker = 'VIO'; break; case markerAttributes[4]: - color = 'BLK'; + marker = 'BLK'; break; case markerAttributes[5]: - color = 'GRY'; + marker = 'GRY'; + break; + case markerAttributes[6]: + marker= 'load'; break; default: break; } - if(color){ - if(newVal > 0 && newVal < 10) { - sendChat('API', `!token-mod --ignore-selected --ids ${charId} --set statusmarkers|-${color}1|-${color}2|-${color}3|-${color}4|-${color}5|-${color}6|-${color}7|-${color}8|-${color}9|-${color}9plus|${color}${newVal}`, null, {noarchive:true} ); - //log(`!token-mod --ignore-selected --ids ${charId} --set statusmarkers|-${color}1|-${color}2|-${color}3|-${color}4|-${color}5|-${color}6|-${color}7|-${color}8|-${color}9|-${color}9plus|${color}${newVal}`); + if(marker){ + if(attr === 'load'){ + sendChat('API', `!token-mod --ignore-selected --ids ${charId} --set statusmarkers|-loadL|-loadS|-loadT|load${newVal}`, null, {noarchive:true}); + //log(`!token-mod --ignore-selected --ids ${charId} --set statusmarkers|-loadL|-loadS|-loadT|load${newVal}`); + } else if(newVal > 0 && newVal < 10) { + sendChat('API', `!token-mod --ignore-selected --ids ${charId} --set statusmarkers|-${marker}1|-${marker}2|-${marker}3|-${marker}4|-${marker}5|-${marker}6|-${marker}7|-${marker}8|-${marker}9|-${marker}9plus|${marker}${newVal}`, null, {noarchive:true} ); + //log(`!token-mod --ignore-selected --ids ${charId} --set statusmarkers|-${marker}1|-${marker}2|-${marker}3|-${marker}4|-${marker}5|-${marker}6|-${marker}7|-${marker}8|-${marker}9|-${marker}9plus|${marker}${newVal}`); } else if(newVal >= 10) { - sendChat('API', `!token-mod --ignore-selected --ids ${charId} --set statusmarkers|-${color}1|-${color}2|-${color}3|-${color}4|-${color}5|-${color}6|-${color}7|-${color}8|-${color}9|${color}9plus`, null, {noarchive:true} ); - //log(`!token-mod --ignore-selected --ids ${charId} --set statusmarkers|-${color}1|-${color}2|-${color}3|-${color}4|-${color}5|-${color}6|-${color}7|-${color}8|-${color}9|${color}9plus`); + sendChat('API', `!token-mod --ignore-selected --ids ${charId} --set statusmarkers|-${marker}1|-${marker}2|-${marker}3|-${marker}4|-${marker}5|-${marker}6|-${marker}7|-${marker}8|-${marker}9|${marker}9plus`, null, {noarchive:true} ); + //log(`!token-mod --ignore-selected --ids ${charId} --set statusmarkers|-${marker}1|-${marker}2|-${marker}3|-${marker}4|-${marker}5|-${marker}6|-${marker}7|-${marker}8|-${marker}9|${marker}9plus`); } else { - sendChat('API', `!token-mod --ignore-selected --ids ${charId} --set statusmarkers|-${color}1|-${color}2|-${color}3|-${color}4|-${color}5|-${color}6|-${color}7|-${color}8|-${color}9|-${color}9plus`, null, {noarchive:true} ); - //log(`!token-mod --ignore-selected --ids ${charId} --set statusmarkers|-${color}1|-${color}2|-${color}3|-${color}4|-${color}5|-${color}6|-${color}7|-${color}8|-${color}9|-${color}9plus`); + sendChat('API', `!token-mod --ignore-selected --ids ${charId} --set statusmarkers|-${marker}1|-${marker}2|-${marker}3|-${marker}4|-${marker}5|-${marker}6|-${marker}7|-${marker}8|-${marker}9|-${marker}9plus`, null, {noarchive:true} ); + //log(`!token-mod --ignore-selected --ids ${charId} --set statusmarkers|-${marker}1|-${marker}2|-${marker}3|-${marker}4|-${marker}5|-${marker}6|-${marker}7|-${marker}8|-${marker}9|-${marker}9plus`); } } } diff --git a/DrD2StatusMarkers/script.json b/DrD2StatusMarkers/script.json index 8b1e65c42e..7dfba69fac 100644 --- a/DrD2StatusMarkers/script.json +++ b/DrD2StatusMarkers/script.json @@ -3,7 +3,7 @@ "script": "DrD2StatusMarkers.js", "version": "0.1.2", "previousversions": ["0.1.0", "0.1.1"], - "description": "Designed for use only with the Draci Doupe II sheet.\n\nThis script sets token markers based on relevant sheet attributes.\nWorks with the DrD2 token marker set, icons must be named `RED`, `BLU`, `GRN`, `VIO`, `BLK`, `GRY`.\nYou can download the token marker set [here](https://download-directory.github.io/?url=https%3A%2F%2Fgithub.com%2Fnesuprachy%2Froll20-character-sheets%2Ftree%2FDraci-doupe-II%2FDraci%2520doupe%2520II%2Fassets%2FDrD2-token_markers).", + "description": "Designed for use only with the Draci Doupe II sheet.\n\nThis script sets token markers based on relevant sheet attributes.\nWorks with the DrD2 token marker set, icons must be named `RED`, `BLU`, `GRN`, `VIO`, `BLK`, `GRY`, `load` followed by corresponding values.\nYou can download the token marker set [here](https://download-directory.github.io/?url=https%3A%2F%2Fgithub.com%2Fnesuprachy%2Froll20-character-sheets%2Ftree%2FDraci-doupe-II%2FDraci%2520doupe%2520II%2Fassets%2FDrD2-token_markers).", "authors": "nesuprachy", "roll20userid": "11071738", "useroptions": [], From 7cfeacf8872b724bbed1cc595437b8e2c3bbf19f Mon Sep 17 00:00:00 2001 From: nesuprachy <64099419+nesuprachy@users.noreply.github.com> Date: Fri, 15 Nov 2024 10:25:54 +0100 Subject: [PATCH 2/2] Update script.json --- DrD2StatusMarkers/script.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DrD2StatusMarkers/script.json b/DrD2StatusMarkers/script.json index 7dfba69fac..6506756b51 100644 --- a/DrD2StatusMarkers/script.json +++ b/DrD2StatusMarkers/script.json @@ -1,8 +1,8 @@ { "name": "DrD2StatusMarkers", "script": "DrD2StatusMarkers.js", - "version": "0.1.2", - "previousversions": ["0.1.0", "0.1.1"], + "version": "0.1.3", + "previousversions": ["0.1.0", "0.1.1", "0.1.2"], "description": "Designed for use only with the Draci Doupe II sheet.\n\nThis script sets token markers based on relevant sheet attributes.\nWorks with the DrD2 token marker set, icons must be named `RED`, `BLU`, `GRN`, `VIO`, `BLK`, `GRY`, `load` followed by corresponding values.\nYou can download the token marker set [here](https://download-directory.github.io/?url=https%3A%2F%2Fgithub.com%2Fnesuprachy%2Froll20-character-sheets%2Ftree%2FDraci-doupe-II%2FDraci%2520doupe%2520II%2Fassets%2FDrD2-token_markers).", "authors": "nesuprachy", "roll20userid": "11071738",