Skip to content

Commit

Permalink
improved next logic and squashed hover/tooltip errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
Norc committed Jul 30, 2020
1 parent dde4866 commit 0b29793
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 48 deletions.
10 changes: 8 additions & 2 deletions card-hotbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,16 @@ export class cardHotbar extends Hotbar {
* @private
*/
_getcardMacrosByPage(page) {
let nextCard = false;
const macros = this.getcardHotbarMacros(page);
for ( let [i, m] of macros.entries() ) {
m.key = i<9 ? i+1 : 0;
m.cssClass = m.macro ? "active" : "inactive";
//additional logic to mark the first empty slot as "next"
if (m.cssClass == "inactive" && nextCard == false ) {
m.cssClass = "next";
nextCard = true;
}
m.icon = m.macro ? m.macro.data.img : null;
}
return macros;
Expand Down Expand Up @@ -376,10 +382,10 @@ export class cardHotbar extends Hotbar {
_onDragStart(event) {
//hide tooltip so it doesn't get in the way
console.debug("card Hotbar | Attempting to hide tooltip.");
document.getElementsByClassName("tooltip")[0].style.display = "none";

const li = event.currentTarget.closest(".macro");
if ( !li.dataset.macroId ) return false;
document.getElementsByClassName("tooltip")[0].style.display = "none";
const dragData = { type: "Macro", id: li.dataset.macroId, cardSlot: li.dataset.slot };
event.dataTransfer.setData("text/plain", JSON.stringify(dragData));
}
Expand Down Expand Up @@ -426,7 +432,7 @@ export class cardHotbar extends Hotbar {
_onHoverMacro(event) {
event.preventDefault();
const li = event.currentTarget;
const hasAction = !li.classList.contains("inactive");
const hasAction = ( !li.classList.contains("inactive") && !li.classList.contains("next") );

// Remove any existing tooltip
const tooltip = li.querySelector(".tooltip");
Expand Down
50 changes: 4 additions & 46 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,37 +101,9 @@ async function cardHotbarInit() {
});

await ui.cardHotbar.render(true, obj);
Hooks.callAll("cardHotbarReady");
}

async function classifyCards () {
//mark the first inactive macro as "next" for CSS styling and button changing
let cardHand = ui.cardHotbar.macros;
console.debug("Card Hotbar | cardHand defined?");
console.debug(cardHand);
for (var i = 0; i < cardHand.length; ++i) {
console.debug(i);
/*not functional yet
//Math.min(i+1,cardHand.length) && cardHand[i+1].cssClass.includes("inactive") )
if( cardHand[i].cssClass.includes("active") ) {
if( cardHand[i].cssClass.includes("next") ) {
console.log("Card Hotbar | Cleaning up recently filled card slot...");
//change button
cardHand[1].cssClass.replace("next", "");
}
}
*/
if( cardHand[i].cssClass.includes("inactive") ) {
//change button
console.log("Card Hotbar | Marking first inactive card slot as next...");
cardHand[i].cssClass = cardHand[i].cssClass.replace("inactive","") + " next";
console.debug(cardHand[i].cssClass);
return;
}
}
}

Hooks.on("init", async () => {

Hooks.once("init", async () => {
CONFIG.ui.hotbar = class extends Hotbar {
_onDragStart(...arg) {
document.getElementsByClassName("tooltip")[0].style.display = "none";
Expand All @@ -149,7 +121,7 @@ Hooks.on("rendercardHotbar", async () => {
});


Hooks.on('ready', () => {
Hooks.once('ready', () => {
console.debug("Card Hotbar | Foundry setup...");

//Check to make sure that a hotbar rendered before initilizing so that PopOut module windows do not have unwanted card hotbars.
Expand All @@ -164,17 +136,8 @@ Hooks.on('ready', () => {

});


Hooks.on('cardHotbarReady', async () => {
console.debug("Card Hotbar | Card Hotbar ready, performing final cleanup...");
classifyCards();
});

Hooks.on('rendercardHotbar', async () => {
console.debug("Card Hotbar | Reclassifying Card Hotbar macros...");
//overwritten by normal logic still
//squash a few random undefined errors
classifyCards();
console.debug("Card Hotbar | Card Hotbar rendered.");
});


Expand Down Expand Up @@ -225,11 +188,6 @@ Hooks.on("hotbarDrop", (hotbar, data, slot) => {
return false;
});

//FROM MQOL:
/* when fixed replace with Hooks.on("hotbarDrop", hotbarHandler)
Hooks._hooks.hotbarDrop = [hotbarHandler].concat(Hooks._hooks.hotbarDrop || []);
*/

/* NOTE: ERRORS/ISSUES WITH CORE HOTBAR (LOL, SHRUG)
0.6.4, DND 5E 0.93 (ALL MODS DISABLED)
Expand Down

0 comments on commit 0b29793

Please sign in to comment.