12 Commits

Author SHA1 Message Date
CDeenen
cc5dc9ab63 v1.2.1 2021-01-07 05:40:07 +01:00
CDeenen
64fd6cb132 Merge branch 'Master' of https://github.com/CDeenen/MaterialDeck into Master 2021-01-07 05:39:02 +01:00
CDeenen
888b089e7b v1.2.1 2021-01-07 05:38:16 +01:00
CDeenen
959b9c9e4e Add files via upload 2021-01-02 05:19:06 +01:00
CDeenen
afaf1c9799 Delete Black.png 2021-01-02 05:18:50 +01:00
CDeenen
2947c54eb8 v1.2.0 2020-12-28 05:31:59 +01:00
CDeenen
561e3f4bd0 Update README.md 2020-12-19 08:01:28 +01:00
CDeenen
33f27047b1 changelog fix 2020-12-12 19:32:07 +01:00
CDeenen
7c532f5155 v1.1.1 2020-12-12 19:17:34 +01:00
CDeenen
e62e82795b v1.1.1 2020-12-12 19:16:07 +01:00
CDeenen
91e07e79c5 changelog fix 2020-12-09 03:32:32 +01:00
CDeenen
fc471ce400 v1.1.0 2020-12-09 03:22:22 +01:00
83 changed files with 1487 additions and 827 deletions

View File

