Skip to content

Commit

Permalink
Fix for setting update
Browse files Browse the repository at this point in the history
Fix #216
  • Loading branch information
mclemente committed Nov 2, 2023
1 parent b82ea7a commit 8b3ba83
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
1 change: 1 addition & 0 deletions src/module/healthEstimate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Hooks.once("i18nInit", function () {
});

Hooks.once("setup", () => game.healthEstimate.setup());
Hooks.once("ready", () => game.healthEstimate.ready());

// Canvas
Hooks.once("canvasReady", HealthEstimateHooks.onceCanvasReady);
Expand Down
54 changes: 28 additions & 26 deletions src/module/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,34 @@ export class HealthEstimate {
this.updateSettings();
}

ready() {
// Setting change handling
if (!Number.isNumeric(this.fontSize)) {
if (!isNaN(this.fontSize) && this.fontSize.match(/[0-9]*\.?[0-9]+(px|%)+/i)) {
this.fontSize = Number(this.fontSize.replace(/(px|%)+/i, ""));
} else {
console.warn(
`Health Estimate | ${game.i18n.format("healthEstimate.notifications.invalidFontSize", {
fontSize: this.fontSize,
})}`
);
this.fontSize = 24;
}
sSet("core.menuSettings.fontSize", this.fontSize || 24);
}
if (!Number.isNumeric(this.height)) {
const heights = {
top: "a",
center: "b",
end: "c",
};
this.position = heights[this.height];
this.height = 0;
sSet("core.menuSettings.position", 0);
sSet("core.menuSettings.position2", this.position);
}
}

/**
* Gets system specifics, such as its hp attribute and other settings.
* @returns {providers.EstimationProvider}
Expand Down Expand Up @@ -343,31 +371,5 @@ export class HealthEstimate {
this.outline = sGet("core.variables.outline");
this.deadColor = sGet("core.variables.deadColor");
this.deadOutline = sGet("core.variables.deadOutline");

// Setting change handling
if (!Number.isNumeric(this.fontSize)) {
if (!isNaN(this.fontSize) && this.fontSize.match(/[0-9]*\.?[0-9]+(px|%)+/i)) {
this.fontSize = Number(this.fontSize.replace(/(px|%)+/i, ""));
} else {
console.warn(
`Health Estimate | ${game.i18n.format("healthEstimate.notifications.invalidFontSize", {
fontSize: this.fontSize,
})}`
);
this.fontSize = 24;
}
sSet("core.menuSettings.fontSize", this.fontSize || 24);
}
if (!Number.isNumeric(this.height)) {
const heights = {
top: "a",
center: "b",
end: "c",
};
this.position = heights[this.height];
this.height = 0;
sSet("core.menuSettings.position", 0);
sSet("core.menuSettings.position2", this.position);
}
}
}

0 comments on commit 8b3ba83

Please sign in to comment.