Skip to content

Commit

Permalink
Merge pull request #92 from manuelVo/gmonly-setting
Browse files Browse the repository at this point in the history
Add GM only setting (resolves #36)
  • Loading branch information
megahead11 authored Apr 12, 2022
2 parents cbad663 + 3cba992 commit c8c8864
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 45 deletions.
108 changes: 67 additions & 41 deletions app/js/Theatre.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,21 @@ class Theatre {
//this._initFaceAPI();
// module settings
this._initModuleSettings();
// inject HTML
this._injectHTML();
// socket
this._initSocket();
// global listeners
window.addEventListener("resize",this.handleWindowResize);
// request a resync if needed
this._sendResyncRequest("any");
}
return Theatre.instance;
}

initialize() {
// inject HTML
this._injectHTML();
// socket
this._initSocket();
// global listeners
window.addEventListener("resize",this.handleWindowResize);
// request a resync if needed
this._sendResyncRequest("any");
}

/**
* Inject HTML
*
Expand Down Expand Up @@ -191,6 +194,9 @@ class Theatre {
this.theatreNavBar = document.createElement("div");
this.theatreChatCover = document.createElement("div");

if (!game.user.isGM && game.settings.get(Theatre.SETTINGS, "gmOnly")) {
this.theatreControls.style.display = "none";
}

let imgCover = document.createElement("img");
let btnSuppress = document.createElement("div");
Expand Down Expand Up @@ -273,32 +279,34 @@ class Theatre {
btnQuote.style["margin"] = "0 4px";
btnResync.style["margin"] = "0 4px";

if (controlButtons) {
controlButtons.style["flex-basis"] = "150px";
KHelpers.insertBefore(btnResync,controlButtons.children[0]);
KHelpers.insertBefore(btnQuote,btnResync);
KHelpers.insertBefore(btnDelayEmote,btnQuote);
} else {
controlButtons = document.createElement("div");
KHelpers.addClass(controlButtons,"control-buttons");
controlButtons.style["flex-basis"] = "66px";
controlButtons.appendChild(btnDelayEmote);
controlButtons.appendChild(btnQuote);
controlButtons.appendChild(btnResync);
chatControls.appendChild(controlButtons);
if (game.user.isGM || !game.settings.get(Theatre.SETTINGS, "gmOnly")) {
if (controlButtons) {
controlButtons.style["flex-basis"] = "150px";
KHelpers.insertBefore(btnResync,controlButtons.children[0]);
KHelpers.insertBefore(btnQuote,btnResync);
KHelpers.insertBefore(btnDelayEmote,btnQuote);
} else {
controlButtons = document.createElement("div");
KHelpers.addClass(controlButtons,"control-buttons");
controlButtons.style["flex-basis"] = "66px";
controlButtons.appendChild(btnDelayEmote);
controlButtons.appendChild(btnQuote);
controlButtons.appendChild(btnResync);
chatControls.appendChild(controlButtons);
}
}

KHelpers.insertBefore(this.theatreControls,chatControls);
KHelpers.insertAfter(this.theatreChatCover,chatMessage);

// bind lisener to chat message
// bind listener to chat message
chatMessage.addEventListener("keydown",this.handleChatMessageKeyDown);
chatMessage.addEventListener("keyup",this.handleChatMessageKeyUp);
chatMessage.addEventListener("focusout",this.handleChatMessageFocusOut);

/*
* Emote Menu
*/
* Emote Menu
*/
this.theatreEmoteMenu = document.createElement("div");
KHelpers.addClass(this.theatreEmoteMenu,"theatre-emote-menu");
KHelpers.addClass(this.theatreEmoteMenu,"app");
Expand All @@ -308,7 +316,6 @@ class Theatre {
* Tooltip
*/
this.theatreEmoteMenu.addEventListener("mousemove",this.handleEmoteMenuMouseMove);

}

