Skip to content

Commit

Permalink
Merge pull request #2623 from Azmoria/QoL---combat-tracker-option-to-…
Browse files Browse the repository at this point in the history
…select-next/prev

QoL - combat tracker option to select next/prev; Small improvement to swapping tokens as DM with token vision enabled.
  • Loading branch information
Azmoria authored Oct 30, 2024
2 parents f4beed3 + d67ec04 commit 6409b9a
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 36 deletions.
39 changes: 29 additions & 10 deletions CombatTracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

}
Expand Down Expand Up @@ -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();
}
}

}
Expand Down Expand Up @@ -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();
}
}
}

Expand Down Expand Up @@ -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}`));
Expand All @@ -470,9 +482,9 @@ function openCombatTrackerSettings(){

function form_row(name, title, inputOverride=null, imageValidation=false) {
const row = $(`<div style='width:100%;' id='${name}_row'/>`);
const rowLabel = $("<div style='display: inline-block; width:80%'>" + title + "</div>");
const rowLabel = $("<div>" + title + "</div>");
rowLabel.css("font-weight", "bold");
const rowInputWrapper = $("<div style='display:inline-block; width:20%; padding-right:8px' />");
const rowInputWrapper = $("<div/>");
let rowInput
if(!inputOverride){
if (imageValidation){
Expand Down Expand Up @@ -508,20 +520,18 @@ function openCombatTrackerSettings(){
$("#edit_dialog").remove();


console.log('edit_scene_dialog');
$("#scene_selector").attr('disabled', 'disabled');
dialog = $(`<div id='edit_dialog'></div>`);
dialog.css('background', "url('/content/1-0-1487-0/skins/waterdeep/images/mon-summary/paper-texture.png')");


scene_properties = $('<div id="scene_properties"/>');
dialog.append(scene_properties);

ctSettings = $('<div id="combat-tracker-settings"/>');
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();

Expand All @@ -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)
});
Expand All @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
48 changes: 25 additions & 23 deletions Token.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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];
Expand All @@ -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) {
Expand Down
18 changes: 15 additions & 3 deletions abovevtt.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6409b9a

Please sign in to comment.