From b988f2c96e2b85d11d85caa1f4ee1965fb5f4772 Mon Sep 17 00:00:00 2001 From: Blair McMillan Date: Mon, 23 May 2022 15:37:18 +1000 Subject: [PATCH] Support players other than the GM in the world --- changelog.md | 4 ++++ module.json | 2 +- scripts/core.js | 18 +++++++++++++----- scripts/setting.js | 4 ++-- templates/settings.html | 16 ++++++++-------- 5 files changed, 28 insertions(+), 16 deletions(-) diff --git a/changelog.md b/changelog.md index 6ad866c..82de393 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # Changelog +## v2.1.3 + +- Fixed issue where having a player other than GM in the world would prevent the importer from correctly importing anything. + ## v2.1.2 * Better handling of config options to make it less likely to break on certain module's configuration settings. diff --git a/module.json b/module.json index f2c90f1..3f59603 100644 --- a/module.json +++ b/module.json @@ -21,7 +21,7 @@ "flags": { "allowBugReporter": true }, - "version": "2.1.2", + "version": "2.1.3", "minimumCoreVersion": "0.6.0", "compatibleCoreVersion": "10", "scripts": [], diff --git a/scripts/core.js b/scripts/core.js index 7b128bf..f8f0d0d 100755 --- a/scripts/core.js +++ b/scripts/core.js @@ -62,6 +62,9 @@ export default class Core extends FormApplication { } this.playerSettings.push(setting.value); this.hasPlayerSettings = true; + break; + default: + throw new Error(`Unknown setting type: ${setting.type}`); } } } catch (e) { @@ -72,7 +75,12 @@ export default class Core extends FormApplication { this.settings = Object.entries(Object.fromEntries(this.settingGroups)); this.settings.sort((a, b) => a[0].localeCompare(b[0])); - this.playerSettings.sort((a, b) => a.key.localeCompare(b.key)); + for (const playerSetting of this.playerSettings) { + playerSetting.playerDifferences = Object.entries(playerSetting.playerDifferences); + playerSetting.playerDifferences.sort((a, b) => a[0].localeCompare(b[0])); + playerSetting.playerFlagDifferences = Object.entries(playerSetting.playerFlagDifferences); + playerSetting.playerFlagDifferences.sort((a, b) => a[0].localeCompare(b[0])); + } log(true, 'Processing world settings', this.settings); log(true, 'Processing player settings', this.playerSettings); @@ -280,12 +288,12 @@ export default class Core extends FormApplication { if (type === 'core') { changes[fieldName] = - this.playerSettings[target].playerDifferences[fieldName].newVal; + Object.fromEntries(this.playerSettings[target].playerDifferences)[fieldName].newVal; } if (type === 'flag') { changes.flags[fieldName] = - this.playerSettings[target].playerFlagDifferences[fieldName].newVal; + Object.fromEntries(this.playerSettings[target].playerFlagDifferences)[fieldName].newVal; } } @@ -359,7 +367,7 @@ export default class Core extends FormApplication { text += `\n${game.i18n.localize('forien-copy-environment.message')}`; - log(false, text); + log(true, text); return text; } @@ -443,7 +451,7 @@ export default class Core extends FormApplication { let coreSettings = new Core(settings); coreSettings.render(true); } catch (e) { - log(false, 'Could not parse import data.'); + console.error('Copy Environment | Could not parse import data.', e); } }); } diff --git a/scripts/setting.js b/scripts/setting.js index 8d61644..3a1b8c6 100755 --- a/scripts/setting.js +++ b/scripts/setting.js @@ -10,7 +10,7 @@ export default class Setting { this.value = undefined; if (!data || typeof data !== 'object') { - log(false, 'Unknown setting received:', data); + console.error('Copy Environment | Unknown setting received:', data); return this; } @@ -100,7 +100,7 @@ export class WorldSetting { return new Difference(this.key, existingSetting, newValue); } catch (e) { - log(false, 'Could not parse world setting values:', e, this.key); + console.error('Copy Environment | Could not parse world setting values:', this.key, e); } // Return the difference of the original values, not the parsed values. diff --git a/templates/settings.html b/templates/settings.html index 0f739f4..9d3c888 100644 --- a/templates/settings.html +++ b/templates/settings.html @@ -57,29 +57,29 @@

{{localize 'forien-copy-environment.intro'}}

{{#each playerDifferences as |diff|}} - {{#with (concat ../name "--" name) as |fkey|}} + {{#with (concat ../name "--" diff.[1].name) as |fkey|}} + data-for="{{ @../index }}" data-type="core" {{checked (lookup @root.selectedProperties fkey)}}>{{ diff.[1].name }} - - + - + {{/with}}