Skip to content
Snippets Groups Projects
Commit 60891598 authored by spencerkee's avatar spencerkee
Browse files

Add clearing buttons

parent 0214e625
Branches master
No related tags found
No related merge requests found
......@@ -49,7 +49,7 @@ const start = document.getElementById("start");
// Recording buttons, i.e. when you click them we'll start recording inputs
// which should later count as that button press when seen on the QR code
const recordNetural = document.getElementById("noInputRec");
const recordNeutral = document.getElementById("neutralRec");
const recordUp = document.getElementById("upRec");
const recordDown = document.getElementById("downRec");
const recordLeft = document.getElementById("leftRec");
......@@ -59,10 +59,18 @@ const recordB = document.getElementById("bRec");
// const recordSelect = document.getElementById("selectRec");
// const recordStart = document.getElementById("startRec");
const isNeutralHeld = false;
const clearNeutral = document.getElementById("neutralClear");
const clearUp = document.getElementById("upClear");
const clearDown = document.getElementById("downClear");
const clearLeft = document.getElementById("leftClear");
const clearRight = document.getElementById("rightClear");
const clearA = document.getElementById("aClear");
const clearB = document.getElementById("bClear");
// const clearSelect = document.getElementById("clearSelect");
// const clearStart = document.getElementById("clearStart");
const recordingButtons = [
recordNetural,
recordNeutral,
recordUp,
recordDown,
recordLeft,
......@@ -73,6 +81,18 @@ const recordingButtons = [
// recordStart,
]
const clearButtons = [
clearNeutral,
clearUp,
clearDown,
clearLeft,
clearRight,
clearA,
clearB,
// clearSelect,
// clearStart,
]
// TODO fix weird indexes
const codeDataButtonIndexes = [
[14, 19], // Neutral
......@@ -149,7 +169,7 @@ let codeDataButtonSubstrings = [
]
let recordingButtonIsHeldArr = [
false, // recordNetural
false, // recordNeutral
false, // recordUp
false, // recordDown
false, // recordLeft
......@@ -187,6 +207,13 @@ function analyze(arr) {
return answer;
}
// Clear the codeDataButtonSubstrings for the given button
clearButtons.forEach((button, index) => {
button.onclick = () => {
codeDataButtonSubstrings[index] = [];
}
});
// Add a listener for each recording button to set the corresponding index in the array to true when pressed
recordingButtons.forEach((button, index) => {
button.onpointerdown = () => {
......@@ -244,30 +271,6 @@ recordingButtons.forEach((button, index) => {
return false;
}
}
// // Check to see if we're already using this substring in the same button.
// if (codeDataButtonSubstrings[index].includes(relevantSlice)) {
// console.log(`Found ${relevantSlice} in codeDataButtonSubstrings[${index}]`);
// return false;
// }
// // Check to see if we're already using this substring in a different button.
// let allSubstringsForCurrentButton = codeDataButtonSubstrings[index];
// for (let i = 0; i < allSubstringsForCurrentButton.length; i++) {
// // Skip self.
// if (i === index) {
// continue
// }
// let sliceStartStop = codeDataButtonIndexes[i];
// // Check if indexes are irrelevant.
// if (!sliceStartStop === codeDataButtonIndexes[index]) {
// continue;
// }
// // Check if relevantSlice is in found for another button
// if (codeDataButtonSubstrings[index].includes(relevantSlice)) {
// console.log(`Found ${relevantSlice} in codeDataButtonSubstrings[${i}]`);
// return false;
// }
// }
return true;
});
// Create accumulator and iterate over sortedRecordedData and filter out values
......@@ -294,46 +297,6 @@ recordingButtons.forEach((button, index) => {
};
});
// if (index === 0) {
// // TODO Only add unique ones.
// codeDataButtonSubstrings[0].push(...bestValues.map(codeData => codeData[0]));
// let junk = analyze(codeDataButtonSubstrings[0]);
// } else {
// let junk = analyze(codeDataButtonSubstrings[index]);
// let minDiff = Infinity;
// let minDiffString = "";
// bestValues.forEach(possibleInput => {
// // Find the string in codeDataButtonSubstrings[0] which differes from
// // possibleInput by the least characters
// codeDataButtonSubstrings[0].forEach(neutralCodeData => {
// let diff = 0;
// for (let i = 0; i < neutralCodeData.length; i++) {
// if (neutralCodeData[i] !== possibleInput[0][i]) {
// diff++;
// }
// }
// if (diff < minDiff) {
// minDiff = diff;
// minDiffString = neutralCodeData;
// }
// });
// });
// let time;
// recordNetural.onpointerdown = function () {
// isNeutralHeld = false;
// // time = Date.now();
// }
// recordNetural.onpointerup = function () {
// isNeutralHeld = false;
// // console.log(`you held me down for ${Date.now() - time} milliseconds`);
// }
let qr = {};
let pressedButtons = {};
......
......@@ -25,7 +25,18 @@
<button id="start">Start</button>
<button id="select">Select</button>
<div>
<button id="noInputRec">NoInput+</button>
<button id="neutralClear">NoInput-</button>
<button id="upClear">Up-</button>
<button id="downClear">Down-</button>
<button id="leftClear">Left-</button>
<button id="rightClear">Right-</button>
<button id="aClear">A-</button>
<button id="bClear">B-</button>
<button id="startClear">Start-</button>
<button id="selectClear">Select-</button>
</div>
<div>
<button id="neutralRec">NoInput+</button>
<button id="upRec">Up+</button>
<button id="downRec">Down+</button>
<button id="leftRec">Left+</button>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment