From 1207b9c1bdaecd3859ee9337f02bd6ffcdffbecb Mon Sep 17 00:00:00 2001 From: Mike Bloy Date: Sun, 26 May 2024 17:25:18 -0500 Subject: [PATCH] use hash of name to assign maintain icon --- src/module/powers/basePowers.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/module/powers/basePowers.js b/src/module/powers/basePowers.js index e224a11..9ddb5d0 100644 --- a/src/module/powers/basePowers.js +++ b/src/module/powers/basePowers.js @@ -17,6 +17,19 @@ const MAINTAIN_ICONS = [ 'icons/magic/symbols/runes-triangle-orange.webp', ]; +function _hashCode(str) { + let hash = 0; + if (str.length === 0) { + return hash; + } + for (let i = 0; i < str.length; i++) { + const c = str.charCodeAt(i); + hash = (hash << 5) - hash + c; + hash |= 0; + } + return Math.abs(hash); +} + export class PowerFormApplication extends FormApplication { constructor(powerEffect) { super(); @@ -522,7 +535,7 @@ export class PowerEffect { } async createMaintainEffect(maintId) { - let icon = MAINTAIN_ICONS[Math.floor(Math.random() * MAINTAIN_ICONS.length)]; + let icon = MAINTAIN_ICONS[_hashCode(this.name) % MAINTAIN_ICONS.length]; if (!this.usePrimaryEffect) { icon = this.icon; }