From 9630d4d927704dd000261d5cf0cd9b2f5d50a255 Mon Sep 17 00:00:00 2001 From: Kum1ta Date: Wed, 20 Nov 2024 15:03:27 +0100 Subject: [PATCH] Game - add key (p) to disable ads --- .../static/javascript/multiOnlineGame/Map.js | 2 +- .../javascript/multiOnlineGame/Player.js | 6 ++-- .../multiOnlineGame/multiOnlineGamePage.js | 32 ++++++++++++++++--- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/docker-compose/requirements/nginx/static/javascript/multiOnlineGame/Map.js b/docker-compose/requirements/nginx/static/javascript/multiOnlineGame/Map.js index 1b62f3f..02ebe79 100644 --- a/docker-compose/requirements/nginx/static/javascript/multiOnlineGame/Map.js +++ b/docker-compose/requirements/nginx/static/javascript/multiOnlineGame/Map.js @@ -6,7 +6,7 @@ /* By: edbernar { this.mapVar.putVideoOnCanvas(0, null); - if (!isMobile && isOnChrome) + if (!isMobile && isOnChrome && !disablePublicity) this.mapVar.putVideoOnCanvas(2, 3); }, 4000); diff --git a/docker-compose/requirements/nginx/static/javascript/multiOnlineGame/multiOnlineGamePage.js b/docker-compose/requirements/nginx/static/javascript/multiOnlineGame/multiOnlineGamePage.js index 192f585..3b9956c 100644 --- a/docker-compose/requirements/nginx/static/javascript/multiOnlineGame/multiOnlineGamePage.js +++ b/docker-compose/requirements/nginx/static/javascript/multiOnlineGame/multiOnlineGamePage.js @@ -6,7 +6,7 @@ /* By: edbernar { mutationsList.forEach((mutation) => { @@ -107,10 +108,9 @@ class MultiOnlineGamePage if (e.key == 'c') debug = !debug; }) - renderer.setAnimationLoop(loop) sendRequest('game', {action: 1}); - if (!isMobile && isOnChrome) + if (!isMobile && isOnChrome && !disablePublicity) map.putVideoOnCanvas(2, 3); let lastPosition = player.object.position.x; let lastUp = player.isUp; @@ -129,6 +129,7 @@ class MultiOnlineGamePage lastPingTime = Date.now(); } }, 800); + document.addEventListener('keyup', tooglePublicity); } static dispose() @@ -141,6 +142,7 @@ class MultiOnlineGamePage map.putVideoOnCanvas(0, null); VrButton = null; window.removeEventListener('resize', windowUpdater); + document.removeEventListener('keyup', tooglePublicity); if (interval) clearInterval(interval); interval = null; @@ -270,6 +272,25 @@ function windowUpdater() player.camera.updateProjectionMatrix(); }; +let tooglePublicityTimeout = null; + +function tooglePublicity(event) +{ + if (tooglePublicityTimeout) + clearTimeout(tooglePublicityTimeout); + tooglePublicityTimeout = setTimeout(() => { + if (event.key === 'p') + { + disablePublicity = !disablePublicity; + if (disablePublicity) + map.putVideoOnCanvas(0, null); + else + map.putVideoOnCanvas(2, 3); + tooglePublicityTimeout = null; + } + }, 500); +} + function loop() { showFps(); @@ -280,7 +301,6 @@ function loop() renderer.render(scene, player.camera); } - function showFps() { const fps = document.getElementById('fps') @@ -314,6 +334,8 @@ function vrMode() let xrReferenceSpace; + + function configButton() { const newButton = document.createElement('button'); @@ -361,4 +383,4 @@ function configButton() } -export { MultiOnlineGamePage, player, opponent, ball, map, scene, renderer, isInVrMode, createBarPlayer }; \ No newline at end of file +export { MultiOnlineGamePage, player, opponent, ball, map, scene, renderer, isInVrMode, createBarPlayer, disablePublicity }; \ No newline at end of file