diff --git a/.gitignore b/.gitignore index 2502740..397fed8 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,5 @@ dist # Junit results junit.xml + +foundry.js diff --git a/src/lang/de.json b/src/lang/de.json new file mode 100644 index 0000000..b8dd4cf --- /dev/null +++ b/src/lang/de.json @@ -0,0 +1,11 @@ +{ + "DarknessDependentVision.WarningLackingPermissionToConfigure": "Dir fehlt die Berechtigung diese Figur zu konfigurieren!", + "DarknessDependentVision.Title": "Einstellungen zur dunkelheitsabhängigen Sicht", + "DarknessDependentVision.TokenConfigHeaderButtonLabel": "DDV", + "DarknessDependentVision.DimVisionDarknessRange": "Dämmersicht Dunkelheitsbereich", + "DarknessDependentVision.DimVisionDarknessRangeHint": "Du kannst einen Bereich an Dunkelheitswerten angeben, in denen diese Figur Dämmersicht hat.", + "DarknessDependentVision.BrightVisionDarknessRange": "Helle Sicht Dunkelheitsbereich", + "DarknessDependentVision.BrightVisionDarknessRangeHint": "Du kannst einen Bereich an Dunkelheitswerten angeben, in denen diese Figur helle Sicht hat.", + "DarknessDependentVision.ConfigurationViaHeaderButtonName": "Konfiguration per Button in der Titelleiste", + "DarknessDependentVision.ConfigurationViaHeaderButtonHint": "Ist diese Einstellung ausgewählt, so erscheint in den Figur Einstellungen ein zusätzlicher Button in der Titelleiste, der ein weiteres Fester öffnet, über das die duneklheitsabhängige Sicht konfiguriert werden kann. Ist sie deaktiviert, so erscheineinen die entsprechenden Eingabefelder direkt im Vision Tab der Figur Einstellungen." +} diff --git a/src/lang/de.json.license b/src/lang/de.json.license new file mode 100644 index 0000000..31803f3 --- /dev/null +++ b/src/lang/de.json.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2021 Johannes Loher + +SPDX-License-Identifier: MIT \ No newline at end of file diff --git a/src/lang/en.json b/src/lang/en.json index e149dce..d809b45 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -5,5 +5,7 @@ "DarknessDependentVision.DimVisionDarknessRange": "Dim Vision Darkness Range", "DarknessDependentVision.DimVisionDarknessRangeHint": "You may specify a range of darkness levels during which this token has dim vision.", "DarknessDependentVision.BrightVisionDarknessRange": "Bright Vision Darkness Range", - "DarknessDependentVision.BrightVisionDarknessRangeHint": "You may specify a range of darkness levels during which this token has bright vision." + "DarknessDependentVision.BrightVisionDarknessRangeHint": "You may specify a range of darkness levels during which this token has bright vision.", + "DarknessDependentVision.ConfigurationViaHeaderButtonName": "Configuration via Header Button", + "DarknessDependentVision.ConfigurationViaHeaderButtonHint": "If checked, a header button that opens a separate window to configure darkness dependent vision is added to the Token Configuration. If unchecked, the corresponding configuration fields are injected directly into the Vision tab of the Token Configuration." } diff --git a/src/module.json b/src/module.json index 2361a45..b11f1f1 100644 --- a/src/module.json +++ b/src/module.json @@ -14,6 +14,11 @@ "compatibleCoreVersion": "0.8.8", "esmodules": ["module/darkness-dependent-vision.js"], "languages": [ + { + "lang": "de", + "name": "Deutsch", + "path": "lang/de.json" + }, { "lang": "en", "name": "English", diff --git a/src/module/handlebars-partials.js b/src/module/handlebars-partials.js new file mode 100644 index 0000000..2c0629a --- /dev/null +++ b/src/module/handlebars-partials.js @@ -0,0 +1,10 @@ +// SPDX-FileCopyrightText: 2021 Johannes Loher +// +// SPDX-License-Identifier: MIT + +export default async function registerHandlebarsPartials() { + const templatePaths = [ + 'modules/darkness-dependent-vision/templates/darkness-dependent-vision-config-form-groups.hbs', + ]; + await loadTemplates(templatePaths); +} diff --git a/src/module/hooks.js b/src/module/hooks.js index 99baf84..99c9b04 100644 --- a/src/module/hooks.js +++ b/src/module/hooks.js @@ -4,6 +4,7 @@ import registerForGetTokenConfigHeaderButtonsHook from './hooks/getTokenConfigHeaderButtons'; import registerForInitHook from './hooks/init'; +import registerForRenderTokenConfigHook from './hooks/renderTokenConfig'; import registerForUpdateSceneHook from './hooks/updateScene'; import registerForUpdateTokenHook from './hooks/updateToken'; @@ -15,4 +16,5 @@ export default function registerForHooks() { registerForUpdateSceneHook(); registerForUpdateTokenHook(); registerForGetTokenConfigHeaderButtonsHook(); + registerForRenderTokenConfigHook(); } diff --git a/src/module/hooks/getTokenConfigHeaderButtons.js b/src/module/hooks/getTokenConfigHeaderButtons.js index 495cf00..2e4546c 100644 --- a/src/module/hooks/getTokenConfigHeaderButtons.js +++ b/src/module/hooks/getTokenConfigHeaderButtons.js @@ -2,6 +2,7 @@ // // SPDX-License-Identifier: MIT +import { packageName } from '../config'; import { DarknessDependentVisionConfig } from '../darkness-dependent-vision-config'; export default function registerForGetTokenConfigHeaderButtonsHook() { @@ -13,6 +14,9 @@ export default function registerForGetTokenConfigHeaderButtonsHook() { * @param {ApplicationHeaderButton[]} buttons */ function onGetTokenConfigHeaderButtons(tokenConfig, buttons) { + if (!game.settings.get(packageName, 'configurationViaHeaderButton')) { + return; + } buttons.unshift({ label: 'DarknessDependentVision.TokenConfigHeaderButtonLabel', class: 'configure-darkness-dependent-vision', diff --git a/src/module/hooks/init.js b/src/module/hooks/init.js index 35039af..5823778 100644 --- a/src/module/hooks/init.js +++ b/src/module/hooks/init.js @@ -3,7 +3,9 @@ // SPDX-License-Identifier: MIT import { packageName } from '../config'; +import registerHandlebarsPartials from '../handlebars-partials'; import logger from '../logger'; +import registerSettings from '../setiings'; import { libWrapper } from '../shims/libWrapperShim'; import { getBrightRadius, getDimRadius, updateSource } from '../wrappers/token'; @@ -11,7 +13,7 @@ export default function registerForInitHook() { Hooks.on('init', onInit); } -function onInit() { +async function onInit() { logger.info(`Initializing ${packageName}`); const dimRadiusTarget = 'Token.prototype.dimRadius'; @@ -29,4 +31,7 @@ function onInit() { } libWrapper.register(packageName, 'Token.prototype.updateSource', updateSource, 'WRAPPER'); + + registerSettings(); + await registerHandlebarsPartials(); } diff --git a/src/module/hooks/renderTokenConfig.js b/src/module/hooks/renderTokenConfig.js new file mode 100644 index 0000000..cf6d08b --- /dev/null +++ b/src/module/hooks/renderTokenConfig.js @@ -0,0 +1,21 @@ +// SPDX-FileCopyrightText: 2021 Johannes Loher +// +// SPDX-License-Identifier: MIT + +import { packageName } from '../config'; + +export default function registerForRenderTokenConfigHook() { + Hooks.on('renderTokenConfig', onRenderTokenConfig); +} + +async function onRenderTokenConfig(app, html, data) { + if (game.settings.get(packageName, 'configurationViaHeaderButton')) { + return; + } + const contents = await renderTemplate( + 'modules/darkness-dependent-vision/templates/darkness-dependent-vision-config-form-groups.hbs', + data, + ); + html.find(`div[data-tab="vision"] .form-group input[name="brightSight"]`).parent().after(contents); + app.setPosition({ height: 'auto' }); +} diff --git a/src/module/setiings.js b/src/module/setiings.js new file mode 100644 index 0000000..d7e625d --- /dev/null +++ b/src/module/setiings.js @@ -0,0 +1,23 @@ +// SPDX-FileCopyrightText: 2021 Johannes Loher +// +// SPDX-License-Identifier: MIT + +import { packageName } from './config'; + +export default function registerSettings() { + game.settings.register(packageName, 'configurationViaHeaderButton', { + name: 'DarknessDependentVision.ConfigurationViaHeaderButtonName', + hint: 'DarknessDependentVision.ConfigurationViaHeaderButtonHint', + scope: 'client', + config: true, + type: Boolean, + default: true, + onChange: () => + Object.values(ui.windows) + .filter((w) => w instanceof TokenConfig) + .forEach(async (w) => { + await w.close(); + w.render(true); + }), + }); +} diff --git a/src/templates/darkness-dependent-vision-config-form-groups.hbs b/src/templates/darkness-dependent-vision-config-form-groups.hbs new file mode 100644 index 0000000..7278b5b --- /dev/null +++ b/src/templates/darkness-dependent-vision-config-form-groups.hbs @@ -0,0 +1,35 @@ +{{!-- +SPDX-FileCopyrightText: 2021 Johannes Loher +// +SPDX-License-Identifier: MIT +--}} + +
+ +
+ + + + +
+

{{ localize "DarknessDependentVision.DimVisionDarknessRangeHint" }}

+
+ +
+ +
+ + + + +
+

{{ localize "DarknessDependentVision.BrightVisionDarknessRangeHint" }}

+
diff --git a/src/templates/darkness-dependent-vision-config.hbs b/src/templates/darkness-dependent-vision-config.hbs index 8546ae2..943bbfe 100644 --- a/src/templates/darkness-dependent-vision-config.hbs +++ b/src/templates/darkness-dependent-vision-config.hbs @@ -5,36 +5,6 @@ SPDX-License-Identifier: MIT --}}
- -
- -
- - - - -
-

{{ localize "DarknessDependentVision.DimVisionDarknessRangeHint" }}

-
- -
- -
- - - - -
-

{{ localize "DarknessDependentVision.BrightVisionDarknessRangeHint" }}

-
- + {{> modules/darkness-dependent-vision/templates/darkness-dependent-vision-config-form-groups.hbs}}