/**
Expand All @@ -319,6 +326,16 @@ class Theatre {
_initModuleSettings() {
// module settings

game.settings.register(Theatre.SETTINGS, "gmOnly", {
name: "Theatre.UI.Settings.gmOnly",
hint: "Theatre.UI.Settings.gmOnlyHint",
scope: "world",
config: true,
defualt: false,
type: Boolean,
onChange: () => {if (!game.user.isGM) location.reload();},
});

game.settings.register(Theatre.SETTINGS, "theatreStyle", {
name: "Theatre.UI.Settings.displayMode",
hint: "Theatre.UI.Settings.displayModeHint",
Expand Down Expand Up @@ -5783,34 +5800,43 @@ class Theatre {
*/
handleBtnSuppressClick(ev) {
if (Theatre.DEBUG) console.log("suppression click");
let primeBar = document.getElementById("theatre-prime-bar");
let secondBar = document.getElementById("theatre-second-bar");

if (Theatre.instance.isSuppressed) {
if (KHelpers.hasClass(ev.currentTarget,"theatre-control-btn-down")) {
KHelpers.removeClass(ev.currentTarget,"theatre-control-btn-down");
}
Theatre.instance.isSuppressed = false;
//Theatre.instance.theatreGroup.style.opacity = "1";
Theatre.instance.theatreDock.style.opacity = "1";
Theatre.instance.theatreBar.style.opacity = "1";
Theatre.instance.theatreNarrator.style.opacity = "1";
}
else {
KHelpers.addClass(ev.currentTarget,"theatre-control-btn-down");
}
Theatre.instance.updateSuppression(!Theatre.instance.isSuppressed);
}

