Skip to content

Commit

Permalink
fear: add intro crawl audio delay
Browse files Browse the repository at this point in the history
* users can now set an optional audio delay (in MS)

#24
  • Loading branch information
Wrycu committed May 26, 2021
1 parent cf72bb7 commit a6dc107
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
"ffg-star-wars-enhancements.opening-crawl.opening-crawl-music-hint": "Provide music to play during the opening crawl. The crawl is timed with the original audio with 8-9 seconds of silence.",
"ffg-star-wars-enhancements.opening-crawl.opening-crawl-logo": "Star Wars opening crawl logo",
"ffg-star-wars-enhancements.opening-crawl.opening-crawl-logo-hint": "Provide an alternative logo for the opening crawl. The default logo uses a copyright safe font.",
"ffg-star-wars-enhancements.opening-crawl.opening-crawl-music-delay": "Delay opening crawl music",
"ffg-star-wars-enhancements.opening-crawl.opening-crawl-music-delay-hint": "Optional delay for opening crawl music, in milliseconds",
"ffg-star-wars-enhancements.opening-crawl.intro-1": "A long time ago in a galaxy far,",
"ffg-star-wars-enhancements.opening-crawl.intro-2": "far away....",
"ffg-star-wars-enhancements.opening-crawl.missing-episode": "Unable to find episode (h1 tag) in journal.",
Expand Down
2 changes: 2 additions & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
`0.1.10` - ?
* Add count for Adversary status ([#40](https://github.com/wrycu/StarWarsFFG-Enhancements/issues/40))
* Intro crawl improvements ([#24](https://github.com/wrycu/StarWarsFFG-Enhancements/issues/24))
* Add a setting for delay of music playback
* Allow the removal of custom attack animations per item ([#39](https://github.com/wrycu/StarWarsFFG-Enhancements/issues/39))
* Fix for incomplete localization of dice spender (thanks `@prolice`!)
* Add French localization (thanks `@prolice`!)
Expand Down
24 changes: 22 additions & 2 deletions scripts/opening_crawl.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ export function init() {
type: setting_image,
default: "",
});
game.settings.register("ffg-star-wars-enhancements", "opening-crawl-music-delay", {
name: game.i18n.localize('ffg-star-wars-enhancements.opening-crawl.opening-crawl-music-delay'),
hint: game.i18n.localize('ffg-star-wars-enhancements.opening-crawl.opening-crawl-music-delay-hint'),
scope: "world",
config: true,
type: Number,
default: 0.0,
});
log('opening-crawl', 'Initialized');
}

Expand Down Expand Up @@ -82,9 +90,12 @@ class OpeningCrawlApplication extends Application {
play_music(callback) {
let volume = game.settings.get("core", "globalPlaylistVolume");
this.howl = game.audio.create({src: this.data.music, preload:true, volume:volume})
this.howl.once("load", () => {
this.howl.play();
this.howl.once("load", async () => {
callback();
await sleep(
game.settings.get("ffg-star-wars-enhancements", "opening-crawl-music-delay")
);
this.howl.play();
});
this.howl.load();
}
Expand Down Expand Up @@ -292,3 +303,12 @@ export async function create_opening_crawl() {
};
JournalEntry.create(data).then(journal => {journal.sheet.render(true)});
}

/**
* Helper function to delay code execution by an arbitrary amount
* @param ms - number of MS to delay by
* @returns {Promise<unknown>}
*/
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

0 comments on commit a6dc107

Please sign in to comment.