Skip to content

Commit

Permalink
Add Grid Size scaling
Browse files Browse the repository at this point in the history
#236
Fix #237.
  • Loading branch information
mclemente committed Jan 30, 2024
1 parent 0cc4322 commit 2eb26a6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@
"name": "Margin Adjustment",
"hint": "Adjust the text's margin. Positive values push it higher; negative, lower."
},
"scaleToGridSize": {
"name": "Scale Estimates to Grid Size",
"hint": "Scales the estimate based on the grid size, assuming 100px as the baseline."
},
"scaleToZoom": {
"name": "Scale Estimates to Zoom",
"hint": "Scales the estimate based on the zoom distance."
Expand Down
2 changes: 2 additions & 0 deletions src/module/forms/StyleSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default class HealthEstimateStyleSettings extends HealthEstimateSettings
mode: this.prepSelection("mode"),
outline: this.prepSelection("outline"),
outlineIntensity: this.prepSetting("outlineIntensity"),
scaleToGridSize: this.prepSetting("scaleToGridSize"),
scaleToZoom: this.prepSetting("scaleToZoom"),
deadText: game.settings.get("healthEstimate", "core.deathStateName"),
};
Expand Down Expand Up @@ -229,6 +230,7 @@ export default class HealthEstimateStyleSettings extends HealthEstimateSettings
"menuSettings.mode",
"menuSettings.outline",
"menuSettings.outlineIntensity",
"menuSettings.scaleToGridSize",
"menuSettings.scaleToZoom",
"variables.colors",
"variables.outline",
Expand Down
7 changes: 6 additions & 1 deletion src/module/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export class HealthEstimate {
this.lastZoom = null;
}

get gridScale() {
return this.scaleToGridSize ? canvas.scene.dimensions.size / 100 : 1;
}

get zoomLevel() {
return this.scaleToZoom ? Math.min(1, canvas.stage.scale.x) : 1;
}
Expand Down Expand Up @@ -127,7 +131,7 @@ export class HealthEstimate {
}

_getFontSize() {
return (this.fontSize / this.zoomLevel) * 4;
return ((this.fontSize * this.gridScale) / this.zoomLevel) * 4;
}

_getUserTextStyle(color, stroke) {
Expand Down Expand Up @@ -365,6 +369,7 @@ export class HealthEstimate {
this.showDead = sGet("core.deathState");
this.NPCsJustDie = sGet("core.NPCsJustDie");
this.deathMarker = sGet("core.deathMarker");
this.scaleToGridSize = sGet("core.menuSettings.scaleToGridSize");
this.scaleToZoom = sGet("core.menuSettings.scaleToZoom");
this.outputChat = sGet("core.outputChat");

Expand Down
7 changes: 7 additions & 0 deletions src/module/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ export const registerSettings = function () {
type: Boolean,
default: true,
});
addMenuSetting("core.menuSettings.scaleToGridSize", {
type: Boolean,
default: false,
onChange: (value) => {
game.healthEstimate.scaleToGridSize = value;
},
});
addMenuSetting("core.menuSettings.scaleToZoom", {
type: Boolean,
default: false,
Expand Down
5 changes: 5 additions & 0 deletions src/templates/styleSettings.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
<input type="checkbox" name="useColor" id="useColor" {{checked useColor.value}} />
<p class="notes">{{useColor.hint}}</p>
</div>
<div class="form-group">
<label>{{scaleToGridSize.name}}</label>
<input type="checkbox" name="scaleToGridSize" id="scaleToGridSize" {{checked scaleToGridSize.value}} />
<p class="notes">{{scaleToGridSize.hint}}</p>
</div>
<div class="form-group">
<label>{{scaleToZoom.name}}</label>
<input type="checkbox" name="scaleToZoom" id="scaleToZoom" {{checked scaleToZoom.value}} />
Expand Down

0 comments on commit 2eb26a6

Please sign in to comment.