-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ new features and settings and oh wow
- Loading branch information
Showing
25 changed files
with
276 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
This file was deleted.
Oops, something went wrong.
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 not shown.
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.