40 lines
966 B
JavaScript
40 lines
966 B
JavaScript
import {
|
|
controlButtonHandler,
|
|
keyboardHandler,
|
|
settingsHandler,
|
|
} from './src/handlers.js'
|
|
import { assignCommands } from './src/utils.js'
|
|
|
|
// Input handlers
|
|
document
|
|
.querySelector('#move-input')
|
|
.addEventListener('change', (event) =>
|
|
assignCommands('backward', 'forward', event)
|
|
)
|
|
document
|
|
.querySelector('#rotate-input')
|
|
.addEventListener('change', (event) =>
|
|
assignCommands('left', 'right', event)
|
|
)
|
|
|
|
// Buttons handlers
|
|
for (const button of document
|
|
.querySelector('#touch-controls')
|
|
.querySelectorAll('button')) {
|
|
button.addEventListener('click', controlButtonHandler)
|
|
}
|
|
|
|
// Keyboard handler
|
|
document.addEventListener('keydown', keyboardHandler)
|
|
|
|
// Settings handler
|
|
document.querySelector('#settings').addEventListener('submit', settingsHandler)
|
|
|
|
// Restore endpoint if available
|
|
const endpoint = sessionStorage.getItem('robot-endpoint')
|
|
if (endpoint) {
|
|
document.querySelector('input[name=ip-address]').value = new URL(
|
|
endpoint
|
|
).host
|
|
}
|