Skip to content

Commit

Permalink
disable drop adder when not selected
Browse files Browse the repository at this point in the history
  • Loading branch information
ben9583 committed Jun 21, 2022
1 parent d94e229 commit 33f011d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion website-src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<input id="dropName" type="text" placeholder="Name" />
<input id="dropMass" type="number" placeholder="Mass" />
<input id="dropRadius" type="number" placeholder="Radius" />
<button id="dropSpawn">Spawn</button>
<span>Click to drop at mouse, drag to give velocity</span>
</div>

<input type="radio" id="preciseAdderButton" name="adderMethod" value="preciseAdderButton" />
Expand Down
35 changes: 20 additions & 15 deletions website-src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,13 @@ preciseAdderButton.checked = "";
dropAdderButton.addEventListener("click", () => {
dropAdder.style.display = "block";
preciseAdder.style.display = "none";
dropAdderEnabled = true;
})

preciseAdderButton.addEventListener("click", () => {
dropAdder.style.display = "none";
preciseAdder.style.display = "block";
dropAdderEnabled = false;
})

const highTrailQualityElem = document.getElementById("highTrailQuality");
Expand All @@ -151,6 +153,7 @@ const ctx2 = canvas2.getContext("2d");
const ctx3 = canvas3.getContext("2d");

ctx3.strokeStyle = "white";
let dropAdderEnabled = false;
let mouseInCanvas = false;
let mouseClicking = false;
let clickedX = 0;
Expand Down Expand Up @@ -194,24 +197,26 @@ canvas3.addEventListener("mouseup", (elem, e) => {
step(false);
});
canvas3.addEventListener("mousemove", (elem, e) => {
let pos = getMousePos(canvas3, elem);
if(dropAdderEnabled) {
let pos = getMousePos(canvas3, elem);

if(mouseInCanvas) {
ctx3.clearRect(0, 0, WIDTH, HEIGHT);
if(mouseInCanvas) {
ctx3.clearRect(0, 0, WIDTH, HEIGHT);

const radius = parseFloat(document.getElementById("dropRadius").value);
if(!(isNaN(radius) || !isFinite(radius) || radius < 0.01)) {
ctx3.beginPath();
const radius = parseFloat(document.getElementById("dropRadius").value);
if(!(isNaN(radius) || !isFinite(radius) || radius < 0.01)) {
ctx3.beginPath();

if(mouseClicking) {
ctx3.arc(clickedX, clickedY, radius, 0, 2 * Math.PI);
ctx3.moveTo(clickedX, clickedY);
ctx3.lineTo(pos.x, pos.y);
} else {
ctx3.arc(pos.x, pos.y, radius, 0, 2 * Math.PI);
}
if(mouseClicking) {
ctx3.arc(clickedX, clickedY, radius, 0, 2 * Math.PI);
ctx3.moveTo(clickedX, clickedY);
ctx3.lineTo(pos.x, pos.y);
} else {
ctx3.arc(pos.x, pos.y, radius, 0, 2 * Math.PI);
}

ctx3.stroke();
ctx3.stroke();
}
}
}
})
Expand Down Expand Up @@ -334,7 +339,7 @@ resetButton.addEventListener("click", (elem, e) => {
step(false);
})

const spawnButton = document.getElementById("spawn");
const spawnButton = document.getElementById("preciseSpawn");

spawnButton.addEventListener("click", (elem, e) => {
const name = document.getElementById("preciseName").value;
Expand Down

0 comments on commit 33f011d

Please sign in to comment.