Skip to content

Commit

Permalink
Merge pull request #18 from strongpauly/master
Browse files Browse the repository at this point in the history
Removal of actors from stage
  • Loading branch information
megahead11 authored Apr 8, 2021
2 parents 9569ad1 + 7532659 commit 165d12a
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 23 deletions.
91 changes: 75 additions & 16 deletions app/js/Theatre.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ class Theatre {
this.rendering = false;
this.renderAnims = 0;
// global insert state related
this.speakingAs = null;
this.speakingAs = null;
// Map of theatreId to TheatreActor
this.stage = {};
this.portraitDocks = [];
this.userEmotes = {};
this.usersTyping = {};
Expand Down Expand Up @@ -3037,7 +3039,7 @@ class Theatre {
* "Stages" an insert by pre-loading the base + all emote images
*
* @params theatreId (String) : The theatreId of the insert to load.
* @params remote (Boolean) : Wither this is being invoked remotely or locally.
* @params remote (Boolean) : Whether this is being invoked remotely or locally.
*/
stageInsertById(theatreId,remote) {
let actorId = theatreId.replace("theatre-","");
Expand Down Expand Up @@ -3787,10 +3789,9 @@ class Theatre {
* @return (HTMLElement) : The nav item, if found, else undefined.
*/
getNavItemById(id) {
for (let navItem of this.theatreNavBar.children) {
if (navItem.getAttribute("imgId") == id)
return navItem;
}
const theatreActor = this.stage[id];
if (theatreActor)
return theatreActor.navElement;
}

/**
Expand Down Expand Up @@ -3864,7 +3865,7 @@ class Theatre {
/**
* Get insert dock by Name
*
* @params id (String) : The theatreId of an insert we want.
* @params name (String) : The name of an insert we want.
*
* @return (Object) : The Object representing the insert, or undefined.
*/
Expand Down Expand Up @@ -6045,7 +6046,7 @@ class Theatre {
let cimg = Theatre.instance.getTheatreCoverPortrait();
if (ev.ctrlKey) {
// unstage the actor
ev.currentTarget.parentNode.removeChild(ev.currentTarget);
Theatre.instance._removeFromStage(id);
return;
}
if (!removed) {
Expand Down Expand Up @@ -7841,8 +7842,22 @@ class Theatre {
*/
static onAddToNavBar(ev,actorSheet) {
if (Theatre.DEBUG) console.log("Click Event on Add to NavBar!!",actorSheet,actorSheet.actor,actorSheet.position);
let actor = actorSheet.object.data;
Theatre.addToNavBar(actor);
const actor = actorSheet.object.data;
const addLabel = game.i18n.localize("Theatre.UI.Config.AddToStage");
const removeLabel = game.i18n.localize("Theatre.UI.Config.RemoveFromStage");
let newText;
if (Theatre.isActorStaged(actor)) {
Theatre.removeFromNavBar(actor)
newText = addLabel
} else {
Theatre.addToNavBar(actor);
newText = removeLabel;
}
ev.currentTarget.innerHTML = `<i class="fas fa-theater-masks"></i>${newText}`
}

static _getTheatreId(actor) {
return `theatre-${actor._id}`;
}

/**
Expand All @@ -7861,7 +7876,7 @@ class Theatre {
// add click handler to push it into the theatre bar, if it already exists on the bar, remove it
// from the bar
// add click handler logic to remove it from the stage
let theatreId = `theatre-${actor._id}`;
let theatreId = Theatre._getTheatreId(actor);
let portrait = (actor.img ? actor.img : "icons/mystery-man.png");
let optAlign = "top";
let name = actor.name;
Expand All @@ -7881,12 +7896,11 @@ class Theatre {
optAlign = actor.flags.theatre.optalign;
}

for (let ni of Theatre.instance.theatreNavBar.children) {
if (ni.getAttribute("imgId") == theatreId) {
ui.notifications.info(actor.name + game.i18n.localize("Theatre.UI.Notification.AlreadyStaged"));
return;
}
if (Theatre.instance.stage[theatreId]) {
ui.notifications.info(actor.name + game.i18n.localize("Theatre.UI.Notification.AlreadyStaged"));
return;
}

if (Theatre.DEBUG) console.log("new theatre id: " + theatreId);

let navItem = document.createElement("img");
Expand All @@ -7910,6 +7924,51 @@ class Theatre {
Theatre.instance.theatreNavBar.appendChild(navItem);
// stage event
Theatre.instance.stageInsertById(theatreId);
// Store reference
Theatre.instance.stage[theatreId] = new TheatreActor(actor, navItem);
}

/**
* Removes the actor from the nav bar.
*
* @params actor (Actor) : The actor to remove from the NavBar staging area.
*/
static removeFromNavBar(actor) {
if (!actor) return;
const theatreId = Theatre._getTheatreId(actor);
Theatre.instance._removeFromStage(theatreId);

}

/**
* Removes the actor from the stage.
*
* @params id (string) : The theatreId to remove from the stage.
*/
_removeFromStage(theatreId) {
const staged = Theatre.instance.stage[theatreId];
if(staged) {
if(staged.navElement) {
Theatre.instance.theatreNavBar.removeChild(staged.navElement);
}
Theatre.instance.removeInsertById(theatreId);
delete Theatre.instance.stage[theatreId];
}
}

/**
* Returns whether the actor is on the stage.
* @params actor (Actor) : The actor.
*/
static isActorStaged(actor) {
if (!actor) return false;
return !!Theatre.instance.stage[Theatre._getTheatreId(actor)]
}

static clearStage() {
Object.keys(Theatre.instance.stage).forEach(theatreId => {
Theatre._removeFromStage(theatreId);
})
}

/**
Expand Down
6 changes: 6 additions & 0 deletions app/js/TheatreActor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class TheatreActor {
constructor(actor, navElement) {
this.actor = actor;
this.navElement = navElement;
}
}
20 changes: 14 additions & 6 deletions app/js/theatre_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ Hooks.on("init", function() {
}
buttons = [
{
label: "Theatre.UI.Config.Stage",
label: Theatre.isActorStaged(this.actor.data) ? "Theatre.UI.Config.RemoveFromStage" : "Theatre.UI.Config.AddToStage",
class: "add-to-theatre-navbar",
icon: "fas fa-theater-masks",
onclick: ev => {
Expand Down Expand Up @@ -630,13 +630,21 @@ Hooks.on("renderChatLog", function() {
* Add to stage button on ActorDirectory Sidebar
*/
Hooks.on("getActorDirectoryEntryContext", async (html, options) => {

const getActorData = target => {
const actor = game.actors.get(target.attr("data-entity-id"));
return actor.data;
}

options.splice(3, 0, {
name: "Add to Stage",
condition: true,
condition: target => !Theatre.isActorStaged(getActorData(target)),
icon: '<i class="fas fa-theater-masks"></i>',
callback: target => {
const actor = game.actors.get(target.attr("data-entity-id"));
Theatre.addToNavBar(actor.data);
}
callback: target => Theatre.addToNavBar(getActorData(target))
}, {
name: "Remove from Stage",
condition: target => Theatre.isActorStaged(getActorData(target)),
icon: '<i class="fas fa-theater-masks"></i>',
callback: target => Theatre.removeFromNavBar(getActorData(target))
});
});
2 changes: 2 additions & 0 deletions app/lang/cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
"Theatre.MOTD.OldVersion" : "剧院当前已过时,请在设置屏幕中启用GM更新剧场。",

"Theatre.UI.Config.Stage" : "入场",
"Theatre.UI.Config.AddToStage" : "Add to Stage",
"Theatre.UI.Config.RemoveFromStage" : "Remove from Stage",
"Theatre.UI.Config.Theatre" : "立绘",
"Theatre.UI.Config.ConfigureTheatre" : "设置立绘的各种属性",
"Theatre.UI.Config.Main" : "主要",
Expand Down
2 changes: 2 additions & 0 deletions app/lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
"Theatre.MOTD.OldVersion" : "Theater ist aktuell veraltet, bitte lass es von deinem SL in den Einstellungen aktualisieren.",

"Theatre.UI.Config.Stage" : "Bühne",
"Theatre.UI.Config.AddToStage" : "Add to Stage",
"Theatre.UI.Config.RemoveFromStage" : "Remove from Stage",
"Theatre.UI.Config.Theatre" : "Theater",
"Theatre.UI.Config.ConfigureTheatre" : "Theater konfigurieren",
"Theatre.UI.Config.Main" : "Haupt",
Expand Down
2 changes: 2 additions & 0 deletions app/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
"Theatre.MOTD.OldVersion" : "Theatre is currently out of date, please have the GM update theatre in the setup screen.",

"Theatre.UI.Config.Stage" : "Stage",
"Theatre.UI.Config.AddToStage" : "Add to Stage",
"Theatre.UI.Config.RemoveFromStage" : "Remove from Stage",
"Theatre.UI.Config.Theatre" : "Theatre",
"Theatre.UI.Config.ConfigureTheatre" : "Configure Theatre",
"Theatre.UI.Config.Main" : "Main",
Expand Down
2 changes: 2 additions & 0 deletions app/lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
"Theatre.MOTD.OldVersion" : "Teatro está desactualizado, pida al GM que lo actualice desde la ventana de configuración",

"Theatre.UI.Config.Stage" : "Escenario",
"Theatre.UI.Config.AddToStage" : "Add to Stage",
"Theatre.UI.Config.RemoveFromStage" : "Remove from Stage",
"Theatre.UI.Config.Theatre" : "Teatro",
"Theatre.UI.Config.ConfigureTheatre" : "Configurar teatro",
"Theatre.UI.Config.Main" : "Principal",
Expand Down
2 changes: 2 additions & 0 deletions app/lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
"Theatre.MOTD.OldVersion" : "Théâtre n'est plus a jour, s'il vous plait demandez au GM de mètre a jour Théâtre.",

"Theatre.UI.Config.Stage" : "Scène",
"Theatre.UI.Config.AddToStage" : "Add to Stage",
"Theatre.UI.Config.RemoveFromStage" : "Remove from Stage",
"Theatre.UI.Config.Theatre" : "Théâtre",
"Theatre.UI.Config.ConfigureTheatre" : "Configurer Théâtre",
"Theatre.UI.Config.Main" : "Principal",
Expand Down
2 changes: 2 additions & 0 deletions app/lang/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
"Theatre.MOTD.OldVersion" : "立ち絵ツールの新しいバージョンがあります、オーナーはツールのセットアップ画面から更新してください。",

"Theatre.UI.Config.Stage" : "控室",
"Theatre.UI.Config.AddToStage" : "Add to Stage",
"Theatre.UI.Config.RemoveFromStage" : "Remove from Stage",
"Theatre.UI.Config.Theatre" : "立ち絵",
"Theatre.UI.Config.ConfigureTheatre" : "立ち絵設定",
"Theatre.UI.Config.Main" : "メイン",
Expand Down
2 changes: 2 additions & 0 deletions app/lang/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
"Theatre.MOTD.OldVersion" : "극장 모드가 현재 오래된 버전입니다. GM은 구성 화면에서 극장 모드를 업데이트 해주세요.",

"Theatre.UI.Config.Stage" : "무대",
"Theatre.UI.Config.AddToStage" : "Add to Stage",
"Theatre.UI.Config.RemoveFromStage" : "Remove from Stage",
"Theatre.UI.Config.Theatre" : "극장",
"Theatre.UI.Config.ConfigureTheatre" : "극장 구성",
"Theatre.UI.Config.Main" : "메인",
Expand Down
3 changes: 2 additions & 1 deletion app/lang/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
"Theatre.MOTD.OldVersion" : "O Theatre está desatualizado. Por favor, peça para seu GM atualizar o Theatre na tela de configurações.",

"Theatre.UI.Config.Stage" : "Palco",
"Theatre.UI.Config.AddToStage" : "Add to Stage",
"Theatre.UI.Config.RemoveFromStage" : "Remove from Stage",
"Theatre.UI.Config.Theatre" : "Theatre",
"Theatre.UI.Config.ConfigureTheatre" : "Configurar Teatro",
"Theatre.UI.Config.Main" : "Principal",
Expand Down Expand Up @@ -122,7 +124,6 @@
"Theatre.Emote.Scared" : "Assustado",
"Theatre.Emote.Pleased" : "Satisfeito",
"Theatre.Emote.Serious" : "Sério",
"Theatre.Emote.Pleased" : "Satisfeito",
"Theatre.Emote.Lazy" : "Preguiçoso",
"Theatre.Emote.Ambitious" : "Ambicioso",

Expand Down
2 changes: 2 additions & 0 deletions app/lang/th.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
"Theatre.MOTD.OldVersion" : "Theatre ขณะนี้ล้าสมัย, กรุณาบอก GM ให้อัปเดต theatre ในหน้าตั้งค่า",

"Theatre.UI.Config.Stage" : "Stage",
"Theatre.UI.Config.AddToStage" : "Add to Stage",
"Theatre.UI.Config.RemoveFromStage" : "Remove from Stage",
"Theatre.UI.Config.Theatre" : "Theatre",
"Theatre.UI.Config.ConfigureTheatre" : "กำหนดค่า Theatre",
"Theatre.UI.Config.Main" : "หลัก",
Expand Down
2 changes: 2 additions & 0 deletions app/lang/zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
"Theatre.MOTD.OldVersion" : "劇院當前已過時,請在設置屏幕中啓用GM更新劇場。",

"Theatre.UI.Config.Stage" : "入場",
"Theatre.UI.Config.AddToStage" : "Add to Stage",
"Theatre.UI.Config.RemoveFromStage" : "Remove from Stage",
"Theatre.UI.Config.Theatre" : "立繪",
"Theatre.UI.Config.ConfigureTheatre" : "設置立繪的各種屬性",
"Theatre.UI.Config.Main" : "主要",
Expand Down
1 change: 1 addition & 0 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"greensock/dist/ScrollToPlugin.min.js",
"greensock/dist/SplitText.min.js",
"app/js/TheatreActorConfig.js",
"app/js/TheatreActor.js",
"app/js/Theatre.js",
"app/js/theatre_main.js"
],
Expand Down

0 comments on commit 165d12a

Please sign in to comment.