Skip to content

Commit

Permalink
✨ new features and settings and oh wow
Browse files Browse the repository at this point in the history
  • Loading branch information
marutypes committed Mar 19, 2023
1 parent fb21c01 commit 436d730
Show file tree
Hide file tree
Showing 25 changed files with 276 additions and 49 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@


# Maru's Combat Themes
I made this for my Fists of The Ruby Phoenix campaign. Mostly silly fighting game references.
I made this for my Fists of The Ruby Phoenix campaign. The module adds some custom themes to the combat theme dropdown, and also extends the combat theme system to work with end of combat and round start clips.

The bundled audio is basically all silly fighting game references.

## Usage
To change your theme, select it from the dropdown menu in Core Settings -> Combat Theme. You can also find settings for whether to use the extra sound effect hooks under the modules settings.

## Themes

The following themes are bundled in:
* Guilty Gear Strive
* BlazBlue Cross Tag Battle

### Adding a theme

To change your theme, select it from the dropdown menu in Core Settings -> Combat Theme
WIP

## Audio sourcing

Expand Down
57 changes: 57 additions & 0 deletions generate-themes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const fs = require("fs");
const path = require("path");

const directoryPath = "/sounds";
const outputFilePath = "/scripts/themes.generated.mjs";
const IGNORE_LIST = ["LICENSE.md"];

fs.readdir(path.join(".", directoryPath), (err, directories) => {
if (err) {
console.error(`Error reading directory ${directoryPath}: ${err}`);
return;
}

const themes = {};
directories.forEach((dir) => {
const dirPath = path.join(".", directoryPath, dir);
console.log(dirPath);
if (IGNORE_LIST.includes(dir)) {
return;
}

const files = fs.readdirSync(dirPath);

themes[dir] = {
label: `MCT.Themes.Names.${dir}`,
startEncounter: files
.filter((file) => file.startsWith("startEncounter"))
.map((file) => `/modules/maru-combat-themes/sounds/${dir}/${file}`),
startRound: files
.filter((file) => file.startsWith("startRound"))
.map((file) => `/modules/maru-combat-themes/sounds/${dir}/${file}`),
nextUp: files
.filter((file) => file.startsWith("nextUp"))
.map((file) => `/modules/maru-combat-themes/sounds/${dir}/${file}`),
yourTurn: files
.filter((file) => file.startsWith("yourTurn"))
.map((file) => `/modules/maru-combat-themes/sounds/${dir}/${file}`),
endCombat: files
.filter((file) => file.startsWith("endCombat"))
.map((file) => `${directoryPath}/${dir}/${file}`),
};
});

const output = `// GENERATED BY \`generate-themes\`.js on ${new Date()}
const themes = ${JSON.stringify(themes, null, 2)};
export default themes;
`;

fs.writeFile(path.join(".", outputFilePath), output, (err) => {
if (err) {
console.error(`Error writing to file ${outputFilePath}: ${err}`);
return;
}

console.log(`Successfully wrote themes to file ${outputFilePath}`);
});
});
13 changes: 11 additions & 2 deletions languages/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
{
"COMBAT.Sounds.GGStrive": "Guilty Gear -Strive-",
"COMBAT.Sounds.BlazBlue": "Blaz Blue Cross Tag Battle"
"MCT.Themes.Names.GGStrive": "Guilty Gear -Strive-",
"MCT.Themes.Names.BlazBlueCrossTagBattle": "Blaz Blue Cross Tag Battle",

"MCT.Config.EndCombatSound.Title": "End Combat Sound",
"MCT.Config.EndCombatSound.Description": "Play custom end combat sounds.",

"MCT.Config.RoundStart.Title": "Round Start Sound",
"MCT.Config.RoundStart.Description": "Play custom round start sounds.",

"MCT.Config.ForceNextUp.Title": "Force Turn Change Sound",
"MCT.Config.ForceNextUp.Description": "Foundry doesn't seem to actually play turn switch sounds. This forces it to do so."
}
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "foundryvtt-maru-combat-themes",
"version": "0.1.0",
"description": "see module.json",
"main": "scripts/main.mjs",
"scripts": {
"generate-themes": "node ./generate-themes.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/marutypes/FoundryVTT-Maru-Combat-Themes.git"
},
"keywords": [
"FoundryVTT"
],
"author": "Mallory \"Maru\" Allen",
"license": "MIT",
"bugs": {
"url": "https://github.com/marutypes/FoundryVTT-Maru-Combat-Themes/issues"
},
"homepage": "https://github.com/marutypes/FoundryVTT-Maru-Combat-Themes#readme"
}
9 changes: 9 additions & 0 deletions scripts/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const MODULE_NAME = "maru-combat-themes";
export const MODULE_ROOT = "/modules/maru-combat-themes/";
export const SOUND_TYPE = {
START_ENCOUNTER: "startEncounter",
START_ROUND: "startRound",
NEXT_UP: "nextUp",
YOUR_TURN: "yourTurn",
END_COMBAT: "endCombat",
};
34 changes: 33 additions & 1 deletion scripts/main.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
import themes from "./themes.mjs";
import themes from "./themes.generated.mjs";
import { SOUND_TYPE } from "./constants.mhs";
import { chooseTheme } from "./macros.mjs";
import { playRandomCombatSound } from "./sounds.mjs";
import settings from "./settings.mjs";

Hooks.on("init", () => {
foundry.utils.mergeObject(CONFIG.Combat.sounds, themes);

settings.register();

Macro.create(chooseTheme);
});

