Skip to content

Commit

Permalink
Update performance and clickable legend
Browse files Browse the repository at this point in the history
  • Loading branch information
Azmoria committed Jun 29, 2024
1 parent 3965d3c commit 02206bd
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 9 deletions.
16 changes: 13 additions & 3 deletions CoreFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,12 @@ async function rebuild_window_pcs() {
});
}

async function rebuild_window_users() {
window.playerUsers = await DDBApi.fetchCampaignUserDetails(window.gameId);
let playerUser = window.playerUsers.filter(d=> d.id == window.PLAYER_ID)[0]?.userId;
window.myUser = playerUser ? playerUser : 'THE_DM';
}

function update_pc_with_data(playerId, data) {
if (data.constructor !== Object) {
console.warn("update_pc_with_data was given invalid data", playerId, data);
Expand Down Expand Up @@ -1258,7 +1264,7 @@ function areArraysEqualSets(a1, a2) {
}


function find_or_create_generic_draggable_window(id, titleBarText, addLoadingIndicator = true, addPopoutButton = false, popoutSelector=``, width='80%', height='80%', top='10%', left='10%') {
function find_or_create_generic_draggable_window(id, titleBarText, addLoadingIndicator = true, addPopoutButton = false, popoutSelector=``, width='80%', height='80%', top='10%', left='10%', showSlow = true) {
console.log(`find_or_create_generic_draggable_window id: ${id}, titleBarText: ${titleBarText}, addLoadingIndicator: ${addLoadingIndicator}, addPopoutButton: ${addPopoutButton}`);
const existing = id.startsWith("#") ? $(id) : $(`#${id}`);
if (existing.length > 0) {
Expand Down Expand Up @@ -1288,8 +1294,12 @@ function find_or_create_generic_draggable_window(id, titleBarText, addLoadingInd
"height": "calc(100% - 25px)"
});
}

container.show("slow")
if(showSlow){
container.show("slow");
}
else{
container.show();
}
container.resize(function(e) {
e.stopPropagation();
});
Expand Down
41 changes: 35 additions & 6 deletions Fog.js
Original file line number Diff line number Diff line change
Expand Up @@ -1403,7 +1403,7 @@ function redraw_drawings() {

ctx.drawImage(offscreenDraw, 0, 0); // draw to visible canvas only once so we render this once
}
function redraw_elev() {
function redraw_elev(openLegened = false) {
window.elevHeights = {};
let canvas = document.getElementById("elev_overlay");
let ctx = canvas.getContext("2d");
Expand All @@ -1416,6 +1416,7 @@ function redraw_elev() {
else{
$('#elev_overlay').css('display', 'none');
}

const drawings = window.DRAWINGS.filter(d => d[1] == 'elev')


Expand Down Expand Up @@ -1486,12 +1487,12 @@ function redraw_elev() {
}

ctx.drawImage(offscreenDraw, 0, 0); // draw to visible canvas only once so we render this once
if($('#elev_legend_window').length>0){
if($('#elev_legend_window').length>0 || openLegened == true){
open_elev_legend()
}
}
function open_elev_legend(){
let elevationWindow = find_or_create_generic_draggable_window('elev_legend_window', 'Elevation Legend', false, false, undefined, '200px', 'fit-content', '32px', '317px');
let elevationWindow = find_or_create_generic_draggable_window('elev_legend_window', 'Elevation Legend', false, false, undefined, '200px', 'fit-content', '32px', '317px', false);
elevationWindow.find('.elevationLegendDiv').remove();


Expand All @@ -1501,12 +1502,19 @@ function open_elev_legend(){
.reduce((r, [k, v]) => ({ ...r, [k]: v }), {});
for(let i in legendHeights){
let row = $(`<div class='row'><div class='row-color' style='background: ${i};'></div><div>${window.elevHeights[i]}</div></div>`)
row.off('click.legendRow').on('click.legendRow', `.row-color`, function(){
$('input#elev_height').val(`${window.elevHeights[i]}`)
});
legend.append(row);
}

elevationWindow.append(legend);
}

function close_elev_legend(){
close_and_cleanup_generic_draggable_window('elev_legend_window')
}

function check_token_elev(tokenid, elevContext=undefined){
if(elevContext == undefined){
elevContext = $('#elev_overlay')[0].getContext('2d');
Expand Down Expand Up @@ -3426,8 +3434,28 @@ function handle_drawing_button_click() {

stop_drawing();
if(window.CURRENT_SCENE_DATA != undefined){
redraw_light_walls();
redraw_elev();
if($(clicked).is("#wall_button")){
redraw_light_walls();
}
else{
$(`[id*='wallHeight']`).remove();
let showWallsToggle = $('#show_walls').hasClass('button-enabled');
let displayWalls = showWallsToggle == true || $('#wall_button').hasClass('button-enabled') || $('.top_menu.visible [data-shape="paint-bucket"]').hasClass('button-enabled')
if(displayWalls){
$('#walls_layer').css('display', '');
}
else{
$('#walls_layer').css('display', 'none');
}
}
if($(clicked).is("#elev_button")){
redraw_elev(true);
}
else{
$('#elev_overlay').css('display', 'none');
close_elev_legend();
}

}
let target = $("#temp_overlay, #black_layer")
data = {
Expand Down Expand Up @@ -4669,7 +4697,8 @@ function init_elev_menu(buttons){
elev_menu.append(`<div class='ddbc-tab-options--layout-pill'>
<button id='elev_legend' class='legend menu-option ddbc-tab-options__header-heading'
data-shape='Legend' data-function="Legend" data-unique-with="Legend">
Legend </button>
Legend
</button>
</div>`)
elev_menu.append("<div class='menu-subtitle'>Controls</div>");
elev_menu.append(`
Expand Down

0 comments on commit 02206bd

Please sign in to comment.