add secret door handler to wall config
This commit is contained in:
parent
a25d86106c
commit
5785b1b491
@ -92,6 +92,67 @@ Hooks.on("renderApplicationV2", (application, element, context, options) => {
|
|||||||
.forEach((el) => el.addEventListener("click", _onClickActorDropperLink));
|
.forEach((el) => el.addEventListener("click", _onClickActorDropperLink));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Hooks.on("renderWallConfig", async (application, element, context, options) => {
|
||||||
|
const doc = application.document;
|
||||||
|
const scope = "mb-assets";
|
||||||
|
const key = "doortile";
|
||||||
|
const defaultValue = null;
|
||||||
|
const value = doc.getFlag(scope, key) ?? defaultValue;
|
||||||
|
const name = `flags.${scope}.${key}`;
|
||||||
|
if (options.parts && !options.parts.includes("body")) return;
|
||||||
|
const dataField = new foundry.data.fields.DocumentUUIDField({
|
||||||
|
type: "Tile",
|
||||||
|
hint: "The tile that should be hidden when the secret door is opened.",
|
||||||
|
nullable: true,
|
||||||
|
required: false,
|
||||||
|
blank: false,
|
||||||
|
initial: null,
|
||||||
|
label: "Door Tile",
|
||||||
|
});
|
||||||
|
const group = dataField.toFormGroup(
|
||||||
|
{ hidden: !context.source.door },
|
||||||
|
{ disabled: !context.source.door, name, value },
|
||||||
|
);
|
||||||
|
const fieldSet = element
|
||||||
|
.querySelector('select[name="door"]')
|
||||||
|
?.closest("fieldset");
|
||||||
|
const form = fieldSet?.closest("form");
|
||||||
|
fieldSet.appendChild(group);
|
||||||
|
application.setPosition();
|
||||||
|
form.addEventListener("change", (event) => {
|
||||||
|
if (event.target.name === "door") {
|
||||||
|
const hidden = event.target.value == 0;
|
||||||
|
console.log("PONIES", hidden, event.target.closest("fieldset"));
|
||||||
|
const fieldSet = event.target.closest("fieldset");
|
||||||
|
const formInput = fieldSet.querySelector(`[name="${name}"]`);
|
||||||
|
formInput.disabled = hidden;
|
||||||
|
formInput.closest(".form-group").hidden = hidden;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
Hooks.on("updateWall", async (doc, changed, options, userId) => {
|
||||||
|
if (!game.user.isActiveGM) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!Object.hasOwn(changed, "ds")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const isOpen = doc.door !== 0 && doc.ds === 1;
|
||||||
|
const scope = "mb-assets";
|
||||||
|
const key = "doortile";
|
||||||
|
const tileUUID = doc.getFlag(scope, key);
|
||||||
|
if (!tileUUID || tileUUID == "null" || tileUUID == "undefined") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const tile = foundry.utils.fromUuidSync(tileUUID);
|
||||||
|
if (!tile || tile.parent.uuid != doc.parent.uuid) {
|
||||||
|
console.log("invalid tile data for door state change", tile, doc);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await tile.update({ hidden: isOpen });
|
||||||
|
});
|
||||||
|
|
||||||
Hooks.on("renderChatMessageHTML", (message, html, context) => {
|
Hooks.on("renderChatMessageHTML", (message, html, context) => {
|
||||||
html
|
html
|
||||||
.querySelectorAll("a.mb-assets-actor-drop-link")
|
.querySelectorAll("a.mb-assets-actor-drop-link")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user