handle all button types
This commit is contained in:
96
app.js
96
app.js
@@ -469,25 +469,6 @@ carousel.addEventListener('touchend', (e) => {
|
||||
saveData();
|
||||
});
|
||||
|
||||
carousel.addEventListener('push', (e) => {
|
||||
console.log('[carousel] Push received');
|
||||
if (!isDragging) return;
|
||||
|
||||
isDragging = false;
|
||||
|
||||
const data = e.data ? e.data.json() : {};
|
||||
const button_id = data.body ? data.body.button_id : '';
|
||||
const click_type = data.body ? data.body.click_type : '';
|
||||
if (button_id === BUTTON_ID && click_type === SINGLE_CLICK) {
|
||||
moveCarousel(-1);
|
||||
}
|
||||
|
||||
// Reset carousel to proper position
|
||||
carousel.style.transform = `translateX(${-100 * currentPlayerIndex}%)`;
|
||||
renderPlayers();
|
||||
saveData();
|
||||
});
|
||||
|
||||
function moveCarousel(diff) {
|
||||
const previousIndex = currentPlayerIndex;
|
||||
|
||||
@@ -534,6 +515,83 @@ function findNextPlayerWithTimeCircular(startIndex, direction) {
|
||||
return -1; // No player has time left
|
||||
}
|
||||
|
||||
function handleFlicAction(action, buttonId) {
|
||||
console.log(`[App] Received Flic Action: ${action} from Button: ${buttonId}`);
|
||||
|
||||
// --- Trigger your PWA action based on the 'action' string ---
|
||||
switch (action) {
|
||||
case 'SingleClick':
|
||||
console.log('[App] Single click action...');
|
||||
handleSingleClickLogic(buttonId);
|
||||
break;
|
||||
|
||||
case 'DoubleClick':
|
||||
console.log('[App] Simulating double click action...');
|
||||
const elementForDoubleClick = document.getElementById('myDoubleClickTarget');
|
||||
if (elementForDoubleClick) {
|
||||
// You might need a specific function, double clicks are harder to simulate directly
|
||||
handleDoubleClickLogic();
|
||||
} else {
|
||||
console.warn('[App] Element #myDoubleClickTarget not found.');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'Hold':
|
||||
console.log('[App] Simulating hold action...');
|
||||
// Example: Call a function associated with holding
|
||||
handleHoldLogic();
|
||||
break;
|
||||
|
||||
default:
|
||||
console.warn(`[App] Unknown Flic action received: ${action}`);
|
||||
}
|
||||
}
|
||||
|
||||
// --- Listener for messages from the Service Worker ---
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.addEventListener('message', event => {
|
||||
console.log('[App] Message received from Service Worker:', event.data);
|
||||
|
||||
// Check if the message is the one we expect
|
||||
if (event.data && event.data.type === 'flic-action') {
|
||||
const { action, button } = event.data;
|
||||
handleFlicAction(action, button);
|
||||
}
|
||||
// Add else if blocks here for other message types if needed
|
||||
});
|
||||
|
||||
// Optional: Send a message TO the service worker if needed
|
||||
// navigator.serviceWorker.ready.then(registration => {
|
||||
// registration.active.postMessage({ type: 'client-ready' });
|
||||
// });
|
||||
}
|
||||
|
||||
function handleSingleClickLogic(buttonId) {
|
||||
console.log(`Single Click Logic Executed from Button: ${buttonId}`);
|
||||
if (!isDragging) return;
|
||||
|
||||
isDragging = false;
|
||||
|
||||
if (buttonId === BUTTON_ID) {
|
||||
moveCarousel(-1);
|
||||
}
|
||||
|
||||
// Reset carousel to proper position
|
||||
carousel.style.transform = `translateX(${-100 * currentPlayerIndex}%)`;
|
||||
renderPlayers();
|
||||
saveData();
|
||||
}
|
||||
|
||||
function handleDoubleClickLogic() {
|
||||
console.log("Double Click Logic Executed!");
|
||||
// Update UI, trigger different game action, etc.
|
||||
}
|
||||
|
||||
function handleHoldLogic() {
|
||||
console.log("Hold Logic Executed!");
|
||||
// Update UI, show a menu, etc.
|
||||
}
|
||||
|
||||
// Setup button
|
||||
setupButton.addEventListener('click', () => {
|
||||
audioManager.play('buttonClick');
|
||||
|
||||
Reference in New Issue
Block a user