@@ -7,6 +7,8 @@ import {CombatTracker} from "./src/combattracker.js";
import {PlaylistControl} from "./src/playlist.js"; 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 {SceneControl} from "./src/scene.js";
export var streamDeck; export var streamDeck;
export var tokenControl; export var tokenControl;
var move; var move;
@@ -15,6 +17,8 @@ export var combatTracker;
export var playlistControl; export var playlistControl;
export var soundboard; export var soundboard;
export var otherControls; export var otherControls;
export var externalModules;
export var sceneControl;
export const moduleName = "MaterialDeck"; export const moduleName = "MaterialDeck";
export var selectedTokenId; export var selectedTokenId;
@@ -48,10 +52,11 @@ 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;
//console.log("Received",data);
const action = data.action; const action = data.action;
const event = data.event; const event = data.event;
const context = data.context; const context = data.context;
@@ -70,6 +75,8 @@ async function analyzeWSmessage(msg){
tokenControl.active = true; tokenControl.active = true;
tokenControl.update(selectedTokenId); tokenControl.update(selectedTokenId);
} }
else if (action == 'move')
move.update(settings,context);
else if (action == 'macro') else if (action == 'macro')
macroControl.update(settings,context); macroControl.update(settings,context);
else if (action == 'combattracker') else if (action == 'combattracker')
@@ -80,6 +87,10 @@ async function analyzeWSmessage(msg){
soundboard.update(settings,context); soundboard.update(settings,context);
else if (action == 'other') else if (action == 'other')
otherControls.update(settings,context); otherControls.update(settings,context);
else if (action == 'external')
externalModules.update(settings,context);
else if (action == 'scene')
sceneControl.update(settings,context);
} }
else if (event == 'willDisappear'){ else if (event == 'willDisappear'){
@@ -100,7 +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')
externalModules.keyPress(settings,context);
else if (action == 'scene')
sceneControl.keyPress(settings);
} }
else if (event == 'keyUp'){ else if (event == 'keyUp'){
@@ -201,7 +216,8 @@ Hooks.once('ready', ()=>{
combatTracker = new CombatTracker(); combatTracker = new CombatTracker();
playlistControl = new PlaylistControl(); playlistControl = new PlaylistControl();
otherControls = new OtherControls(); otherControls = new OtherControls();
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');
@@ -285,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)=>{
@@ -312,16 +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;
sceneControl.updateAll();
externalModules.updateAll();
otherControls.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

@@ -81,6 +81,8 @@ If you have any suggestions or bugs to report, feel free to create an issue, con
<b>Author:</b> Cristian Deenen (Cris#6864 on Discord)<br> <b>Author:</b> Cristian Deenen (Cris#6864 on Discord)<br>
<br> <br>
Special thanks to Asmodeus#7588 who made this module possible by generously donating a Stream Deck XL Special thanks to Asmodeus#7588 who made this module possible by generously donating a Stream Deck XL
<br>
Please consider supporting me on <a href="https://www.patreon.com/materialfoundry">Patreon</a>, and feel free to join the Material Foundry <a href="https://discord.gg/3hd4G6TkmA">Discord</a> server.
## Abandonment ## Abandonment
Abandoned modules are a (potential) problem for Foundry, because users and/or other modules might rely on abandoned modules, which might break in future Foundry updates.<br> Abandoned modules are a (potential) problem for Foundry, because users and/or other modules might rely on abandoned modules, which might break in future Foundry updates.<br>

View File

@@ -1,4 +1,77 @@
# 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
Fixes
<ul>
<li>Incorrect link to some black backgrounds fixed</li>
<li>Token Action: Movement speed wouldn't be displayed for DnD5e 1.2.0</li>
<li>Macro Action => Hotbar: 10th macro would not trigger and display correctly</li>
<li>Combat Tracker Action => Function: Default value would not properly initialize</li>
<li>Other Actions => Darkness Control => Display would not function correctly</li>
<li>Fixed some issues in the SD plugin where correct settings would not be displayed</li>
</ul>
Additions:
<ul>
<li>Added new 'External Modules Action', which will contain all module integrations that don't fit anywhere else</li>
<li>Added support for the Custom Hotbar module in 'Macro Action' => Mode: 'Custom Hotbar'. Link to module: https://foundryvtt.com/packages/custom-hotbar/</li>
<li>Added support for the FxMaster module in 'External Modules Action' => Mode: 'Fx Master'. Link to module: https://foundryvtt.com/packages/fxmaster/</li>
</ul>
### v1.1.1 - 12-12-2020
Fixes
<ul>
<li>Fixed issue where deleting a playlist would cause an error preventing the Soundboard Configuration to show up</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.1.0 (unchanged): https://github.com/CDeenen/MaterialDeck_SD/releases<br>
### v1.1.0 - 09-12-2020
Fixes
<ul>
<li>Settings would not show for Combat Tracker action</li>
<li>Macro Action => Macro Board default settings fixed</li>
<li>API has been improved, making integration with other hardware/software easier, and making future changes/additions easier</li>
</ul>
Additions:
<ul>
<li>Added support for Pathfinder 1e and Shadow of the Demon Lord</li>
<li>All dialogs that are openable using the SD can now be closed by pressing the button while the dialog is open</li>
<li>Playlist Action & Soundboard Action => Stop All now indicates if there are tracks/playlists/sounds playing</li>
<li>Confirmed Foundry 0.7.8 compatibility</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.1.0: https://github.com/CDeenen/MaterialDeck_SD/releases<br>
### V1.0.1 - 26-11-2020 ### V1.0.1 - 26-11-2020
<ul> <ul>
<li>Fixed issue where macro from macroboard wouldn't execute if furnace arguments were not defined</li> <li>Fixed issue where macro from macroboard wouldn't execute if furnace arguments were not defined</li>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -0,0 +1,5 @@
combattracker.png: Edited from https://fontawesome.com/icons/fist-raised?style=solid
nextturn.png, previousturn.png: Edited from https://fontawesome.com/icons/arrow-right?style=solid
nextround.png, previousround.png: Edited from https://fontawesome.com/icons/step-forward?style=solid
startcombat.png: Edited from https://fontawesome.com/icons/play?style=solid
stopcombat.png: Edited from https://fontawesome.com/icons/stop?style=solid

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

2
img/external/SOURCES.txt vendored Normal file
View File

@@ -0,0 +1,2 @@
external.png: Edited from https://fontawesome.com/icons/external-link-alt?style=solid
fxmaster.png: Edited from https://fontawesome.com/icons/magic?style=solid

BIN
img/external/external.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

BIN
img/external/external@2x.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

BIN
img/external/fxmaster.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

1
img/macro/SOURCES.txt Normal file
View File

@@ -0,0 +1 @@
macro.png: Foundry's icon folder, converted from .svg, original name: dice-target.svg

BIN
img/macro/macro.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
img/macro/macro@2x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

3
img/move/SOURCES.txt Normal file
View File

@@ -0,0 +1,3 @@
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

BIN
img/move/center.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
img/move/center@2x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
img/move/down.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

BIN
img/move/downleft.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

BIN
img/move/downright.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

BIN
img/move/left.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

BIN
img/move/right.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

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

BIN
img/move/up.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

BIN
img/move/upleft.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

BIN
img/move/upright.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

BIN
img/move/zoomin.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

BIN
img/move/zoomout.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

2
img/other/SOURCES.txt Normal file
View File

@@ -0,0 +1,2 @@
other.png: Made using https://www.elgato.com/en/gaming/keycreator
cogs.png: Edited from https://fontawesome.com/icons/cogs?style=solid

BIN
img/other/cogs.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@@ -0,0 +1,2 @@
decreasedarkness.png: Made using https://www.elgato.com/en/gaming/keycreator
increasedarkness.png: Made using https://www.elgato.com/en/gaming/keycreator

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
img/other/other.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
img/other/other@2x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@@ -0,0 +1,3 @@
resume.png: Edited from https://fontawesome.com/icons/play?style=solid
pause.png: Edited from https://fontawesome.com/icons/pause?style=solid
playpause.png: Combined resume.png and pause.png

BIN
img/other/pause/pause.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

BIN
img/other/pause/resume.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

2
img/playlist/SOURCES.txt Normal file
View File

@@ -0,0 +1,2 @@
play.png: Edited from https://fontawesome.com/icons/play?style=solid
stop.png: Edited from https://fontawesome.com/icons/stop?style=solid

BIN
img/playlist/play.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

BIN
img/playlist/play@2x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
img/playlist/stop.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

@@ -0,0 +1,2 @@
soundboard.png: Edited from https://fontawesome.com/icons/music?style=solid
play.png: Edited from https://fontawesome.com/icons/play?style=solid

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

BIN
img/soundboard/stop.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

5
img/token/SOURCES.txt Normal file
View File

@@ -0,0 +1,5 @@
ac.webp: Foundry's icon folder, original name: heater-steel-worn.webp
hp.png: made using Elgato's key creator: https://www.elgato.com/en/gaming/keycreator
init.png: freepngimg.com, color inverted, from: https://freepngimg.com/png/81025-art-dice-dungeons-system-dragons-d20-triangle/icon
speed.webp: Foundry's icon folder, original name: shoes-collared-leather-blue.webp
mystery-man.png: Foundry's icon folder, converted from .svg

BIN
img/token/ac.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

BIN
img/token/hp.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

BIN
img/token/init.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 KiB

BIN
img/token/mystery-man.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

BIN
img/token/speed.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 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",
@@ -40,6 +42,9 @@
"MaterialDeck.Off": "Off", "MaterialDeck.Off": "Off",
"MaterialDeck.Name": "Name", "MaterialDeck.Name": "Name",
"MaterialDeck.None": "None", "MaterialDeck.None": "None",
"MaterialDeck.Save": "Save" "MaterialDeck.Save": "Save",
"MaterialDeck.FxMaster.Colorize": "Colorize",
"MaterialDeck.FxMaster.Clear": "Clear All"
} }

View File

@@ -2,14 +2,14 @@
"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.0.1", "version": "1.2.1",
"author": "CDeenen", "author": "CDeenen",
"esmodules": [ "esmodules": [
"./MaterialDeck.js" "./MaterialDeck.js"
], ],
"socket": true, "socket": true,
"minimumCoreVersion": "0.7.5", "minimumCoreVersion": "0.7.5",
"compatibleCoreVersion": "0.7.7", "compatibleCoreVersion": "0.7.9",
"languages": [ "languages": [
{ {
"lang": "en", "lang": "en",

View File

@@ -18,83 +18,77 @@ 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 == 0; const mode = settings.combatTrackerMode ? settings.combatTrackerMode : 'combatants';
const combat = game.combat;
let src = "modules/MaterialDeck/img/black.png";
let combat = game.combat;
let src = "action/images/black.png";
let txt = ""; let txt = "";
let background = "#000000"; let background = "#000000";
let mode = settings.combatTrackerMode;
if (mode == undefined) mode = 0; if (mode == 'combatants'){
if (mode == 0){
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;
} }
else { else {
streamDeck.setIcon(0,context,src,background); streamDeck.setIcon(context,src,background);
streamDeck.setTitle(txt,context); streamDeck.setTitle(txt,context);
} }
} }
else { else {
streamDeck.setIcon(0,context,src,background); streamDeck.setIcon(context,src,background);
streamDeck.setTitle(txt,context); streamDeck.setTitle(txt,context);
} }
} }
else if (mode == 1){ 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 {
streamDeck.setIcon(0,context,src,background); streamDeck.setIcon(context,src,background);
streamDeck.setTitle(txt,context); streamDeck.setTitle(txt,context);
} }
} }
else if (mode == 2){ else if (mode == 'function'){
if (ctFunction == 'startStop') {
if (ctFunction == 0) {
if (combat == null || combat == undefined || combat.combatants.length == 0) { if (combat == null || combat == undefined || combat.combatants.length == 0) {
src = "action/images/combattracker/startcombat.png"; src = "modules/MaterialDeck/img/combattracker/startcombat.png";
background = "#000000"; background = "#000000";
} }
else { else {
if (combat.started == false) { if (combat.started == false) {
src = "action/images/combattracker/startcombat.png"; src = "modules/MaterialDeck/img/combattracker/startcombat.png";
background = "#008000"; background = "#008000";
} }
else { else {
src = "action/images/combattracker/stopcombat.png"; src = "modules/MaterialDeck/img/combattracker/stopcombat.png";
background = "#FF0000"; background = "#FF0000";
} }
} }
} }
else if (ctFunction == 1) { else if (ctFunction == 'nextTurn') {
src = "action/images/combattracker/nextturn.png"; src = "modules/MaterialDeck/img/combattracker/nextturn.png";
} }
else if (ctFunction == 2) { else if (ctFunction == 'prevTurn') {
src = "action/images/combattracker/previousturn.png"; src = "modules/MaterialDeck/img/combattracker/previousturn.png";
} }
else if (ctFunction == 3) { else if (ctFunction == 'nextRound') {
src = "action/images/combattracker/nextround.png"; src = "modules/MaterialDeck/img/combattracker/nextround.png";
} }
else if (ctFunction == 4) { else if (ctFunction == 'prevRound') {
src = "action/images/combattracker/previousround.png"; src = "modules/MaterialDeck/img/combattracker/previousround.png";
} }
else if (ctFunction == 5){ else if (ctFunction == 'turnDisplay'){
src = "action/images/black.png"; src = "modules/MaterialDeck/img/black.png";
let round = 0; let round = 0;
let turn = 0; let turn = 0;
if (combat != null && combat != undefined && combat.started != false){ if (combat != null && combat != undefined && combat.started != false){
@@ -105,79 +99,29 @@ export class CombatTracker{
if (txt != "") txt += "\n"; if (txt != "") txt += "\n";
if (settings.displayTurn) txt += "Turn\n"+turn; if (settings.displayTurn) txt += "Turn\n"+turn;
} }
streamDeck.setIcon(0,context,src,background); streamDeck.setIcon(context,src,background);
streamDeck.setTitle(txt,context); streamDeck.setTitle(txt,context);
} }
} }
keyPress(settings,context){ keyPress(settings,context){
let mode = parseInt(settings.combatTrackerMode); const mode = settings.combatTrackerMode ? settings.combatTrackerMode : 'combatants';
if (isNaN(mode)) mode = 0; const combat = game.combat;
if (mode < 2) {
let onClick = settings.onClick;
if (onClick == undefined) onClick = 0;
let tokenId;
let combat = game.combat;
if (mode == 0) {
if (combat != null && combat != undefined && combat.turns.length != 0){
let initiativeOrder = combat.turns;
let nr = settings.combatantNr - 1;
if (nr == undefined || nr < 1) nr = 0;
let combatantState = 1;
if (nr == combat.turn) combatantState = 2;
let combatant = initiativeOrder[nr]
if (combatant == undefined) return; if (mode == 'function'){
tokenId = combatant.tokenId;
}
}
else if (mode == 1)
if (combat != null && combat != undefined && combat.started)
tokenId = combat.combatant.tokenId;
let token
if (canvas.tokens.children[0] != undefined) token = canvas.tokens.children[0].children.find(p => p.id == tokenId);
if (token == undefined) return;
if (onClick == 0) //Do nothing
return;
else if (onClick == 1){ //select token
token.control();
}
else if (onClick == 2){ //center on token
let location = token.getCenter(token.x,token.y);
canvas.animatePan(location);
}
else if (onClick == 3){ //center on token and select
let location = token.getCenter(token.x,token.y);
canvas.animatePan(location);
token.control();
}
else if (onClick == 4){ //Open character sheet
token.actor.sheet.render(true);
}
else { //Open token config
token.sheet._render(true);
}
}
else if (mode == 2){
let combat = game.combat;
if (combat == null || combat == undefined) return; if (combat == null || combat == undefined) return;
const ctFunction = settings.combatTrackerFunction ? settings.combatTrackerFunction : 'startStop';
let ctFunction = settings.combatTrackerFunction; if (ctFunction == 'startStop'){
if (ctFunction == undefined) ctFunction == 0;
if (ctFunction == 0){
let src; let src;
let background; let background;
if (game.combat.started){ if (game.combat.started){
game.combat.endCombat(); game.combat.endCombat();
src = "action/images/combattracker/startcombat.png"; src = "modules/MaterialDeck/img/combattracker/startcombat.png";
background = "#000000"; background = "#000000";
} }
else { else {
game.combat.startCombat(); game.combat.startCombat();
src = "action/images/combattracker/stopcombat.png"; src = "modules/MaterialDeck/img/combattracker/stopcombat.png";
background = "#FF0000"; background = "#FF0000";
} }
streamDeck.setIcon(context,src,background); streamDeck.setIcon(context,src,background);
@@ -185,10 +129,55 @@ export class CombatTracker{
} }
if (game.combat.started == false) return; if (game.combat.started == false) return;
if (ctFunction == 1) game.combat.nextTurn(); if (ctFunction == 'nextTurn') game.combat.nextTurn();
else if (ctFunction == 2) game.combat.previousTurn(); else if (ctFunction == 'prevTurn') game.combat.previousTurn();
else if (ctFunction == 3) game.combat.nextRound(); else if (ctFunction == 'nextRound') game.combat.nextRound();
else if (ctFunction == 4) game.combat.previousRound(); else if (ctFunction == 'prevRound') game.combat.previousRound();
} }
else {
const onClick = settings.onClick ? settings.onClick : 'doNothing';
let tokenId;
if (mode == 'combatants') {
if (combat != null && combat != undefined && combat.turns.length != 0){
const initiativeOrder = combat.turns;
let nr = settings.combatantNr - 1;
if (nr == undefined || nr < 1) nr = 0;
const combatant = initiativeOrder[nr]
if (combatant == undefined) return;
tokenId = combatant.tokenId;
}
}
else if (mode == 'currentCombatant')
if (combat != null && combat != undefined && combat.started)
tokenId = combat.combatant.tokenId;
let token = (canvas.tokens.children[0] != undefined) ? canvas.tokens.children[0].children.find(p => p.id == tokenId) : undefined;
if (token == undefined) return;
if (onClick == 'doNothing') //Do nothing
return;
else if (onClick == 'select'){ //select token
token.control();
}
else if (onClick == 'center'){ //center on token
let location = token.getCenter(token.x,token.y);
canvas.animatePan(location);
}
else if (onClick == 'centerSelect'){ //center on token and select
const location = token.getCenter(token.x,token.y);
canvas.animatePan(location);
token.control();
}
else if (onClick == 'charSheet'){ //Open character sheet
const element = document.getElementById(token.actor.sheet.id);
if (element == null) token.actor.sheet.render(true);
else token.actor.sheet.close();
}
else if (onClick == 'tokenConfig'){ //Open token config
const element = document.getElementById(token.sheet.id);
if (element == null) token.sheet.render(true);
else token.sheet.close();
}
}
} }
} }

270
src/external.js Normal file
View File

@@ -0,0 +1,270 @@
import * as MODULE from "../MaterialDeck.js";
import {streamDeck} from "../MaterialDeck.js";
export class ExternalModules{
constructor(){
this.active = false;
}
async updateAll(){
if (this.active == false) return;
for (let i=0; i<32; i++){
let data = streamDeck.buttonContext[i];
if (data == undefined || data.action != 'external') continue;
await this.update(data.settings,data.context);
}
}
update(settings,context){
this.active = true;
let module = settings.module;
if (module == undefined) module = 'fxmaster';
if (module == 'fxmaster') this.updateFxMaster(settings,context);
else if (module == 'gmscreen') this.updateGMScreen(settings,context);
}
keyPress(settings,context){
if (this.active == false) return;
let module = settings.module;
if (module == undefined) module = 'fxmaster';
if (module == 'fxmaster')
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;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//FxMaster
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
updateFxMaster(settings,context){
const fxmaster = game.modules.get("fxmaster");
if (fxmaster == undefined || fxmaster.active == false) return;
const type = (settings.fxMasterType == undefined) ? 'weatherControls' : settings.fxMasterType;
const displayIcon = settings.displayFxMasterIcon;
const displayName = settings.displayFxMasterName;
let ring = 0;
let ringColor = "#000000";
let background = "#000000"
let icon = '';
let name = '';
if (type == 'weatherControls') {
const effect = (settings.weatherEffect == undefined) ? 'leaves' : settings.weatherEffect;
name = CONFIG.weatherEffects[effect].label;
icon = CONFIG.weatherEffects[effect].icon;
ring = this.findWeatherEffect(effect) != undefined ? 2 : 1;
ringColor = ring < 2 ? '#000000' : "#00ff00";
}
else if (type == 'colorize') {
background = (settings.fxMasterColorizeColor == undefined) ? '#000000' : settings.fxMasterColorizeColor;
icon = "fas fa-palette";
name = game.i18n.localize("MaterialDeck.FxMaster.Colorize");
const filters = canvas.scene.getFlag("fxmaster", "filters");
ring = 2;
if (filters == undefined || filters['core_color'] == undefined) {
ringColor = "#000000";
}
else {
const colors = filters['core_color'].options;
let red = Math.ceil(colors.red*255).toString(16);
if (red.length == 1) red = '0' + red;
let green = Math.ceil(colors.green*255).toString(16);
if (green.length == 1) green = '0' + green;
let blue = Math.ceil(colors.blue*255).toString(16);
if (blue.length == 1) blue = '0' + blue;
ringColor = "#" + red + green + blue;
}
}
else if (type == 'filters') {
const filter = (settings.fxMasterFilter == undefined) ? 'underwater' : settings.fxMasterFilter;
name = CONFIG.fxmaster.filters[filter].label;
background = "#340057";
if (displayIcon){
if (filter == 'underwater') icon = "fas fa-water";
else if (filter == 'predator') icon = "fas fa-wave-square";
else if (filter == 'oldfilm') icon = "fas fa-film";
else if (filter == 'bloom') icon = "fas fa-ghost";
}
const fxmaster = canvas.scene.getFlag("fxmaster", "filters");
ring = 1;
if (fxmaster != undefined) {
const objKeys = Object.keys(fxmaster);
for (let i=0; i<objKeys.length; i++){
if (objKeys[i] == "core_"+filter) {
ring = 2;
ringColor = "#A600FF";
break;
}
}
}
}
else if (type == 'clear'){
icon = "fas fa-trash";
name = game.i18n.localize("MaterialDeck.FxMaster.Clear");
}
if (displayIcon) streamDeck.setIcon(context,icon,background,ring,ringColor);
else streamDeck.setIcon(context, "", background,ring,ringColor);
if (displayName == 0) name = "";
streamDeck.setTitle(name,context);
}
hexToRgb(hex) {
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
red: parseInt(result[1], 16)/256,
green: parseInt(result[2], 16)/256,
blue: parseInt(result[3], 16)/256
} : null;
}
keyPressFxMaster(settings,context){
const fxmaster = game.modules.get("fxmaster");
if (fxmaster == undefined || fxmaster.active == false) return;
const type = (settings.fxMasterType == undefined) ? 'weatherControls' : settings.fxMasterType;
if (type == 'weatherControls') {
const effect = (settings.weatherEffect == undefined) ? 'leaves' : settings.weatherEffect;
let exists = false;
let newEffects = {};
let effects = canvas.scene.getFlag("fxmaster", "effects");
if (effects != undefined){
const weatherIds = Object.keys(effects);
for (let i=0; i<weatherIds.length; i++){
const weather = effects[weatherIds[i]].type;
if (weather === effect) {
exists = true;
continue;
}
newEffects[weatherIds[i]] = effects[weatherIds[i]];
}
}
const density = (settings.densitySlider == undefined) ? 50 : settings.densitySlider;
const speed = (settings.speedSlider == undefined) ? 50 : settings.speedSlider;
const direction = (settings.directionSlider == undefined) ? 50 : settings.directionSlider;
const scale = (settings.scaleSlider == undefined) ? 50 : settings.scaleSlider;
const color = (settings.fxMasterWeatherColor == undefined) ? "#000000" : settings.fxMasterWeatherColor;
const applyColor = (settings.fxWeatherEnColor == undefined) ? false : settings.fxWeatherEnColor;
if (exists == false) {
newEffects[randomID()] = {
type: effect,
options: {
density: density,
speed: speed,
scale: scale,
tint: color,
direction: direction,
apply_tint: applyColor
}
};
}
canvas.scene.unsetFlag("fxmaster", "effects").then(() => {
canvas.scene.setFlag("fxmaster", "effects", newEffects);
});
}
else if (type == 'colorize') {
const color = (settings.fxMasterColorizeColor == undefined) ? '#000000' : settings.fxMasterColorizeColor;
const filters = canvas.scene.getFlag("fxmaster", "filters");
let newFilters = {};
if (filters != undefined){
const filterObjects = Object.keys(filters);
for (let i=0; i<filterObjects.length; i++){
if (filterObjects[i] == 'core_color'){
//continue;
}
newFilters[filterObjects[i]] = filters[filterObjects[i]];
}
}
newFilters['core_color'] = {
type : 'color',
options: this.hexToRgb(color)
};
canvas.scene.unsetFlag("fxmaster", "filters").then(() => {
canvas.scene.setFlag("fxmaster", "filters", newFilters);
});
}
else if (type == 'filters') {
const filter = (settings.fxMasterFilter == undefined) ? 'underwater' : settings.fxMasterFilter;
const filters = canvas.scene.getFlag("fxmaster", "filters");
let newFilters = {};
let exists = false;
if (filters != undefined){
const filterObjects = Object.keys(filters);
for (let i=0; i<filterObjects.length; i++){
if (filterObjects[i] == 'core_'+filter){
exists = true;
continue;
}
newFilters[filterObjects[i]] = filters[filterObjects[i]];
}
}
if (exists == false) {
newFilters['core_'+filter] = {type : filter};
}
canvas.scene.unsetFlag("fxmaster", "filters").then(() => {
canvas.scene.setFlag("fxmaster", "filters", newFilters);
});
}
else if (type == 'clear'){
canvas.scene.unsetFlag("fxmaster", "filters");
canvas.scene.unsetFlag("fxmaster", "effects");
}
}
findWeatherEffect(effect){
const effects = canvas.scene.getFlag("fxmaster", "effects");
if (effects == undefined) return undefined;
const weatherIds = Object.keys(effects);
for (let i = 0; i < weatherIds.length; ++i) {
const weather = effects[weatherIds[i]].type;
if (weather === effect) return weatherIds[i];
}
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

@@ -29,18 +29,62 @@ export class MacroControl{
if(macroNumber == undefined || isNaN(parseInt(macroNumber))){ if(macroNumber == undefined || isNaN(parseInt(macroNumber))){
macroNumber = 0; macroNumber = 0;
} }
if (mode == undefined) mode = 0; if (mode == undefined) mode = 'hotbar';
if (displayName == undefined) displayName = false; if (displayName == undefined) displayName = false;
if (background == undefined) background = '#000000'; if (background == undefined) background = '#000000';
macroNumber = parseInt(macroNumber); macroNumber = parseInt(macroNumber);
if (mode == 'macroBoard') { //Macro board
let name = "";
let src = '';
if (settings.macroBoardMode == 'offset') { //Offset
let ringOffColor = settings.offRing;
if (ringOffColor == undefined) ringOffColor = '#000000';
//Macro Hotbar let ringOnColor = settings.onRing;
if (mode < 2){ if (ringOnColor == undefined) ringOnColor = '#00FF00';
let macroOffset = parseInt(settings.macroOffset);
if (macroOffset == undefined || isNaN(macroOffset)) macroOffset = 0;
if (macroOffset == parseInt(this.offset)) ringColor = ringOnColor;
else ringColor = ringOffColor;
ring = 2;
}
else { //Execute macro
macroNumber += this.offset - 1;
if (macroNumber < 0) macroNumber = 0;
var macroId = game.settings.get(MODULE.moduleName,'macroSettings').macros[macroNumber];
background = game.settings.get(MODULE.moduleName,'macroSettings').color[macroNumber];
if (background == undefined) background = '#000000';
src = "";
if (macroId != undefined){
let macro = game.macros._source.find(p => p._id == macroId);
if (macro != undefined) {
name += macro.name;
src += macro.img;
}
}
ring = 0;
}
if (icon) streamDeck.setIcon(context,src,background,ring,ringColor);
else streamDeck.setIcon(context, "", background,ring,ringColor);
if (displayName == 0) name = "";
streamDeck.setTitle(name,context);
}
else { //Macro Hotbar
let macroId let macroId
if (mode == 0) macroId = game.user.data.hotbar[macroNumber]; if (mode == 'hotbar') macroId = game.user.data.hotbar[macroNumber];
else { else {
let macros = game.macros.apps[0].macros; let macros;
if (mode == 'customHotbar' && game.modules.get('custom-hotbar') != undefined) {
macros = ui.customHotbar.macros;
}
else macros = game.macros.apps[0].macros;
if (macroNumber > 9) macroNumber = 0;
for (let j=0; j<10; j++){ for (let j=0; j<10; j++){
if (macros[j].key == macroNumber){ if (macros[j].key == macroNumber){
if (macros[j].macro == null) macroId == undefined; if (macros[j].macro == null) macroId == undefined;
@@ -58,56 +102,18 @@ export class MacroControl{
src += macro.img; src += macro.img;
} }
} }
if (icon) streamDeck.setIcon(1,context,src,background); if (icon) streamDeck.setIcon(context,src,background);
else streamDeck.setIcon(0, context, "", background); else streamDeck.setIcon(context, "", background);
if (displayName == 0) name = "";
streamDeck.setTitle(name,context);
}
else { //Macro board
let name = "";
let src = '';
if (settings.macroBoardMode == 0) { //Execute macro
macroNumber += this.offset - 1;
if (macroNumber < 0) macroNumber = 0;
var macroId = game.settings.get(MODULE.moduleName,'macroSettings').macros[macroNumber];
background = game.settings.get(MODULE.moduleName,'macroSettings').color[macroNumber];
if (background == undefined) background = '#000000';
src = "";
if (macroId != undefined){
let macro = game.macros._source.find(p => p._id == macroId);
if (macro != undefined) {
name += macro.name;
src += macro.img;
}
}
}
else { //Offset
let ringOffColor = settings.offRing;
if (ringOffColor == undefined) ringOffColor = '#000000';
let ringOnColor = settings.onRing;
if (ringOnColor == undefined) ringOnColor = '#00FF00';
let macroOffset = parseInt(settings.macroOffset);
if (macroOffset == undefined || isNaN(macroOffset)) macroOffset = 0;
if (macroOffset == parseInt(this.offset)) ringColor = ringOnColor;
else ringColor = ringOffColor;
ring = 2;
}
if (icon) streamDeck.setIcon(1, context,src,background,ring,ringColor);
else streamDeck.setIcon(0, context, "", background,ring,ringColor);
if (displayName == 0) name = ""; if (displayName == 0) name = "";
streamDeck.setTitle(name,context); streamDeck.setTitle(name,context);
} }
} }
hotbar(macros){ hotbar(macros){
for (let i=0; i<32; i++){ for (let i=0; i<32; i++){
let data = streamDeck.buttonContext[i]; let data = streamDeck.buttonContext[i];
if (data == undefined || data.action != 'macro') continue; if (data == undefined || data.action != 'macro' || data.settings.macroMode == 'macroBoard') continue;
let context = data.context; let context = data.context;
let mode = data.settings.macroMode; let mode = data.settings.macroMode;
let displayName = data.settings.displayName; let displayName = data.settings.displayName;
@@ -118,16 +124,17 @@ export class MacroControl{
if(macroNumber == undefined || isNaN(parseInt(macroNumber))){ if(macroNumber == undefined || isNaN(parseInt(macroNumber))){
macroNumber = 1; macroNumber = 1;
} }
if (mode == undefined) mode = 0; if (mode == undefined) mode = 'hotbar';
if (mode == 2) continue; if (mode == 'Macro Board') continue;
if (displayName == undefined) displayName = false; if (displayName == undefined) displayName = false;
if (background == undefined) background = '#000000'; if (background == undefined) background = '#000000';
let macroId; let macroId;
if (mode == 0){ if (mode == 'hotbar'){
macroId = game.user.data.hotbar[macroNumber]; macroId = game.user.data.hotbar[macroNumber];
} }
else { else {
if (macroNumber > 9) macroNumber = 0;
for (let j=0; j<10; j++){ for (let j=0; j<10; j++){
if (macros[j].key == macroNumber){ if (macros[j].key == macroNumber){
if (macros[j].macro == null) macroId == undefined; if (macros[j].macro == null) macroId == undefined;
@@ -141,7 +148,7 @@ export class MacroControl{
name += macro.name; name += macro.name;
src += macro.img; src += macro.img;
} }
streamDeck.setIcon(1,context,src,background); streamDeck.setIcon(context,src,background);
if (displayName == 0) name = ""; if (displayName == 0) name = "";
streamDeck.setTitle(name,context); streamDeck.setTitle(name,context);
} }
@@ -149,32 +156,37 @@ export class MacroControl{
keyPress(settings){ keyPress(settings){
let mode = settings.macroMode; let mode = settings.macroMode;
if (mode == undefined) mode = 0; if (mode == undefined) mode = 'hotbar';
let macroNumber = settings.macroNumber; let macroNumber = settings.macroNumber;
if(macroNumber == undefined || isNaN(parseInt(macroNumber))){ if(macroNumber == undefined || isNaN(parseInt(macroNumber))){
macroNumber = 0; macroNumber = 0;
} }
if (mode == 0 || mode == 1) if (mode == 'hotbar' || mode == 'visibleHotbar' || mode == 'customHotbar')
this.executeHotbar(macroNumber,mode); this.executeHotbar(macroNumber,mode);
else { else {
if (settings.macroBoardMode == 0) if (settings.macroBoardMode == 'offset') {
this.executeBoard(macroNumber);
else {
let macroOffset = settings.macroOffset; let macroOffset = settings.macroOffset;
if (macroOffset == undefined) macroOffset = 0; if (macroOffset == undefined) macroOffset = 0;
this.offset = macroOffset; this.offset = macroOffset;
this.updateAll(); this.updateAll();
} }
else
this.executeBoard(macroNumber);
} }
} }
executeHotbar(macroNumber,mode){ executeHotbar(macroNumber,mode){
let macroId let macroId
if (mode == 0) macroId = game.user.data.hotbar[macroNumber]; if (mode == 'hotbar') macroId = game.user.data.hotbar[macroNumber];
else { else {
let macros = game.macros.apps[0].macros; let macros;
if (mode == 'customHotbar' && game.modules.get('custom-hotbar') != undefined) {
macros = ui.customHotbar.macros;
}
else macros = game.macros.apps[0].macros;
if (macroNumber > 9) macroNumber = 0;
for (let j=0; j<10; j++){ for (let j=0; j<10; j++){
if (macros[j].key == macroNumber){ if (macros[j].key == macroNumber){
if (macros[j].macro == null) macroId == undefined; if (macros[j].macro == null) macroId == undefined;
@@ -200,7 +212,7 @@ export class MacroControl{
let furnaceEnabled = false; let furnaceEnabled = false;
let furnace = game.modules.get("furnace"); let furnace = game.modules.get("furnace");
if (furnace != undefined && furnace.active) furnaceEnabled = true; if (furnace != undefined && furnace.active) furnaceEnabled = true;
if (args == undefined || args[number] == undefined || args[macroNumber] == "") furnaceEnabled = false; if (args == undefined || args[macroNumber] == undefined || args[macroNumber] == "") furnaceEnabled = false;
if (furnaceEnabled == false) macro.execute(); if (furnaceEnabled == false) macro.execute();
else { else {
let chatData = { let chatData = {

View File

@@ -359,8 +359,14 @@ export class soundboardConfigForm extends FormApplication {
else if (this.settings.selectedPlaylists[iteration] == 'FP') selectedPlaylist = 'FP'; else if (this.settings.selectedPlaylists[iteration] == 'FP') selectedPlaylist = 'FP';
else { else {
const pl = game.playlists.entities.find(p => p._id == this.settings.selectedPlaylists[iteration]); const pl = game.playlists.entities.find(p => p._id == this.settings.selectedPlaylists[iteration]);
selectedPlaylist = pl._id; if (pl == undefined){
sounds = pl.sounds; selectedPlaylist = 'none';
sounds = [];
}
else {
sounds = pl.sounds;
selectedPlaylist = pl._id;
}
} }
let styleSS = ""; let styleSS = "";
let styleFP ="display:none"; let styleFP ="display:none";

View File

@@ -1,33 +1,90 @@
import * as MODULE from "../MaterialDeck.js"; import * as MODULE from "../MaterialDeck.js";
import {streamDeck} from "../MaterialDeck.js";
export class Move{ export class Move{
constructor(){ constructor(){
this.active = false; this.active = false;
} }
update(settings,context){
const background = settings.background ? settings.background : '#000000';
const mode = settings.mode ? settings.mode : 'canvas';
const type = settings.type ? settings.type : 'move';
let url = '';
if (mode == 'canvas' || (mode == 'selectedToken' && type == 'move')){
const dir = settings.dir ? settings.dir : 'center';
if (dir == 'center') //center
url = "modules/MaterialDeck/img/move/center.png";
else if (dir == 'up') //up
url = "modules/MaterialDeck/img/move/up.png";
else if (dir == 'down') //down
url = "modules/MaterialDeck/img/move/down.png";
else if (dir == 'right') //right
url = "modules/MaterialDeck/img/move/right.png";
else if (dir == 'left') //left
url = "modules/MaterialDeck/img/move/left.png";
else if (dir == 'upRight')
url = "modules/MaterialDeck/img/move/upright.png";
else if (dir == 'upLeft')
url = "modules/MaterialDeck/img/move/upleft.png";
else if (dir == 'downRight')
url = "modules/MaterialDeck/img/move/downright.png";
else if (dir == 'downLeft')
url = "modules/MaterialDeck/img/move/downleft.png";
else if (dir == 'zoomIn')
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);
}
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 = 0; const type = settings.type ? settings.type : 'move';
if (dir == undefined) dir = 0;
if (dir < 9){ if (type == 'move'){
if (settings.mode == '1') if (dir == 'zoomIn') {//zoom in
this.moveToken(MODULE.selectedTokenId,dir); let viewPosition = canvas.scene._viewPosition;
else viewPosition.scale = viewPosition.scale*1.05;
this.moveCanvas(dir); 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 == 9) {//zoom in 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*1.05; 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 (dir == 10) {//zoom out
let viewPosition = canvas.scene._viewPosition; let rotationVal;
viewPosition.scale = viewPosition.scale*0.95; if (rotType == 'by') rotationVal = token.data.rotation + value;
viewPosition.duration = 100; else if (rotType == 'to') rotationVal = value;
canvas.animatePan(viewPosition);
token.update({rotation: rotationVal});
} }
} }
@@ -38,27 +95,27 @@ export class Move{
let x = token.x; let x = token.x;
let y = token.y; let y = token.y;
if (dir == '1') y -= gridSize; if (dir == 'up') y -= gridSize;
else if (dir == '2') y += gridSize; else if (dir == 'down') y += gridSize;
else if (dir == '3') x += gridSize; else if (dir == 'right') x += gridSize;
else if (dir == '4') x -= gridSize; else if (dir == 'left') x -= gridSize;
else if (dir == '5') { else if (dir == 'upRight') {
x += gridSize; x += gridSize;
y -= gridSize; y -= gridSize;
} }
else if (dir == '6') { else if (dir == 'upLeft') {
x -= gridSize; x -= gridSize;
y -= gridSize; y -= gridSize;
} }
else if (dir == '7') { else if (dir == 'downRight') {
x += gridSize; x += gridSize;
y += gridSize; y += gridSize;
} }
else if (dir == '8') { else if (dir == 'downLeft') {
x -= gridSize; x -= gridSize;
y += gridSize; y += gridSize;
} }
else if (dir == '0') { else if (dir == 'center') {
let location = token.getCenter(x,y); let location = token.getCenter(x,y);
canvas.animatePan(location); canvas.animatePan(location);
} }
@@ -71,27 +128,27 @@ export class Move{
const gridSize = canvas.scene.data.grid; const gridSize = canvas.scene.data.grid;
viewPosition.duration = 100; viewPosition.duration = 100;
if (dir == '1') viewPosition.y -= gridSize; if (dir == 'up') viewPosition.y -= gridSize;
else if (dir == '2') viewPosition.y += gridSize; else if (dir == 'down') viewPosition.y += gridSize;
else if (dir == '3') viewPosition.x += gridSize; else if (dir == 'right') viewPosition.x += gridSize;
else if (dir == '4') viewPosition.x -= gridSize; else if (dir == 'left') viewPosition.x -= gridSize;
else if (dir == '5') { else if (dir == 'upRight') {
viewPosition.x += gridSize; viewPosition.x += gridSize;
viewPosition.y -= gridSize; viewPosition.y -= gridSize;
} }
else if (dir == '6') { else if (dir == 'upLeft') {
viewPosition.x -= gridSize; viewPosition.x -= gridSize;
viewPosition.y -= gridSize; viewPosition.y -= gridSize;
} }
else if (dir == '7') { else if (dir == 'downRight') {
viewPosition.x += gridSize; viewPosition.x += gridSize;
viewPosition.y += gridSize; viewPosition.y += gridSize;
} }
else if (dir == '8') { else if (dir == 'downLeft') {
viewPosition.x -= gridSize; viewPosition.x -= gridSize;
viewPosition.y += gridSize; viewPosition.y += gridSize;
} }
else if (dir == '0') { else if (dir == 'center') {
viewPosition.x = (canvas.dimensions.sceneWidth+window.innerWidth)/2; viewPosition.x = (canvas.dimensions.sceneWidth+window.innerWidth)/2;
viewPosition.y = (canvas.dimensions.sceneHeight+window.innerHeight)/2; viewPosition.y = (canvas.dimensions.sceneHeight+window.innerHeight)/2;
} }

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,231 +18,108 @@ 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 = 0;
if (mode == 0) { //pause if (mode == 'pause') //pause
this.updatePause(settings.pauseFunction,context); this.updatePause(settings,context);
} else if (mode == 'controlButtons') //control buttons
else if (mode == 1) { //scene selection
this.updateScene(settings,context);
}
else if (mode == 2){ //control buttons
this.updateControl(settings,context); this.updateControl(settings,context);
} else if (mode == 'darkness') //darkness
else if (mode == 3){ //darkness
this.updateDarkness(settings,context); this.updateDarkness(settings,context);
} else if (mode == 'rollDice') //roll dice
else if (mode == 4){ //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 == 5) { //open sidebar tab
this.updateSidebar(settings,context); this.updateSidebar(settings,context);
} else if (mode == 'compendium') //open compendium
else if (mode == 6) { //open compendium
this.updateCompendium(settings,context); this.updateCompendium(settings,context);
} else if (mode == 'journal') //open journal
else if (mode == 7) { //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 = 0;
if (mode == 0) { //pause if (mode == 'pause') //pause
this.keyPressPause(settings.pauseFunction); this.keyPressPause(settings);
} else if (mode == 'controlButtons') //control buttons
else if (mode == 1) { //scene
this.keyPressScene(settings);
}
else if (mode == 2) { //control buttons
this.keyPressControl(settings); this.keyPressControl(settings);
} else if (mode == 'darkness') //darkness controll
else if (mode == 3) { //darkness controll
this.keyPressDarkness(settings); this.keyPressDarkness(settings);
} else if (mode == 'rollDice') //roll dice
else if (mode == 4) { //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 == 5) { //sidebar
this.keyPressSidebar(settings); this.keyPressSidebar(settings);
} else if (mode == 'compendium') //open compendium
else if (mode == 6) { //open compendium
this.keyPressCompendium(settings); this.keyPressCompendium(settings);
} else if (mode == 'journal') //open journal
else if (mode == 7) { //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 = 0; 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
src = 'modules/MaterialDeck/img/other/pause/pause.png';
let ringOffColor = settings.offRing; else if (pauseFunction == 'resume'){ //Resume game
if (ringOffColor == undefined) ringOffColor = '#000000'; ringColor = game.paused ? ringOffColor : ringOnColor;
src = 'modules/MaterialDeck/img/other/pause/resume.png';
let ringOnColor = settings.onRing;
if (ringOnColor == undefined) ringOnColor = '#00FF00';
let playlistType = settings.playlistType;
if (playlistType == undefined) playlistType = 0;
if (pauseFunction == 0){ //Pause game
if (game.paused) ringColor = ringOnColor;
else ringColor = ringOffColor;
src = 'action/images/other/pause/pause.png';
} }
else if (pauseFunction == 1){ //Resume game else if (pauseFunction == 'toggle') //toggle
if (game.paused == false) ringColor = ringOnColor; src = 'modules/MaterialDeck/img/other/pause/playpause.png';
else ringColor = ringOffColor; streamDeck.setIcon(context,src,background,2,ringColor,true);
src = 'action/images/other/pause/resume.png';
}
else if (pauseFunction == 2) { //toggle
if (game.paused == false) ringColor = ringOnColor;
else ringColor = ringOffColor;
src = 'action/images/other/pause/playpause.png';
}
streamDeck.setIcon(0,context,src,background,2,ringColor);
} }
keyPressPause(pauseFunction){ keyPressPause(settings){
if (pauseFunction == undefined) pauseFunction = 0; const pauseFunction = settings.pauseFunction ? settings.pauseFunction : 'pause';
if (pauseFunction == 0){ //Pause game
if (pauseFunction == 'pause'){ //Pause game
if (game.paused) return; if (game.paused) return;
game.togglePause(); game.togglePause();
} }
else if (pauseFunction == 1){ //Resume game else if (pauseFunction == 'resume'){ //Resume game
if (game.paused == false) return; if (game.paused == false) return;
game.togglePause(); game.togglePause();
} }
else if (pauseFunction == 2) { //toggle else if (pauseFunction == 'toggle') { //toggle
game.togglePause(); game.togglePause();
} }
} }
//////////////////////////////////////////////////////////////////////////////////////////////////
updateScene(settings,context){
if (canvas.scene == null) return;
let func = settings.sceneFunction;
if (func == undefined) func = 0;
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 playlistType = settings.playlistType;
if (playlistType == undefined) playlistType = 0;
let src = "";
let name = "";
if (func == 0){ //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 == 1) { //all scenes
let scene = game.scenes.apps[1].entities.find(p=>p.data.name == name);
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(1, context,src,background,2,ringColor);
}
keyPressScene(settings){
let func = settings.sceneFunction;
if (func == undefined) func = 0;
if (func == 0){ //visible scenes
let viewFunc = settings.sceneViewFunction;
if (viewFunc == undefined) viewFunc = 0;
let nr = parseInt(settings.sceneNr);
if (isNaN(nr)) nr = 1;
nr--;
let scene = game.scenes.apps[0].scenes[nr];
if (scene != undefined){
if (viewFunc == 0){
scene.view();
}
else if (viewFunc == 1){
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 = 0; const tool = settings.tool ? settings.tool : 'open';
let background = settings.background ? settings.background : '#000000';
let tool = settings.tool;
if (tool == undefined) tool = 0;
let background = settings.background;
if (background == undefined) background = '#000000';
let ringColor = '#000000' let ringColor = '#000000'
const controlName = this.getControlName(control);
const toolName = this.getToolName(control,tool);
let txt = ""; let txt = "";
let src = ""; let src = "";
const activeControl = ui.controls.activeControl; const activeControl = ui.controls.activeControl;
const activeTool = ui.controls.activeTool; const activeTool = ui.controls.activeTool;
if (control == 0) { //displayed controls if (control == 'dispControls') { //displayed controls
let controlNr = parseInt(settings.controlNr); let controlNr = parseInt(settings.controlNr);
if (isNaN(controlNr)) controlNr = 1; if (isNaN(controlNr)) controlNr = 1;
controlNr--; controlNr--;
const selectedControl = ui.controls.controls[controlNr]; const selectedControl = ui.controls.controls[controlNr];
if (selectedControl != undefined){ if (selectedControl != undefined){
if (tool == 0){ //open category if (tool == 'open'){ //open category
txt = game.i18n.localize(selectedControl.title); txt = game.i18n.localize(selectedControl.title);
src = selectedControl.icon; src = selectedControl.icon;
if (activeControl == selectedControl.name) if (activeControl == selectedControl.name)
@@ -250,7 +127,7 @@ export class OtherControls{
} }
} }
} }
else if (control == 1){ //displayed tools else if (control == 'dispTools'){ //displayed tools
let controlNr = parseInt(settings.controlNr); let controlNr = parseInt(settings.controlNr);
if (isNaN(controlNr)) controlNr = 1; if (isNaN(controlNr)) controlNr = 1;
controlNr--; controlNr--;
@@ -263,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";
@@ -274,25 +148,22 @@ export class OtherControls{
} }
} }
else { // specific control/tool else { // specific control/tool
const selectedControl = ui.controls.controls.find(c => c.name == controlName); const selectedControl = ui.controls.controls.find(c => c.name == control);
if (selectedControl != undefined){ if (selectedControl != undefined){
if (tool == 0){ //open category if (tool == 'open'){ //open category
txt = game.i18n.localize(selectedControl.title); txt = game.i18n.localize(selectedControl.title);
src = selectedControl.icon; src = selectedControl.icon;
if (activeControl == selectedControl.name) if (activeControl == selectedControl.name)
ringColor = "#FF7B00"; ringColor = "#FF7B00";
} }
else { else {
const selectedTool = selectedControl.tools.find(t => t.name == toolName); const selectedTool = selectedControl.tools.find(t => t.name == tool);
if (selectedTool != undefined){ if (selectedTool != undefined){
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";
@@ -300,33 +171,27 @@ export class OtherControls{
} }
} }
} }
streamDeck.setIcon(1,context,src,background,2,ringColor); streamDeck.setIcon(context,src,background,2,ringColor);
streamDeck.setTitle(txt,context); streamDeck.setTitle(txt,context);
} }
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 = 0; const tool = settings.tool ? settings.tool : 'open';
let tool = settings.tool;
if (tool == undefined) tool = 0;
const controlName = this.getControlName(control);
const toolName = this.getToolName(control,tool);
if (control == 0){ //displayed controls if (control == 'dispControls'){ //displayed controls
let controlNr = parseInt(settings.controlNr); let controlNr = parseInt(settings.controlNr);
if (isNaN(controlNr)) controlNr = 1; if (isNaN(controlNr)) controlNr = 1;
controlNr--; controlNr--;
const selectedControl = ui.controls.controls[controlNr]; const selectedControl = ui.controls.controls[controlNr];
if (selectedControl != undefined){ if (selectedControl != undefined){
ui.controls.activeControl = controlName; ui.controls.activeControl = 'token';
selectedControl.activeTool = selectedControl.activeTool; selectedControl.activeTool = selectedControl.activeTool;
canvas.getLayer(selectedControl.layer).activate(); canvas.getLayer(selectedControl.layer).activate();
} }
} }
else if (control == 1){ //displayed tools else if (control == 'dispTools'){ //displayed tools
let controlNr = parseInt(settings.controlNr); let controlNr = parseInt(settings.controlNr);
if (isNaN(controlNr)) controlNr = 1; if (isNaN(controlNr)) controlNr = 1;
controlNr--; controlNr--;
@@ -347,17 +212,17 @@ export class OtherControls{
} }
} }
else { //select control else { //select control
const selectedControl = ui.controls.controls.find(c => c.name == controlName); const selectedControl = ui.controls.controls.find(c => c.name == control);
if (selectedControl != undefined){ if (selectedControl != undefined){
if (tool == 0){ //open category if (tool == 'open'){ //open category
ui.controls.activeControl = controlName; ui.controls.activeControl = 'token';
selectedControl.activeTool = selectedControl.activeTool; selectedControl.activeTool = selectedControl.activeTool;
canvas.getLayer(selectedControl.layer).activate(); canvas.getLayer(selectedControl.layer).activate();
} }
else { else {
const selectedTool = selectedControl.tools.find(t => t.name == toolName); const selectedTool = selectedControl.tools.find(t => t.name == tool);
if (selectedTool != undefined){ if (selectedTool != undefined){
ui.controls.activeControl = controlName; ui.controls.activeControl = control;
canvas.getLayer(selectedControl.layer).activate(); canvas.getLayer(selectedControl.layer).activate();
if (selectedTool.toggle) { if (selectedTool.toggle) {
selectedTool.active = !selectedTool.active; selectedTool.active = !selectedTool.active;
@@ -367,7 +232,7 @@ export class OtherControls{
selectedTool.onClick(); selectedTool.onClick();
} }
else else
selectedControl.activeTool = toolName; selectedControl.activeTool = tool;
} }
} }
} }
@@ -375,128 +240,41 @@ export class OtherControls{
ui.controls.render(); ui.controls.render();
} }
getControlName(control){
control -= 2;
let name;
if (control == 0) name = 'token';
else if (control == 1) name = 'measure';
else if (control == 2) name = 'tiles';
else if (control == 3) name = 'drawings';
else if (control == 4) name = 'walls';
else if (control == 5) name = 'lighting';
else if (control == 6) name = 'sounds';
else if (control == 7) name = 'notes';
return name;
}
getToolName(control,tool){
control -= 2;
tool--;
let name;
if (control == 0){ //basic controls
if (tool == 0) name = 'select';
else if (tool == 1) name = 'target';
else if (tool == 2) name = 'ruler';
}
else if (control == 1){ //measurement controls
if (tool == 0) name = 'circle';
else if (tool == 1) name = 'cone';
else if (tool == 2) name = 'rect';
else if (tool == 3) name = 'ray';
else if (tool == 4) name = 'clear';
}
else if (control == 2){ //tile controls
if (tool == 0) name = 'select';
else if (tool == 1) name = 'tile';
else if (tool == 2) name = 'browse';
}
else if (control == 3){ //drawing tools
if (tool == 0) name = 'select';
else if (tool == 1) name = 'rect';
else if (tool == 2) name = 'ellipse';
else if (tool == 3) name = 'polygon';
else if (tool == 4) name = 'freehand';
else if (tool == 5) name = 'text';
else if (tool == 6) name = 'configure';
else if (tool == 7) name = 'clear';
}
else if (control == 4){ //wall controls
if (tool == 0) name = 'select';
else if (tool == 1) name = 'walls';
else if (tool == 2) name = 'terrain';
else if (tool == 3) name = 'invisible';
else if (tool == 4) name = 'ethereal';
else if (tool == 5) name = 'doors';
else if (tool == 6) name = 'secret';
else if (tool == 7) name = 'clone';
else if (tool == 8) name = 'snap';
else if (tool == 9) name = 'clear';
}
else if (control == 5){ //lighting controls
if (tool == 0) name = 'light';
else if (tool == 1) name = 'day';
else if (tool == 2) name = 'night';
else if (tool == 3) name = 'reset';
else if (tool == 4) name = 'clear';
}
else if (control == 6){ //ambient sound controls
if (tool == 0) name = 'sound';
else if (tool == 1) name = 'clear';
}
else if (control == 7){ //journal notes
if (tool == 0) name = 'select';
else if (tool == 1) name = 'toggle';
else if (tool == 2) name = 'clear';
}
return name;
}
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
updateDarkness(settings,context){ updateDarkness(settings,context){
let func = settings.darknessFunction; const func = settings.darknessFunction ? settings.darknessFunction : 'value';
if (func == undefined) func = 0; 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 = "";
if (func == 0){ //value if (func == 'value'){ //value
src = 'action/images/other/darkness/darkness.png'; src = 'modules/MaterialDeck/img/other/darkness/darkness.png';
} }
else if (func == 1){ //increase/decrease else if (func == 'incDec'){ //increase/decrease
if (value < 0) src = 'action/images/other/darkness/decreasedarkness.png'; if (value < 0) src = 'modules/MaterialDeck/img/other/darkness/decreasedarkness.png';
else src = 'action/images/other/darkness/increasedarkness.png'; else src = 'modules/MaterialDeck/img/other/darkness/increasedarkness.png';
} }
else if (func == 2){ //display darkness else if (func == 'disp'){ //display darkness
src = 'action/images/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);
streamDeck.setIcon(0, context,src,background); streamDeck.setIcon(context,src,background);
} }
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 = 0; const value = parseFloat(settings.darknessValue) ? parseFloat(settings.darknessValue) : 0;
let value = parseFloat(settings.darknessValue); if (func == 'value') //value
if (value == undefined) value = 0;
if (func == 0){ //value
canvas.scene.update({darkness: value}); canvas.scene.update({darkness: value});
} else if (func == 'incDec'){ //increase/decrease
else if (func == 1){ //increase/decrease let darkness = canvas.scene.data.darkness - value;
let darkness = canvas.scene.data.darkness;
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});
@@ -505,168 +283,167 @@ export class OtherControls{
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
updateRollTable(settings,context){ updateRollDice(settings,context){
let name = settings.rollTableName; const background = settings.background ? settings.background : '#000000';
if (name == undefined) return; let txt = '';
let background = settings.background; if (settings.displayDiceName) txt = 'Roll: ' + settings.rollDiceFormula;
if (background == undefined) background = "#000000";
let table = game.tables.entities.find(p=>p.name == name);
let 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(1, context,src,background); streamDeck.setIcon(context,'',background);
} }
keyPressRollTable(settings){ keyPressRollDice(settings,context){
let func = settings.rolltableFunction; if (settings.rollDiceFormula == undefined || settings.rollDiceFormula == '') return;
if (func == undefined) func = 0; const rollFunction = settings.rollDiceFunction ? settings.rollDiceFunction : 'public';
let name = settings.rollTableName; let actor;
if (name == undefined) return; let tokenControlled = false;
let background = settings.background; if (MODULE.selectedTokenId != undefined) actor = canvas.tokens.children[0].children.find(p => p.id == MODULE.selectedTokenId).actor;
if (background == undefined) background = "#000000"; if (actor != undefined) tokenControlled = true;
let table = game.tables.entities.find(p=>p.name == name); let r;
if (tokenControlled) r = new Roll(settings.rollDiceFormula,actor.getRollData());
else r = new Roll(settings.rollDiceFormula);
if (table != undefined) { r.evaluate();
if (func == 0){ //open
table.sheet.render(true); if (rollFunction == 'public') {
} r.toMessage(r,{rollMode:"roll"})
else if (func == 1) {//Public roll }
table.draw({rollMode:"roll"}); else if (rollFunction == 'private') {
} r.toMessage(r,{rollMode:"selfroll"})
else if (func == 2) {//private roll }
table.draw({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;
} }
} }
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
getSidebarId(nr){ updateRollTable(settings,context){
let id; const name = settings.rollTableName;
if (nr == 0) id = 'chat'; if (name == undefined) return;
else if (nr == 1) id = 'combat';
else if (nr == 2) id = 'scenes'; const background = settings.background ? settings.background : '#000000';
else if (nr == 3) id = 'actors'; const table = game.tables.entities.find(p=>p.name == name);
else if (nr == 4) id = 'items'; let txt = settings.displayRollName ? table.name : '';
else if (nr == 5) id = 'journal'; let src = settings.displayRollIcon ? table.data.img : '';
else if (nr == 6) id = 'tables';
else if (nr == 7) id = 'playlists'; if (table == undefined) {
else if (nr == 8) id = 'compendium'; src = '';
else if (nr == 9) id = 'settings'; txt = '';
else id = ''; }
return id;
streamDeck.setTitle(txt,context);
streamDeck.setIcon(context,src,background);
} }
keyPressRollTable(settings){
const name = settings.rollTableName;
if (name == undefined) return;
const func = settings.rolltableFunction ? settings.rolltableFunction : 'open';
const table = game.tables.entities.find(p=>p.name == name);
if (table != undefined) {
if (func == 'open'){ //open
const element = document.getElementById(table.sheet.id);
if (element == null) table.sheet.render(true);
else table.sheet.close();
}
else if (func == 'public') //Public roll
table.draw({rollMode:"roll"});
else if (func == 'private') //private roll
table.draw({rollMode:"selfroll"});
}
}
//////////////////////////////////////////////////////////////////////////////////////////
getSidebarName(nr){ getSidebarName(nr){
let name; let name;
if (nr == 0) name = game.i18n.localize("SIDEBAR.TabChat"); if (nr == 'chat') name = game.i18n.localize("SIDEBAR.TabChat");
else if (nr == 1) name = game.i18n.localize("SIDEBAR.TabCombat"); else if (nr == 'combat') name = game.i18n.localize("SIDEBAR.TabCombat");
else if (nr == 2) name = game.i18n.localize("SIDEBAR.TabScenes"); else if (nr == 'scenes') name = game.i18n.localize("SIDEBAR.TabScenes");
else if (nr == 3) name = game.i18n.localize("SIDEBAR.TabActors"); else if (nr == 'actors') name = game.i18n.localize("SIDEBAR.TabActors");
else if (nr == 4) name = game.i18n.localize("SIDEBAR.TabItems"); else if (nr == 'items') name = game.i18n.localize("SIDEBAR.TabItems");
else if (nr == 5) name = game.i18n.localize("SIDEBAR.TabJournal"); else if (nr == 'journal') name = game.i18n.localize("SIDEBAR.TabJournal");
else if (nr == 6) name = game.i18n.localize("SIDEBAR.TabTables"); else if (nr == 'tables') name = game.i18n.localize("SIDEBAR.TabTables");
else if (nr == 7) name = game.i18n.localize("SIDEBAR.TabPlaylists"); else if (nr == 'playlists') name = game.i18n.localize("SIDEBAR.TabPlaylists");
else if (nr == 8) name = game.i18n.localize("SIDEBAR.TabCompendium"); else if (nr == 'compendium') name = game.i18n.localize("SIDEBAR.TabCompendium");
else if (nr == 9) name = game.i18n.localize("SIDEBAR.TabSettings"); else if (nr == 'settings') name = game.i18n.localize("SIDEBAR.TabSettings");
else if (nr == 10) name = game.i18n.localize("SIDEBAR.CollapseToggle"); else if (nr == 'collapse') name = game.i18n.localize("SIDEBAR.CollapseToggle");
return name; return name;
} }
getSidebarIcon(nr){ getSidebarIcon(nr){
let icon; let icon;
if (nr == 0) icon = window.CONFIG.ChatMessage.sidebarIcon; if (nr == 'chat') icon = window.CONFIG.ChatMessage.sidebarIcon;
else if (nr == 1) icon = window.CONFIG.Combat.sidebarIcon; else if (nr == 'combat') icon = window.CONFIG.Combat.sidebarIcon;
else if (nr == 2) icon = window.CONFIG.Scene.sidebarIcon; else if (nr == 'scenes') icon = window.CONFIG.Scene.sidebarIcon;
else if (nr == 3) icon = window.CONFIG.Actor.sidebarIcon; else if (nr == 'actors') icon = window.CONFIG.Actor.sidebarIcon;
else if (nr == 4) icon = window.CONFIG.Item.sidebarIcon; else if (nr == 'items') icon = window.CONFIG.Item.sidebarIcon;
else if (nr == 5) icon = window.CONFIG.JournalEntry.sidebarIcon; else if (nr == 'journal') icon = window.CONFIG.JournalEntry.sidebarIcon;
else if (nr == 6) icon = window.CONFIG.RollTable.sidebarIcon; else if (nr == 'tables') icon = window.CONFIG.RollTable.sidebarIcon;
else if (nr == 7) icon = window.CONFIG.Playlist.sidebarIcon; else if (nr == 'playlists') icon = window.CONFIG.Playlist.sidebarIcon;
else if (nr == 8) icon = "fas fa-atlas"; else if (nr == 'compendium') icon = "fas fa-atlas";
else if (nr == 9) icon = "fas fa-cogs"; else if (nr == 'settings') icon = "fas fa-cogs";
else if (nr == 10) icon = "fas fa-caret-right"; else if (nr == 'collapse') icon = "fas fa-caret-right";
return icon; return icon;
} }
updateSidebar(settings,context){ updateSidebar(settings,context){
let sidebarTab = settings.sidebarTab; const sidebarTab = settings.sidebarTab ? settings.sidebarTab : 'chat';
if (sidebarTab == undefined) sidebarTab = 0; 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 == 10 && collapsed))
ringColor = ringOnColor;
else
ringColor = ringOffColor;
streamDeck.setTitle(name,context); streamDeck.setTitle(name,context);
streamDeck.setIcon(1,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 = 0;
let collapsed = ui.sidebar._collapsed; if (sidebarTab == 'collapse'){
const collapsed = ui.sidebar._collapsed;
if (sidebarTab < 10) ui.sidebar.activateTab(this.getSidebarId(sidebarTab)); if (collapsed) ui.sidebar.expand();
else if (collapsed) ui.sidebar.expand(); else if (collapsed == false) ui.sidebar.collapse();
else if (collapsed == false) ui.sidebar.collapse(); }
else ui.sidebar.activateTab(sidebarTab);
} }
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
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'; streamDeck.setIcon(context,"",background,2,ringColor);
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(0,context,"",background,2,ringColor);
} }
keyPressCompendium(settings){ keyPressCompendium(settings){
@@ -685,36 +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'; streamDeck.setIcon(context,"",background,2,ringColor);
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(0,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;
journal.render(true); const element = document.getElementById("journal-"+journal.id);
if (element == null) journal.render(true);
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, {});
} }
} }

View File

@@ -19,16 +19,19 @@ export class PlaylistControl{
update(settings,context){ update(settings,context){
this.active = true; this.active = true;
if (settings.playlistMode == undefined) settings.playlistMode = 0; if (settings.playlistMode == undefined) settings.playlistMode = 'playlist';
if (settings.playlistMode == 0){ if (settings.playlistMode == 'playlist'){
this.updatePlaylist(settings,context); this.updatePlaylist(settings,context);
} }
else if (settings.playlistMode == 1){ else if (settings.playlistMode == 'track'){
this.updateTrack(settings,context); this.updateTrack(settings,context);
} }
else { else {
let src = 'action/images/playlist/stop.png'; let src = 'modules/MaterialDeck/img/playlist/stop.png';
streamDeck.setIcon(0,context,src,settings.background); if (game.playlists.playing.length > 0)
streamDeck.setIcon(context,src,settings.background,2,'#00FF00',true);
else
streamDeck.setIcon(context,src,settings.background,1,'#000000',true);
} }
} }
@@ -47,10 +50,10 @@ export class PlaylistControl{
if (ringOnColor == undefined) ringOnColor = '#00FF00'; if (ringOnColor == undefined) ringOnColor = '#00FF00';
let playlistType = settings.playlistType; let playlistType = settings.playlistType;
if (playlistType == undefined) playlistType = 0; if (playlistType == undefined) playlistType = 'playStop';
//Play/Stop //Play/Stop
if (playlistType == 0){ if (playlistType == 'playStop'){
let playlistNr = parseInt(settings.playlistNr); let playlistNr = parseInt(settings.playlistNr);
if (isNaN(playlistNr) || playlistNr < 1) playlistNr = 1; if (isNaN(playlistNr) || playlistNr < 1) playlistNr = 1;
playlistNr--; playlistNr--;
@@ -67,12 +70,12 @@ export class PlaylistControl{
} }
} }
//Offset //Offset
else { else if (playlistType == 'offset') {
let playlistOffset = parseInt(settings.offset); let playlistOffset = parseInt(settings.offset);
if (isNaN(playlistOffset)) playlistOffset = 0; if (isNaN(playlistOffset)) playlistOffset = 0;
if (playlistOffset == this.playlistOffset) ringColor = ringOnColor; if (playlistOffset == this.playlistOffset) ringColor = ringOnColor;
} }
streamDeck.setIcon(0,context,"",background,2,ringColor); streamDeck.setIcon(context,"",background,2,ringColor);
streamDeck.setTitle(name,context); streamDeck.setTitle(name,context);
} }
@@ -91,10 +94,10 @@ export class PlaylistControl{
if (ringOnColor == undefined) ringOnColor = '#00FF00'; if (ringOnColor == undefined) ringOnColor = '#00FF00';
let playlistType = settings.playlistType; let playlistType = settings.playlistType;
if (playlistType == undefined) playlistType = 0; if (playlistType == undefined) playlistType = 'playStop';
//Play/Stop //Play/Stop
if (playlistType == 0){ if (playlistType == 'playStop'){
let playlistNr = parseInt(settings.playlistNr); let playlistNr = parseInt(settings.playlistNr);
if (isNaN(playlistNr) || playlistNr < 1) playlistNr = 1; if (isNaN(playlistNr) || playlistNr < 1) playlistNr = 1;
playlistNr--; playlistNr--;
@@ -123,7 +126,7 @@ export class PlaylistControl{
if (isNaN(trackOffset)) trackOffset = 0; if (isNaN(trackOffset)) trackOffset = 0;
if (trackOffset == this.trackOffset) ringColor = ringOnColor; if (trackOffset == this.trackOffset) ringColor = ringOnColor;
} }
streamDeck.setIcon(0,context,"",background,2,ringColor); streamDeck.setIcon(context,"",background,2,ringColor);
streamDeck.setTitle(name,context); streamDeck.setTitle(name,context);
} }
@@ -163,13 +166,16 @@ export class PlaylistControl{
trackNr--; trackNr--;
trackNr += this.trackOffset; trackNr += this.trackOffset;
if (settings.playlistMode == undefined) settings.playlistMode = 0; if (settings.playlistMode == undefined) settings.playlistMode = 'playlist';
if (settings.playlistType == undefined) settings.playlistType = 0; if (settings.playlistType == undefined) settings.playlistType = 'playStop';
if (settings.playlistMode < 2){ if (settings.playlistMode == 'stopAll') {
if (settings.playlistType == 0) { this.stopAll(true);
}
else {
if (settings.playlistType == 'playStop') {
let playlist = this.getPlaylist(playlistNr); let playlist = this.getPlaylist(playlistNr);
if (playlist != undefined){ if (playlist != undefined){
if (settings.playlistMode == 0) if (settings.playlistMode == 'playlist')
this.playPlaylist(playlist,playlistNr); this.playPlaylist(playlist,playlistNr);
else { else {
let track = playlist.data.sounds[trackNr]; let track = playlist.data.sounds[trackNr];
@@ -180,7 +186,7 @@ export class PlaylistControl{
} }
} }
else { else {
if (settings.playlistMode == 0) { if (settings.playlistMode == 'playlist') {
this.playlistOffset = parseInt(settings.offset); this.playlistOffset = parseInt(settings.offset);
if (isNaN(this.playlistOffset)) this.playlistOffset = 0; if (isNaN(this.playlistOffset)) this.playlistOffset = 0;
} }
@@ -191,9 +197,7 @@ export class PlaylistControl{
this.updateAll(); this.updateAll();
} }
} }
else {
this.stopAll(true);
}
} }
async playPlaylist(playlist,playlistNr){ async playPlaylist(playlist,playlistNr){

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

@@ -22,7 +22,7 @@ export class SoundboardControl{
update(settings,context){ update(settings,context){
this.active = true; this.active = true;
let mode = settings.soundboardMode; let mode = settings.soundboardMode;
if (mode == undefined) mode = 0; if (mode == undefined) mode = 'playSound';
let txt = ""; let txt = "";
let src = ""; let src = "";
@@ -32,7 +32,7 @@ export class SoundboardControl{
let ringColor = "#000000" let ringColor = "#000000"
if (mode == 0){ //play sound if (mode == 'playSound'){ //play sound
let soundNr = parseInt(settings.soundNr); let soundNr = parseInt(settings.soundNr);
if (isNaN(soundNr)) soundNr = 1; if (isNaN(soundNr)) soundNr = 1;
soundNr--; soundNr--;
@@ -48,9 +48,9 @@ export class SoundboardControl{
if (settings.displayName && soundboardSettings.name != undefined) txt = soundboardSettings.name[soundNr]; if (settings.displayName && soundboardSettings.name != undefined) txt = soundboardSettings.name[soundNr];
if (settings.displayIcon && soundboardSettings.img != undefined) src = soundboardSettings.img[soundNr]; if (settings.displayIcon && soundboardSettings.img != undefined) src = soundboardSettings.img[soundNr];
streamDeck.setTitle(txt,context); streamDeck.setTitle(txt,context);
streamDeck.setIcon(1,context,src,background,2,ringColor); streamDeck.setIcon(context,src,background,2,ringColor);
} }
else if (mode == 1) { //Offset else if (mode == 'offset') { //Offset
let ringOffColor = settings.offRing; let ringOffColor = settings.offRing;
if (ringOffColor == undefined) ringOffColor = '#000000'; if (ringOffColor == undefined) ringOffColor = '#000000';
@@ -62,18 +62,24 @@ export class SoundboardControl{
if (offset == this.offset) ringColor = ringOnColor; if (offset == this.offset) ringColor = ringOnColor;
else ringColor = ringOffColor; else ringColor = ringOffColor;
streamDeck.setTitle(txt,context); streamDeck.setTitle(txt,context);
streamDeck.setIcon(1,context,"",background,2,ringColor); streamDeck.setIcon(context,"",background,2,ringColor);
} }
else if (mode == 2) { //Stop all sounds else if (mode == 'stopAll') { //Stop all sounds
let src = 'action/images/soundboard/stop.png'; let src = 'modules/MaterialDeck/img/playlist/stop.png';
streamDeck.setIcon(0,context,src,background); let soundPlaying = false;
for (let i=0; i<this.activeSounds.length; i++)
if (this.activeSounds[i]) soundPlaying = true;
if (soundPlaying)
streamDeck.setIcon(context,src,settings.background,2,'#00FF00',true);
else
streamDeck.setIcon(context,src,settings.background,1,'#000000',true);
} }
} }
keyPressDown(settings){ keyPressDown(settings){
let mode = settings.soundboardMode; let mode = settings.soundboardMode;
if (mode == undefined) mode = 0; if (mode == undefined) mode = 'playSound';
if (mode == 0) { //Play sound if (mode == 'playSound') { //Play sound
let soundNr = parseInt(settings.soundNr); let soundNr = parseInt(settings.soundNr);
if (isNaN(soundNr)) soundNr = 1; if (isNaN(soundNr)) soundNr = 1;
soundNr--; soundNr--;
@@ -87,13 +93,13 @@ export class SoundboardControl{
if (this.activeSounds[soundNr] == false) play = true; if (this.activeSounds[soundNr] == false) play = true;
this.playSound(soundNr,repeat,play); this.playSound(soundNr,repeat,play);
} }
else if (mode == 1) { //Offset else if (mode == 'offset') { //Offset
let offset = parseInt(settings.offset); let offset = parseInt(settings.offset);
if (isNaN(offset)) offset = 0; if (isNaN(offset)) offset = 0;
this.offset = offset; this.offset = offset;
this.updateAll(); this.updateAll();
} }
else { //Stop All Sounds else if (mode == 'stopAll') { //Stop All Sounds
for (let i=0; i<64; i++) { for (let i=0; i<64; i++) {
if (this.activeSounds[i] != false){ if (this.activeSounds[i] != false){
this.playSound(i,false,false); this.playSound(i,false,false);
@@ -104,8 +110,8 @@ export class SoundboardControl{
keyPressUp(settings){ keyPressUp(settings){
let mode = settings.soundboardMode; let mode = settings.soundboardMode;
if (mode == undefined) mode = 0; if (mode == undefined) mode = 'playSound';
if (mode != 0) return; if (mode != 'playSound') return;
let soundNr = parseInt(settings.soundNr); let soundNr = parseInt(settings.soundNr);
if (isNaN(soundNr)) soundNr = 1; if (isNaN(soundNr)) soundNr = 1;
soundNr--; soundNr--;

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){
@@ -51,6 +56,8 @@ export class StreamDeck{
else if (action == 'playlist') MODULE.playlistControl.active = false; else if (action == 'playlist') MODULE.playlistControl.active = false;
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 == 'scene') MODULE.sceneControl.active = false;
} }
} }
@@ -170,33 +177,61 @@ 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)); MODULE.sendWS(JSON.stringify(json));
} }
setIcon(iconLocation, context,src='',background = '#000000',ring=0,ringColor = "#000000",overlay=false){ setBufferImage(context,nr,id){
var json = {
target: "SD",
event: "setBufferImage",
context: context,
payload: {
nr: nr,
id: id,
target: 0
}
};
MODULE.sendWS(JSON.stringify(json));
}
setIcon(context,src='',background = '#000000',ring=0,ringColor = "#000000",overlay=false){
if (src == null || src == undefined) src = ''; if (src == null || src == undefined) src = '';
if (src == '') src = 'modules/MaterialDeck/img/black.png';
for (let i=0; i<32; i++){ for (let i=0; i<32; i++){
if (this.buttonContext[i] == undefined) continue; if (this.buttonContext[i] == undefined) continue;
if (this.buttonContext[i].context == context) { if (this.buttonContext[i].context == context) {
if (this.buttonContext[i].icon == src && this.buttonContext[i].ring == ring && this.buttonContext[i].ringColor == ringColor && this.buttonContext[i].background == background && this.buttonContext[i].iconLocation == iconLocation) if (this.buttonContext[i].icon == src && this.buttonContext[i].ring == ring && this.buttonContext[i].ringColor == ringColor && this.buttonContext[i].background == background)
return; return;
this.buttonContext[i].icon = src; this.buttonContext[i].icon = src;
this.buttonContext[i].ring = ring; this.buttonContext[i].ring = ring;
this.buttonContext[i].ringColor = ringColor; this.buttonContext[i].ringColor = ringColor;
this.buttonContext[i].background = background; this.buttonContext[i].background = background;
this.buttonContext[i].iconLocation = iconLocation;
} }
} }
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
@@ -214,11 +249,7 @@ export class StreamDeck{
ringColor: ringColor, ringColor: ringColor,
overlay: overlay overlay: overlay
}; };
if (iconLocation == 0){ this.getImage(msg);
MODULE.sendWS(JSON.stringify(msg));
}
else
this.getImage(msg);
} }
setState(state,context,action){ setState(state,context,action){
@@ -268,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;
@@ -282,11 +314,8 @@ export class StreamDeck{
if (BGvalid == false) background = '#000000'; if (BGvalid == false) background = '#000000';
let canvas; let canvas;
let canvasId = 'sdCanvas' + this.counter; if (canvas == null || canvas == undefined){
canvas = document.getElementById(canvasId);
if (canvas == null){
canvas = document.createElement('canvas'); canvas = document.createElement('canvas');
canvas.id = canvasId;
canvas.width="144"; canvas.width="144";
canvas.height="144"; canvas.height="144";
canvas.style="background-color:transparent;visibility:hidden"; canvas.style="background-color:transparent;visibility:hidden";
@@ -333,9 +362,8 @@ export class StreamDeck{
} }
if (format != 'jpg' && format != 'jpeg' && format != 'png' && format != 'webm' && format != 'webp' && format != 'gif' && format != 'svg') url = "modules/MaterialDeck/img/transparant.png"; 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" //if (url == "") url = "modules/MaterialDeck/img/transparant.png"
let resImageURL = url; let resImageURL = url;
let img = new Image(); let img = new Image();
img.setAttribute('crossorigin', 'anonymous'); img.setAttribute('crossorigin', 'anonymous');
img.onload = () => { img.onload = () => {
@@ -373,8 +401,47 @@ 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();
this.setImage(dataURL,data.context); canvas.remove();
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,25 +23,46 @@ 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 = 0;
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 = "";
let iconSrc = ""; let iconSrc = "";
let overlay = false;
if (tokenId != undefined) { if (tokenId != undefined) {
let token = canvas.tokens.children[0].children.find(p => p.id == tokenId); let token = canvas.tokens.children[0].children.find(p => p.id == tokenId);
tokenName = token.data.name; tokenName = token.data.name;
if (name) txt += tokenName; if (name) txt += tokenName;
if (name && stats != 0) 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') txt += attributes.hp.value + "/" + attributes.hp.max; if (stats == 'HP') {
txt += attributes.hp.value + "/" + attributes.hp.max;
}
else if (stats == 'TempHP') { else if (stats == 'TempHP') {
txt += attributes.hp.temp; txt += attributes.hp.temp;
if (attributes.hp.tempmax != null) if (attributes.hp.tempmax != null)
@@ -50,7 +71,7 @@ export class TokenControl{
else if (stats == 'AC') txt += attributes.ac.value; else if (stats == 'AC') txt += attributes.ac.value;
else if (stats == 'Speed'){ else if (stats == 'Speed'){
let speed = ""; let speed = "";
if (attributes.speed._deprecated){ if (attributes.movement != undefined){
if (attributes.movement.burrow > 0) speed += game.i18n.localize("DND5E.MovementBurrow") + ': ' + attributes.movement.burrow + attributes.movement.units; if (attributes.movement.burrow > 0) speed += game.i18n.localize("DND5E.MovementBurrow") + ': ' + attributes.movement.burrow + attributes.movement.units;
if (attributes.movement.climb > 0) { if (attributes.movement.climb > 0) {
if (speed.length > 0) speed += '\n'; if (speed.length > 0) speed += '\n';
@@ -83,7 +104,7 @@ export class TokenControl{
else if (stats == 'PassivePerception') txt += actor.data.data.skills.prc.passive; else if (stats == 'PassivePerception') txt += actor.data.data.skills.prc.passive;
else if (stats == 'PassiveInvestigation') txt += actor.data.data.skills.inv.passive; else if (stats == 'PassiveInvestigation') txt += actor.data.data.skills.inv.passive;
} }
else if (system == 'dnd3.5e' && game.system.id == 'D35E'){ else if ((system == 'dnd3.5e' && game.system.id == 'D35E') || (system == 'pf1e' && game.system.id == 'pf1')){
let attributes = actor.data.data.attributes; let attributes = actor.data.data.attributes;
if (stats == 'HP') txt += attributes.hp.value + "/" + attributes.hp.max; if (stats == 'HP') txt += attributes.hp.value + "/" + attributes.hp.max;
else if (stats == 'TempHP') { else if (stats == 'TempHP') {
@@ -138,6 +159,13 @@ export class TokenControl{
if (init != undefined) txt += init; if (init != undefined) txt += init;
} }
} }
else if (system == 'demonlord' && game.system.id == 'demonlord'){
let characteristics = actor.data.data.characteristics;
if (statsDemonlord == 'HP') txt += characteristics.health.value + "/" + characteristics.health.max;
else if (statsDemonlord == 'AC') txt += characteristics.defense;
else if (statsDemonlord == 'Speed') txt += characteristics.speed;
else if (statsDemonlord == 'Init') txt += actor.data.data.fastturn ? "FAST" : "SLOW";
}
else { else {
//Other systems //Other systems
@@ -146,7 +174,7 @@ export class TokenControl{
} }
if (settings.onClick == 4) { //toggle visibility if (settings.onClick == 'visibility') { //toggle visibility
ring = 1; ring = 1;
if (token.data.hidden){ if (token.data.hidden){
ring = 2; ring = 2;
@@ -154,10 +182,10 @@ export class TokenControl{
} }
if (icon == false) { if (icon == false) {
iconSrc = window.CONFIG.controlIcons.visibility; iconSrc = window.CONFIG.controlIcons.visibility;
streamDeck.setIcon(1,context,iconSrc,background,ring,ringColor,true); overlay = true;
} }
} }
else if (settings.onClick == 5) { //toggle combat state else if (settings.onClick == 'combatState') { //toggle combat state
ring = 1; ring = 1;
if (token.inCombat){ if (token.inCombat){
ring = 2; ring = 2;
@@ -165,10 +193,10 @@ export class TokenControl{
} }
if (icon == false) { if (icon == false) {
iconSrc = window.CONFIG.controlIcons.combat; iconSrc = window.CONFIG.controlIcons.combat;
streamDeck.setIcon(1,context,iconSrc,background,ring,ringColor,true); overlay = true;
} }
} }
else if (settings.onClick == 6) { //target token else if (settings.onClick == 'target') { //target token
ring = 1; ring = 1;
if (token.isTargeted){ if (token.isTargeted){
ring = 2; ring = 2;
@@ -176,78 +204,133 @@ export class TokenControl{
} }
if (icon == false) { if (icon == false) {
iconSrc = "fas fa-bullseye"; iconSrc = "fas fa-bullseye";
streamDeck.setIcon(1,context,iconSrc,background,ring,ringColor);
} }
} }
else if (settings.onClick == 7) { //toggle condition else if (settings.onClick == 'condition') { //toggle condition
ring = 1; ring = 1;
let condition = settings.condition; if ((system == 'dnd5e' && game.system.id == 'dnd5e') || (system == 'dnd3.5e' && game.system.id == 'D35E') || (system == 'pf1e' && game.system.id == 'pf1')){
if (condition == undefined) condition = 0; let condition = settings.condition;
if (condition == 0 && icon == false){ if (condition == undefined) condition = 'removeAll';
iconSrc = window.CONFIG.controlIcons.effects; if (condition == 'removeAll' && icon == false)
} iconSrc = window.CONFIG.controlIcons.effects;
else if (icon == false) { else if (icon == false) {
if ((system == 'dnd5e' && game.system.id == 'dnd5e') || (system == 'dnd3.5e' && game.system.id == 'D35E')){ let effect = CONFIG.statusEffects.find(e => e.id === condition);
let effect = CONFIG.statusEffects.find(e => e.id === this.getStatusId(condition));
iconSrc = effect.icon; iconSrc = effect.icon;
let effects = token.actor.effects.entries; let effects = token.actor.effects.entries;
let active = effects.find(e => e.isTemporary === this.getStatusId(condition)); let active = effects.find(e => e.isTemporary === condition);
if (active != undefined){ if (active != undefined){
ring = 2; ring = 2;
ringColor = "#FF7B00"; ringColor = "#FF7B00";
} }
} }
else if (system == 'pf2e' && game.system.id == 'pf2e') { }
else if (system == 'pf2e' && game.system.id == 'pf2e') {
let condition = settings.conditionPF2E;
if (condition == undefined) condition = 'removeAll';
if (condition == 'removeAll' && icon == false)
iconSrc = window.CONFIG.controlIcons.effects;
else if (icon == false) {
let effects = token.data.effects; let effects = token.data.effects;
for (let i=0; i<effects.length; i++){ for (let i=0; i<effects.length; i++){
if (CONFIG.statusEffects[condition-1] == effects[i]){ if (this.pf2eCondition(condition) == effects[i]){
ring = 2; ring = 2;
ringColor = "#FF7B00"; ringColor = "#FF7B00";
} }
} }
iconSrc = CONFIG.statusEffects[condition-1]; iconSrc = this.pf2eCondition(condition);
} }
} }
streamDeck.setIcon(1,context,iconSrc,background,ring,ringColor,true); else if (system == 'demonlord' && game.system.id == 'demonlord'){
let condition = settings.conditionDemonlord;
if (condition == undefined) condition = 'removeAll';
if (condition == 'removeAll' && icon == false)
iconSrc = window.CONFIG.controlIcons.effects;
else if (icon == false) {
let effect = CONFIG.statusEffects.find(e => e.id === condition);
iconSrc = effect.icon;
let effects = token.actor.effects.entries;
let active = effects.find(e => e.isTemporary === condition);
if (active != undefined){
ring = 2;
ringColor = "#FF7B00";
}
}
}
else
iconSrc = "";
overlay = true;
} }
} }
else { else {
iconSrc += ""; iconSrc += "";
if (settings.onClick == 4) { //toggle visibility if (settings.onClick == 'visibility') { //toggle visibility
if (icon == false) { if (icon == false) {
iconSrc = window.CONFIG.controlIcons.visibility; iconSrc = window.CONFIG.controlIcons.visibility;
streamDeck.setIcon(1,context,iconSrc,background,1,'#000000',true); ring = 2;
overlay = true;
} }
} }
else if (settings.onClick == 5) { //toggle combat state else if (settings.onClick == 'combatState') { //toggle combat state
if (icon == false) { if (icon == false) {
iconSrc = window.CONFIG.controlIcons.combat; iconSrc = window.CONFIG.controlIcons.combat;
streamDeck.setIcon(1,context,iconSrc,background,1,'#000000',true); ring = 2;
overlay = true;
} }
} }
else if (settings.onClick == 6) { //target token else if (settings.onClick == 'target') { //target token
if (icon == false) { if (icon == false) {
iconSrc = "fas fa-bullseye"; iconSrc = "fas fa-bullseye";
streamDeck.setIcon(1,context,iconSrc,background,1,'#000000'); ring = 2;
overlay = true;
} }
} }
else if (settings.onClick == 7) { //toggle condition else if (settings.onClick == 'condition') { //toggle condition
let condition = settings.condition; if ((system == 'dnd5e' && game.system.id == 'dnd5e') || (system == 'dnd3.5e' && game.system.id == 'D35E') || (system == 'pf1e' && game.system.id == 'pf1')){
if (condition == undefined) condition = 0; let condition = settings.condition;
if (condition == undefined) condition = 'removeAll';
if (condition == 0 && icon == false){ if (condition == 'removeAll' && icon == false)
iconSrc = window.CONFIG.controlIcons.effects; iconSrc = window.CONFIG.controlIcons.effects;
else if (icon == false)
iconSrc = CONFIG.statusEffects.find(e => e.id === condition).icon;
} }
else if (icon == false) { else if (system == 'pf2e' && game.system.id == 'pf2e') {
if ((system == 'dnd5e' && game.system.id == 'dnd5e') || (system == 'dnd3.5e' && game.system.id == 'D35E')) let condition = settings.conditionPF2E;
iconSrc = CONFIG.statusEffects.find(e => e.id === this.getStatusId(condition)).icon; if (condition == undefined) condition = 'removeAll';
else if (system == 'pf2e' && game.system.id == 'pf2e')
iconSrc = CONFIG.statusEffects[condition-1]; if (condition == 'removeAll' && icon == false)
} iconSrc = window.CONFIG.controlIcons.effects;
streamDeck.setIcon(1,context,iconSrc,background,1,'#000000',true); else if (icon == false)
iconSrc = this.pf2eCondition(condition);
}
else if (system == 'demonlord' && game.system.id == 'demonlord'){
let condition = settings.conditionDemonlord;
if (condition == undefined) condition = 'removeAll';
if (condition == 'removeAll' && icon == false)
iconSrc = window.CONFIG.controlIcons.effects;
else if (icon == false)
iconSrc = CONFIG.statusEffects.find(e => e.id === condition).icon;
}
ring = 1;
overlay = true;
} }
} }
if (icon) streamDeck.setIcon(1,context,iconSrc,background,ring,ringColor); if (icon == false){
if (stats == 'HP' || stats == 'TempHP') //HP
iconSrc = "modules/MaterialDeck/img/token/hp.png";
else if (stats == 'AC' || stats == 'ShieldHP') //AC
iconSrc = "modules/MaterialDeck/img/token/ac.webp";
else if (stats == 'Speed') //Speed
iconSrc = "modules/MaterialDeck/img/token/speed.webp";
else if (stats == 'Init') //Initiative
iconSrc = "modules/MaterialDeck/img/token/init.png";
else if (stats == 'PassivePerception')
iconSrc = "modules/MaterialDeck/img/black.png";
else if (stats == 'PassiveInvestigation')
iconSrc = "modules/MaterialDeck/img/black.png";
}
streamDeck.setIcon(context,iconSrc,background,ring,ringColor,overlay);
streamDeck.setTitle(txt,context); streamDeck.setTitle(txt,context);
} }
@@ -257,7 +340,7 @@ export class TokenControl{
const tokenId = MODULE.selectedTokenId; const tokenId = MODULE.selectedTokenId;
let onClick = settings.onClick; let onClick = settings.onClick;
if (onClick == undefined) onClick = 0; if (onClick == undefined) onClick = 'doNothing';
const token = canvas.tokens.children[0].children.find(p => p.id == tokenId); const token = canvas.tokens.children[0].children.find(p => p.id == tokenId);
if (token == undefined) return; if (token == undefined) return;
@@ -265,89 +348,131 @@ export class TokenControl{
let system = settings.system; let system = settings.system;
if (system == undefined) system = 'dnd5e'; if (system == undefined) system = 'dnd5e';
if (onClick == 0) //Do nothing if (onClick == 'doNothing') //Do nothing
return; return;
else if (onClick == 1){ //center on token else if (onClick == 'center'){ //center on token
let location = token.getCenter(token.x,token.y); let location = token.getCenter(token.x,token.y);
canvas.animatePan(location); canvas.animatePan(location);
} }
else if (onClick == 2){ //Open character sheet else if (onClick == 'charSheet'){ //Open character sheet
token.actor.sheet.render(true); const element = document.getElementById(token.actor.sheet.id);
if (element == null) token.actor.sheet.render(true);
else token.actor.sheet.close();
} }
else if (onClick == 3) { //Open token config else if (onClick == 'tokenConfig') { //Open token config
token.sheet._render(true); const element = document.getElementById(token.sheet.id);
if (element == null) token.sheet.render(true);
else token.sheet.close();
} }
else if (onClick == 4) { //Toggle visibility else if (onClick == 'visibility') { //Toggle visibility
token.toggleVisibility(); token.toggleVisibility();
} }
else if (onClick == 5) { //Toggle combat state else if (onClick == 'combatState') { //Toggle combat state
token.toggleCombat(); token.toggleCombat();
} }
else if (onClick == 6) { //Target token else if (onClick == 'target') { //Target token
token.setTarget(!token.isTargeted,{releaseOthers:false}); token.setTarget(!token.isTargeted,{releaseOthers:false});
} }
else if (onClick == 7) { //Toggle condition else if (onClick == 'condition') { //Toggle condition
let condition = settings.condition; if ((system == 'dnd5e' && game.system.id == 'dnd5e') || (system == 'dnd3.5e' && game.system.id == 'D35E') || (system == 'pf1e' && game.system.id == 'pf1')){
if (condition == undefined) condition = 0; let condition = settings.condition;
if (condition == undefined) condition = 'removeAll';
if (condition == 0){ if (condition == 'removeAll'){
const effects = token.actor.effects.entries; const effects = token.actor.effects.entries;
for (let i=0; i<effects.length; i++){ for (let i=0; i<effects.length; i++){
let effect; const effect = CONFIG.statusEffects.find(e => e.icon === effects[i].data.icon);
if ((system == 'dnd5e' && game.system.id == 'dnd5e') || (system == 'dnd3.5e' && game.system.id == 'D35E')) await token.toggleEffect(effect)
effect = CONFIG.statusEffects.find(e => e.icon === effects[i].data.icon); }
else if (system == 'pf2e' && game.system.id == 'pf2e') }
effect = CONFIG.statusEffects[condition-1]; else {
await token.toggleEffect(effect) const effect = CONFIG.statusEffects.find(e => e.id === condition);
await token.toggleEffect(effect);
} }
} }
else { else if (system == 'pf2e' && game.system.id == 'pf2e'){
let effect; let condition = settings.conditionPF2E;
if ((system == 'dnd5e' && game.system.id == 'dnd5e') || (system == 'dnd3.5e' && game.system.id == 'D35E')) if (condition == undefined) condition = 'removeAll';
effect = CONFIG.statusEffects.find(e => e.id === this.getStatusId(condition)); if (condition == 'removeAll'){
else if (system == 'pf2e' && game.system.id == 'pf2e') const effects = token.actor.effects.entries;
effect = CONFIG.statusEffects[condition-1]; for (let i=0; i<effects.length; i++){
token.toggleEffect(effect); const effect = this.pf2eCondition(condition);
await token.toggleEffect(effect)
}
}
else {
const effect = this.pf2eCondition(condition);
await token.toggleEffect(effect);
}
}
else if (system == 'demonlord' && game.system.id == 'demonlord'){
let condition = settings.conditionDemonlord;
if (condition == undefined) condition = 'removeAll';
if (condition == 'removeAll'){
const effects = token.actor.effects.entries;
for (let i=0; i<effects.length; i++){
const effect = CONFIG.statusEffects.find(e => e.icon === effects[i].data.icon);
await token.toggleEffect(effect)
}
}
else {
const effect = CONFIG.statusEffects.find(e => e.id === condition);
await token.toggleEffect(effect);
}
}
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'){
token.actor.update({
'data.fastturn': !token.actor.data?.data?.fastturn
})
} }
} }
getStatusId(nr){ pf2eCondition(condition){
let id; return "systems/pf2e/icons/conditions-2/" + condition + ".png";
if (nr == 1) id = 'dead';
else if (nr == 2) id = 'unconscious';
else if (nr == 3) id = 'sleep';
else if (nr == 4) id = 'stun';
else if (nr == 5) id = 'prone';
else if (nr == 6) id = 'restrain';
else if (nr == 7) id = 'paralysis';
else if (nr == 8) id = 'fly';
else if (nr == 9) id = 'bind';
else if (nr == 10) id = 'deaf';
else if (nr == 11) id = 'silence';
else if (nr == 12) id = 'fear';
else if (nr == 13) id = 'burning';
else if (nr == 14) id = 'frozen';
else if (nr == 15) id = 'shock';
else if (nr == 16) id = 'corrode';
else if (nr == 17) id = 'bleeding';
else if (nr == 18) id = 'disease';
else if (nr == 19) id = 'poison';
else if (nr == 20) id = 'radiation';
else if (nr == 21) id = 'regen';
else if (nr == 22) id = 'degen';
else if (nr == 23) id = 'upgrade';
else if (nr == 24) id = 'downgrade';
else if (nr == 25) id = 'target';
else if (nr == 26) id = 'eye';
else if (nr == 27) id = 'curse';
else if (nr == 28) id = 'bless';
else if (nr == 29) id = 'fireShield';
else if (nr == 30) id = 'coldShield';
else if (nr == 31) id = 'magicShield';
else if (nr == 32) id = 'holyShield';
return id;
} }
} }