Hooks.on("updateCombat", (combat, changed) => {
if (changed.round) {
// This code will run at the start of each round
console.log(`Starting round ${combat.round}`);
if (settings.roundStartSound) {
playRandomCombatSound(SOUND_TYPE.START_ROUND);
}
}

if (changed.turn) {
// This code will run when the turn changes
const currentCombatant = combat.combatants[combat.turns];
if (settings.forceNextUpSound) {
playRandomCombatSound(SOUND_TYPE.NEXT_UP)
}
console.log(`It is now ${currentCombatant.name}'s turn.`);
}
});

Hooks.on("deleteCombat", () => {
console.log(`Combat deleted`);
if (settings.endCombatSound) {
playRandomCombatSound(SOUND_TYPE.END_COMBAT);
}
});
67 changes: 67 additions & 0 deletions scripts/settings.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { MODULE_NAME } from "./constants.mjs";

const PLAY_END_COMBAT_SOUND = "play-end-combat-sound";
const PLAY_ROUND_START_SOUND = "play-round-start-sound";
const FORCE_NEXTUP_SOUND = "force-nextup-sound";

class Settings {
register() {
game.settings.register(MODULE_NAME, PLAY_END_COMBAT_SOUND, {
name: "MCT.Config.EndCombatSound.Title",
hint: "MCT.Config.EndCombatSound.Description",
scope: "client",
config: true,
type: Boolean,
default: true,
});

game.settings.register(MODULE_NAME, PLAY_ROUND_START_SOUND, {
name: "MCT.Config.RoundStart.Title",
hint: "MCT.Config.RoundStart.Description",
scope: "client",
config: true,
type: Boolean,
default: true,
});

game.settings.register(MODULE_NAME, FORCE_NEXTUP_SOUND, {
name: "MCT.Config.ForceNextUp.Title",
hint: "MCT.Config.ForceNextUp.Description",
scope: "client",
config: true,
type: Boolean,
default: true,
});
}

get endCombatSound() {
return this.getSetting(PLAY_END_COMBAT_SOUND);
}
set endCombatSound(value) {
this.setSetting(PLAY_END_COMBAT_SOUND, value);
}

get roundStartSound() {
return this.getSetting(PLAY_ROUND_START_SOUND);
}
set roundStartSound(value) {
this.setSetting(PLAY_ROUND_START_SOUND, value);
}

get forceNextUpSound() {
return this.getSetting(FORCE_NEXTUP_SOUND);
}
set forceNextUpSound(value) {
this.setSetting(FORCE_NEXTUP_SOUND, value);
}

getSetting(setting, value) {
return game.settings.get(MODULE_NAME, setting);
}

setSetting(setting, value) {
game.settings.set(MODULE_NAME, setting, value);
}
}

export default new Settings();
24 changes: 24 additions & 0 deletions scripts/sounds.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export function playCombatSound(theme, type, index = 0) {
const themeObject = CONFIG.Combat.sounds[theme];
if (themeObject && themeObject[type] && themeObject[type].hasOwnProperty(index)) {
AudioHelper.play(
{
src: themeObject[type][index],
volume: 0.8,
autoplay: true,
loop: false,
},
true
);
}
}

export function playRandomCombatSound(type) {
let theme = game.settings.get("core", "combatTheme");
let sounds = CONFIG.Combat.sounds[theme][type];

if (sounds && Array.isArray(sounds) && sounds.length > 0) {
const randomIndex = Math.floor(Math.random() * sounds.length);
playCombatSound(theme, type, randomIndex);
}
}
42 changes: 42 additions & 0 deletions scripts/themes.generated.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// GENERATED BY `generate-themes`.js on Sat Mar 18 2023 20:08:26 GMT-0400 (Eastern Daylight Saving Time)
const themes = {
"BlazBlueCrossTagBattle": {
"label": "MCT.Themes.Names.BlazBlueCrossTagBattle",
"startEncounter": [
"/modules/maru-combat-themes/sounds/BlazBlueCrossTagBattle/startEncounter0.wav",
"/modules/maru-combat-themes/sounds/BlazBlueCrossTagBattle/startEncounter1.wav"
],
"startRound": [
"/modules/maru-combat-themes/sounds/BlazBlueCrossTagBattle/startRound0.wav"
],
"nextUp": [
"/modules/maru-combat-themes/sounds/BlazBlueCrossTagBattle/nextUp0.wav"
],
"yourTurn": [
"/modules/maru-combat-themes/sounds/BlazBlueCrossTagBattle/yourTurn0.wav"
],
"endCombat": [
"/sounds/BlazBlueCrossTagBattle/endCombat0.wav"
]
},
"GGStrive": {
"label": "MCT.Themes.Names.GGStrive",
"startEncounter": [
"/modules/maru-combat-themes/sounds/GGStrive/startEncounter-0.ogg",
"/modules/maru-combat-themes/sounds/GGStrive/startEncounter-1.ogg",
"/modules/maru-combat-themes/sounds/GGStrive/startEncounter-2.ogg"
],
"startRound": [],
"nextUp": [
"/modules/maru-combat-themes/sounds/GGStrive/nextUp-0.ogg"
],
"yourTurn": [
"/modules/maru-combat-themes/sounds/GGStrive/yourTurn-0.ogg",
"/modules/maru-combat-themes/sounds/GGStrive/yourTurn-1.ogg",
"/modules/maru-combat-themes/sounds/GGStrive/yourTurn-2.ogg"
],
"endCombat": []
}
};
export default themes;

44 changes: 0 additions & 44 deletions scripts/themes.mjs

This file was deleted.

Binary file added sounds/BlazBlueCrossTagBattle/endCombat0.wav
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added sounds/GGStrive/endCombat-destroyed.ogg
Binary file not shown.
Binary file added sounds/GGStrive/endCombat-slash.ogg
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 436d730

Please sign in to comment.