Skip to content

Commit

Permalink
feat: changed **sounds** dependency from attack-roll-check-5e with mi…
Browse files Browse the repository at this point in the history
…di-qol
  • Loading branch information
EddieDover committed Oct 15, 2023
1 parent 543e3fe commit 3ef2430
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/lang/en.json
Expand Up @@ -7,6 +7,10 @@
"classes": "Classes"
},
"settings": {
"enable-sounds": {
"name": "Enable Syrinscape Sounds",
"hint": "This option requires the Syrinscape Integration (fvtt-synrin-control) and the Attack Roll Check (foundryvtt-attack-roll-check-5e) modules."
},
"enable-dark-mode": {
"name": "Enable Dark Mode",
"hint": "Enable dark mode for the party sheet."
Expand Down
4 changes: 4 additions & 0 deletions src/lang/es.json
Expand Up @@ -7,6 +7,10 @@
"classes": "Clases"
},
"settings": {
"enable-sounds": {
"name": "Habilitar Sonidos de Syrinscape",
"hint": "Esta opción requiere los módulos de Integración de Syrinscape (fvtt-syrin-control) y Comprobación de Tirada de Ataque (foundryvtt-attack-roll-check-5e)."
},
"enable-dark-mode": {
"name": "Habilitar el modo oscuro",
"hint": "Habilitar la hoja de fiesta en modo oscuro."
Expand Down
14 changes: 14 additions & 0 deletions src/module/sounds.js
@@ -0,0 +1,14 @@
import { SPELL_SOUNDS } from "./sounds/spells.js";
import { WEAPON_SOUNDS } from "./sounds/weapons.js";

export const THEATER_SOUNDS = {
...Object.keys(WEAPON_SOUNDS).reduce((acc, key) => {
acc[key.toLowerCase()] = WEAPON_SOUNDS[key];
return acc;
}, {}),

...Object.keys(SPELL_SOUNDS).reduce((acc, key) => {
acc[key.toLowerCase()] = SPELL_SOUNDS[key];
return acc;
}, {}),
};
93 changes: 93 additions & 0 deletions src/module/sounds/spells.js
@@ -0,0 +1,93 @@
export const SPELL_SOUNDS = {
"Official D&D": { any: 1493812 },
"0th level spell": { any: 415540 },
"1st level spell": { any: 415541 },
"2nd level spell": { any: 415542 },
"3rd level spell": { any: 415543 },
"4th level spell": { any: 415544 },
"5th level spell": { any: 415545 },
"6th level spell": { any: 415546 },
"7th level spell": { any: 415547 },
"8th level spell": { any: 415548 },
"9th level spell": { any: 415549 },
"Acid Splash": { any: 415550 },
"Acid Spray": { any: 211808 },
"Alarm": { any: 415551 },
"Banishment": { any: 595715 },
"Barkskin": { any: 546604 },
"Bestow Curse": { any: 415693 },
"Blur": { any: 1171146 },
"Burning Hands": { any: 627192 },
"Cure Wounds": { any: 1065131 },
"Charm Person": { any: 415556 },
"Chill Touch": { any: 415557 },
"Color Spray": { any: 415558 },
"Comprehend Languages": { any: 415559 },
"Conjure Elemental": { any: 415592 },
"Counterspell": { any: 556020 },
"Dancing Lights": { any: 415560 },
"Detect Magic": { any: 415562 },
"Dimension Door": { any: 556021 },
"Dispel Magic": { any: 425941 },
"Enlarge/Reduce": { any: 415565 },
"Fear": { any: 415555 },
"Finger of Death": { any: 659999 },
"Fire Bolt": { any: 415568 },
"Fire Shield": { any: 415553 },
"Fireball": { any: 415567 },
"Flaming Sphere": { any: 1171148 },
"Fog Cloud": { any: 415583 },
"Forcecage": { any: 556023 },
"Grease": { any: 415572 },
"Haste": { any: 415591 },
"Hold Person": { any: 546618 },
"Hypnotic Pattern": { any: 415574 },
"Identify": { any: 415586 },
"Infestation": { any: 556024 },
"Jump": { any: 415575 },
"Knock": { any: 415584 },
"Light": { any: 415576 },
"Lightning Bolt": { any: 415692 },
"Longstrider": { any: 556025 },
"Mage Armor": { any: 415577 },
"Mage Hand": { any: 415578 },
"Magic Circle": { any: 415579 },
"Magic Missile": { any: 415569 },
"Mending": { any: 415580 },
"Message": { any: 415581 },
"Meteor Swarm": { any: 556026 },
"Mirror Image": { any: 556027 },
"Modify Memory": { any: 415566 },
"Mold Earth": { any: 556028 },
"Mordenkainen’s Sword": { any: 415694 },
"Phantasmal killer": { any: 415571 },
"Phantom Steed": { any: 415582 },
"Poison Spray": { any: 556029 },
"Power Word Kill": { any: 556030 },
"Prestidigitation": { any: 415552 },
"Prismatic Spray": { any: 556031 },
"Protection from Energy": { any: 415564 },
"Protection from Evil and Good": { any: 556032 },
"Ray of Enfeeblement": { any: 415561 },
"Ray of Frost": { any: 415570 },
"Ray of Sickness": { any: 415554 },
"Reverse Gravity": { any: 556033 },
"Shield": { any: 415588 },
"Shocking Grasp": { any: 415589 },
"Sleep": { any: 415590 },
"Slow": { any: 415585 },
"Stinking Cloud": { any: 415563 },
"Stoneskin": { any: 415573 },
"Teleport": { any: 556034 },
"Thunderwave": { any: 415695 },
"Toll the Dead": { any: 556035 },
"Tongues": { any: 425944 },
"True Strike": { any: 415593 },
"Turn Undead": { any: 1065132 },
"Vampiric Touch": { any: 415587 },
"Wall of Force": { any: 578160 },
"Wall of Fire": { any: 556036 },
"Wall of Ice": { any: 578159 },
"Wall of Stone": { any: 578158 },
"Wish": { any: 454168 },
};
43 changes: 43 additions & 0 deletions src/module/sounds/weapons.js
@@ -0,0 +1,43 @@
export const WEAPON_SOUNDS = {
"club": { miss: 3021162, hit: 3021163, critical: 3021164 },
"greatclub": { hit: 3021166, critical: 3021167 },
"handaxe": { hit: 3021168, miss: 3021169, critical: 3021171 },
"javelin": { miss: 3021173, hit: 3021177, critical: 3021180 },
"warhammer": { miss: 3021181, critical: 3021182, hit: 3021183 },
"light hammer": { miss: 3021184, hit: 3021185, critical: 3021186 },
"sickle": { miss: 3021187, critical: 3021188, hit: 3021189 },
"battle axe": { miss: 3021190, critical: 3021192, hit: 3021193 },
"war pick": { miss: 3021196, hit: 3021197, critical: 3021198 },
"morningstar": { miss: 3022792, hit: 3022794, critical: 3022887 },
"mace": { critical: 3022793, miss: 3022885, hit: 3022886 },
"spear": { miss: 3022795, critical: 3022796, hit: 3022797 },
"greatsword": { hit: 3022880, miss: 3021165, critical: 3022881 },
"great club": { miss: 3022876 },
"greataxe": { critical: 3022877, hit: 3022878, miss: 3022879 },
"maul": { miss: 3022928, hit: 3022929, critical: 3022930 },
"scimitar unsheathe": { any: 2746 },
"scimitar swoosh": { any: 2747 },
"scimitar": { hit: 2717047, miss: 2717046, critical: 2717048 },
"scimitar sheath": { any: 2749 },
"scimitar crit": { any: 2750 },
"bow fire": { any: 6012 },
"shortbow": { any: 2208069 },
"crossbow fire": { any: 2208075 },
"flail": { hit: 2712690, critical: 2712691, miss: 2712692 },
"glaive": { hit: 2712706, critical: 2712708, miss: 3022882 },
"halberd": { miss: 2712707, hit: 3022883, critical: 3022884 },
"pike": { hit: 2717016, critical: 2717019, miss: 2717020 },
"trident": { critical: 2717021, hit: 2717022, miss: 2717023 },
"unarmed": { hit: 2717028, miss: 2717029, critical: 2717030 },
"rapier": { miss: 2717034, hit: 2717035, critical: 2717036 },
"dagger": { miss: 2717037, hit: 2717038, critical: 2717039 },
"longsword": { miss: 2717040, hit: 2717041, critical: 2717042 },
"quarterstaff": { miss: 2717050, hit: 2717051, critical: 2717052 },
"whip": { miss: 2717053, critical: 2717054, hit: 2717068 },
"shortsword": {
any: 2208068,
miss: 2717043,
hit: 2717044,
critical: 2717045,
},
};
64 changes: 63 additions & 1 deletion src/module/theater-of-the-mind.js
@@ -1,3 +1,5 @@
import { THEATER_SOUNDS } from "./sounds.js";

function log(...message) {
console.log("Theater of the Mind | ", message);
}
Expand Down Expand Up @@ -168,6 +170,32 @@ function togglePartySheet() {
}
}

async function playSound(weapon, crit, hitmiss, override = null) {
const hitmisscrit = override ? "any" : (crit ? "critical" : hitmiss ? "hit" : "miss");

if (!game.settings.get("theater-of-the-mind", "enableSounds")) {
return;
}

// Get the sound from the THEATER_SOUNDS object
const weaponsound = THEATER_SOUNDS[weapon.toLowerCase()];

if (!weaponsound) {
log(`No sound key found [${weapon.toLowerCase()}].`);
return;
}

const subsound = hitmisscrit.toLowerCase() || "any";
const soundid = weaponsound[subsound];

if (!soundid) {
log(
`Key found: [${weapon.toLowerCase()}], No sound sub-type found [${subsound}].`,
);
} else {
game.syrinscape.playElement(soundid);
}
}
/* Hooks */

Hooks.on("init", () => {
Expand All @@ -178,14 +206,48 @@ Hooks.on("init", () => {
"hint": "theater-of-the-mind.settings.enable-dark-mode.hint",
"scope": "world",
"config": true,
"default": true,
"default": false,
"type": Boolean,
"onChange": () => {
// Hooks.call("renderSceneControls");
},
});

game.settings.register("theater-of-the-mind", "enableSounds", {
"name": "theater-of-the-mind.settings.enable-sounds.name",
"hint": "theater-of-the-mind.settings.enable-sounds.hint",
"scope": "world",
"config": true,
"default": false,
"type": Boolean,
"onChange": () => {
},
});
});

//
Hooks.on('midi-qol.AttackRollComplete', async (roll) => {
const weapon = roll.item.name;
const roll_results = roll.attackTotal;
const target = roll?.targets?.values().next().value || null;
const target_actor = target?.document?.actors?.values().next().value || null;
const ac = target_actor?.system?.attributes?.ac?.value || null;

if (ac) {
playSound(weapon, roll_results === 20, roll_results >= ac);
}

});

Hooks.on('midi-qol.preambleComplete', async (roll) => {

if (roll?.item?.type != "spell") {
return;
}
playSound(roll.item.name, false, false, "any");

})

Hooks.on("ready", async () => {
log("Ready");
});
Expand Down

0 comments on commit 3ef2430

Please sign in to comment.