Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
ChasarooniZ committed Sep 15, 2024
1 parent 4ec17cf commit c0ba7df
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# [12.5.3](https://github.com/ChasarooniZ/pf2e-rpg-numbers/compare/12.5.2...12.5.3) - Fix for Styling

- `From Software - Noun Verbed`
- Fixed styling for Custom Text (@RavenRaconteur)
- Automatically Capitalize text passed in to `Noun Verbed` and `You Died` text
# [12.5.2](https://github.com/ChasarooniZ/pf2e-rpg-numbers/compare/12.5.1...12.5.2) - Shaking and Polish

- Update Polish Translation (@LioHeart)
- Fixed issue with Sequencer based shake on damage not checking flipped or rotated (@spen)
# [12.5.2](https://github.com/ChasarooniZ/pf2e-rpg-numbers/compare/12.5.1...12.5.2) - Shaking and Polish

- Update Polish Translation (@LioHeart)
Expand Down
18 changes: 14 additions & 4 deletions scripts/helpers/animation/text/fromSoftwareText.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import { getSetting } from "../../misc.js";
* @returns {Promise<Sequence>} A promise that resolves to the played Sequence.
*/
export async function eldenRingNounVerbed(options = {}) {
const text = options.text ?? getSetting(`from-software.noun-verbed.text`);
const text = (options.text ?? getSetting(`from-software.noun-verbed.text`)).toUpperCase();
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 [partOne, partTwo] = [text.slice(0, text.length / 2), text.slice(text.length / 2)];
const [partOneOffset, partTwoOffset] = [(partOne.length + 0.5) * fontSize / 3, (partTwo.length + 0.5) * fontSize / 3];
const [partOneOffset, partTwoOffset] = [(getTextWidth(partOne, `${fontSize}pt Lusitana-Regular`)) / 2, (getTextWidth(partTwo, `${fontSize}pt Lusitana-Regular`)) / 2];

const rect = { height: fontSize * 3, width: 4000 };
const fadein = 500;
Expand Down Expand Up @@ -71,7 +71,7 @@ export async function eldenRingNounVerbed(options = {}) {
* @returns {Promise<Sequence>} A promise that resolves to the played Sequence.
*/
export async function eldenRingDeath(options = {}) {
const text = options.text ?? getSetting(`from-software.death.text`);
const text = (options.text ?? getSetting(`from-software.death.text`)).toUpperCase();
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;
Expand Down Expand Up @@ -105,4 +105,14 @@ export async function eldenRingDeath(options = {}) {
padding: 10
}).forUsers(users)
.play();
}
}

function getTextWidth(text, font) {
// if given, use cached canvas for better performance
// else, create new canvas
var canvas = getTextWidth.canvas || (getTextWidth.canvas = document.createElement("canvas"));
var context = canvas.getContext("2d");
context.font = font;
var metrics = context.measureText(text + "||"); // The '||' adds a little bit of separation
return metrics.width;
};

0 comments on commit c0ba7df

Please sign in to comment.