Skip to content

Commit eb70e7f

Browse files
authored
Merge pull request #1984 from nesuprachy/DrD2StatusMarkers
DrD2StatusMarkers patch 0.1.3
2 parents 654fa68 + 7cfeacf commit eb70e7f

File tree

3 files changed

+130
-24
lines changed

3 files changed

+130
-24
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// Github: TBD
2+
// By: nesuprachy
3+
// Contact: https://app.roll20.net/users/11071738/nesuprachy
4+
//
5+
// This script sets token markers based on relevant sheet attributes.
6+
// Works with the DrD2 token marker set, icons must be named `RED`, `BLU`, `GRN`, `VIO`, `BLK`, `GRY`, `load` followed by corresponding values
7+
// Uses TokenMod to set token markers from chat https://wiki.roll20.net/Script:Token_Mod
8+
9+
var DrD2StatusMarkers = DrD2StatusMarkers || (function() {
10+
'use strict';
11+
12+
const version = '0.1.3';
13+
const lastUpdate = 1731662174989;
14+
const markerAttributes = ['body_scarred', 'spirit_scarred', 'influence_scarred', 'danger', 'advantages', 'companion_bond_scarred', 'load'];
15+
16+
checkInstall = function () {
17+
log(`-=> DrD2StatusMarkers v${version} <=- [${new Date(lastUpdate)}]`);
18+
},
19+
20+
handleMarkerAttributes = function (obj, prev) {
21+
var attr = obj.get('name');
22+
if(markerAttributes.includes(attr)) {
23+
var prevVal, newVal;
24+
if(attr === 'load') {
25+
prevVal = prev.current;
26+
newVal = obj.get('current');
27+
}else {
28+
prevVal = parseInt(prev.current)||0;
29+
newVal = parseInt(obj.get('current'))||0;
30+
}
31+
var charId = obj.get('_characterid');
32+
var marker = '';
33+
//log(`${obj.get('name')} changed`);
34+
//log(`prevVal ${prevVal} -> newVal ${newVal}`);
35+
switch (attr) {
36+
case markerAttributes[0]:
37+
marker = 'RED';
38+
break;
39+
case markerAttributes[1]:
40+
marker = 'BLU';
41+
break;
42+
case markerAttributes[2]:
43+
marker = 'GRN';
44+
break;
45+
case markerAttributes[3]:
46+
marker = 'VIO';
47+
break;
48+
case markerAttributes[4]:
49+
marker = 'BLK';
50+
break;
51+
case markerAttributes[5]:
52+
marker = 'GRY';
53+
break;
54+
case markerAttributes[6]:
55+
marker= 'load';
56+
break;
57+
default:
58+
break;
59+
}
60+
if(marker){
61+
if(attr === 'load'){
62+
sendChat('API', `!token-mod --ignore-selected --ids ${charId} --set statusmarkers|-loadL|-loadS|-loadT|load${newVal}`, null, {noarchive:true});
63+
//log(`!token-mod --ignore-selected --ids ${charId} --set statusmarkers|-loadL|-loadS|-loadT|load${newVal}`);
64+
} else if(newVal > 0 && newVal < 10) {
65+
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} );
66+
//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}`);
67+
} else if(newVal >= 10) {
68+
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} );
69+
//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`);
70+
} else {
71+
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} );
72+
//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`);
73+
}
74+
}
75+
}
76+
},
77+
78+
registerEventHandlers = function () {
79+
on('change:attribute:current', function(obj, prev){handleMarkerAttributes(obj, prev)});
80+
};
81+
82+
return {
83+
CheckInstall: checkInstall,
84+
RegisterEventHandlers: registerEventHandlers
85+
};
86+
87+
}());
88+
89+
on('ready', () => {
90+
'use strict';
91+
92+
DrD2StatusMarkers.CheckInstall();
93+
DrD2StatusMarkers.RegisterEventHandlers();
94+
});

DrD2StatusMarkers/DrD2StatusMarkers.js

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
// Contact: https://app.roll20.net/users/11071738/nesuprachy
44
//
55
// This script sets token markers based on relevant sheet attributes.
6-
// Works with the DrD2 token marker set, icons must be named `RED`, `BLU`, `GRN`, `VIO`, `BLK`
6+
// Works with the DrD2 token marker set, icons must be named `RED`, `BLU`, `GRN`, `VIO`, `BLK`, `GRY`, `load` followed by corresponding values
77
// Uses TokenMod to set token markers from chat https://wiki.roll20.net/Script:Token_Mod
88

