Skip to content

Commit ad49df7

Browse files
committed
Reorder loading sequence
1 parent 4e362c6 commit ad49df7

File tree

2 files changed

+40
-36
lines changed

2 files changed

+40
-36
lines changed

src/module/polyglot.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,25 @@ Hooks.once("init", () => {
2626
});
2727

2828
Hooks.once("i18nInit", () => {
29+
registerProviderSettings();
2930
game.polyglot.languageProvider.i18nInit();
3031
});
3132

32-
Hooks.on("setup", async () => {
33+
Hooks.on("setup", () => {
3334
if (game.user.isGM && game.user.character) {
3435
console.warn(
3536
`Polyglot | ${game.i18n.format("POLYGLOT.GameMasterHasAssignedCharacter", {
3637
GM: game.i18n.localize("USER.RoleGamemaster"),
3738
})}`,
3839
);
3940
}
40-
registerProviderSettings();
4141
registerTours();
42-
await game.polyglot.languageProvider.setup();
42+
game.polyglot.languageProvider.setup();
4343
});
44-
Hooks.on("ready", () => {
45-
game.polyglot.ready();
44+
Hooks.on("ready", async () => {
45+
await game.polyglot.ready();
4646
Hooks.callAll("polyglot.ready", LanguageProvider);
47-
game.polyglot.languageProvider.ready();
47+
await game.polyglot.languageProvider.ready();
4848
});
4949
Hooks.on("renderSettingsConfig", renderSettingsConfigHandler);
5050
Hooks.on("renderPolyglotGeneralSettings", renderPolyglotGeneralSettingsHandler);

src/module/providers/templates/Base.js

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -273,45 +273,49 @@ export default class LanguageProvider {
273273
// Hooks //
274274
// /////////
275275

276-
init() {}
276+
async initSequence() {
277+
await this.getLanguages();
278+
this.loadFonts();
279+
this.loadLanguages();
280+
this.loadCustomFonts();
281+
this.reloadLanguages();
282+
}
277283

278-
i18nInit() {}
284+
async setupSequence() {
285+
this.getDefaultLanguage();
286+
}
279287

280-
/**
281-
* Loads everything that can't be loaded on the constructor due to async/await.
282-
* It Hooks on ready if the system depends on reading compendiums.
283-
*/
284-
async setup() {
288+
init() {
285289
game.polyglot.omniglot = game.settings.get("polyglot", "omniglot");
286290
game.polyglot.comprehendLanguages = game.settings.get("polyglot", "comprehendLanguages");
287291
game.polyglot.truespeech = game.settings.get("polyglot", "truespeech");
292+
}
288293

289-
const setupSteps = async () => {
290-
await this.getLanguages();
291-
this.loadFonts();
292-
this.loadLanguages();
293-
this.loadCustomFonts();
294-
this.reloadLanguages();
295-
this.getDefaultLanguage();
296-
};
297-
if (this.requiresReady) {
298-
if (game.modules.get("babele")?.active) {
299-
Hooks.on("babele.ready", async () => {
300-
await setupSteps();
301-
Hooks.callAll("polyglot.languageProvider.ready");
302-
});
303-
} else {
304-
Hooks.on("ready", async () => {
305-
await setupSteps();
306-
Hooks.callAll("polyglot.languageProvider.ready");
307-
});
308-
}
309-
} else {
310-
await setupSteps();
294+
async i18nInit() {
295+
if (!this.requiresReady) {
296+
await this.initSequence();
297+
}
298+
}
299+
300+
async setup() {
301+
if (!this.requiresReady) {
302+
await this.setupSequence();
303+
} else if (game.modules.get("babele")?.active) {
304+
Hooks.on("babele.ready", async () => {
305+
await this.initSequence();
306+
await this.setupSequence();
307+
Hooks.callAll("polyglot.languageProvider.ready");
308+
});
311309
}
312310
}
313311

314-
ready() {}
312+
async ready() {
313+
if (this.requiresReady && !game.modules.get("babele")?.active) {
314+
await this.initSequence();
315+
await this.setupSequence();
316+
Hooks.callAll("polyglot.languageProvider.ready");
317+
}
318+
}
315319

316320
/**
317321
* Even though the base method doesn't have an await, some providers might need it to look into compendiums.

0 commit comments

Comments
 (0)