primeBar.style["pointer-events"] = "all";
secondBar.style["pointer-events"] = "all";
} else {
updateSuppression(suppress) {
Theatre.instance.isSuppressed = suppress;

let primeBar = document.getElementById("theatre-prime-bar");
let secondBar = document.getElementById("theatre-second-bar");
if (Theatre.instance.isSuppressed) {
let combatActive = game.combats.active;
KHelpers.addClass(ev.currentTarget,"theatre-control-btn-down");
Theatre.instance.isSuppressed = true;
//Theatre.instance.theatreGroup.style.opacity = (combatActive ? "0.05" : "0.20");
Theatre.instance.theatreDock.style.opacity = (combatActive ? "0.05" : "0.20");
Theatre.instance.theatreBar.style.opacity = (combatActive ? "0.05" : "0.20");
Theatre.instance.theatreNarrator.style.opacity = (combatActive ? "0.05" : "0.20");
//Theatre.instance.theatreGroup.style.opacity = (combatActive ? "0.05" : "0.20");
Theatre.instance.theatreDock.style.opacity = (combatActive ? "0.05" : "0.20");
Theatre.instance.theatreBar.style.opacity = (combatActive ? "0.05" : "0.20");
Theatre.instance.theatreNarrator.style.opacity = (combatActive ? "0.05" : "0.20");


primeBar.style["pointer-events"] = "none";
secondBar.style["pointer-events"] = "none";
} else {
//Theatre.instance.theatreGroup.style.opacity = "1";
Theatre.instance.theatreDock.style.opacity = "1";
Theatre.instance.theatreBar.style.opacity = "1";
Theatre.instance.theatreNarrator.style.opacity = "1";

primeBar.style["pointer-events"] = "all";
secondBar.style["pointer-events"] = "all";
}

// call hooks
Hooks.call("theatreSuppression", Theatre.instance.isSuppressed);
}
Expand Down
28 changes: 24 additions & 4 deletions app/js/theatre_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ Handlebars.registerHelper("resprop", function(propPath, hash) {
* Hook in on Actorsheet's Header buttons + context menus
*/
Hooks.on("getActorSheetHeaderButtons",(app,buttons)=>{
if (!game.user.isGM && game.settings.get("theatre", "gmOnly")) return;

let theatreButtons = []
if (app.object.isOwner) {
// only prototype actors
Expand Down Expand Up @@ -555,10 +557,8 @@ Hooks.on("createChatMessage", function(chatEntity, _, userId) {
}
});

// Fixed global singleton/global object
var theatre = null;
Hooks.on("renderChatLog", function() {
theatre = new Theatre();
theatre.initialize();
// window may not be ready?
console.log(
"%cTheatre Inserts",
Expand All @@ -575,6 +575,7 @@ Hooks.on("renderChatLog", function() {
* Add to stage button on ActorDirectory Sidebar
*/
Hooks.on("getActorDirectoryEntryContext", async (html, options) => {
if (!game.user.isGM && game.settings.get("theatre", "gmOnly")) return;

const getActorData = target => {
const actor = game.actors.get(target.data("documentId"));
Expand All @@ -594,8 +595,10 @@ Hooks.on("getActorDirectoryEntryContext", async (html, options) => {
});
});


// Fixed global singleton/global object
var theatre = null;
Hooks.once("init", () => {
theatre = new Theatre();
// module keybinds

game.keybindings.register("theatre", "unfocusTextArea", {
Expand Down Expand Up @@ -912,3 +915,20 @@ Hooks.on("updateActor", (actor, data) => {
insert.label.text = Theatre.getActorDisplayName(actor.id);
Theatre.instance._renderTheatre(performance.now());
});

Hooks.on("getSceneControlButtons", controls => {
// Use "theatre", since Theatre.SETTINGS may not be available yet
if (!game.user.isGM && game.settings.get("theatre", "gmOnly")) {
const suppressTheatreTool = {
name: "suppressTheatre",
title: "Theatre.UI.Title.SuppressTheatre",
icon: "fas fa-theater-masks",
toggle: true,
active: false,
onClick: toggle => Theatre.instance.updateSuppression(toggle), // TODO Suppress theatre
visible: true,
};
const tokenControls = controls.find(group => group.name === "token").tools;
tokenControls.push(suppressTheatreTool);
}
})
2 changes: 2 additions & 0 deletions app/lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
"Theatre.UI.Settings.displayModeTextBox" : "Textbox-Stil",
"Theatre.UI.Settings.displayModeLightBox" : "Lichtkasten-Stil",
"Theatre.UI.Settings.displayModeClearBox" : "Transparenter Box-Stil",
"Theatre.UI.Settings.gmOnly" : "SSteuerung nur für Spielleiter",
"Theatre.UI.Settings.gmOnlyHint" : "Wenn diese Option aktiviert ist, kann nur der Spielleiter die Bühne steuern. Die Theatre-Steuerelemente werden für die Spieler ausgeblendet.",
"Theatre.UI.Settings.narrHeight" : "Erzähler-Leisten-Position",
"Theatre.UI.Settings.narrHeightHint" : "Die Position der Erzähler-Leiste als Prozentwert der Bildschirmhöhe.",
"Theatre.UI.Settings.textDecayMin" : "Minimum Textverfall-Zeit",
Expand Down
2 changes: 2 additions & 0 deletions app/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
"Theatre.UI.Settings.displayModeTextBox" : "Text Box Style",
"Theatre.UI.Settings.displayModeLightBox" : "Light Box Style",
"Theatre.UI.Settings.displayModeClearBox" : "Clear Box Style",
"Theatre.UI.Settings.gmOnly" : "GM controls only",
"Theatre.UI.Settings.gmOnlyHint" : "If enabled, only the GM will be able to control the stage. The Theatre controls will be hidden for the players.",
"Theatre.UI.Settings.narrHeight" : "Narrator Bar Position",
"Theatre.UI.Settings.narrHeightHint" : "The position of the narrator bar as a percentage of the screen height.",
"Theatre.UI.Settings.textDecayMin" : "Minimum Text Decay Time",
Expand Down

0 comments on commit c8c8864

Please sign in to comment.