This commit is contained in:
CDeenen
2021-02-02 05:32:08 +01:00
parent cc5dc9ab63
commit f0c1b0e1e0
56 changed files with 478 additions and 12 deletions

View File

@@ -4,9 +4,13 @@ import {streamDeck} from "../MaterialDeck.js";
export class ExternalModules{
constructor(){
this.active = false;
this.gmScreenOpen = false;
}
async updateAll(){
async updateAll(data={}){
if (data.gmScreen != undefined){
this.gmScreenOpen = data.gmScreen.isOpen;
}
if (this.active == false) return;
for (let i=0; i<32; i++){
let data = streamDeck.buttonContext[i];
@@ -254,7 +258,7 @@ export class ExternalModules{
let src = '';
let txt = '';
//if (document.getElementsByClassName("gm-screen-app gm-screen-drawer expanded")[0] != undefined) ring = 2;
if (this.gmScreenOpen) ring = 2;
if (settings.displayGmScreenIcon) src = "fas fa-book-reader";
streamDeck.setIcon(context,src,background,ring,ringColor);
@@ -264,7 +268,6 @@ export class ExternalModules{
keyPressGMScreen(settings,context){
if (this.getModuleEnable("gm-screen") == false) return;
document.getElementsByClassName("gm-screen-button")[0].click();
window['gm-screen'].toggleGmScreenVisibility();
}
}

View File

@@ -11,7 +11,7 @@ export const registerSettings = function() {
name: "MaterialDeck.Sett.Enable",
scope: "global",
config: true,
default: false,
default: true,
type: Boolean,
onChange: x => window.location.reload()
});
@@ -50,6 +50,13 @@ export const registerSettings = function() {
});
//Create the Help button
game.settings.registerMenu(MODULE.moduleName, 'helpMenu',{
name: "MaterialDeck.Sett.Help",
label: "MaterialDeck.Sett.Help",
type: helpMenu,
restricted: true
});
/**
* Playlist soundboard
*/
@@ -110,3 +117,45 @@ export const registerSettings = function() {
restricted: true
});
}
export class helpMenu extends FormApplication {
constructor(data, options) {
super(data, options);
}
/**
* Default Options for this FormApplication
*/
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
id: "helpMenu",
title: "Material Deck: "+game.i18n.localize("MaterialDeck.Sett.Help"),
template: "./modules/MaterialDeck/templates/helpMenu.html",
width: "500px"
});
}
/**
* Provide data to the template
*/
getData() {
return {
}
}
/**
* Update on form submit
* @param {*} event
* @param {*} formData
*/
async _updateObject(event, formData) {
}
activateListeners(html) {
super.activateListeners(html);
}
}

View File

