import * as MODULE from "../MaterialDeck.js"; export class StreamDeck{ constructor() { this.pluginId; this.tokenHealthContext; this.tokenNameContext; this.tokenACContext; this.buttonContext = []; for (let i=0; i<23; i++){ this.buttonContext[i] = undefined; } this.playlistTrackBuffer = []; this.playlistSelector = 0; this.trackSelector = 0; for (let i=0; i<23; i++) this.playlistTrackBuffer[i] = {state: 3, name: ""}; this.playlistBuffer = []; for (let i=0; i<3; i++) this.playlistBuffer[i] = {state: 3, name: ""}; this.counter = 0; let canvasBox = document.createElement('div'); canvasBox.id = 'sdCanvasBox'; document.body.appendChild(canvasBox); // adds the canvas to the body element this.syllableRegex = /[^aeiouy]*[aeiouy]+(?:[^aeiouy]*$|[^aeiouy](?=[^aeiouy]))?/gi; } setScreen(action){ } setContext(action,context,coordinates = {column:0,row:0},settings){ const data = { context: context, action: action, settings: settings } let num = coordinates.column + coordinates.row*8; this.buttonContext[num] = data; } clearContext(action,coordinates = {column:0,row:0}){ let num = coordinates.column + coordinates.row*8; this.buttonContext[num] = undefined; if (this.getActive(action) == false){ if (action == 'token') MODULE.tokenControl.active = false; else if (action == 'macro') MODULE.macroControl.active = false; else if (action == 'combattracker') MODULE.combatTracker.active = false; else if (action == 'playlist') MODULE.playlistControl.active = false; else if (action == 'soundboard') MODULE.soundboard.active = false; else if (action == 'other') MODULE.otherControls.active = false; } } getActive(action){ for (let i=0; i0){ txtArray[counter] = ''; counter++; } let txtArrayTemp = txtArrayOriginal[i].split(" "); for (let j=0; j 10){ let syllables = this.syllabify(txtNewPart); for (let j=0; j j) newTxtArray[counter] += '-'; counter++; j++; } else { newTxtArray[counter] = syllables[j]; if (syllables.length > j) newTxtArray[counter] += '-'; counter++; } } } else{ newTxtArray[counter] = txtNewPart; counter++; } } for (let i=0; i 0) txtNew += "\n"; if (i 31) this.counter = 0; let ctx = canvas.getContext("2d"); ctx.filter = "none"; let margin = 0; if (data.ring != undefined && data.ring > 0){ ctx.fillStyle = background; ctx.fillRect(0, 0, canvas.width, canvas.height); margin = 10; if (data.ring == 2) { ctx.fillStyle = data.ringColor; ctx.fillRect(0, 0, canvas.width, canvas.height); ctx.fillStyle = background; ctx.fillRect(margin, margin, canvas.width-2*margin, canvas.height-2*margin); } } else { ctx.fillStyle = background; ctx.fillRect(0, 0, canvas.width, canvas.height); } if (format == 'icon' && url != ""){ ctx.font = '600 90px "Font Awesome 5 Free"'; ctx.fillStyle = "gray"; var elm = document.createElement('i'); elm.className = url; elm.style.display = 'none'; canvas.appendChild(elm); var content = window.getComputedStyle( elm, ':before' ).getPropertyValue('content') canvas.removeChild(elm); const iconMeasurement = ctx.measureText(content[1]); const horOffset = (144-iconMeasurement.width)/2; const vertOffset = 144-(iconMeasurement.actualBoundingBoxAscent-iconMeasurement.actualBoundingBoxDescent)/2; ctx.fillText(content[1], horOffset, vertOffset); } if (format != 'jpg' && format != 'jpeg' && format != 'png' && format != 'webm' && format != 'webp' && format != 'gif' && format != 'svg') url = "modules/MaterialDeck/img/transparant.png"; if (url == "") url = "modules/MaterialDeck/img/transparant.png" let resImageURL = url; let img = new Image(); img.setAttribute('crossorigin', 'anonymous'); img.onload = () => { if (format == 'color') ctx.filter = "opacity(0)"; if (data.overlay) ctx.filter = "brightness(60%)"; //ctx.filter = "brightness(0) saturate(100%) invert(38%) sepia(62%) saturate(2063%) hue-rotate(209deg) brightness(90%) contrast(95%)"; var imageAspectRatio = img.width / img.height; var canvasAspectRatio = canvas.width / canvas.height; var renderableHeight, renderableWidth, xStart, yStart; // If image's aspect ratio is less than canvas's we fit on height // and place the image centrally along width if(imageAspectRatio < canvasAspectRatio) { renderableHeight = canvas.height; renderableWidth = img.width * (renderableHeight / img.height); xStart = (canvas.width - renderableWidth) / 2; yStart = 0; } // If image's aspect ratio is greater than canvas's we fit on width // and place the image centrally along height else if(imageAspectRatio > canvasAspectRatio) { renderableWidth = canvas.width renderableHeight = img.height * (renderableWidth / img.width); xStart = 0; yStart = (canvas.height - renderableHeight) / 2; } // Happy path - keep aspect ratio else { renderableHeight = canvas.height; renderableWidth = canvas.width; xStart = 0; yStart = 0; } ctx.drawImage(img, xStart+margin, yStart+margin, renderableWidth - 2*margin, renderableHeight - 2*margin); var dataURL = canvas.toDataURL(); this.setImage(dataURL,data.context); }; img.src = resImageURL; } }