diff --git a/languages/en.json b/languages/en.json index 957b7ab..a2fcded 100644 --- a/languages/en.json +++ b/languages/en.json @@ -2,7 +2,7 @@ "oronder.Auth-Token": "Auth Token", "oronder.Discord-Server-Id": "Discord Server Id", "oronder.Fetch-Discord-User-Ids": "Fetch Discord User Ids", - "oronder.Full-Sync": "Full Sync", + "oronder.Full-Sync": "Manually Sync All Actors", "oronder.Fetching-Discord-Ids": "Fetching Discord Ids", "oronder.Oronder-Configuration": "Oronder Configuration", "oronder.Configure-Oronder": "Configure Oronder", diff --git a/package.json b/package.json index f49e619..2ef4005 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,6 @@ }, "scripts": { "build": "esbuild src/module.mjs --bundle --minify --format=esm --outdir=dist", - "build-dev": "esbuild src/module.mjs --bundle --sourcemap=inline --format=esm --outdir=dist && mkdir -p ../foundry_data/Data/modules/oronder/ && cp -r ./* ../foundry_data/Data/modules/oronder/", - "build-dev-win": "esbuild src/module.mjs --bundle --sourcemap=inline --format=esm --outdir=dist && mkdir ..\\foundry_data\\Data\\modules\\oronder\\ && xcopy /E /Y .\\* ..\\foundry_data\\Data\\modules\\oronder\\" + "build-dev": "esbuild src/module.mjs --bundle --sourcemap=inline --format=esm --outdir=dist" } } diff --git a/src/module.mjs b/src/module.mjs index 674c31e..ec349ad 100644 --- a/src/module.mjs +++ b/src/module.mjs @@ -36,7 +36,7 @@ Hooks.on("createActor", async (actor, data, options, userId) => { await sync_actor(actor) }) Hooks.on("updateActor", async (actor, data, options, userId) => { - if ('currency' in data?.system) { + if ((data?.system || []).includes('currency')) { //todo handle currency } await sync_actor(actor) diff --git a/src/settings-form-application.mjs b/src/settings-form-application.mjs index 799cd22..33530ac 100644 --- a/src/settings-form-application.mjs +++ b/src/settings-form-application.mjs @@ -90,9 +90,9 @@ export class OronderSettingsFormApplication extends FormApplication { const requestOptions = this._requestOptions(this.object.guild_id, this.object.auth) let valid_config = false await fetch(`${ORONDER_BASE_URL}/validate_discord_ids?${queryParams}`, requestOptions) - .then(self._handle_json_response) - .then(result => { - const invalid_player_names = result.map(invalid_discord_id => { + .then(this._handle_json_response) + .then(invalid_discord_ids => { + const invalid_player_names = invalid_discord_ids.map(invalid_discord_id => { return this.object.players.find(p => p.discord_id === invalid_discord_id).foundry_name }) if (invalid_player_names.length) { @@ -168,16 +168,14 @@ export class OronderSettingsFormApplication extends FormApplication { const requestOptions = this._requestOptions(this.object.guild_id, this.object.auth) await fetch(`${ORONDER_BASE_URL}/discord_id?${queryParams}`, requestOptions) - .then(self._handle_json_response) - .then(async result => { + .then(this._handle_json_response) + .then(result => { for (const [foundry_name, discord_user_id] of Object.entries(result)) { this.object.players.find(p => p.foundry_name === foundry_name).discord_id = discord_user_id } - - await full_sync() }) - .catch(error => { - Logger.logError(error) + .catch(e => { + Logger.logError(e) }) this.object.fetch_button_icon = "fa-solid fa-rotate" @@ -188,11 +186,11 @@ export class OronderSettingsFormApplication extends FormApplication { _handle_json_response(response) { if (!response.ok) { if (response.status === 401) { - Logger.logError(game.i18n.localize("oronder.Invalid-Auth")); + throw new Error(game.i18n.localize("oronder.Invalid-Auth")) } else if (response.status === 400) { - Logger.logError(game.i18n.localize("oronder.Server-Id-NaN")); + throw new Error(game.i18n.localize("oronder.Server-Id-NaN")) } else { - Logger.logError(game.i18n.localize("oronder.Unexpected-Error")); + throw new Error(game.i18n.localize("oronder.Unexpected-Error")) } } return response.json()