From 61016cda28b15fc9b946f86f472910fd533638c2 Mon Sep 17 00:00:00 2001 From: Kum1ta Date: Thu, 3 Oct 2024 04:31:39 +0200 Subject: [PATCH] Site - Making the goal selection --- .../nginx/static/javascript/lobbyPage/3d.js | 105 +++++++++++++++--- .../static/javascript/multiOnlineGame/Map.js | 2 +- 2 files changed, 90 insertions(+), 17 deletions(-) diff --git a/docker-compose/requirements/nginx/static/javascript/lobbyPage/3d.js b/docker-compose/requirements/nginx/static/javascript/lobbyPage/3d.js index ec3df9e..eb15218 100644 --- a/docker-compose/requirements/nginx/static/javascript/lobbyPage/3d.js +++ b/docker-compose/requirements/nginx/static/javascript/lobbyPage/3d.js @@ -6,16 +6,18 @@ /* By: edbernar { + const popup = document.getElementById('popup-goal-selector'); + const skins = document.getElementsByClassName('color-box-goal'); + + popup.style.display = 'flex'; + for (let i = 0; i < skins.length; i++) + { + skins[i].setAttribute('goalId', i); + skins[i].appendChild(this.showObject(availableGoals[i], skins[i].getBoundingClientRect())); + skins[i].removeEventListener('click', this.boundChangeSkin); + skins[i].addEventListener('click', this.boundChangeSkin); + } + popup.removeEventListener('click', this.hideGoalSelector); + popup.addEventListener('click', this.hideGoalSelector); + }); } - createGoal(color) + showObject(func, pos) { - const geometry = new THREE.BoxGeometry(1, 0.1, 0.1); - const material = new THREE.MeshPhysicalMaterial({color: color}); - const mesh = new THREE.Mesh(geometry, material); - - mesh.castShadow = true; - return (mesh); + const scene = new THREE.Scene(); + const renderer = new THREE.WebGLRenderer({antialias: true}); + const camera = new THREE.PerspectiveCamera(60, (pos.width - 5) / (pos.height - 5)); + const mesh = func(colorList[Math.floor(Math.random() * 100 % colorList.length)]); + const spotLight = new THREE.SpotLight(0xffffff, 5000); + + renderer.setSize(pos.width - 5, pos.height - 5); + scene.add(mesh); + camera.position.set(1.5, 1.5, 1.5); + spotLight.position.set(1.5, 1.5, 1.5); + spotLight.target = mesh; + camera.lookAt(mesh.position); + scene.add(spotLight); + scene.background = new THREE.Color(0x1a1a1a); + this.sceneList.push(scene); + this.rendererList.push(renderer); + this.cameraList.push(camera); + return (renderer.domElement) } + changeGoal (event) + { + const popup = document.getElementById('popup-skin-selector'); + + const id = event.target.getAttribute('goalId'); + popup.style.display = 'none'; + this.bar.material.dispose(); + lastSelectedGoal = availableGoals[id]; + // if (availableSkins[id].color != null) + // this.bar.material = new THREE.MeshPhysicalMaterial({color: availableSkins[id].color}); + // else + // this.bar.material = new THREE.MeshPhysicalMaterial({map: new THREE.TextureLoader().load(availableSkins[id].texture)}); + this.selected = availableGoals[id]; + } + + hideGoalSelector(event) + { + const popup = document.getElementById('popup-skin-selector'); + + if (event.target.getAttribute('id') == 'popup-skin-selector') + popup.style.display = 'none'; + } + #loop() { - actualGoalSelecter.goal.rotation.y += 0.1; - actualGoalSelecter.goal.rotation.x += 0.1; - actualGoalSelecter.goal.rotation.z += 0.1; + actualGoalSelecter.goal.rotation.y += 0.01; + actualGoalSelecter.goal.rotation.x += 0.01; actualGoalSelecter.renderer.render(actualGoalSelecter.scene, actualGoalSelecter.camera); + for (let i = 0; this.rendererList && i < this.rendererList.length; i++) + { + this.sceneList[i].children[0].rotation.y -= 0.01; + this.sceneList[i].children[0].rotation.x += 0.01; + this.rendererList[i].render(this.sceneList[i], this.cameraList[i]); + } } dispose() @@ -205,6 +270,14 @@ class goalSelecter this.renderer.dispose(); this.renderer.forceContextLoss(); } + if (this.rendererList) + { + for (let i = 0; i < this.rendererList.length; i++) + { + this.rendererList[i].dispose(); + this.rendererList[i].forceContextLoss(); + } + } this.renderer = null; if (this.scene) { diff --git a/docker-compose/requirements/nginx/static/javascript/multiOnlineGame/Map.js b/docker-compose/requirements/nginx/static/javascript/multiOnlineGame/Map.js index 6b5c5a5..c987654 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