@@ -4,6 +4,7 @@ import {streamDeck} from "../MaterialDeck.js";
export class TokenControl{
constructor(){
this.active = false;
this.wildcardOffset = 0;
}
async update(tokenId){
@@ -15,7 +16,7 @@ export class TokenControl{
}
}
pushData(tokenId,settings,context,ring=0,ringColor='#000000'){
async pushData(tokenId,settings,context,ring=0,ringColor='#000000'){
let name = false;
let icon = false;
let stats = settings.stats;
@@ -260,6 +261,40 @@ export class TokenControl{
iconSrc = "";
overlay = true;
}
else if (settings.onClick == 'wildcard') { //wildcard images
if (icon == false) return;
const method = settings.wildcardMethod ? settings.wildcardMethod : 'iterate';
let value = parseInt(settings.wildcardValue);
if (isNaN(value)) value = 1;
const images = await token.actor.getTokenImages();
let currentImgNr = 0
let imgNr;
for (let i=0; i<images.length; i++)
if (images[i] == token.data.img){
currentImgNr = i;
break;
}
if (method == 'iterate'){
imgNr = currentImgNr + value + this.wildcardOffset;
while (imgNr >= images.length) imgNr -= images.length;
while (imgNr < 0) imgNr += images.length;
iconSrc = images[imgNr];
}
else if (method == 'set'){
imgNr = value - 1 + this.wildcardOffset;
if (value >= images.length) iconSrc = "modules/MaterialDeck/img/black.png";
else iconSrc = images[imgNr];
ring = 1;
if (currentImgNr == imgNr) {
ring = 2;
ringColor = "#FF7B00";
}
}
else return;
}
}
else {
iconSrc += "";
@@ -461,7 +496,6 @@ export class TokenControl{
animation.speed = animationSpeed;
}
data.lightAnimation = animation;
token.update(data);
}
else if (system == 'demonlord' && game.system.id == 'demonlord' && onClick == 'initiative'){
@@ -470,6 +504,172 @@ export class TokenControl{
})
}
else if (settings.onClick == 'wildcard') { //wildcard images
const method = settings.wildcardMethod ? settings.wildcardMethod : 'iterate';
let value = parseInt(settings.wildcardValue);
if (isNaN(value)) value = 1;
const images = await token.actor.getTokenImages();
let imgNr;
let iconSrc;
if (method == 'iterate'){
let currentImgNr = 0
for (let i=0; i<images.length; i++)
if (images[i] == token.data.img){
currentImgNr = i;
break;
}
imgNr = currentImgNr + value + this.wildcardOffset;
while (imgNr >= images.length) imgNr -= images.length;
while (imgNr < 0) imgNr += images.length;
}
else if (method == 'set'){
imgNr = value - 1 + this.wildcardOffset;
if (value >= images.length || value < 1) return;
}
else if (method == 'offset'){
this.wildcardOffset = value;
this.update(MODULE.selectedTokenId);
}
else return;
iconSrc = images[imgNr];
token.update({img: iconSrc})
}
else if (settings.onClick == 'custom') {//custom onClick function
const formula = settings.customOnClickFormula ? settings.customOnClickFormula : '';
if (formula == '') return;
let targetArrayTemp;
let formulaArrayTemp;
let split1 = formula.split(';');
for (let i=0; i<split1.length; i++){
let split2 = split1[i].split(' = ');
targetArrayTemp = split2[0];
formulaArrayTemp = split2[1];
let targetArray = this.splitCustom(targetArrayTemp);
for (let i=0; i<targetArray.length; i++){
if (targetArray[i][0] == '@') {
const dataPath = targetArray[i].split('@')[1].split('.');
targetArray[i] = dataPath;
}
}
let formulaArray = this.splitCustom(formulaArrayTemp);
let value = 0;
let previousOperation = '+';
if (formulaArray.length == 1 && formulaArray[0][0] == '[')
value = formulaArray[0].split('[')[1];
else if (formulaArray.length == 1)
value = formulaArray[0];
else {
for (let i=0; i<formulaArray.length; i++){
let val;
if (formulaArray[i][0] == '@') {
let dataPath;
if (formulaArray[i] == '@this') dataPath = targetArray[0];
else dataPath = formulaArray[i].split('@')[1].split('.');
let data = token;
for (let j=0; j<dataPath.length; j++)
data = data?.[dataPath[j]];
if (data == undefined) return;
formulaArray[i] = data;
val = data;
}
else if (isNaN(formulaArray[i])) {
previousOperation = formulaArray[i];
if (previousOperation == '++') value++;
else if (previousOperation == '--') value--;
continue;
}
else
val = parseFloat(formulaArray[i]);
if (previousOperation == '+') value += val;
else if (previousOperation == '-') value -= val;
else if (previousOperation == '*') value *= val;
else if (previousOperation == '/') value /= val;
else if (previousOperation == '**') value **= val;
else if (previousOperation == '%') value %= val;
else if (previousOperation == '<' && value >= val) {value = val-1;}
else if (previousOperation == '>' && value <= val) {value = val+1;}
else if (previousOperation == '<=' && value > val) {value = val;}
else if (previousOperation == '>=' && value < val) {value = val;}
}
}
for (let i=0; i<targetArray.length; i++){
const dataPath = targetArray[i];
let data;
if (dataPath[0] == 'actor') {
let actor = token.actor;
if (dataPath[1] == 'data'){
let path = '';
for (let j=2; j<targetArray[i].length; j++){
if (path != '') path += '.';
path += targetArray[i][j];
}
actor.update({[path]:value})
}
else {
let path = '';
for (let j=1; j<targetArray[i].length; j++){
if (path != '') path += '.';
path += targetArray[i][j];
}
actor.update({[path]:value})
}
}
else {
data = token;
let path = '';
for (let j=1; j<targetArray[i].length; j++){
if (path != '') path += '.';
path += targetArray[i][j];
}
token.update({[path]:value})
}
}
}
}
}
splitCustom(string){
const split = string.split('[');
let array1 = [];
for (let i=0; i<split.length; i++){
if (i>0 && split[i][0] != '@' && split[i] != "" && isNaN(split[i])) split[i] = '['+split[i]
const split2 = split[i].split(']');
for (let j=0; j<split2.length; j++){
array1.push(split2[j]);
}
}
let array2 = [];
for (let i=0; i<array1.length; i++){
if (array1[i][0] == '[') {
array2.push(array1[i]);
continue;
}
const split3 = array1[i].split(' ');
for (let j=0; j<split3.length; j++){
array2.push(split3[j]);
}
}
let array3 = [];
for (let i=0; i<array2.length; i++){
if (array2[i] == "") continue;
array3.push(array2[i]);
}
return array3;
}
pf2eCondition(condition){