99
var DrD2StatusMarkers = DrD2StatusMarkers || (function() {
1010
'use strict';
1111

12-
const version = '0.1.2';
13-
const lastUpdate = 1725975609706;
14-
const markerAttributes = ['body_scarred', 'spirit_scarred', 'influence_scarred', 'danger', 'advantages', 'companion_bond_scarred'];
12+
const version = '0.1.3';
13+
const lastUpdate = 1731662174989;
14+
const markerAttributes = ['body_scarred', 'spirit_scarred', 'influence_scarred', 'danger', 'advantages', 'companion_bond_scarred', 'load'];
1515

1616
checkInstall = function () {
1717
log(`-=> DrD2StatusMarkers v${version} <=- [${new Date(lastUpdate)}]`);
@@ -20,44 +20,56 @@ var DrD2StatusMarkers = DrD2StatusMarkers || (function() {
2020
handleMarkerAttributes = function (obj, prev) {
2121
var attr = obj.get('name');
2222
if(markerAttributes.includes(attr)) {
23-
var prevVal = parseInt(prev.current)||0;
24-
var newVal = parseInt(obj.get('current'))||0;
23+
var prevVal, newVal;
24+
if(attr === 'load') {
25+
prevVal = prev.current;
26+
newVal = obj.get('current');
27+
}else {
28+
prevVal = parseInt(prev.current)||0;
29+
newVal = parseInt(obj.get('current'))||0;
30+
}
2531
var charId = obj.get('_characterid');
26-
var color = '';
32+
var marker = '';
2733
//log(`${obj.get('name')} changed`);
2834
//log(`prevVal ${prevVal} -> newVal ${newVal}`);
2935
switch (attr) {
3036
case markerAttributes[0]:
31-
color = 'RED';
37+
marker = 'RED';
3238
break;
3339
case markerAttributes[1]:
34-
color = 'BLU';
40+
marker = 'BLU';
3541
break;
3642
case markerAttributes[2]:
37-
color = 'GRN';
43+
marker = 'GRN';
3844
break;
3945
case markerAttributes[3]:
40-
color = 'VIO';
46+
marker = 'VIO';
4147
break;
4248
case markerAttributes[4]:
43-
color = 'BLK';
49+
marker = 'BLK';
4450
break;
4551
case markerAttributes[5]:
46-
color = 'GRY';
52+
marker = 'GRY';
53+
break;
54+
case markerAttributes[6]:
55+
marker= 'load';
4756
break;
4857
default:
4958
break;
5059
}
51-
if(color){
52-
if(newVal > 0 && newVal < 10) {
53-
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} );
54-
//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}`);
60+
if(marker){
61+
if(attr === 'load'){
62+
sendChat('API', `!token-mod --ignore-selected --ids ${charId} --set statusmarkers|-loadL|-loadS|-loadT|load${newVal}`, null, {noarchive:true});
63+
//log(`!token-mod --ignore-selected --ids ${charId} --set statusmarkers|-loadL|-loadS|-loadT|load${newVal}`);
64+
} else if(newVal > 0 && newVal < 10) {
65+
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} );
66+
//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}`);
5567
} else if(newVal >= 10) {
56-
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} );
57-
//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`);
68+
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} );
69+
//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`);
5870
} else {
59-
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} );
60-
//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`);
71+
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} );
72+
//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`);
6173
}
6274
}
6375
}

DrD2StatusMarkers/script.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "DrD2StatusMarkers",
33
"script": "DrD2StatusMarkers.js",
4-
"version": "0.1.2",
5-
"previousversions": ["0.1.0", "0.1.1"],
6-
"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).",
4+
"version": "0.1.3",
5+
"previousversions": ["0.1.0", "0.1.1", "0.1.2"],
6+
"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).",
77
"authors": "nesuprachy",
88
"roll20userid": "11071738",
99
"useroptions": [],

0 commit comments

Comments
 (0)