keyMapInput selection
This commit is contained in:
parent
8fe3699d70
commit
0d024ad390
48
app.js
48
app.js
@ -350,6 +350,24 @@ function pause() {
|
||||
|
||||
settingsButton.onclick = showSettings
|
||||
|
||||
keyMapInput.onclick = keyMapInput.onkeyup = function(event) {
|
||||
let cursorPosition = keyMapInput.selectionEnd
|
||||
keyMapInput.setSelectionRange(cursorPosition-1, cursorPosition)
|
||||
}
|
||||
|
||||
keyMapInput.onchange = function(event) {
|
||||
keyMap = keyMapInput.value
|
||||
if (midiKeyboard) {
|
||||
cannonSprites.forEach((cannonSprite, index) => {
|
||||
cannonSprite.key = NOTE_NAMES[index % NOTE_NAMES.length]
|
||||
})
|
||||
} else {
|
||||
cannonSprites.forEach((cannonSprite, index) => {
|
||||
cannonSprite.key = keyMap[index - FIRST_NOTE].toUpperCase()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
var midiIputs
|
||||
var midiKeyboard = window.localStorage.midiKeyboard || ""
|
||||
midiSelect.onfocus = function() {
|
||||
@ -385,21 +403,13 @@ midiSelect.oninput = () => {
|
||||
window.localStorage.midiKeyboard = midiKeyboard
|
||||
}
|
||||
|
||||
keyMapInput.onclick=()=>{
|
||||
let cursorPosition = keyMapInput.selectionStart
|
||||
keyMapInput.setSelectionRange(cursorPosition-1, cursorPosition)
|
||||
}
|
||||
function onMIDIMessage(event) {
|
||||
let [code, note, velocity] = event.data
|
||||
|
||||
keyMapInput.onchange = function(event) {
|
||||
keyMap = keyMapInput.value
|
||||
if (midiKeyboard) {
|
||||
cannonSprites.forEach((cannonSprite, index) => {
|
||||
cannonSprite.key = NOTE_NAMES[index % NOTE_NAMES.length]
|
||||
})
|
||||
} else {
|
||||
cannonSprites.forEach((cannonSprite, index) => {
|
||||
cannonSprite.key = keyMap[index - FIRST_NOTE].toUpperCase()
|
||||
})
|
||||
if (144 <= code && code <= 159 && cannonSprites[note]) {
|
||||
cannonSprites[note].shooting = true
|
||||
} else if (128 <= code && code <= 143 && cannonSprites[note]) {
|
||||
cannonSprites[note].shooting = false
|
||||
}
|
||||
}
|
||||
|
||||
@ -422,16 +432,6 @@ function onpartialinput() {
|
||||
}
|
||||
}
|
||||
|
||||
function onMIDIMessage(event) {
|
||||
let [code, note, velocity] = event.data
|
||||
|
||||
if (144 <= code && code <= 159 && cannonSprites[note]) {
|
||||
cannonSprites[note].shooting = true
|
||||
} else if (128 <= code && code <= 143 && cannonSprites[note]) {
|
||||
cannonSprites[note].shooting = false
|
||||
}
|
||||
}
|
||||
|
||||
let level
|
||||
function newGame() {
|
||||
level = 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user