This commit is contained in:
CDeenen
2021-01-07 05:38:16 +01:00
parent 2947c54eb8
commit 888b089e7b
20 changed files with 690 additions and 402 deletions

View File

@@ -8,6 +8,7 @@ import {PlaylistControl} from "./src/playlist.js";
import {SoundboardControl} from "./src/soundboard.js"; import {SoundboardControl} from "./src/soundboard.js";
import {OtherControls} from "./src/othercontrols.js"; import {OtherControls} from "./src/othercontrols.js";
import {ExternalModules} from "./src/external.js"; import {ExternalModules} from "./src/external.js";
import {SceneControl} from "./src/scene.js";
export var streamDeck; export var streamDeck;
export var tokenControl; export var tokenControl;
var move; var move;
@@ -17,6 +18,7 @@ export var playlistControl;
export var soundboard; export var soundboard;
export var otherControls; export var otherControls;
export var externalModules; export var externalModules;
export var sceneControl;
export const moduleName = "MaterialDeck"; export const moduleName = "MaterialDeck";
export var selectedTokenId; export var selectedTokenId;
@@ -50,6 +52,7 @@ async function analyzeWSmessage(msg){
if (data.type == "connected" && data.data == "SD"){ if (data.type == "connected" && data.data == "SD"){
console.log("streamdeck connected to server"); console.log("streamdeck connected to server");
streamDeck.resetImageBuffer();
} }
if (data == undefined || data.payload == undefined) return; if (data == undefined || data.payload == undefined) return;
@@ -86,6 +89,8 @@ async function analyzeWSmessage(msg){
otherControls.update(settings,context); otherControls.update(settings,context);
else if (action == 'external') else if (action == 'external')
externalModules.update(settings,context); externalModules.update(settings,context);
else if (action == 'scene')
sceneControl.update(settings,context);
} }
else if (event == 'willDisappear'){ else if (event == 'willDisappear'){
@@ -106,9 +111,11 @@ async function analyzeWSmessage(msg){
else if (action == 'soundboard') else if (action == 'soundboard')
soundboard.keyPressDown(settings); soundboard.keyPressDown(settings);
else if (action == 'other') else if (action == 'other')
otherControls.keyPress(settings); otherControls.keyPress(settings,context);
else if (action == 'external') else if (action == 'external')
externalModules.keyPress(settings,context); externalModules.keyPress(settings,context);
else if (action == 'scene')
sceneControl.keyPress(settings);
} }
else if (event == 'keyUp'){ else if (event == 'keyUp'){
@@ -210,7 +217,7 @@ Hooks.once('ready', ()=>{
playlistControl = new PlaylistControl(); playlistControl = new PlaylistControl();
otherControls = new OtherControls(); otherControls = new OtherControls();
externalModules = new ExternalModules(); externalModules = new ExternalModules();
sceneControl = new SceneControl();
let soundBoardSettings = game.settings.get(moduleName,'soundboardSettings'); let soundBoardSettings = game.settings.get(moduleName,'soundboardSettings');
let macroSettings = game.settings.get(moduleName, 'macroSettings'); let macroSettings = game.settings.get(moduleName, 'macroSettings');
@@ -294,18 +301,18 @@ Hooks.on('controlToken',(token,controlled)=>{
Hooks.on('renderHotbar', (hotbar)=>{ Hooks.on('renderHotbar', (hotbar)=>{
if (enableModule == false || ready == false) return; if (enableModule == false || ready == false) return;
macroControl.hotbar(hotbar.macros); if (macroControl != undefined) macroControl.hotbar(hotbar.macros);
}); });
Hooks.on('renderCombatTracker',()=>{ Hooks.on('renderCombatTracker',()=>{
if (enableModule == false || ready == false) return; if (enableModule == false || ready == false) return;
combatTracker.updateAll(); if (combatTracker != undefined) combatTracker.updateAll();
tokenControl.update(selectedTokenId); if (tokenControl != undefined) tokenControl.update(selectedTokenId);
}); });
Hooks.on('renderPlaylistDirectory', (playlistDirectory)=>{ Hooks.on('renderPlaylistDirectory', (playlistDirectory)=>{
if (enableModule == false || ready == false) return; if (enableModule == false || ready == false) return;
playlistControl.updateAll(); if (playlistControl != undefined) playlistControl.updateAll();
}); });
Hooks.on('closeplaylistConfigForm', (form)=>{ Hooks.on('closeplaylistConfigForm', (form)=>{
@@ -321,17 +328,19 @@ Hooks.on('pauseGame',()=>{
Hooks.on('renderSidebarTab',()=>{ Hooks.on('renderSidebarTab',()=>{
if (enableModule == false || ready == false) return; if (enableModule == false || ready == false) return;
otherControls.updateAll(); if (otherControls != undefined) otherControls.updateAll();
if (sceneControl != undefined) sceneControl.updateAll();
}); });
Hooks.on('updateScene',()=>{ Hooks.on('updateScene',()=>{
if (enableModule == false || ready == false) return; if (enableModule == false || ready == false) return;
otherControls.updateAll(); sceneControl.updateAll();
externalModules.updateAll(); externalModules.updateAll();
otherControls.updateAll();
}); });
Hooks.on('renderSceneControls',()=>{ Hooks.on('renderSceneControls',()=>{
if (enableModule == false || ready == false) return; if (enableModule == false || ready == false || otherControls == undefined) return;
otherControls.updateAll(); otherControls.updateAll();
}); });

View File

@@ -71,7 +71,7 @@ Instructions and more info can be found in the <a href="https://github.com/CDeen
Module manifest: https://raw.githubusercontent.com/CDeenen/MaterialDeck/Master/module.json Module manifest: https://raw.githubusercontent.com/CDeenen/MaterialDeck/Master/module.json
## Software Versions & Module Incompatibilities ## Software Versions & Module Incompatibilities
<b>Foundry VTT:</b> Tested on 0.7.5-0.7.9<br> <b>Foundry VTT:</b> Tested on 0.7.7<br>
<b>Module Incompatibilities:</b> None known.<br> <b>Module Incompatibilities:</b> None known.<br>
## Feedback ## Feedback

View File

@@ -1,4 +1,31 @@
# Changelog Material Deck Module # Changelog Material Deck Module
### v1.2.1 - 07-01-2021
<b>Note:</b> Due to a change in how scene control is handled (moved from 'Other Controls' to its own 'Scene Action'), any actions related to scenes no longer work. You will have to set them up again using the new Scene Action.<br>
<br>
Additions:
<ul>
<li>(EXPERIMENTAL) Added an image buffer to prevent resending of images that have already been sent, giving a slight performance boost. Buffer size can be set in the module settings</li>
<li>Token Action => Display Stats: Added option to select a data path for an attribute</li>
<li>External Modules => GM Screen: Open and close the GM screen. Link to module: https://foundryvtt.com/packages/gm-screen/</li>
<li>Other Actions => Roll dice: Roll dice in foundry and select between public roll, private roll, or displaying result on the SD</li>
<li>Scene Action: Added way to create scene selection screen similar to soundboard/macro board. New functions to do this: 'Scene Directory' and 'Scene Offset'</li>
<li>Scene Action: Added 'Active Scene' function</li>
<li>Move Action => Selected Token: Added rotate to and rotate by functions</li>
<li>Token Action => On Click: Added 'Set Vision' option to set the token's vision and light emission</li>
<li>Other Actions => Send Chat Message: Send a message to the Foundry chat</li>
</ul>
Other Changes:
<ul>
<li>Plugin: Scene Action created that replaces Other Actions => Scene Selection</li>
<li>Plugin: Scene Action: Changed 'Any Scene' to 'Scene by Name'</li>
<li>Plugin: Actions are now ordered alphabetically</li>
<li>Plugin: Replaced color strings with color pickers</li>
<li>Various minor bug fixes</li>
</ul>
<b>Compatible server app and SD plugin:</b><br>
Material Server v1.0.2 (unchanged): https://github.com/CDeenen/MaterialServer/releases <br>
SD plugin v1.2.1: https://github.com/CDeenen/MaterialDeck_SD/releases<br>
### v1.2.0 - 28-12-2020 ### v1.2.0 - 28-12-2020
Fixes Fixes
<ul> <ul>

BIN
img/.thumb/black.png.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
img/black.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

View File

@@ -1,2 +1,3 @@
center.png: made by me center.png: made by me.
rotatecw.png & rotateccw.png Edited from https://fontawesome.com/icons/sync-alt?style=solid.
All other images taken from freepngimg.com, iverted color and rotated. Source: https://freepngimg.com/png/24691-right-arrow-hd All other images taken from freepngimg.com, iverted color and rotated. Source: https://freepngimg.com/png/24691-right-arrow-hd

BIN
img/move/rotateccw.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

BIN
img/move/rotatecw.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

View File

@@ -14,6 +14,8 @@
"MaterialDeck.Sett.SoundboardConfig": "Soundboard Configuration", "MaterialDeck.Sett.SoundboardConfig": "Soundboard Configuration",
"MaterialDeck.Sett.ServerAddr": "Material Server Address", "MaterialDeck.Sett.ServerAddr": "Material Server Address",
"MaterialDeck.Sett.ServerAddrHint": "Fill in the IP address and port of the Material Server. Must follow the format [ip_address]:[port], for example: 'localhost:3001' or '192.168.1.1:4000'.", "MaterialDeck.Sett.ServerAddrHint": "Fill in the IP address and port of the Material Server. Must follow the format [ip_address]:[port], for example: 'localhost:3001' or '192.168.1.1:4000'.",
"MaterialDeck.Sett.ImageBuffer": "Image Buffer Size (EXPERIMENTAL)",
"MaterialDeck.Sett.ImageBufferHint": "Sets the amount of images to store in the image buffer. The image buffer will store all images sent to the Steram Deck in a buffer. This greatly improves the update speed, but can use big amounts of memory if set too high.",
"MaterialDeck.PL.Unrestricted": "Unrestricted", "MaterialDeck.PL.Unrestricted": "Unrestricted",
"MaterialDeck.PL.OneTrackPlaylist": "One track per playlist", "MaterialDeck.PL.OneTrackPlaylist": "One track per playlist",

View File

@@ -2,7 +2,7 @@
"name": "MaterialDeck", "name": "MaterialDeck",
"title": "Material Deck", "title": "Material Deck",
"description": "Material Deck allows you to control Foundry using an Elgato Stream Deck", "description": "Material Deck allows you to control Foundry using an Elgato Stream Deck",
"version": "1.2.0", "version": "1.2.1",
"author": "CDeenen", "author": "CDeenen",
"esmodules": [ "esmodules": [
"./MaterialDeck.js" "./MaterialDeck.js"

View File

@@ -18,28 +18,23 @@ export class CombatTracker{
update(settings,context){ update(settings,context){
this.active = true; this.active = true;
let ctFunction = settings.combatTrackerFunction; const ctFunction = settings.combatTrackerFunction ? settings.combatTrackerFunction : 'startStop';
if (ctFunction == undefined) ctFunction = 'startStop'; const mode = settings.combatTrackerMode ? settings.combatTrackerMode : 'combatants';
const combat = game.combat;
let combat = game.combat;
let src = "modules/MaterialDeck/img/black.png"; let src = "modules/MaterialDeck/img/black.png";
let txt = ""; let txt = "";
let background = "#000000"; let background = "#000000";
let mode = settings.combatTrackerMode;
if (mode == undefined) mode = 'combatants';
if (mode == 'combatants'){ if (mode == 'combatants'){
if (combat != null && combat != undefined && combat.turns.length != 0){ if (combat != null && combat != undefined && combat.turns.length != 0){
let initiativeOrder = combat.turns; const initiativeOrder = combat.turns;
let nr = settings.combatantNr - 1; let nr = settings.combatantNr - 1;
if (nr == undefined || nr < 1) nr = 0; if (nr == undefined || nr < 1) nr = 0;
let combatantState = 1; const combatantState = (nr == combat.turn) ? 2 : 1;
if (nr == combat.turn) combatantState = 2; const combatant = initiativeOrder[nr]
let combatant = initiativeOrder[nr]
if (combatant != undefined){ if (combatant != undefined){
let tokenId = combatant.tokenId; const tokenId = combatant.tokenId;
tokenControl.pushData(tokenId,settings,context,combatantState,'#cccc00'); tokenControl.pushData(tokenId,settings,context,combatantState,'#cccc00');
return; return;
} }
@@ -55,7 +50,7 @@ export class CombatTracker{
} }
else if (mode == 'currentCombatant'){ else if (mode == 'currentCombatant'){
if (combat != null && combat != undefined && combat.started){ if (combat != null && combat != undefined && combat.started){
let tokenId = combat.combatant.tokenId; const tokenId = combat.combatant.tokenId;
tokenControl.pushData(tokenId,settings,context); tokenControl.pushData(tokenId,settings,context);
} }
else { else {
@@ -64,7 +59,6 @@ export class CombatTracker{
} }
} }
else if (mode == 'function'){ else if (mode == 'function'){
if (ctFunction == 'startStop') { if (ctFunction == 'startStop') {
if (combat == null || combat == undefined || combat.combatants.length == 0) { if (combat == null || combat == undefined || combat.combatants.length == 0) {
src = "modules/MaterialDeck/img/combattracker/startcombat.png"; src = "modules/MaterialDeck/img/combattracker/startcombat.png";
@@ -111,15 +105,12 @@ export class CombatTracker{
} }
keyPress(settings,context){ keyPress(settings,context){
let mode = settings.combatTrackerMode; const mode = settings.combatTrackerMode ? settings.combatTrackerMode : 'combatants';
if (mode == undefined) mode = 'combatants'; const combat = game.combat;
if (mode == 'function'){
let combat = game.combat;
if (combat == null || combat == undefined) return;
let ctFunction = settings.combatTrackerFunction; if (mode == 'function'){
if (ctFunction == undefined) ctFunction = 'startStop'; if (combat == null || combat == undefined) return;
const ctFunction = settings.combatTrackerFunction ? settings.combatTrackerFunction : 'startStop';
if (ctFunction == 'startStop'){ if (ctFunction == 'startStop'){
let src; let src;
let background; let background;
@@ -144,19 +135,14 @@ export class CombatTracker{
else if (ctFunction == 'prevRound') game.combat.previousRound(); else if (ctFunction == 'prevRound') game.combat.previousRound();
} }
else { else {
let onClick = settings.onClick; const onClick = settings.onClick ? settings.onClick : 'doNothing';
if (onClick == undefined) onClick = 'doNothing';
let tokenId; let tokenId;
let combat = game.combat;
if (mode == 'combatants') { if (mode == 'combatants') {
if (combat != null && combat != undefined && combat.turns.length != 0){ if (combat != null && combat != undefined && combat.turns.length != 0){
let initiativeOrder = combat.turns; const initiativeOrder = combat.turns;
let nr = settings.combatantNr - 1; let nr = settings.combatantNr - 1;
if (nr == undefined || nr < 1) nr = 0; if (nr == undefined || nr < 1) nr = 0;
let combatantState = 1; const combatant = initiativeOrder[nr]
if (nr == combat.turn) combatantState = 2;
let combatant = initiativeOrder[nr]
if (combatant == undefined) return; if (combatant == undefined) return;
tokenId = combatant.tokenId; tokenId = combatant.tokenId;
} }
@@ -165,8 +151,7 @@ export class CombatTracker{
if (combat != null && combat != undefined && combat.started) if (combat != null && combat != undefined && combat.started)
tokenId = combat.combatant.tokenId; tokenId = combat.combatant.tokenId;
let token let token = (canvas.tokens.children[0] != undefined) ? canvas.tokens.children[0].children.find(p => p.id == tokenId) : undefined;
if (canvas.tokens.children[0] != undefined) token = canvas.tokens.children[0].children.find(p => p.id == tokenId);
if (token == undefined) return; if (token == undefined) return;
if (onClick == 'doNothing') //Do nothing if (onClick == 'doNothing') //Do nothing
return; return;
@@ -178,7 +163,7 @@ export class CombatTracker{
canvas.animatePan(location); canvas.animatePan(location);
} }
else if (onClick == 'centerSelect'){ //center on token and select else if (onClick == 'centerSelect'){ //center on token and select
let location = token.getCenter(token.x,token.y); const location = token.getCenter(token.x,token.y);
canvas.animatePan(location); canvas.animatePan(location);
token.control(); token.control();
} }

View File

@@ -21,6 +21,7 @@ export class ExternalModules{
if (module == undefined) module = 'fxmaster'; if (module == undefined) module = 'fxmaster';
if (module == 'fxmaster') this.updateFxMaster(settings,context); if (module == 'fxmaster') this.updateFxMaster(settings,context);
else if (module == 'gmscreen') this.updateGMScreen(settings,context);
} }
@@ -29,9 +30,17 @@ export class ExternalModules{
let module = settings.module; let module = settings.module;
if (module == undefined) module = 'fxmaster'; if (module == undefined) module = 'fxmaster';
if (module == 'fxmaster') { //scene if (module == 'fxmaster')
this.keyPressFxMaster(settings,context); this.keyPressFxMaster(settings,context);
} else if (module == 'gmscreen')
this.keyPressGMScreen(settings,context);
}
getModuleEnable(moduleId){
const module = game.modules.get(moduleId);
if (module == undefined || module.active == false) return false;
return true;
} }
////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -231,4 +240,31 @@ export class ExternalModules{
} }
return undefined; return undefined;
} }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//GM Screen
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
updateGMScreen(settings,context){
if (this.getModuleEnable("gm-screen") == false) return;
const background = settings.gmScreenBackground ? settings.gmScreenBackground : '#000000';
let ring = 1;
let ringColor = '#00FF00'
let src = '';
let txt = '';
//if (document.getElementsByClassName("gm-screen-app gm-screen-drawer expanded")[0] != undefined) ring = 2;
if (settings.displayGmScreenIcon) src = "fas fa-book-reader";
streamDeck.setIcon(context,src,background,ring,ringColor);
if (settings.displayGmScreenName) txt = game.i18n.localize(`GMSCR.gmScreen.Open`);
streamDeck.setTitle(txt,context);
}
keyPressGMScreen(settings,context){
if (this.getModuleEnable("gm-screen") == false) return;
document.getElementsByClassName("gm-screen-button")[0].click();
}
} }

View File

@@ -7,59 +7,84 @@ export class Move{
} }
update(settings,context){ update(settings,context){
let background; const background = settings.background ? settings.background : '#000000';
if (settings.background) background = settings.background; const mode = settings.mode ? settings.mode : 'canvas';
else background = '#000000'; const type = settings.type ? settings.type : 'move';
let url = ''; let url = '';
if (settings.dir == 'center') //center if (mode == 'canvas' || (mode == 'selectedToken' && type == 'move')){
url = "modules/MaterialDeck/img/move/center.png"; const dir = settings.dir ? settings.dir : 'center';
else if (settings.dir == 'up') //up if (dir == 'center') //center
url = "modules/MaterialDeck/img/move/up.png"; url = "modules/MaterialDeck/img/move/center.png";
else if (settings.dir == 'down') //down else if (dir == 'up') //up
url = "modules/MaterialDeck/img/move/down.png"; url = "modules/MaterialDeck/img/move/up.png";
else if (settings.dir == 'right') //right else if (dir == 'down') //down
url = "modules/MaterialDeck/img/move/right.png"; url = "modules/MaterialDeck/img/move/down.png";
else if (settings.dir == 'left') //left else if (dir == 'right') //right
url = "modules/MaterialDeck/img/move/left.png"; url = "modules/MaterialDeck/img/move/right.png";
else if (settings.dir == 'upRight') else if (dir == 'left') //left
url = "modules/MaterialDeck/img/move/upright.png"; url = "modules/MaterialDeck/img/move/left.png";
else if (settings.dir == 'upLeft') else if (dir == 'upRight')
url = "modules/MaterialDeck/img/move/upleft.png"; url = "modules/MaterialDeck/img/move/upright.png";
else if (settings.dir == 'downRight') else if (dir == 'upLeft')
url = "modules/MaterialDeck/img/move/downright.png"; url = "modules/MaterialDeck/img/move/upleft.png";
else if (settings.dir == 'downLeft') else if (dir == 'downRight')
url = "modules/MaterialDeck/img/move/downleft.png"; url = "modules/MaterialDeck/img/move/downright.png";
else if (settings.dir == 'zoomIn') else if (dir == 'downLeft')
url = "modules/MaterialDeck/img/move/zoomin.png"; url = "modules/MaterialDeck/img/move/downleft.png";
else if (settings.dir == 'zoomOut') else if (dir == 'zoomIn')
url = "modules/MaterialDeck/img/move/zoomout.png"; url = "modules/MaterialDeck/img/move/zoomin.png";
else if (dir == 'zoomOut')
url = "modules/MaterialDeck/img/move/zoomout.png";
}
else if (mode == 'selectedToken' && type == 'rotate'){
const value = isNaN(parseInt(settings.rotValue)) ? 0 : parseInt(settings.rotValue);
if (value >= 0)
url = "modules/MaterialDeck/img/move/rotatecw.png";
else
url = "modules/MaterialDeck/img/move/rotateccw.png";
}
streamDeck.setIcon(context,url,background); streamDeck.setIcon(context,url,background);
} }
keyPress(settings){ keyPress(settings){
if (canvas.scene == null) return; if (canvas.scene == null) return;
let dir = settings.dir; const dir = settings.dir ? settings.dir : 'center';
let mode = settings.mode; const mode = settings.mode ? settings.mode : 'canvas';
if (mode == undefined) mode = 'canvas'; const type = settings.type ? settings.type : 'move';
if (dir == undefined) dir = 'center';
if (dir == 'zoomIn') {//zoom in if (type == 'move'){
let viewPosition = canvas.scene._viewPosition; if (dir == 'zoomIn') {//zoom in
viewPosition.scale = viewPosition.scale*1.05; let viewPosition = canvas.scene._viewPosition;
viewPosition.duration = 100; viewPosition.scale = viewPosition.scale*1.05;
canvas.animatePan(viewPosition); viewPosition.duration = 100;
canvas.animatePan(viewPosition);
}
else if (dir == 'zoomOut') {//zoom out
let viewPosition = canvas.scene._viewPosition;
viewPosition.scale = viewPosition.scale*0.95;
viewPosition.duration = 100;
canvas.animatePan(viewPosition);
}
else {
if (settings.mode == 'selectedToken')
this.moveToken(MODULE.selectedTokenId,dir);
else
this.moveCanvas(dir);
}
} }
else if (dir == 'zoomOut') {//zoom out else if (type == 'rotate' && mode == 'selectedToken'){
let viewPosition = canvas.scene._viewPosition; const token = canvas.tokens.children[0].children.find(p => p.id == MODULE.selectedTokenId);
viewPosition.scale = viewPosition.scale*0.95; if (token == undefined) return;
viewPosition.duration = 100;
canvas.animatePan(viewPosition); const rotType = settings.rot ? settings.rot : 'to';
} const value = isNaN(parseInt(settings.rotValue)) ? 0 : parseInt(settings.rotValue);
else {
if (settings.mode == 'selectedToken') let rotationVal;
this.moveToken(MODULE.selectedTokenId,dir); if (rotType == 'by') rotationVal = token.data.rotation + value;
else else if (rotType == 'to') rotationVal = value;
this.moveCanvas(dir);
token.update({rotation: rotationVal});
} }
} }

View File

@@ -4,7 +4,7 @@ import {streamDeck} from "../MaterialDeck.js";
export class OtherControls{ export class OtherControls{
constructor(){ constructor(){
this.active = false; this.active = false;
this.offset = 0; this.rollData = {};
} }
async updateAll(){ async updateAll(){
@@ -18,108 +18,75 @@ export class OtherControls{
update(settings,context){ update(settings,context){
this.active = true; this.active = true;
let mode = settings.otherMode; const mode = settings.otherMode ? settings.otherMode : 'pause';
if (mode == undefined) mode = 'pause';
if (mode == 'pause') { //pause if (mode == 'pause') //pause
this.updatePause(settings.pauseFunction,context); this.updatePause(settings,context);
} else if (mode == 'controlButtons') //control buttons
else if (mode == 'sceneSelect') { //scene selection
this.updateScene(settings,context);
}
else if (mode == 'controlButtons'){ //control buttons
this.updateControl(settings,context); this.updateControl(settings,context);
} else if (mode == 'darkness') //darkness
else if (mode == 'darkness'){ //darkness
this.updateDarkness(settings,context); this.updateDarkness(settings,context);
} else if (mode == 'rollDice') //roll dice
else if (mode == 'rollTables'){ //roll tables this.updateRollDice(settings,context);
else if (mode == 'rollTables') //roll tables
this.updateRollTable(settings,context); this.updateRollTable(settings,context);
} else if (mode == 'sidebarTab') //open sidebar tab
else if (mode == 'sidebarTab') { //open sidebar tab
this.updateSidebar(settings,context); this.updateSidebar(settings,context);
} else if (mode == 'compendium') //open compendium
else if (mode == 'compendium') { //open compendium
this.updateCompendium(settings,context); this.updateCompendium(settings,context);
} else if (mode == 'journal') //open journal
else if (mode == 'journal') { //open journal
this.updateJournal(settings,context); this.updateJournal(settings,context);
} else if (mode == 'chatMessage')
this.updateChatMessage(settings,context);
} }
keyPress(settings){ keyPress(settings,context){
let mode = settings.otherMode; const mode = settings.otherMode ? settings.otherMode : 'pause';
if (mode == undefined) mode = 'pause';
if (mode == 'pause') { //pause if (mode == 'pause') //pause
this.keyPressPause(settings.pauseFunction); this.keyPressPause(settings);
} else if (mode == 'controlButtons') //control buttons
else if (mode == 'sceneSelect') { //scene
this.keyPressScene(settings);
}
else if (mode == 'controlButtons') { //control buttons
this.keyPressControl(settings); this.keyPressControl(settings);
} else if (mode == 'darkness') //darkness controll
else if (mode == 'darkness') { //darkness controll
this.keyPressDarkness(settings); this.keyPressDarkness(settings);
} else if (mode == 'rollDice') //roll dice
else if (mode == 'rollTables') { //roll tables this.keyPressRollDice(settings,context);
else if (mode == 'rollTables') //roll tables
this.keyPressRollTable(settings); this.keyPressRollTable(settings);
} else if (mode == 'sidebarTab') //sidebar
else if (mode == 'sidebarTab') { //sidebar
this.keyPressSidebar(settings); this.keyPressSidebar(settings);
} else if (mode == 'compendium') //open compendium
else if (mode == 'compendium') { //open compendium
this.keyPressCompendium(settings); this.keyPressCompendium(settings);
} else if (mode == 'journal') //open journal
else if (mode == 'journal') { //open journal
this.keyPressJournal(settings); this.keyPressJournal(settings);
} else if (mode == 'chatMessage')
this.keyPressChatMessage(settings);
} }
////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////
updatePause(pauseFunction,context){ updatePause(settings,context){
let src = ""; let src = "";
if (pauseFunction == undefined) pauseFunction = 'pause'; const pauseFunction = settings.pauseFunction ? settings.pauseFunction : 'pause';
const background = settings.background ? settings.background : '#000000';
let background = settings.background; const ringOffColor = settings.offRing ? settings.offRing : '#000000';
if(background == undefined) background = '#000000'; const ringOnColor = settings.onRing ? settings.onRing : '#00FF00';
let ringColor = game.paused ? ringOnColor : ringOffColor;
let ringColor = "#000000"; if (pauseFunction == 'pause') //Pause game
let ringOffColor = settings.offRing;
if (ringOffColor == undefined) ringOffColor = '#000000';
let ringOnColor = settings.onRing;
if (ringOnColor == undefined) ringOnColor = '#00FF00';
let playlistType = settings.playlistType;
if (playlistType == undefined) playlistType = 0;
if (pauseFunction == 'pause'){ //Pause game
if (game.paused) ringColor = ringOnColor;
else ringColor = ringOffColor;
src = 'modules/MaterialDeck/img/other/pause/pause.png'; src = 'modules/MaterialDeck/img/other/pause/pause.png';
//src = 'action/images/other/pause/pause.png';
}
else if (pauseFunction == 'resume'){ //Resume game else if (pauseFunction == 'resume'){ //Resume game
if (game.paused == false) ringColor = ringOnColor; ringColor = game.paused ? ringOffColor : ringOnColor;
else ringColor = ringOffColor;
src = 'modules/MaterialDeck/img/other/pause/resume.png'; src = 'modules/MaterialDeck/img/other/pause/resume.png';
//src = 'action/images/other/pause/resume.png';
} }
else if (pauseFunction == 'toggle') { //toggle else if (pauseFunction == 'toggle') //toggle
if (game.paused == false) ringColor = ringOnColor;
else ringColor = ringOffColor;
src = 'modules/MaterialDeck/img/other/pause/playpause.png'; src = 'modules/MaterialDeck/img/other/pause/playpause.png';
//src = 'action/images/other/pause/playpause.png';
}
streamDeck.setIcon(context,src,background,2,ringColor,true); streamDeck.setIcon(context,src,background,2,ringColor,true);
} }
keyPressPause(pauseFunction){ keyPressPause(settings){
if (pauseFunction == undefined) pauseFunction = 'pause'; const pauseFunction = settings.pauseFunction ? settings.pauseFunction : 'pause';
if (pauseFunction == 'pause'){ //Pause game if (pauseFunction == 'pause'){ //Pause game
if (game.paused) return; if (game.paused) return;
game.togglePause(); game.togglePause();
@@ -133,122 +100,13 @@ export class OtherControls{
} }
} }
//////////////////////////////////////////////////////////////////////////////////////////////////
updateScene(settings,context){
if (canvas.scene == null) return;
let func = settings.sceneFunction;
if (func == undefined) func = 'visible';
let background = settings.background;
if(background == undefined) background = '#000000';
let ringColor = "#000000";
let ringOffColor = settings.offRing;
if (ringOffColor == undefined) ringOffColor = '#000000';
let ringOnColor = settings.onRing;
if (ringOnColor == undefined) ringOnColor = '#00FF00';
let src = "";
let name = "";
if (func == 'visible'){ //visible scenes
let nr = parseInt(settings.sceneNr);
if (isNaN(nr)) nr = 1;
nr--;
let scene = game.scenes.apps[0].scenes[nr];
if (scene != undefined){
if (scene.isView)
ringColor = ringOnColor;
else
ringColor = ringOffColor;
if (settings.displaySceneName) name = scene.name;
if (settings.displaySceneIcon) src = scene.img;
if (scene.active) name += "\n(Active)";
}
}
else if (func == 'any') { //all scenes
if (settings.sceneName == undefined || settings.sceneName == '') return;
let scene = game.scenes.apps[1].entities.find(p=>p.data.name == settings.sceneName);
if (scene != undefined){
if (scene.isView)
ringColor = ringOnColor;
else
ringColor = ringOffColor;
if (settings.displaySceneName) name = scene.name;
if (settings.displaySceneIcon) src = scene.img;
if (scene.active) name += "\n(Active)";
}
}
streamDeck.setTitle(name,context);
streamDeck.setIcon(context,src,background,2,ringColor);
}
keyPressScene(settings){
let func = settings.sceneFunction;
if (func == undefined) func = 'visible';
if (func == 'visible'){ //visible scenes
let viewFunc = settings.sceneViewFunction;
if (viewFunc == undefined) viewFunc = 'view';
let nr = parseInt(settings.sceneNr);
if (isNaN(nr)) nr = 1;
nr--;
let scene = game.scenes.apps[0].scenes[nr];
if (scene != undefined){
if (viewFunc == 'view'){
scene.view();
}
else if (viewFunc == 'activate'){
scene.activate();
}
else {
if (scene.isView) scene.activate();
scene.view();
}
}
}
else if (func == 'any'){ //any scene
if (settings.sceneName == undefined || settings.sceneName == '') return;
const scenes = game.scenes.entries;
let scene = game.scenes.apps[1].entities.find(p=>p.data.name == settings.sceneName);
if (scene == undefined) return;
let viewFunc = settings.sceneViewFunction;
if (viewFunc == undefined) viewFunc = 'view';
if (viewFunc == 'view'){
scene.view();
}
else if (viewFunc == 'activate'){
scene.activate();
}
else {
if (scene.isView) scene.activate();
scene.view();
}
}
}
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
updateControl(settings,context){ updateControl(settings,context){
let control = settings.control; const control = settings.control ? settings.control : 'dispControls';
if (control == undefined) control = 'dispControls'; const tool = settings.tool ? settings.tool : 'open';
let background = settings.background ? settings.background : '#000000';
let tool = settings.tool;
if (tool == undefined) tool = 'open';
let background = settings.background;
if (background == undefined) background = '#000000';
let ringColor = '#000000' let ringColor = '#000000'
let txt = ""; let txt = "";
let src = ""; let src = "";
const activeControl = ui.controls.activeControl; const activeControl = ui.controls.activeControl;
@@ -282,10 +140,7 @@ export class OtherControls{
src = selectedTool.icon; src = selectedTool.icon;
if (selectedTool.toggle){ if (selectedTool.toggle){
background = "#340057" background = "#340057"
if (selectedTool.active) ringColor = selectedTool.active ? "#A600FF" : "#340057";
ringColor = "#A600FF"
else
ringColor = "#340057";
} }
else if (activeTool == selectedTool.name) else if (activeTool == selectedTool.name)
ringColor = "#FF7B00"; ringColor = "#FF7B00";
@@ -307,11 +162,8 @@ export class OtherControls{
txt = game.i18n.localize(selectedTool.title); txt = game.i18n.localize(selectedTool.title);
src = selectedTool.icon; src = selectedTool.icon;
if (selectedTool.toggle){ if (selectedTool.toggle){
background = "#340057" background = "#340057";
if (selectedTool.active) ringColor = selectedTool.active ? "#A600FF" : "#340057";
ringColor = "#A600FF"
else
ringColor = "#340057"
} }
else if (activeTool == selectedTool.name && activeControl == selectedControl.name) else if (activeTool == selectedTool.name && activeControl == selectedControl.name)
ringColor = "#FF7B00"; ringColor = "#FF7B00";
@@ -325,11 +177,8 @@ export class OtherControls{
keyPressControl(settings){ keyPressControl(settings){
if (canvas.scene == null) return; if (canvas.scene == null) return;
let control = settings.control; const control = settings.control ? settings.control : 'dispControls';
if (control == undefined) control = 'dispControls'; const tool = settings.tool ? settings.tool : 'open';
let tool = settings.tool;
if (tool == undefined) tool = 'open';
if (control == 'dispControls'){ //displayed controls if (control == 'dispControls'){ //displayed controls
let controlNr = parseInt(settings.controlNr); let controlNr = parseInt(settings.controlNr);
@@ -394,14 +243,9 @@ export class OtherControls{
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
updateDarkness(settings,context){ updateDarkness(settings,context){
let func = settings.darknessFunction; const func = settings.darknessFunction ? settings.darknessFunction : 'value';
if (func == undefined) func = 'value'; const value = parseFloat(settings.darknessValue) ? parseFloat(settings.darknessValue) : 0;
const background = settings.background ? settings.background : '#000000';
let value = settings.darknessValue;
if (value == undefined) value = 0;
let background = settings.background;
if (background == undefined) background = "#000000";
let src = ""; let src = "";
let txt = ""; let txt = "";
@@ -415,8 +259,7 @@ export class OtherControls{
} }
else if (func == 'disp'){ //display darkness else if (func == 'disp'){ //display darkness
src = 'modules/MaterialDeck/img/other/darkness/darkness.png'; src = 'modules/MaterialDeck/img/other/darkness/darkness.png';
let darkness = ''; const darkness = canvas.scene != null ? Math.floor(canvas.scene.data.darkness*100)/100 : '';
if (canvas.scene != null) darkness = Math.floor(canvas.scene.data.darkness*100)/100;
txt += darkness; txt += darkness;
} }
streamDeck.setTitle(txt,context); streamDeck.setTitle(txt,context);
@@ -425,17 +268,13 @@ export class OtherControls{
keyPressDarkness(settings) { keyPressDarkness(settings) {
if (canvas.scene == null) return; if (canvas.scene == null) return;
let func = settings.darknessFunction; const func = settings.darknessFunction ? settings.darknessFunction : 'value';
if (func == undefined) func = 'value'; const value = parseFloat(settings.darknessValue) ? parseFloat(settings.darknessValue) : 0;
let value = parseFloat(settings.darknessValue);
if (value == undefined) value = 0;
if (func == 'value') //value if (func == 'value') //value
canvas.scene.update({darkness: value}); canvas.scene.update({darkness: value});
else if (func == 'incDec'){ //increase/decrease else if (func == 'incDec'){ //increase/decrease
let darkness = canvas.scene.data.darkness; let darkness = canvas.scene.data.darkness - value;
darkness += -1*value;
if (darkness > 1) darkness = 1; if (darkness > 1) darkness = 1;
if (darkness < 0) darkness = 0; if (darkness < 0) darkness = 0;
canvas.scene.update({darkness: darkness}); canvas.scene.update({darkness: darkness});
@@ -444,37 +283,77 @@ export class OtherControls{
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
updateRollDice(settings,context){
const background = settings.background ? settings.background : '#000000';
let txt = '';
if (settings.displayDiceName) txt = 'Roll: ' + settings.rollDiceFormula;
streamDeck.setTitle(txt,context);
streamDeck.setIcon(context,'',background);
}
keyPressRollDice(settings,context){
if (settings.rollDiceFormula == undefined || settings.rollDiceFormula == '') return;
const rollFunction = settings.rollDiceFunction ? settings.rollDiceFunction : 'public';
let actor;
let tokenControlled = false;
if (MODULE.selectedTokenId != undefined) actor = canvas.tokens.children[0].children.find(p => p.id == MODULE.selectedTokenId).actor;
if (actor != undefined) tokenControlled = true;
let r;
if (tokenControlled) r = new Roll(settings.rollDiceFormula,actor.getRollData());
else r = new Roll(settings.rollDiceFormula);
r.evaluate();
if (rollFunction == 'public') {
r.toMessage(r,{rollMode:"roll"})
}
else if (rollFunction == 'private') {
r.toMessage(r,{rollMode:"selfroll"})
}
else if (rollFunction == 'sd'){
let txt = settings.displayDiceName ? 'Roll: '+settings.rollDiceFormula + '\nResult: ' : '';
txt += r.total;
streamDeck.setTitle(txt,context);
let data = this.rollData
data[context] = {
formula: settings.rollDiceFormula,
result: txt
}
this.rollData = data;
}
}
//////////////////////////////////////////////////////////////////////////////////////////
updateRollTable(settings,context){ updateRollTable(settings,context){
let name = settings.rollTableName; const name = settings.rollTableName;
if (name == undefined) return; if (name == undefined) return;
let background = settings.background; const background = settings.background ? settings.background : '#000000';
if (background == undefined) background = "#000000"; const table = game.tables.entities.find(p=>p.name == name);
let txt = settings.displayRollName ? table.name : '';
let src = settings.displayRollIcon ? table.data.img : '';
let table = game.tables.entities.find(p=>p.name == name); if (table == undefined) {
src = '';
let txt = ""; txt = '';
let src = "";
if (table != undefined) {
if (settings.displayRollIcon) src = table.data.img;
if (settings.displayRollName) txt = table.name;
} }
streamDeck.setTitle(txt,context); streamDeck.setTitle(txt,context);
streamDeck.setIcon(context,src,background); streamDeck.setIcon(context,src,background);
} }
keyPressRollTable(settings){ keyPressRollTable(settings){
let func = settings.rolltableFunction; const name = settings.rollTableName;
if (func == undefined) func = 'open';
let name = settings.rollTableName;
if (name == undefined) return; if (name == undefined) return;
let background = settings.background; const func = settings.rolltableFunction ? settings.rolltableFunction : 'open';
if (background == undefined) background = "#000000"; const table = game.tables.entities.find(p=>p.name == name);
let table = game.tables.entities.find(p=>p.name == name);
if (table != undefined) { if (table != undefined) {
if (func == 'open'){ //open if (func == 'open'){ //open
@@ -524,43 +403,24 @@ export class OtherControls{
} }
updateSidebar(settings,context){ updateSidebar(settings,context){
let sidebarTab = settings.sidebarTab; const sidebarTab = settings.sidebarTab ? settings.sidebarTab : 'chat';
if (sidebarTab == undefined) sidebarTab = 'chat'; const background = settings.background ? settings.background : '#000000';
const collapsed = ui.sidebar._collapsed;
const ringOffColor = settings.offRing ? settings.offRing : '#000000';
const ringOnColor = settings.onRing ? settings.onRing : '#00FF00';
const ringColor = (sidebarTab == 'collapse' && collapsed) ? ringOnColor : ringOffColor;
const name = settings.displaySidebarName ? this.getSidebarName(sidebarTab) : '';
const icon = settings.displaySidebarIcon ? this.getSidebarIcon(sidebarTab) : '';
let activeTab = ui.sidebar.activeTab;
let collapsed = ui.sidebar._collapsed;
let name = "";
let icon = "";
let background = settings.background;
if(background == undefined) background = '#000000';
let ringColor = "#000000";
let ringOffColor = settings.offRing;
if (ringOffColor == undefined) ringOffColor = '#000000';
let ringOnColor = settings.onRing;
if (ringOnColor == undefined) ringOnColor = '#00FF00';
if (settings.displaySidebarName) name = this.getSidebarName(sidebarTab);
if (settings.displaySidebarIcon) icon = this.getSidebarIcon(sidebarTab);
if ((sidebarTab == 'collapse' && collapsed))
ringColor = ringOnColor;
else
ringColor = ringOffColor;
streamDeck.setTitle(name,context); streamDeck.setTitle(name,context);
streamDeck.setIcon(context,icon,background,2,ringColor); streamDeck.setIcon(context,icon,background,2,ringColor);
} }
keyPressSidebar(settings){ keyPressSidebar(settings){
let sidebarTab = settings.sidebarTab; const sidebarTab = settings.sidebarTab ? settings.sidebarTab : 'chat';
if (sidebarTab == undefined) sidebarTab = 'chat';
let collapsed = ui.sidebar._collapsed;
if (sidebarTab == 'collapse'){ if (sidebarTab == 'collapse'){
const collapsed = ui.sidebar._collapsed;
if (collapsed) ui.sidebar.expand(); if (collapsed) ui.sidebar.expand();
else if (collapsed == false) ui.sidebar.collapse(); else if (collapsed == false) ui.sidebar.collapse();
} }
@@ -570,27 +430,19 @@ export class OtherControls{
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
updateCompendium(settings,context){ updateCompendium(settings,context){
let background = settings.background; const name = settings.compendiumName;
if(background == undefined) background = '#000000';
let name = settings.compendiumName;
if (name == undefined) return; if (name == undefined) return;
const compendium = game.packs.entries.find(p=>p.metadata.label == name); const compendium = game.packs.entries.find(p=>p.metadata.label == name);
if (compendium == undefined) return; if (compendium == undefined) return;
let ringColor = "#000000"; const background = settings.background ? settings.background : '#000000';
const ringOffColor = settings.offRing ? settings.offRing : '#000000';
const ringOnColor = settings.onRing ? settings.onRing : '#00FF00';
const ringColor = compendium.rendered ? ringOnColor : ringOffColor;
const txt = settings.displayCompendiumName ? name : '';
let ringOffColor = settings.offRing; streamDeck.setTitle(txt,context);
if (ringOffColor == undefined) ringOffColor = '#000000';
let ringOnColor = settings.onRing;
if (ringOnColor == undefined) ringOnColor = '#00FF00';
if (compendium.rendered) ringColor = ringOnColor;
else ringColor = ringOffColor;
if (settings.displayCompendiumName) streamDeck.setTitle(name,context);
streamDeck.setIcon(context,"",background,2,ringColor); streamDeck.setIcon(context,"",background,2,ringColor);
} }
@@ -610,37 +462,50 @@ export class OtherControls{
//game.journal.entries[0].render(true) //game.journal.entries[0].render(true)
updateJournal(settings,context){ updateJournal(settings,context){
let background = settings.background; const name = settings.compendiumName;
if(background == undefined) background = '#000000';
let name = settings.compendiumName;
if (name == undefined) return; if (name == undefined) return;
const journal = game.journal.entries.find(p=>p.name == name); const journal = game.journal.entries.find(p=>p.name == name);
if (journal == undefined) return; if (journal == undefined) return;
let ringColor = "#000000"; const background = settings.background ? settings.background : '#000000';
const ringOffColor = settings.offRing ? settings.offRing : '#000000';
const ringOnColor = settings.onRing ? settings.onRing : '#00FF00';
const ringColor = journal.sheet.rendered ? ringOnColor : ringOffColor;
const txt = settings.displayCompendiumName ? name : '';
let ringOffColor = settings.offRing; streamDeck.setTitle(txt,context);
if (ringOffColor == undefined) ringOffColor = '#000000';
let ringOnColor = settings.onRing;
if (ringOnColor == undefined) ringOnColor = '#00FF00';
if (journal.sheet.rendered) ringColor = ringOnColor;
else ringColor = ringOffColor;
if (settings.displayCompendiumName) streamDeck.setTitle(name,context);
streamDeck.setIcon(context,"",background,2,ringColor); streamDeck.setIcon(context,"",background,2,ringColor);
} }
keyPressJournal(settings){ keyPressJournal(settings){
let name = settings.compendiumName; const name = settings.compendiumName;
if (name == undefined) return; if (name == undefined) return;
const journal = game.journal.entries.find(p=>p.name == name); const journal = game.journal.entries.find(p=>p.name == name);
if (journal == undefined) return; if (journal == undefined) return;
const element = document.getElementById("journal-"+journal.id); const element = document.getElementById("journal-"+journal.id);
if (element == null) journal.render(true); if (element == null) journal.render(true);
else journal.sheet.close(); else journal.sheet.close();
} }
//////////////////////////////////////////////////////////////////////////////////////////
updateChatMessage(settings,context){
const background = settings.background ? settings.background : '#000000';
streamDeck.setTitle("",context);
streamDeck.setIcon(context,"",background);
}
keyPressChatMessage(settings){
const message = settings.chatMessage ? settings.chatMessage : '';
let chatData = {
user: game.user._id,
speaker: ChatMessage.getSpeaker(),
content: message
};
ChatMessage.create(chatData, {});
}
} }

196
src/scene.js Normal file
View File

@@ -0,0 +1,196 @@
import * as MODULE from "../MaterialDeck.js";
import {streamDeck} from "../MaterialDeck.js";
export class SceneControl{
constructor(){
this.active = false;
this.rollData = {};
this.sceneOffset = 0;
}
async updateAll(){
if (this.active == false) return;
for (let i=0; i<32; i++){
let data = streamDeck.buttonContext[i];
if (data == undefined || data.action != 'scene') continue;
await this.update(data.settings,data.context);
}
}
update(settings,context){
if (canvas.scene == null) return;
this.active = true;
const func = settings.sceneFunction ? settings.sceneFunction : 'visible';
const background = settings.background ? settings.background : '#000000';
const ringOffColor = settings.offRing ? settings.offRing : '#000000';
const ringOnColor = settings.onRing ? settings.onRing : '#00FF00';
let ringColor = "#000000";
let ring = 2;
let src = "";
let name = "";
if (func == 'visible'){ //visible scenes
let nr = parseInt(settings.sceneNr);
if (isNaN(nr) || nr < 1) nr = 1;
nr--;
let scene = game.scenes.apps[0].scenes[nr];
if (scene != undefined){
if (scene.isView)
ringColor = ringOnColor;
else
ringColor = ringOffColor;
if (settings.displaySceneName) name = scene.name;
if (settings.displaySceneIcon) src = scene.img;
if (scene.active) name += "\n(Active)";
}
}
else if (func == 'dir') { //from directory
let nr = parseInt(settings.sceneNr);
if (isNaN(nr) || nr < 1) nr = 1;
nr--;
let sceneList = [];
for (let i=0; i<ui.scenes.tree.children.length; i++){
const scenesInFolder = ui.scenes.tree.children[i].entities;
for (let j=0; j<scenesInFolder.length; j++)
sceneList.push(scenesInFolder[j])
}
for (let i=0; i<ui.scenes.tree.content.length; i++)
sceneList.push(ui.scenes.tree.content[i])
const scene = sceneList[nr+this.sceneOffset];
if (scene != undefined){
if (scene.isView)
ringColor = ringOnColor;
else if (scene.data.navigation && scene.data.permission.default == 0)
ringColor = '#000791';
else if (scene.data.navigation)
ringColor = '#2d2d2d';
else
ringColor = ringOffColor;
if (settings.displaySceneName) name = scene.name;
if (settings.displaySceneIcon) src = scene.img;
if (scene.active) name += "\n(Active)";
}
}
else if (func == 'any') { //by name
if (settings.sceneName == undefined || settings.sceneName == '') return;
let scene = game.scenes.apps[1].entities.find(p=>p.data.name == settings.sceneName);
if (scene != undefined){
if (scene.isView)
ringColor = ringOnColor;
else
ringColor = ringOffColor;
if (settings.displaySceneName) name = scene.name;
if (settings.displaySceneIcon) src = scene.img;
if (scene.active) name += "\n(Active)";
}
}
else if (func == 'active'){
const scene = game.scenes.active;
if (scene == undefined) return;
if (settings.displaySceneName) name = scene.name;
if (settings.displaySceneIcon) src = scene.img;
ring = 0;
}
else if (func == 'offset'){
let offset = parseInt(settings.sceneOffset);
if (isNaN(offset)) offset = 0;
if (offset == this.sceneOffset) ringColor = ringOnColor;
else ringColor = ringOffColor;
}
streamDeck.setTitle(name,context);
streamDeck.setIcon(context,src,background,ring,ringColor);
}
keyPress(settings){
const func = settings.sceneFunction ? settings.sceneFunction : 'visible';
if (func == 'visible'){ //visible scenes
const viewFunc = settings.sceneViewFunction ? settings.sceneViewFunction : 'view';
let nr = parseInt(settings.sceneNr);
if (isNaN(nr) || nr < 1) nr = 1;
nr--;
let scene = game.scenes.apps[0].scenes[nr];
if (scene != undefined){
if (viewFunc == 'view'){
scene.view();
}
else if (viewFunc == 'activate'){
scene.activate();
}
else {
if (scene.isView) scene.activate();
scene.view();
}
}
}
else if (func == 'dir') { //from directory
const viewFunc = settings.sceneViewFunction ? settings.sceneViewFunction : 'view';
let nr = parseInt(settings.sceneNr);
if (isNaN(nr) || nr < 1) nr = 1;
nr--;
let sceneList = [];
for (let i=0; i<ui.scenes.tree.children.length; i++){
const scenesInFolder = ui.scenes.tree.children[i].entities;
for (let j=0; j<scenesInFolder.length; j++)
sceneList.push(scenesInFolder[j])
}
for (let i=0; i<ui.scenes.tree.content.length; i++)
sceneList.push(ui.scenes.tree.content[i])
const scene = sceneList[nr+this.sceneOffset];
if (scene != undefined){
if (viewFunc == 'view'){
scene.view();
}
else if (viewFunc == 'activate'){
scene.activate();
}
else {
if (scene.isView) scene.activate();
scene.view();
}
}
}
else if (func == 'any'){ //by name
if (settings.sceneName == undefined || settings.sceneName == '') return;
const scenes = game.scenes.entries;
let scene = game.scenes.apps[1].entities.find(p=>p.data.name == settings.sceneName);
if (scene == undefined) return;
let viewFunc = settings.sceneViewFunction;
if (viewFunc == undefined) viewFunc = 'view';
if (viewFunc == 'view'){
scene.view();
}
else if (viewFunc == 'activate'){
scene.activate();
}
else {
if (scene.isView) scene.activate();
scene.view();
}
}
else if (func == 'active'){
const scene = game.scenes.active;
if (scene == undefined) return;
scene.view();
}
else if (func == 'offset'){
let offset = parseInt(settings.sceneOffset);
if (isNaN(offset)) offset = 0;
this.sceneOffset = offset;
this.updateAll();
}
}
}

View File

@@ -39,6 +39,17 @@ export const registerSettings = function() {
onChange: x => window.location.reload() onChange: x => window.location.reload()
}); });
game.settings.register(MODULE.moduleName, 'imageBuffer', {
name: "MaterialDeck.Sett.ImageBuffer",
hint: "MaterialDeck.Sett.ImageBufferHint",
default: 0,
type: Number,
scope: 'world',
range: { min: 0, max: 500, step: 10 },
config: true
});
/** /**
* Playlist soundboard * Playlist soundboard
*/ */

View File

@@ -25,6 +25,11 @@ export class StreamDeck{
document.body.appendChild(canvasBox); // adds the canvas to the body element document.body.appendChild(canvasBox); // adds the canvas to the body element
this.syllableRegex = /[^aeiouy]*[aeiouy]+(?:[^aeiouy]*$|[^aeiouy](?=[^aeiouy]))?/gi; this.syllableRegex = /[^aeiouy]*[aeiouy]+(?:[^aeiouy]*$|[^aeiouy](?=[^aeiouy]))?/gi;
this.imageBuffer = [];
this.imageBufferCounter = 0;
} }
setScreen(action){ setScreen(action){
@@ -52,6 +57,7 @@ export class StreamDeck{
else if (action == 'soundboard') MODULE.soundboard.active = false; else if (action == 'soundboard') MODULE.soundboard.active = false;
else if (action == 'other') MODULE.otherControls.active = false; else if (action == 'other') MODULE.otherControls.active = false;
else if (action == 'external') MODULE.externalModules.active = false; else if (action == 'external') MODULE.externalModules.active = false;
else if (action == 'scene') MODULE.sceneControl.active = false;
} }
} }
@@ -171,14 +177,30 @@ export class StreamDeck{
MODULE.sendWS(JSON.stringify(msg)); MODULE.sendWS(JSON.stringify(msg));
} }
setImage(image,context){ setImage(image,context,nr,id){
var json = { var json = {
target: "SD", target: "SD",
event: "setImage", event: "setImage",
context: context, context: context,
payload: { payload: {
image: "" + image, nr: nr,
target: 0 id: id,
image: "" + image,
target: 0
}
};
MODULE.sendWS(JSON.stringify(json));
}
setBufferImage(context,nr,id){
var json = {
target: "SD",
event: "setBufferImage",
context: context,
payload: {
nr: nr,
id: id,
target: 0
} }
}; };
MODULE.sendWS(JSON.stringify(json)); MODULE.sendWS(JSON.stringify(json));
@@ -198,6 +220,18 @@ export class StreamDeck{
this.buttonContext[i].background = background; this.buttonContext[i].background = background;
} }
} }
const data = {
url: src,
background:background,
ring:ring,
ringColor:ringColor,
overlay:overlay
}
const imgBuffer = this.checkImageBuffer(data);
if (imgBuffer != false) {
this.setBufferImage(context,imgBuffer,this.getImageBufferId(data))
return;
}
let split = src.split('.'); let split = src.split('.');
//filter out stuff from Tokenizer //filter out stuff from Tokenizer
@@ -215,7 +249,7 @@ export class StreamDeck{
ringColor: ringColor, ringColor: ringColor,
overlay: overlay overlay: overlay
}; };
this.getImage(msg); this.getImage(msg);
} }
setState(state,context,action){ setState(state,context,action){
@@ -265,6 +299,7 @@ export class StreamDeck{
getImage(data){ getImage(data){
if (data == undefined) if (data == undefined)
return; return;
const context = data.context; const context = data.context;
var url = data.url; var url = data.url;
const format = data.format; const format = data.format;
@@ -367,8 +402,46 @@ export class StreamDeck{
ctx.drawImage(img, xStart+margin, yStart+margin, renderableWidth - 2*margin, renderableHeight - 2*margin); ctx.drawImage(img, xStart+margin, yStart+margin, renderableWidth - 2*margin, renderableHeight - 2*margin);
var dataURL = canvas.toDataURL(); var dataURL = canvas.toDataURL();
canvas.remove(); canvas.remove();
this.setImage(dataURL,data.context); const nr = this.addToImageBuffer(dataURL,data);
this.setImage(dataURL,data.context,nr,this.getImageBufferId(data));
}; };
img.src = resImageURL; img.src = resImageURL;
} }
getImageBufferId(data){
return data.url+data.background+data.ring+data.ringColor+data.overlay;
}
addToImageBuffer(img,data){
const id = this.getImageBufferId(data);
const maxBufferSize = game.settings.get(MODULE.moduleName,'imageBuffer');
if (maxBufferSize == 0) return false;
if (this.imageBufferCounter > maxBufferSize) this.imageBufferCounter = 0;
const newData = {
id: id,
img: img
}
if (this.imageBuffer[this.imageBufferCounter] == undefined) this.imageBuffer.push(newData);
else this.imageBuffer[this.imageBufferCounter] = newData;
this.imageBufferCounter++;
return this.imageBufferCounter - 1;
}
checkImageBuffer(data){
if (game.settings.get(MODULE.moduleName,'imageBuffer') == 0) return false;
const id = this.getImageBufferId(data);
for (let i=0; i<this.imageBuffer.length; i++){
if (this.imageBuffer[i].id == id) return i;
}
return false;
}
resetImageBuffer(){
this.imageBufferCounter = 0;
this.imageBuffer = [];
}
} }

View File

@@ -23,11 +23,11 @@ export class TokenControl{
if (settings.displayIcon) icon = true; if (settings.displayIcon) icon = true;
if (settings.displayName) name = true; if (settings.displayName) name = true;
if (stats == undefined) stats = 'none';
if (settings.background) background = settings.background;
let system = settings.system; let system = settings.system;
if (system == undefined) system = 'dnd5e'; if (system == undefined) system = 'dnd5e';
if (system == 'demonlord') stats = settings.statsDemonlord;
if (stats == undefined) stats = 'none';
if (settings.background) background = settings.background;
let tokenName = ""; let tokenName = "";
let txt = ""; let txt = "";
@@ -40,7 +40,25 @@ export class TokenControl{
if (name && stats != 'none') txt += "\n"; if (name && stats != 'none') txt += "\n";
iconSrc = token.data.img; iconSrc = token.data.img;
let actor = canvas.tokens.children[0].children.find(p => p.id == tokenId).actor; let actor = canvas.tokens.children[0].children.find(p => p.id == tokenId).actor;
if (system == 'dnd5e' && game.system.id == 'dnd5e'){ if (stats == 'custom'){
const custom = settings.custom ? settings.custom : '';
let split = custom.split('[');
for (let i=0; i<split.length; i++) split[i] = split[i].split(']');
for (let i=0; i<split.length; i++)
for (let j=0; j<split[i].length; j++){
if (split[i][j][0] != '@') txt += split[i][j];
else {
const dataPath = split[i][j].split('@')[1].split('.');
let data = token;
for (let i=0; i<dataPath.length; i++)
data = data?.[dataPath[i]];
if (data == undefined) txt += '[undef]';
else txt += data;
}
}
}
else if (system == 'dnd5e' && game.system.id == 'dnd5e'){
let attributes = actor.data.data.attributes; let attributes = actor.data.data.attributes;
if (stats == 'HP') { if (stats == 'HP') {
txt += attributes.hp.value + "/" + attributes.hp.max; txt += attributes.hp.value + "/" + attributes.hp.max;
@@ -143,10 +161,10 @@ export class TokenControl{
} }
else if (system == 'demonlord' && game.system.id == 'demonlord'){ else if (system == 'demonlord' && game.system.id == 'demonlord'){
let characteristics = actor.data.data.characteristics; let characteristics = actor.data.data.characteristics;
if (stats == 'HP') txt += characteristics.health.value + "/" + characteristics.health.max; if (statsDemonlord == 'HP') txt += characteristics.health.value + "/" + characteristics.health.max;
else if (stats == 'AC') txt += characteristics.defense; else if (statsDemonlord == 'AC') txt += characteristics.defense;
else if (stats == 'Speed') txt += characteristics.speed; else if (statsDemonlord == 'Speed') txt += characteristics.speed;
else if (stats == 'Init') txt += actor.data.data.fastturn ? "FAST" : "SLOW"; else if (statsDemonlord == 'Init') txt += actor.data.data.fastturn ? "FAST" : "SLOW";
} }
else { else {
//Other systems //Other systems
@@ -406,6 +424,46 @@ export class TokenControl{
this.update(tokenId); this.update(tokenId);
} }
else if (onClick == 'vision'){
const token = canvas.tokens.children[0].children.find(p => p.id == tokenId);
if (token == undefined) return;
let tokenData = token.data;
const dimVision = parseInt(settings.dimVision);
const brightVision = parseInt(settings.brightVision);
const sightAngle = parseInt(settings.sightAngle);
const dimRadius = parseInt(settings.dimRadius);
const brightRadius = parseInt(settings.brightRadius);
const emissionAngle = parseInt(settings.emissionAngle);
const lightColor = settings.lightColor ? settings.lightColor : '#000000';
const colorIntensity = isNaN(parseInt(settings.colorIntensity)) ? 0 : parseInt(settings.colorIntensity)/100;
const animationType = settings.animationType ? settings.animationType : 'none';
const animationSpeed = isNaN(parseInt(settings.animationSpeed)) ? 1 : parseInt(settings.animationSpeed);
const animationIntensity = isNaN(parseInt(settings.animationIntensity)) ? 1 : parseInt(settings.animationIntensity);
let data = {};
if (isNaN(dimVision)==false) data.dimSight = dimVision;
if (isNaN(brightVision)==false) data.brightSight = brightVision;
if (isNaN(sightAngle)==false) data.sightAngle = sightAngle;
if (isNaN(dimRadius)==false) data.dimLight = dimRadius;
if (isNaN(brightRadius)==false) data.brightLight = brightRadius;
if (isNaN(emissionAngle)==false) data.lightAngle = emissionAngle;
data.lightColor = lightColor;
data.lightAlpha = Math.sqrt(colorIntensity).toNearest(0.05)
let animation = {
type: '',
speed: tokenData.lightAnimation.speed,
intensity: tokenData.lightAnimation.intensity
};
if (animationType != 'none'){
animation.type = animationType;
animation.intensity = animationIntensity;
animation.speed = animationSpeed;
}
data.lightAnimation = animation;
token.update(data);
}
else if (system == 'demonlord' && game.system.id == 'demonlord' && onClick == 'initiative'){ else if (system == 'demonlord' && game.system.id == 'demonlord' && onClick == 'initiative'){
token.actor.update({ token.actor.update({
'data.fastturn': !token.actor.data?.data?.fastturn 'data.fastturn': !token.actor.data?.data?.fastturn