mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-11 19:25:21 +01:00
[PR] [Feature] 652 Allow override range measurement settings (#1030)
* Look for rangeMeasurementSettingsOverride on the scene to switch off DH global range measurement settings. * Part progress on adding config tab to scene config * Hard coded template; no value applied/saved * Flag fix * Use the flags setting * Clean up * Remove import * Better initialisation of PARTS and TABS * Fix localisation --------- Co-authored-by: Chris Ryan <chrisr@blackhole> Co-authored-by: WBHarry <williambjrklund@gmail.com>
This commit is contained in:
parent
7a6bbe3488
commit
60b55619e1
10 changed files with 82 additions and 15 deletions
|
|
@ -145,6 +145,11 @@ Hooks.once('init', () => {
|
|||
// Make Compendium Dialog resizable
|
||||
foundry.applications.sidebar.apps.Compendium.DEFAULT_OPTIONS.window.resizable = true;
|
||||
|
||||
DocumentSheetConfig.registerSheet(foundry.documents.Scene, SYSTEM.id, applications.scene.DhSceneConfigSettings, {
|
||||
makeDefault: true,
|
||||
label: 'Daggerheart'
|
||||
});
|
||||
|
||||
settingsRegistration.registerDHSettings();
|
||||
RegisterHandlebarsHelpers.registerHelpers();
|
||||
|
||||
|
|
|
|||
11
lang/en.json
11
lang/en.json
|
|
@ -26,6 +26,14 @@
|
|||
"CONTROLS": {
|
||||
"inFront": "In Front"
|
||||
},
|
||||
"SCENE": {
|
||||
"TABS": {
|
||||
"SHEET": {
|
||||
"dh": "Daggerheart"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
"DAGGERHEART": {
|
||||
"ACTIONS": {
|
||||
"TYPES": {
|
||||
|
|
@ -2283,6 +2291,9 @@
|
|||
"ResetSettings": {
|
||||
"resetConfirmationTitle": "Reset Settings",
|
||||
"resetConfirmationText": "Are you sure you want to reset the {settings}?"
|
||||
},
|
||||
"Scene": {
|
||||
"rangeMeasurementOverride": "Override Global Range Measurement Settings"
|
||||
}
|
||||
},
|
||||
"UI": {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ export * as characterCreation from './characterCreation/_module.mjs';
|
|||
export * as dialogs from './dialogs/_module.mjs';
|
||||
export * as hud from './hud/_module.mjs';
|
||||
export * as levelup from './levelup/_module.mjs';
|
||||
export * as scene from './scene/_module.mjs';
|
||||
export * as settings from './settings/_module.mjs';
|
||||
export * as sheets from './sheets/_module.mjs';
|
||||
export * as sheetConfigs from './sheets-configs/_module.mjs';
|
||||
|
|
|
|||
1
module/applications/scene/_module.mjs
Normal file
1
module/applications/scene/_module.mjs
Normal file
|
|
@ -0,0 +1 @@
|
|||
export { default as DhSceneConfigSettings } from './sceneConfigSettings.mjs';
|
||||
25
module/applications/scene/sceneConfigSettings.mjs
Normal file
25
module/applications/scene/sceneConfigSettings.mjs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
export default class DhSceneConfigSettings extends foundry.applications.sheets.SceneConfig {
|
||||
constructor(options, ...args) {
|
||||
super(options, ...args);
|
||||
}
|
||||
|
||||
static buildParts() {
|
||||
const { footer, ...parts } = super.PARTS;
|
||||
const tmpParts = {
|
||||
...parts,
|
||||
dh: { template: "systems/daggerheart/templates/scene/dh-config.hbs" },
|
||||
footer
|
||||
}
|
||||
return tmpParts;
|
||||
}
|
||||
|
||||
static PARTS = DhSceneConfigSettings.buildParts();
|
||||
|
||||
static buildTabs() {
|
||||
super.TABS.sheet.tabs.push({ id: "dh", icon: "fa-solid" });
|
||||
return super.TABS;
|
||||
}
|
||||
|
||||
static TABS = DhSceneConfigSettings.buildTabs();
|
||||
|
||||
}
|
||||
|
|
@ -10,29 +10,41 @@ export default class DhMeasuredTemplate extends foundry.canvas.placeables.Measur
|
|||
const splitRulerText = this.ruler.text.split(' ');
|
||||
if (splitRulerText.length > 0) {
|
||||
const rulerValue = Number(splitRulerText[0]);
|
||||
const vagueLabel = this.constructor.getDistanceLabel(rulerValue, rangeMeasurementSettings);
|
||||
this.ruler.text = vagueLabel;
|
||||
const result = this.constructor.getRangeLabels(rulerValue, rangeMeasurementSettings);
|
||||
this.ruler.text = result.distance + result.units ? (' ' + result.units) : '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static getDistanceLabel(distance, settings) {
|
||||
static getRangeLabels(distance, settings) {
|
||||
let result = { distance: '', units: null }
|
||||
const rangeMeasurementOverride = canvas.scene.flags.daggerheart?.rangeMeasurementOverride;
|
||||
|
||||
if (rangeMeasurementOverride === true) {
|
||||
result.distance = distance;
|
||||
result.units = canvas.scene?.grid?.units;
|
||||
return result
|
||||
}
|
||||
if (distance <= settings.melee) {
|
||||
return game.i18n.localize('DAGGERHEART.CONFIG.Range.melee.name');
|
||||
result.distance = game.i18n.localize('DAGGERHEART.CONFIG.Range.melee.name');
|
||||
return result;
|
||||
}
|
||||
if (distance <= settings.veryClose) {
|
||||
return game.i18n.localize('DAGGERHEART.CONFIG.Range.veryClose.name');
|
||||
result.distance = game.i18n.localize('DAGGERHEART.CONFIG.Range.veryClose.name');
|
||||
return result;
|
||||
}
|
||||
if (distance <= settings.close) {
|
||||
return game.i18n.localize('DAGGERHEART.CONFIG.Range.close.name');
|
||||
result.distance = game.i18n.localize('DAGGERHEART.CONFIG.Range.close.name');
|
||||
return result;
|
||||
}
|
||||
if (distance <= settings.far) {
|
||||
return game.i18n.localize('DAGGERHEART.CONFIG.Range.far.name');
|
||||
result.distance = game.i18n.localize('DAGGERHEART.CONFIG.Range.far.name');
|
||||
return result;
|
||||
}
|
||||
if (distance > settings.far) {
|
||||
return game.i18n.localize('DAGGERHEART.CONFIG.Range.veryFar.name');
|
||||
result.distance = game.i18n.localize('DAGGERHEART.CONFIG.Range.veryFar.name');
|
||||
}
|
||||
|
||||
return '';
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ export default class DhpRuler extends foundry.canvas.interaction.Ruler {
|
|||
const range = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.variantRules).rangeMeasurement;
|
||||
|
||||
if (range.enabled) {
|
||||
const distance = DhMeasuredTemplate.getDistanceLabel(waypoint.measurement.distance.toNearest(0.01), range);
|
||||
context.cost = { total: distance, units: null };
|
||||
context.distance = { total: distance, units: null };
|
||||
const result = DhMeasuredTemplate.getRangeLabels(waypoint.measurement.distance.toNearest(0.01), range);
|
||||
context.cost = { total: result.distance, units: result.units };
|
||||
context.distance = { total: result.distance, units: result.units };
|
||||
}
|
||||
|
||||
return context;
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ export default class DhpTokenRuler extends foundry.canvas.placeables.tokens.Toke
|
|||
const range = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.variantRules).rangeMeasurement;
|
||||
|
||||
if (range.enabled) {
|
||||
const distance = DhMeasuredTemplate.getDistanceLabel(waypoint.measurement.distance.toNearest(0.01), range);
|
||||
context.cost = { total: distance, units: null };
|
||||
context.distance = { total: distance, units: null };
|
||||
const result = DhMeasuredTemplate.getRangeLabels(waypoint.measurement.distance.toNearest(0.01), range);
|
||||
context.cost = { total: result.distance, units: result.units };
|
||||
context.distance = { total: result.distance, units: result.units };
|
||||
}
|
||||
|
||||
return context;
|
||||
|
|
|
|||
|
|
@ -35,5 +35,8 @@ export const preloadHandlebarsTemplates = async function () {
|
|||
'systems/daggerheart/templates/ui/chat/parts/damage-part.hbs',
|
||||
'systems/daggerheart/templates/ui/chat/parts/target-part.hbs',
|
||||
'systems/daggerheart/templates/ui/chat/parts/button-part.hbs',
|
||||
|
||||
'systems/daggerheart/templates/scene/dh-config.hbs',
|
||||
|
||||
]);
|
||||
};
|
||||
|
|
|
|||
9
templates/scene/dh-config.hbs
Normal file
9
templates/scene/dh-config.hbs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<div class="tab{{#if tab.active}} active{{/if}}" data-group="{{tab.group}}" data-tab="{{tab.id}}">
|
||||
<div class="form-group">
|
||||
<div class="form-fields">
|
||||
<label>{{localize 'DAGGERHEART.SETTINGS.Scene.rangeMeasurementOverride'}}</label>
|
||||
<input type="checkbox" name="flags.daggerheart.rangeMeasurementOverride" {{checked
|
||||
document.flags.daggerheart.rangeMeasurementOverride}} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Loading…
Add table
Add a link
Reference in a new issue