From f64a3bae814dea4ebf2b6496c1c8dd393afe53c5 Mon Sep 17 00:00:00 2001 From: byxor Date: Sun, 20 Oct 2024 18:31:20 +0100 Subject: [PATCH] Cap wind-select max strength based on current hole --- models/hole.js | 13 +++++++++++++ notes/browser/components/wind-select.js | 13 +++++++++++-- notes/browser/index.js | 22 +++++++++++----------- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/models/hole.js b/models/hole.js index fa1c159..d5efe6e 100644 --- a/models/hole.js +++ b/models/hole.js @@ -5,6 +5,19 @@ class Hole { this.notes = this.#validateNotes(notes); this.pins = this.#validatePins(pins); this.courseName = this.#validateCourseName(courseName); + this.maxWind = (() => { + switch (number) { + case 1: + case 2: + return 3; + case 3: + return 5; + case 4: + return 8; + default: + return 15; + } + })(); } equals(other) { diff --git a/notes/browser/components/wind-select.js b/notes/browser/components/wind-select.js index 2239e2d..b9df289 100644 --- a/notes/browser/components/wind-select.js +++ b/notes/browser/components/wind-select.js @@ -21,6 +21,7 @@ class WindSelectComponent extends HTMLElement { this.documentListenersConfiguredForDirectionDrag = false; this.isDraggingDirection = false; + this.maxWind = 15; this.setWind(newWind(0, "N")); this.emitSelectedWind(); @@ -30,6 +31,14 @@ class WindSelectComponent extends HTMLElement { this.setWind(wind); } }); + + this.navigationController?.onHoleChanged(hole => { + console.log(this.maxWind); + this.maxWind = hole?.maxWind || 15; + if (this.wind.strength > this.maxWind) { + this.setWind(newWind(this.maxWind, this.wind.direction)); + } + }) } connectedCallback() { @@ -222,8 +231,8 @@ class WindSelectComponent extends HTMLElement { const strengthDelta = Math.round(pixelsDragged / pixelsPerIncrement); let strength = this.initialStrengthForDrag + strengthDelta; - if (strength > 15) { - strength = 15; + if (strength > this.maxWind) { + strength = this.maxWind; } else if (strength < 0) { strength = 0; } diff --git a/notes/browser/index.js b/notes/browser/index.js index 0476651..60f005e 100644 --- a/notes/browser/index.js +++ b/notes/browser/index.js @@ -52,6 +52,17 @@ class NavigationController { const windParam = getQueryParam("into"); const pinParam = getQueryParam("pin"); + if (windParam) { + const wind = (() => { + const segments = windParam?.split("_"); + const strength = parseInt(segments[0]); + const direction = segments[2]?.replace("1", "+1"); + const wind = newWind(strength, direction); + return wind; + })(); + this.setWind(wind); + } + if (courseParam) { const course = (() => { return { @@ -74,17 +85,6 @@ class NavigationController { this.setHole(hole); } - if (windParam) { - const wind = (() => { - const segments = windParam?.split("_"); - const strength = parseInt(segments[0]); - const direction = segments[2]?.replace("1", "+1"); - const wind = newWind(strength, direction); - return wind; - })(); - this.setWind(wind); - } - if (pinParam) { const pin = (() => { return this.#hole.pins.find(pin => {