From 4e766f0ef2e2bc8c448b7ee4c534edc7e2ca5b91 Mon Sep 17 00:00:00 2001 From: cadowtin Date: Fri, 13 Sep 2024 21:24:23 -0500 Subject: [PATCH] Added death effect to thing --- .../animation/text/fromSoftwareText.js | 190 ++++++++---------- scripts/hooks.js | 10 +- scripts/module.js | 3 + 3 files changed, 93 insertions(+), 110 deletions(-) diff --git a/scripts/helpers/animation/text/fromSoftwareText.js b/scripts/helpers/animation/text/fromSoftwareText.js index d2edd28..f6b5de1 100644 --- a/scripts/helpers/animation/text/fromSoftwareText.js +++ b/scripts/helpers/animation/text/fromSoftwareText.js @@ -1,136 +1,108 @@ import { getSetting } from "../../misc.js"; -export async function eldenRingNounVerbed(text = getSetting(`from-software.noun-verbed.sound-text`), options = {}) { - const sound = options?.sound ?? getSetting(`from-software.noun-verbed.sound-effect`) - const fontSize = option?.fontSize ?? getSetting(`from-software.noun-verbed.font-size`) - const partOne = text.slice(0, text.length / 2) - const partOneOffset = (partOne.length + 0.5) * fontSize / 2; - const partTwo = text.slice(text.length / 2, text.length) - const partTwoOffset = (partTwo.length + 0.5) * fontSize / 2; +/** + * Creates an Elden Ring-style "Noun Verbed" sequence. + * @param {Object} options - Configuration options. + * @param {string} [options.text] - The text to display. + * @param {string} [options.sound] - The sound effect file path. + * @param {number} [options.fontSize] - The font size for the text. + * @param {number} [options.duration] - The duration of the sequence in seconds. + * @returns {Promise} A promise that resolves to the played Sequence. + */ +export async function eldenRingNounVerbed(options = {}) { + const text = options.text ?? getSetting(`from-software.noun-verbed.sound-text`); + const sound = options.sound ?? getSetting(`from-software.noun-verbed.sound-effect`); + const fontSize = options.fontSize ?? getSetting(`from-software.noun-verbed.font-size`); + const duration = (options.duration ?? getSetting(`from-software.noun-verbed.duration`)) * 1000; + const users = options?.users ?? game.users.map(u => u.id); - const rect = { - height: fontSize * 3, - width: 4000 - } + const [partOne, partTwo] = [text.slice(0, text.length / 2), text.slice(text.length / 2)]; + const [partOneOffset, partTwoOffset] = [(partOne.length + 0.5) * fontSize / 2, (partTwo.length + 0.5) * fontSize / 2]; - const duration = (options?.duration ?? getSetting(`from-software.noun-verbed.duration`)) * 1000; + const rect = { height: fontSize * 3, width: 4000 }; const fadein = 500; return new Sequence() - //Sound - .sound() - .file(sound) - .delay(fadein / 2) - //Background - .effect() - .syncGroup("eldenRing.nounVerbed") - .screenSpaceAboveUI() - .duration(duration - 100) - .fadeIn(fadein) - .fadeOut(fadein / 2) - .screenSpace() - .screenSpacePosition({ x: 0, y: 0 }) + .sound().file(sound).delay(fadein / 2).forUsers(users) + .effect().syncGroup("eldenRing.nounVerbed") + .screenSpaceAboveUI().duration(duration - 100) + .fadeIn(fadein).fadeOut(fadein / 2) + .screenSpace().screenSpacePosition({ x: 0, y: 0 }) .screenSpaceAnchor({ x: 0.5, y: 0.5 }) .shape("rectangle", { - width: rect.width, - height: rect.height, - fillColor: "#000001", - fillAlpha: 0.8, - lineSize: 0, - lineColor: "#FF0000", + width: rect.width, height: rect.height, + fillColor: "#000001", fillAlpha: 0.8, + lineSize: 0, lineColor: "#FF0000", offset: { x: -rect.width / 2, y: -rect.height / 2 } - } - ) - .filter("Blur", { - strength: 1, // Number, strength of the filter - blurY: 30, // Number, blur strength on the vertical axis - quality: 15, // Number, quality of the filter - resolution: 4, // Number, sets the resolution of the blur filter - kernelSize: 5 // Number, effectively how many passes the blur goes through }) - //Text part 1 - .effect() - .syncGroup("eldenRing.nounVerbed") - .screenSpaceAboveUI() - .duration(duration) - .fadeIn(fadein) - .fadeOut(fadein / 2) - .screenSpace() - .screenSpaceAnchor({ x: 0.5, y: 0.5 }) + .filter("Blur", { strength: 1, blurY: 30, quality: 15, resolution: 4, kernelSize: 5 }).forUsers(users) + .effect().syncGroup("eldenRing.nounVerbed") + .screenSpaceAboveUI().duration(duration) + .fadeIn(fadein).fadeOut(fadein / 2) + .screenSpace().screenSpaceAnchor({ x: 0.5, y: 0.5 }) .screenSpacePosition({ x: -partOneOffset, y: 0 }) - .text(partOne, { "align": "left", "dropShadow": true, "dropShadowAlpha": 0.2, "dropShadowAngle": 3.14, "dropShadowColor": "#ffd042", "dropShadowDistance": 13, "fill": "#dcaf2d", "fontFamily": "Lusitana-Regular", "fontSize": fontSize, "padding": 10, "stroke": "#dcaf2d" }) - //Text Part 2 - .effect() - .syncGroup("eldenRing.nounVerbed") - .screenSpaceAboveUI() - .duration(duration) - .fadeIn(fadein) - .fadeOut(fadein / 2) - .screenSpace() - .screenSpacePosition({ x: partTwoOffset, y: 0 }) + .text(partOne, { + align: "left", dropShadow: true, dropShadowAlpha: 0.2, + dropShadowAngle: 3.14, dropShadowColor: "#ffd042", dropShadowDistance: 13, + fill: "#dcaf2d", fontFamily: "Lusitana-Regular", fontSize: fontSize, + padding: 10, stroke: "#dcaf2d" + }).forUsers(users) + .effect().syncGroup("eldenRing.nounVerbed") + .screenSpaceAboveUI().duration(duration) + .fadeIn(fadein).fadeOut(fadein / 2) + .screenSpace().screenSpacePosition({ x: partTwoOffset, y: 0 }) .screenSpaceAnchor({ x: 0.5, y: 0.5 }) - .text(partTwo, { "align": "right", "dropShadow": true, "dropShadowAlpha": 0.2, "dropShadowAngle": 0, "dropShadowColor": "#ffd042", "dropShadowDistance": 13, "fill": "#dcaf2d", "fontFamily": "Lusitana-Regular", "fontSize": fontSize, "padding": 10, "stroke": "#dcaf2d" }) + .text(partTwo, { + align: "right", dropShadow: true, dropShadowAlpha: 0.2, + dropShadowAngle: 0, dropShadowColor: "#ffd042", dropShadowDistance: 13, + fill: "#dcaf2d", fontFamily: "Lusitana-Regular", fontSize: fontSize, + padding: 10, stroke: "#dcaf2d" + }).forUsers(users) .play(); } -export async function eldenRingDeath(text = getSetting(`from-software.death.sound-text`), options = {}) { - const sound = options?.sound ?? getSetting(`from-software.death.sound-effect`) - const fontSize = option?.fontSize ?? getSetting(`from-software.death.font-size`) - - const rect = { - height: fontSize * 3, - width: 4000 - } +/** + * Creates an Elden Ring-style "Death" sequence. + * @param {Object} options - Configuration options. + * @param {string} [options.text] - The text to display. + * @param {string} [options.sound] - The sound effect file path. + * @param {number} [options.fontSize] - The font size for the text. + * @param {number} [options.duration] - The duration of the sequence in seconds. + * @returns {Promise} A promise that resolves to the played Sequence. + */ +export async function eldenRingDeath(options = {}) { + const text = options.text ?? getSetting(`from-software.death.sound-text`); + const sound = options.sound ?? getSetting(`from-software.death.sound-effect`); + const fontSize = options.fontSize ?? getSetting(`from-software.death.font-size`); + const duration = (options.duration ?? getSetting(`from-software.death.duration`)) * 1000; + const users = options?.users ?? game.users.map(u => u.id); - const duration = (options?.duration ?? getSetting(`from-software.death.duration`)) * 1000; + const rect = { height: fontSize * 3, width: 4000 }; const fadein = 500; return new Sequence() - //Sound - .sound() - .file(sound) - .delay(fadein / 2) - //Background - .effect() - .syncGroup("eldenRing.death") - .screenSpaceAboveUI() - .duration(duration) - .fadeIn(fadein) - .fadeOut(fadein / 2) - .screenSpace() - .screenSpacePosition({ x: 0, y: 0 }) + .sound().file(sound).delay(fadein / 2).forUsers(users) + .effect().syncGroup("eldenRing.death") + .screenSpaceAboveUI().duration(duration) + .fadeIn(fadein).fadeOut(fadein / 2) + .screenSpace().screenSpacePosition({ x: 0, y: 0 }) .screenSpaceAnchor({ x: 0.5, y: 0.5 }) .shape("rectangle", { - width: rect.width, - height: rect.height, - fillColor: "#000001", - fillAlpha: 0.8, - lineSize: 0, - lineColor: "#FF0000", + width: rect.width, height: rect.height, + fillColor: "#000001", fillAlpha: 0.8, + lineSize: 0, lineColor: "#FF0000", offset: { x: -rect.width / 2, y: -rect.height / 2 } - } - ) - .filter("Blur", { - strength: 1, // Number, strength of the filter - blurY: 30, // Number, blur strength on the vertical axis - quality: 15, // Number, quality of the filter - resolution: 4, // Number, sets the resolution of the blur filter - kernelSize: 5 // Number, effectively how many passes the blur goes through }) - //Text part 1 - .effect() - .syncGroup("eldenRing.death") - .screenSpaceAboveUI() - .duration(duration + 100) - .fadeIn(fadein) - .fadeOut(fadein / 2) - .screenSpace() - .screenSpaceAnchor({ x: 0.5, y: 0.5 }) + .filter("Blur", { strength: 1, blurY: 30, quality: 15, resolution: 4, kernelSize: 5 }).forUsers(users) + .effect().syncGroup("eldenRing.death") + .screenSpaceAboveUI().duration(duration + 100) + .fadeIn(fadein).fadeOut(fadein / 2) + .screenSpace().screenSpaceAnchor({ x: 0.5, y: 0.5 }) .text(text, { - "fill": "#82101d", - "fontFamily": "Lusitana-Regular", - "fontSize": fontSize, - "padding": 10 - }) + fill: "#82101d", + fontFamily: "Lusitana-Regular", + fontSize: fontSize, + padding: 10 + }).forUsers(users) .play(); } \ No newline at end of file diff --git a/scripts/hooks.js b/scripts/hooks.js index 5b4ff4c..e382560 100644 --- a/scripts/hooks.js +++ b/scripts/hooks.js @@ -1,4 +1,4 @@ -import { eldenRingNounVerbed } from "./helpers/animation/text/fromSoftwareText.js"; +import { eldenRingDeath, eldenRingNounVerbed } from "./helpers/animation/text/fromSoftwareText.js"; import { getSetting } from "./helpers/misc.js"; /** @@ -41,6 +41,14 @@ export async function preDeleteCombat(encounter, _changed, _userid) { await eldenRingNounVerbed(); } } +export async function applyTokenStatusEffect(token, status, isAdd) { + if (status == 'dead' && isAdded && getSetting('from-software.death.enable')) { + const userId = game.users.find(c => c?.character?.uuid == token?.actor?.uuid)?.id + if (userId) { + await eldenRingDeath({ users: [userId] }) + } + } +} /** * Extracts actor levels based on a filter condition. diff --git a/scripts/module.js b/scripts/module.js index 4682b28..994b218 100644 --- a/scripts/module.js +++ b/scripts/module.js @@ -55,7 +55,10 @@ Hooks.on("init", () => { Hooks.on("ready", () => { console.log("PF2e RPG Numbers is starting"); createAPI(); + // Noun Verbed Elden Ring Hooks.on("preDeleteCombat", preDeleteCombat); + // You died Elden Ring + Hooks.on("applyTokenStatusEffect", applyTokenStatusEffect); Hooks.on("createChatMessage", async function (msg, _status, userid) { if (game.user.id === userid) { if (!getSetting("enabled")) return;