This commit is contained in:
CDeenen
2021-05-05 01:00:18 +02:00
parent bf8c5c0076
commit 484b7a0b7f
39 changed files with 197 additions and 117 deletions

View File

@@ -11,6 +11,7 @@ export class CombatTracker{
async updateAll(){
if (this.active == false) return;
for (let device of streamDeck.buttonContext) {
if (device?.buttons == undefined) continue;
for (let i=0; i<device.buttons.length; i++){
const data = device.buttons[i];
if (data == undefined || data.action != 'combattracker') continue;

View File

@@ -13,6 +13,7 @@ export class ExternalModules{
}
if (this.active == false) return;
for (let device of streamDeck.buttonContext) {
if (device?.buttons == undefined) continue;
for (let i=0; i<device.buttons.length; i++){
const data = device.buttons[i];
if (data == undefined || data.action != 'external') continue;

View File

@@ -11,6 +11,7 @@ export class MacroControl{
async updateAll(){
if (this.active == false) return;
for (let device of streamDeck.buttonContext) {
if (device?.buttons == undefined) continue;
for (let i=0; i<device.buttons.length; i++){
const data = device.buttons[i];
if (data == undefined || data.action != 'macro') continue;
@@ -109,48 +110,51 @@ export class MacroControl{
return uses;
}
async hotbar(macros){
for (let i=0; i<32; i++){
const data = streamDeck.buttonContext[i];
if (data == undefined || data.action != 'macro' || data.settings.macroMode == 'macroBoard') continue;
async hotbar(){
for (let device of streamDeck.buttonContext) {
if (device?.buttons == undefined) continue;
for (let i=0; i<device.buttons.length; i++){
const data = device.buttons[i];
if (data == undefined || data.action != 'macro' || data.settings.macroMode == 'macroBoard') continue;
const context = data.context;
const mode = data.settings.macroMode ? data.settings.macroMode : 'hotbar';
const displayName = data.settings.displayName ? data.settings.displayName : false;
const displayIcon = data.settings.displayIcon ? data.settings.displayIcon : false;
const displayUses = data.settings.displayUses ? data.settings.displayUses : false;
let background = data.settings.background ? data.settings.background : '#000000';
let macroNumber = data.settings.macroNumber;
if(macroNumber == undefined || isNaN(parseInt(macroNumber))) macroNumber = 1;
const context = data.context;
const mode = data.settings.macroMode ? data.settings.macroMode : 'hotbar';
const displayName = data.settings.displayName ? data.settings.displayName : false;
const displayIcon = data.settings.displayIcon ? data.settings.displayIcon : false;
const displayUses = data.settings.displayUses ? data.settings.displayUses : false;
let background = data.settings.background ? data.settings.background : '#000000';
let macroNumber = data.settings.macroNumber;
if(macroNumber == undefined || isNaN(parseInt(macroNumber))) macroNumber = 1;
if ((MODULE.getPermission('MACRO','HOTBAR') == false )) {
streamDeck.noPermission(context,device);
return;
}
if ((MODULE.getPermission('MACRO','HOTBAR') == false )) {
streamDeck.noPermission(context,device);
return;
}
let src = "";
let name = "";
let src = "";
let name = "";
if (mode == 'Macro Board') continue;
let macroId;
if (mode == 'hotbar'){
macroId = game.user.data.hotbar[macroNumber];
if (mode == 'Macro Board') continue;
let macroId;
if (mode == 'hotbar'){
macroId = game.user.data.hotbar[macroNumber];
}
else {
if (macroNumber > 9) macroNumber = 0;
macroId = game.macros.apps[0].macros.find(m => m.key == macroNumber).macro?.id
}
let macro = undefined;
let uses = undefined;
if (macroId != undefined) macro = game.macros._source.find(p => p._id == macroId);
if (macro != undefined && macro != null) {
if (displayName) name += macro.name;
if (displayIcon) src += macro.img;
if (MODULE.hotbarUses && displayUses) uses = await this.getUses(macro);
}
streamDeck.setIcon(context,device,src,{background:background,uses:uses});
streamDeck.setTitle(name,context);
}
else {
if (macroNumber > 9) macroNumber = 0;
macroId = game.macros.apps[0].macros.find(m => m.key == macroNumber).macro?.id
}
let macro = undefined;
let uses = undefined;
if (macroId != undefined) macro = game.macros._source.find(p => p._id == macroId);
if (macro != undefined && macro != null) {
if (displayName) name += macro.name;
if (displayIcon) src += macro.img;
if (MODULE.hotbarUses && displayUses) uses = await this.getUses(macro);
}
streamDeck.setIcon(context,device,src,{background:background,uses:uses});
streamDeck.setTitle(name,context);
}
}

View File

@@ -70,7 +70,7 @@ export class Move{
const selection = settings.selection ? settings.selection : 'selected';
const tokenIdentifier = settings.tokenName ? settings.tokenName : '';
if (selection == 'selected') token = canvas.tokens.children[0].children.find(p => p.id == MODULE.selectedTokenId);
if (selection == 'selected') token = canvas.tokens.controlled[0];
else if (selection != 'selected' && tokenIdentifier == '') {}
else if (selection == 'tokenName') token = canvas.tokens.children[0].children.find(p => p.name == tokenIdentifier);
else if (selection == 'actorName') token = canvas.tokens.children[0].children.find(p => p.actor.name == tokenIdentifier);

View File

@@ -17,10 +17,11 @@ export class OtherControls{
async updateAll(options={}){
if (this.active == false) return;
for (let device of streamDeck.buttonContext) {
if (device?.buttons == undefined) continue;
for (let i=0; i<device.buttons.length; i++){
const data = device.buttons[i];
if (data == undefined || data.action != 'other') continue;
await this.update(data.settings,data.context,device.device);
await this.update(data.settings,data.context,device.device,options);
}
}
}
@@ -240,7 +241,16 @@ export class OtherControls{
}
ui.controls.activeControl = selectedControl.name;
selectedControl.activeTool = selectedControl.activeTool;
canvas.getLayer(selectedControl.layer).activate();
if (compatibleCore("0.8.2")) {
for (let layer of canvas.layers) {
if (layer.options == undefined) continue;
if (layer.options.name == selectedControl.layer) {
layer.activate();
break;
}
}
}
else canvas.getLayer(selectedControl.layer).activate();
}
}
else if (control == 'dispTools'){ //displayed tools
@@ -281,7 +291,16 @@ export class OtherControls{
if (tool == 'open'){ //open category
ui.controls.activeControl = control;
selectedControl.activeTool = selectedControl.activeTool;
canvas.getLayer(selectedControl.layer).activate();
if (compatibleCore("0.8.2")) {
for (let layer of canvas.layers) {
if (layer.options == undefined) continue;
if (layer.options.name == selectedControl.layer) {
layer.activate();
break;
}
}
}
else canvas.getLayer(selectedControl.layer).activate();
}
else {
const selectedTool = selectedControl.tools.find(t => t.name == tool);
@@ -291,7 +310,16 @@ export class OtherControls{
return;
}
ui.controls.activeControl = control;
canvas.getLayer(selectedControl.layer).activate();
if (compatibleCore("0.8.2")) {
for (let layer of canvas.layers) {
if (layer.options == undefined) continue;
if (layer.options.name == selectedControl.layer) {
layer.activate();
break;
}
}
}
else canvas.getLayer(selectedControl.layer).activate();
if (selectedTool.toggle) {
selectedTool.active = !selectedTool.active;
selectedTool.onClick(selectedTool.active);
@@ -378,7 +406,7 @@ export class OtherControls{
let actor;
let tokenControlled = false;
if (MODULE.selectedTokenId != undefined) actor = canvas.tokens.children[0].children.find(p => p.id == MODULE.selectedTokenId).actor;
if (canvas.tokens.controlled[0] != undefined) actor = canvas.tokens.controlled[0].actor;
if (actor != undefined) tokenControlled = true;
let r;
@@ -418,6 +446,7 @@ export class OtherControls{
const background = settings.background ? settings.background : '#000000';
const table = game.tables.getName(name);
if (table == undefined) return;
let txt = settings.displayRollName ? table.name : '';
let src = settings.displayRollIcon ? table.data.img : '';
@@ -509,7 +538,7 @@ export class OtherControls{
if (popOut && options.sidebarTab == sidebarTab) {
ringColor = options.renderPopout ? ringOnColor : ringOffColor;
}
else ringColor = (sidebarTab == 'collapse' && collapsed || (activeTab == sidebarTab)) ? ringOnColor : ringOffColor;
else if (popOut == false) ringColor = (sidebarTab == 'collapse' && collapsed || (activeTab == sidebarTab)) ? ringOnColor : ringOffColor;
const name = settings.displaySidebarName ? this.getSidebarName(sidebarTab) : '';
const icon = settings.displaySidebarIcon ? this.getSidebarIcon(sidebarTab) : '';

View File

@@ -12,6 +12,7 @@ export class PlaylistControl{
async updateAll(){
if (this.active == false) return;
for (let device of streamDeck.buttonContext) {
if (device?.buttons == undefined) continue;
for (let i=0; i<device.buttons.length; i++){
const data = device.buttons[i];
if (data == undefined || data.action != 'playlist') continue;

View File

@@ -12,6 +12,7 @@ export class SceneControl{
async updateAll(){
if (this.active == false) return;
for (let device of streamDeck.buttonContext) {
if (device?.buttons == undefined) continue;
for (let i=0; i<device.buttons.length; i++){
const data = device.buttons[i];
if (data == undefined || data.action != 'scene') continue;

View File

@@ -222,7 +222,8 @@ export const registerSettings = async function() {
if (permissionSettings.permissions.TOKEN.OBSERVER == undefined) permissionSettings.permissions.TOKEN.OBSERVER = [false,true,true,true];
if (permissionSettings.permissions.MACRO.BY_NAME == undefined) permissionSettings.permissions.MACRO.BY_NAME = [false,false,true,true];
}
game.settings.set(MODULE.moduleName,'userPermission',permissionSettings);
if (game.user.isGM)
game.settings.set(MODULE.moduleName,'userPermission',permissionSettings);
}

View File

@@ -14,6 +14,7 @@ export class SoundboardControl{
async updateAll(){
if (this.active == false) return;
for (let device of streamDeck.buttonContext) {
if (device?.buttons == undefined) continue;
for (let i=0; i<device.buttons.length; i++){
const data = device.buttons[i];
if (data == undefined || data.action != 'soundboard') continue;
@@ -171,7 +172,7 @@ export class SoundboardControl{
volume *= game.settings.get("core", "globalAmbientVolume");
if (compatibleCore("0.8.1")) {
let newSound = new SoundNode(src);
let newSound = new Sound(src);
if(newSound.loaded == false) await newSound.load({autoplay:true});
newSound.on('end', ()=>{
if (repeat == false) {

View File

@@ -35,6 +35,7 @@ export class StreamDeck{
}
setContext(device,size,iteration,action,context,coordinates = {column:0,row:0},settings){
if (device == undefined) return;
if (this.buttonContext[iteration] == undefined) {
const deckSize = size.columns*size.rows;
let buttons = [];

View File

@@ -11,6 +11,7 @@ export class TokenControl{
async update(tokenId=null){
if (this.active == false) return;
for (let device of streamDeck.buttonContext) {
if (device?.buttons == undefined) continue;
for (let i=0; i<device.buttons.length; i++){
const data = device.buttons[i];
if (data == undefined || data.action != 'token') continue;
@@ -649,8 +650,7 @@ export class TokenControl{
let skill = settings.skill;
if (skill == undefined) skill = 'acr';
else iconSrc = "modules/MaterialDeck/img/token/skills/" + skill + ".png";
}
}
}
streamDeck.setIcon(context,device,iconSrc,{background:background,ring:ring,ringColor:ringColor,overlay:overlay,uses:uses,hp:hp});
streamDeck.setTitle(txt,context);
@@ -659,13 +659,13 @@ export class TokenControl{
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
async keyPress(settings){
const tokenId = MODULE.selectedTokenId;
const tokenId = canvas.tokens.controlled[0]?.id;
const selection = settings.selection ? settings.selection : 'selected';
const tokenIdentifier = settings.tokenName ? settings.tokenName : '';
let token;
if (selection == 'selected') token = canvas.tokens.children[0].children.find(p => p.id == tokenId);
if (selection == 'selected') token = canvas.tokens.controlled[0];
else if (selection != 'selected' && tokenIdentifier == '') {}
else if (selection == 'tokenName') token = canvas.tokens.children[0].children.find(p => p.name == tokenIdentifier);
else if (selection == 'actorName') token = canvas.tokens.children[0].children.find(p => p.actor.name == tokenIdentifier);
@@ -834,7 +834,7 @@ export class TokenControl{
}
else if (method == 'offset'){
this.wildcardOffset = value;
this.update(MODULE.selectedTokenId);
this.update(canvas.tokens.controlled[0]?.id);
}
else return;