From d67ec047ef7ed1e3aea8e813ec89da09dece4c77 Mon Sep 17 00:00:00 2001
From: Azmoria <65363489+Azmoria@users.noreply.github.com>
Date: Wed, 30 Oct 2024 06:31:28 -0400
Subject: [PATCH] QoL - combat tracker option to select next/prev; Small
improvement to swapping tokens as DM with token vision enabled.
---
CombatTracker.js | 39 +++++++++++++++++++++++++++++----------
Token.js | 48 +++++++++++++++++++++++++-----------------------
abovevtt.css | 18 +++++++++++++++---
3 files changed, 69 insertions(+), 36 deletions(-)
diff --git a/CombatTracker.js b/CombatTracker.js
index 1ce494166..122a56882 100644
--- a/CombatTracker.js
+++ b/CombatTracker.js
@@ -289,6 +289,9 @@ function init_combat_tracker(){
if(combatSettingData['scroll_to_next'] == '1'){
window.TOKEN_OBJECTS[currentTarget].highlight();
}
+ if(combatSettingData['select_next'] == '1'){
+ $(`#tokens .token[data-id='${currentTarget}']`).click();
+ }
}
}
@@ -327,6 +330,9 @@ function init_combat_tracker(){
if(combatSettingData['scroll_to_next'] == '1'){
window.TOKEN_OBJECTS[newTarget].highlight();
}
+ if(combatSettingData['select_next'] == '1'){
+ $(`#tokens .token[data-id='${newTarget}']`).click();
+ }
}
}
@@ -375,6 +381,9 @@ function init_combat_tracker(){
if(combatSettingData['scroll_to_next'] == '1'){
window.TOKEN_OBJECTS[newTarget].highlight();
}
+ if(combatSettingData['select_next'] == '1'){
+ $(`#tokens .token[data-id='${newTarget}']`).click();
+ }
}
}
@@ -458,7 +467,10 @@ function getCombatTrackersettings(){
if(localStorage.getItem(`abovevtt-combat-tracker-settings-${window.DM}`) == null){
combatSettingData = {
tie_breaker: 0,
- scroll_to_next: 0
+ scroll_to_next: 0,
+ select_next: 0,
+ auto_init: 0,
+ remove_init: 0
}
}else{
combatSettingData = $.parseJSON(localStorage.getItem(`abovevtt-combat-tracker-settings-${window.DM}`));
@@ -470,9 +482,9 @@ function openCombatTrackerSettings(){
function form_row(name, title, inputOverride=null, imageValidation=false) {
const row = $(`
`);
- const rowLabel = $("" + title + "
");
+ const rowLabel = $("" + title + "
");
rowLabel.css("font-weight", "bold");
- const rowInputWrapper = $("");
+ const rowInputWrapper = $("");
let rowInput
if(!inputOverride){
if (imageValidation){
@@ -508,20 +520,18 @@ function openCombatTrackerSettings(){
$("#edit_dialog").remove();
- console.log('edit_scene_dialog');
$("#scene_selector").attr('disabled', 'disabled');
dialog = $(``);
dialog.css('background', "url('/content/1-0-1487-0/skins/waterdeep/images/mon-summary/paper-texture.png')");
- scene_properties = $('');
- dialog.append(scene_properties);
-
+ ctSettings = $('');
+ dialog.append(ctSettings);
- adjust_create_import_edit_container(dialog, undefined, undefined, 2000, 300);
+ adjust_create_import_edit_container(dialog, undefined, undefined, 2000, 360);
- let container = scene_properties;
+ let container = ctSettings;
container.empty();
@@ -545,6 +555,12 @@ function openCombatTrackerSettings(){
let scrollToNextRow = form_row(`scroll_to_next`, `Auto Center Token on Next/Prev`, scrollToNextToggle)
form.append(scrollToNextRow);
+ let autoSelectNextToggle = form_toggle('select_next', 'Select Token on Next/Prev', combatSettingData['select_next'] == '1', function(e){
+ handle_basic_form_toggle_click(e)
+ });
+ let autoSelectNextRow = form_row(`select_next`, `Select Token on Next/Prev`, autoSelectNextToggle)
+ form.append(autoSelectNextRow);
+
let autoRollInitAtTopToggle = form_toggle('auto_init', `${window.DM ? 'Auto Roll Monster Init at Top of Round' : 'Auto Roll Initiative at Top of Round'}`, combatSettingData['auto_init'] == '1', function(e){
handle_basic_form_toggle_click(e)
});
@@ -554,7 +570,7 @@ function openCombatTrackerSettings(){
let removeInitToggle = form_toggle('remove_init', `When enabled instead of using a tokens saved initiative when removed and added back to combat it will be rerolled.`, combatSettingData['remove_init'] == '1', function(e){
handle_basic_form_toggle_click(e)
});
- let removeInitRow = form_row(`remove_init`, `Disable Init Save on Clear/Remove`, removeInitToggle)
+ let removeInitRow = form_row(`remove_init`, `Ignore token's saved init on add to combat`, removeInitToggle)
if(window.DM)
form.append(removeInitRow);
@@ -1164,6 +1180,9 @@ function ct_load(data=null){
if(combatSettingData['scroll_to_next'] == '1'){
window.TOKEN_OBJECTS[data[i]['data-target']].highlight();
}
+ if(combatSettingData['select_next'] == '1'){
+ $(`#tokens .token[data-id='${data[i]['data-target']}']`).click();
+ }
}
if(window.all_token_objects[data[i]['data-target']].isCurrentPlayer() || window.all_token_objects[data[i]['data-target']].options.player_owned){
$("#endplayerturn").toggleClass('enabled', true);
diff --git a/Token.js b/Token.js
index bbb4ebb0e..f3b836af9 100644
--- a/Token.js
+++ b/Token.js
@@ -2004,7 +2004,7 @@ class Token {
let thisSelected = !(parentToken.hasClass('tokenselected'));
let count = 0;
if (shiftHeld == false) {
- deselect_all_tokens();
+ deselect_all_tokens(true);
}
if (thisSelected == true) {
parentToken.addClass('tokenselected');
@@ -3046,7 +3046,7 @@ class Token {
let thisSelected = !(parentToken.hasClass('tokenselected'));
let count = 0;
if (shiftHeld == false) {
- deselect_all_tokens();
+ deselect_all_tokens(true);
}
if (thisSelected == true) {
parentToken.addClass('tokenselected');
@@ -3555,7 +3555,7 @@ function token_menu() {
return;
}
-function deselect_all_tokens() {
+function deselect_all_tokens(ignoreVisionUpdate = false) {
window.MULTIPLE_TOKEN_SELECTED = false;
for (let id in window.TOKEN_OBJECTS) {
let curr = window.TOKEN_OBJECTS[id];
@@ -3566,26 +3566,28 @@ function deselect_all_tokens() {
}
remove_selected_token_bounding_box();
window.CURRENTLY_SELECTED_TOKENS = [];
- let darknessFilter = (window.CURRENT_SCENE_DATA.darkness_filter != undefined) ? window.CURRENT_SCENE_DATA.darkness_filter : 0;
- let darknessPercent = window.DM ? Math.max(40, 100 - parseInt(darknessFilter)) : 100 - parseInt(darknessFilter);
-
- if(window.DM && darknessPercent < 40){
- darknessPercent = 40;
- $('#raycastingCanvas').css('opacity', '0');
- }
- else if(window.DM){
- $('#raycastingCanvas').css('opacity', '');
- }
- $('#VTT').css('--darkness-filter', darknessPercent + "%");
- if(window.DM){
- $("#light_container [id^='light_']").css('visibility', "visible");
- $(`.token`).show();
- $(`.door-button`).css('visibility', '');
- $(`.aura-element`).show();
- }
- if($('#selected_token_vision .ddbc-tab-options__header-heading--is-active').length==0){
- window.SelectedTokenVision = false;
- }
+ if(ignoreVisionUpdate == false){
+ let darknessFilter = (window.CURRENT_SCENE_DATA.darkness_filter != undefined) ? window.CURRENT_SCENE_DATA.darkness_filter : 0;
+ let darknessPercent = window.DM ? Math.max(40, 100 - parseInt(darknessFilter)) : 100 - parseInt(darknessFilter);
+
+ if(window.DM && darknessPercent < 40){
+ darknessPercent = 40;
+ $('#raycastingCanvas').css('opacity', '0');
+ }
+ else if(window.DM){
+ $('#raycastingCanvas').css('opacity', '');
+ }
+ $('#VTT').css('--darkness-filter', darknessPercent + "%");
+ if(window.DM){
+ $("#light_container [id^='light_']").css('visibility', "visible");
+ $(`.token`).show();
+ $(`.door-button`).css('visibility', '');
+ $(`.aura-element`).show();
+ }
+ if($('#selected_token_vision .ddbc-tab-options__header-heading--is-active').length==0){
+ window.SelectedTokenVision = false;
+ }
+ }
}
function token_health_aura(hpPercentage, auraType) {
diff --git a/abovevtt.css b/abovevtt.css
index ae8a83de4..70cb5d34d 100644
--- a/abovevtt.css
+++ b/abovevtt.css
@@ -1264,7 +1264,9 @@ input {
border: 1px solid #3d3d3d;
}
-#scene_properties form > button {
+#scene_properties form > button,
+#combat-tracker-settings form > button
+ {
float: right;
vertical-align: bottom;
margin-top: 20px;
@@ -1459,14 +1461,24 @@ div#template_section {
border-bottom: 1px solid #00000066;
}
-div#scene_properties {
+div#scene_properties,
+div#combat-tracker-settings {
margin: 0 5px;
}
-div#scene_properties form > div {
+div#scene_properties form > div,
+div#combat-tracker-settings form > div {
margin: 5px 0;
}
+#combat-tracker-settings form > div {
+ text-transform: uppercase;
+ display: flex;
+ justify-content: space-between;
+ font-weight: bold;
+ align-items: center;
+}
+
#importer_toggles {
display: flex;
align-items: flex-end;