Skip to content

Commit

Permalink
Cap wind-select max strength based on current hole
Browse files Browse the repository at this point in the history
  • Loading branch information
byxor committed Oct 20, 2024
1 parent 8d79234 commit f64a3ba
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
13 changes: 13 additions & 0 deletions models/hole.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 11 additions & 2 deletions notes/browser/components/wind-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class WindSelectComponent extends HTMLElement {
this.documentListenersConfiguredForDirectionDrag = false;
this.isDraggingDirection = false;

this.maxWind = 15;
this.setWind(newWind(0, "N"));

this.emitSelectedWind();
Expand All @@ -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() {
Expand Down Expand Up @@ -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;
}
Expand Down
22 changes: 11 additions & 11 deletions notes/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 => {
Expand Down

0 comments on commit f64a3ba

Please sign in to comment.