Skip to content

Commit

Permalink
Lock status icon as token overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
coffiarts committed Dec 16, 2023
1 parent 44c6279 commit bdc9aee
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 32 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# TODO
- readme =)> chatinfo vereinfachen
- token flag?

# Sheet Locker for Foundry VTT
<table style="border:0">
<tr>
Expand Down
4 changes: 4 additions & 0 deletions src/sheet-locker/lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
"lockForGM": {
"name": "Sperrung auch für Spielleiter anwenden",
"hint": "Gleiche Regeln für alle! Sperrung gilt auch für den SL (als Schutz vor unbeabsichtigten Änderungen)."
},
"lockedStatusIcon": {
"name": "Status Icon bei Sperrung (optional)",
"hint": "Welches Icon soll auf Tokens und Akteuren angezeigt werden, wenn sie gesperrt sind (zum Deaktivieren leer lassen)?"
}
},
"chatInfoContent": {
Expand Down
4 changes: 4 additions & 0 deletions src/sheet-locker/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
"lockForGM": {
"name": "Lock changes by GM",
"hint": "Same rules for all! Apply locking to me as the GM as well (protecting myself from doing unintended changes)."
},
"lockedStatusIcon": {
"name": "Status Icon when locked (optional)",
"hint": "Pick which icon to display on tokens and actors when locked (leave empty to disable)?"
}
},
"chatInfoContent": {
Expand Down
3 changes: 3 additions & 0 deletions src/sheet-locker/scripts/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export class Config {
},
alertGMOnReject: {
scope: 'world', config: true, type: Boolean, default: true
},
lockedStatusIcon: {
scope: 'world', config: true, type: String, filePicker: "image", default: `${Config.data.modPath}/artwork/red-lock.png`
}
};
Config.registerSettings(data);
Expand Down
83 changes: 55 additions & 28 deletions src/sheet-locker/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,43 @@ let permanentUIMsgID;
Logger.infoGreen(`Ready to play! Version: ${game.modules.get(Config.data.modID).version}`);
Logger.info(Config.data.modDescription);
SheetLocker.isActive = Config.setting('isActive');
stateChangeUIMessage();
});

Hooks.on("preCreateItem", function (item, data, options, userid) {
return onItemChangedInSheet(item, data, options, userid);
});
Hooks.on("preCreateActiveEffect", function (item, data, options, userid) {
return onItemChangedInSheet(item, data, options, userid);
});
Hooks.on("preCreateItem", function (item, data, options, userid) {
return onItemChangedInSheet(item, data, options, userid);
});
Hooks.on("preCreateActiveEffect", function (item, data, options, userid) {
return onItemChangedInSheet(item, data, options, userid);
});

Hooks.on("preUpdateActor", function (actor, data, options, userid) {
return onSheetChanged(actor, data, options, userid);
});
Hooks.on("preUpdateItem", function (item, data, options, userid) {
return onItemChangedInSheet(item, data, options, userid);
});
Hooks.on("preUpdateActiveEffect", function (item, data, options, userid) {
return onItemChangedInSheet(item, data, options, userid);
});
Hooks.on("preUpdateActor", function (actor, data, options, userid) {
return onSheetChanged(actor, data, options, userid);
});
Hooks.on("preUpdateItem", function (item, data, options, userid) {
return onItemChangedInSheet(item, data, options, userid);
});
Hooks.on("preUpdateActiveEffect", function (item, data, options, userid) {
return onItemChangedInSheet(item, data, options, userid);
});

Hooks.on("preDeleteItem", function (item, options, userid) {
return onItemDeletedFromSheet(item, options, userid);
});
Hooks.on("preDeleteActiveEffect", function (item, options, userid) {
return onItemDeletedFromSheet(item, options, userid);
});
Hooks.on("preDeleteItem", function (item, options, userid) {
return onItemDeletedFromSheet(item, options, userid);
});
Hooks.on("preDeleteActiveEffect", function (item, options, userid) {
return onItemDeletedFromSheet(item, options, userid);
});

Hooks.on("getSceneControlButtons", (controls) => {
createControlButton(controls);
Hooks.on("getSceneControlButtons", (controls) => {
createControlButton(controls);
});

if (game.user.isGM) {
Hooks.on("refreshToken", async () => {
await renderTokenOverlays();
});
}

renderTokenOverlays();
stateChangeUIMessage();
});
}
)
Expand Down Expand Up @@ -196,11 +204,25 @@ function onItemDeletedFromSheet(item, options, userid) {
}
}

/**
* inspired by // https://github.com/LeafWulf/deathmark/blob/master/scripts/deathmark.js
*/
async function renderTokenOverlays() {
let img = (SheetLocker.isActive) ? Config.setting('lockedStatusIcon') : "";
/*if (token != null && aToken.actorLink) {
await token.update({overlayEffect: img});
return;
} else */for (const aToken of game.scenes.current.tokens) {
if (aToken.actorLink) {
await aToken.update({overlayEffect: img});
}
}
}
function getButton() {
return ui.controls.controls.find(control => control.name === "token").tools.find(tool => tool.name === "toggleSheetLocker");
}

function onGameSettingChanged() {
async function onGameSettingChanged() {
SheetLocker.isActive = Config.setting('isActive');

if (game.user.isGM && Config.setting('notifyOnChange')) {
Expand All @@ -214,8 +236,9 @@ function onGameSettingChanged() {
}

if (game.user.isGM) {
let button = getButton();

// Refresh scene control button (if active) to reflect the potentially new state.
let button = getButton();
if (Config.setting('showUIButton')) {
if (button == null) {
createControlButton(ui.controls.controls);
Expand All @@ -228,6 +251,10 @@ function onGameSettingChanged() {
ui.controls.controls.find(control => control.name === "token").tools.pop(button);
ui.controls.render();
}

// Refresh status overlays
await renderTokenOverlays();

}
}

Expand Down Expand Up @@ -260,7 +287,7 @@ function stateChangeUIMessage() {
localize: false,
console: false
});
};
}
if (!isPermanent) permanentUIMsgID = null;
}
Logger.info(message);
Expand Down

0 comments on commit bdc9aee

Please sign in to comment.