- add key (p) to disable ads
This commit is contained in:
Kum1ta
2024-11-20 15:03:27 +01:00
parent 7dd6e4b6fe
commit 9630d4d927
3 changed files with 31 additions and 9 deletions

View File

@ -6,7 +6,7 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/20 14:52:55 by hubourge #+# #+# */
/* Updated: 2024/11/19 16:35:13 by edbernar ### ########.fr */
/* Updated: 2024/11/20 14:37:03 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */

View File

@ -6,13 +6,13 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/18 00:30:31 by edbernar #+# #+# */
/* Updated: 2024/11/20 14:08:04 by edbernar ### ########.fr */
/* Updated: 2024/11/20 14:43:02 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
import { fetchProfile, MotionController } from '/static/javascript/three/examples/jsm/libs/motion-controllers.module.js'
import { XRControllerModelFactory } from '/static/javascript/three/examples/jsm/webxr/XRControllerModelFactory.js'
import { scene, renderer, isInVrMode, ball } from '/static/javascript/multiOnlineGame/multiOnlineGamePage.js'
import { scene, renderer, isInVrMode, ball, disablePublicity } from '/static/javascript/multiOnlineGame/multiOnlineGamePage.js'
import { lastSelectedGoal, availableGoals } from '/static/javascript/lobbyPage/3d.js';
import * as THREE from '/static/javascript/three/build/three.module.js'
import { layoutSelected } from '/static/javascript/lobbyPage/main.js'
@ -120,7 +120,7 @@ class Player
this.mapVar.putVideoOnCanvas(3, 'goal');
setTimeout(() => {
this.mapVar.putVideoOnCanvas(0, null);
if (!isMobile && isOnChrome)
if (!isMobile && isOnChrome && !disablePublicity)
this.mapVar.putVideoOnCanvas(2, 3);
}, 4000);

View File

@ -6,7 +6,7 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/18 00:53:53 by edbernar #+# #+# */
/* Updated: 2024/11/19 18:25:40 by edbernar ### ########.fr */
/* Updated: 2024/11/20 14:57:08 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
@ -38,6 +38,7 @@ let lastFpsDisplayed = 0;
let lastFpsArr = [60];
let VrButton = null;
let isInVrMode = false;
let disablePublicity = false;
const observer = new MutationObserver((mutationsList) => {
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 };
export { MultiOnlineGamePage, player, opponent, ball, map, scene, renderer, isInVrMode, createBarPlayer, disablePublicity };