From f56c241702337c8090c155d68f2fead6161d3727 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 24 May 2021 18:26:01 +1000 Subject: [PATCH] round floats before comparing against default values tabbing through the Advanced section was marking things like 'easy bonus' as modified --- ts/deckoptions/RevertButton.svelte | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ts/deckoptions/RevertButton.svelte b/ts/deckoptions/RevertButton.svelte index dd2c0b720..9f7afaa50 100644 --- a/ts/deckoptions/RevertButton.svelte +++ b/ts/deckoptions/RevertButton.svelte @@ -6,7 +6,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import * as tr from "lib/i18n"; import { revertIcon } from "./icons"; import { createEventDispatcher } from "svelte"; - import { isEqual, cloneDeep } from "lodash-es"; + import { isEqual as isEqualLodash, cloneDeep } from "lodash-es"; // import { onMount } from "svelte"; // import Tooltip from "bootstrap/js/dist/tooltip"; @@ -26,6 +26,17 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html const dispatch = createEventDispatcher(); + function isEqual(a: unknown, b: unknown): boolean { + if (typeof a === "number" && typeof b === "number") { + // round to .01 precision before comparing, + // so the values coming out of the UI match + // the originals + return isEqualLodash(Math.round(a * 100) / 100, Math.round(b * 100) / 100); + } else { + return isEqualLodash(a, b); + } + } + let modified: boolean; $: modified = !isEqual(value, defaultValue);