rename gui to menu

This commit is contained in:
Adrien MALINGREY 2024-10-01 18:39:26 +02:00
parent 1e42c2160f
commit 7fd3c04a2d
3 changed files with 37 additions and 42 deletions

45
app.js
View File

@ -3,9 +3,10 @@ import { scheduler } from './jsm/scheduler.js'
import { TRANSLATION, ROTATION, environment, Mino, Playfield, HoldQueue, NextQueue } from './jsm/Tetrominoes.js' import { TRANSLATION, ROTATION, environment, Mino, Playfield, HoldQueue, NextQueue } from './jsm/Tetrominoes.js'
import Settings from './jsm/Settings.js' import Settings from './jsm/Settings.js'
import { Stats } from './jsm/Stats.js' import { Stats } from './jsm/Stats.js'
import { TetraGUI } from './jsm/TetraGUI.js' import { Menu } from './jsm/Menu.js'
import TetraControls from './jsm/TetraControls.js' import TetraControls from './jsm/TetraControls.js'
import { TetraScene } from './jsm/TetraScene.js' import { TetraScene } from './jsm/TetraScene.js'
import * as FPS from 'three/addons/libs/stats.module.js'
HTMLElement.prototype.addNewChild = function (tag, properties) { HTMLElement.prototype.addNewChild = function (tag, properties) {
@ -25,9 +26,9 @@ let game = {
start: function() { start: function() {
stats.init() stats.init()
gui.startButton.hide() menu.startButton.hide()
gui.settings.close() menu.stats.show()
gui.stats.show() menu.settings.close()
Mino.meshes.clear() Mino.meshes.clear()
@ -49,11 +50,11 @@ let game = {
document.onkeydown = onkeydown document.onkeydown = onkeydown
document.onkeyup = onkeyup document.onkeyup = onkeyup
window.onblur = game.pause window.onblur = game.pause
gui.settings.domElement.onclick = game.pause menu.settings.domElement.onclick = game.pause
document.body.classList.remove("pause") document.body.classList.remove("pause")
gui.resumeButton.hide() menu.resumeButton.hide()
gui.pauseButton.show() menu.pauseButton.show()
stats.clock.start() stats.clock.start()
stats.clock.elapsedTime = stats.elapsedTime stats.clock.elapsedTime = stats.elapsedTime
@ -106,7 +107,7 @@ let game = {
}, },
pause: function() { pause: function() {
gui.settings.domElement.onclick = null menu.settings.domElement.onclick = null
stats.elapsedTime = stats.clock.elapsedTime stats.elapsedTime = stats.clock.elapsedTime
stats.clock.stop() stats.clock.stop()
@ -123,8 +124,8 @@ let game = {
pauseSpan.onfocus = game.resume pauseSpan.onfocus = game.resume
document.body.classList.add("pause") document.body.classList.add("pause")
gui.pauseButton.hide() menu.pauseButton.hide()
gui.resumeButton.show() menu.resumeButton.show()
}, },
over: function() { over: function() {
@ -133,15 +134,15 @@ let game = {
document.onkeydown = null document.onkeydown = null
window.onblur = null window.onblur = null
renderer.domElement.onfocus = null renderer.domElement.onfocus = null
gui.settings.domElement.onfocus = null menu.settings.domElement.onfocus = null
game.playing = false game.playing = false
scene.music.pause() scene.music.pause()
stats.clock.stop() stats.clock.stop()
messagesSpan.addNewChild("div", { className: "show-level-animation", innerHTML: `<h1>GAME<br/>OVER</h1>` }) messagesSpan.addNewChild("div", { className: "show-level-animation", innerHTML: `<h1>GAME<br/>OVER</h1>` })
gui.pauseButton.hide() menu.pauseButton.hide()
gui.startButton.name("Rejouer") menu.startButton.name("Rejouer")
gui.startButton.show() menu.startButton.show()
}, },
} }
@ -278,7 +279,7 @@ renderer.domElement.tabIndex = 1
let loadingManager = new THREE.LoadingManager( let loadingManager = new THREE.LoadingManager(
function() { function() {
loadingDiv.style.display = "none" loadingDiv.style.display = "none"
gui.startButton.show() menu.startButton.show()
renderer.setAnimationLoop(animate) renderer.setAnimationLoop(animate)
}, },
function (url, itemsLoaded, itemsTotal) { function (url, itemsLoaded, itemsTotal) {
@ -306,8 +307,14 @@ scene.add(playfield)
const nextQueue = new NextQueue() const nextQueue = new NextQueue()
scene.add(nextQueue) scene.add(nextQueue)
const gui = new TetraGUI(game, settings, stats, scene, controls, playfield) const menu = new Menu(game, settings, stats, scene, controls, playfield)
gui.load() menu.load()
let fps
if (window.location.search.includes("fps")) {
let fps = new FPS.default()
document.body.appendChild(fps.dom)
}
messagesSpan.onanimationend = function (event) { messagesSpan.onanimationend = function (event) {
event.target.remove() event.target.remove()
@ -327,7 +334,7 @@ function animate() {
renderer.render(scene, scene.camera) renderer.render(scene, scene.camera)
environment.camera.update(renderer, scene) environment.camera.update(renderer, scene)
gui.update() fps?.update()
} }
window.addEventListener("resize", () => { window.addEventListener("resize", () => {
@ -337,7 +344,7 @@ window.addEventListener("resize", () => {
}) })
window.onbeforeunload = function (event) { window.onbeforeunload = function (event) {
gui.save() menu.save()
localStorage["teTraHighScore"] = stats.highScore localStorage["teTraHighScore"] = stats.highScore
return !game.playing return !game.playing
} }

View File

@ -11,12 +11,12 @@ span {
position: absolute; position: absolute;
} }
.lil-gui { .lil-menu {
--background-color: rgba(33, 37, 41, 30%); --background-color: rgba(33, 37, 41, 30%);
--width: 200px; --width: 200px;
} }
@supports (backdrop-filter: blur()) { @supports (backdrop-filter: blur()) {
.lil-gui { .lil-menu {
backdrop-filter: blur(15px); backdrop-filter: blur(15px);
} }
} }
@ -27,11 +27,11 @@ span {
left: 15px; left: 15px;
} }
.lil-gui.root > .title { .lil-menu.root > .title {
font-size: 1.5em; font-size: 1.5em;
} }
.lil-gui .controller.disabled { .lil-menu .controller.disabled {
opacity: .8; opacity: .8;
} }

View File

@ -1,10 +1,9 @@
import * as THREE from 'three' import * as THREE from 'three'
import { GUI } from 'three/addons/libs/lil-gui.module.min.js' import { GUI } from 'three/addons/libs/lil-gui.module.min.js'
import * as FPS from 'three/addons/libs/stats.module.js'
import { Mino, environment } from './Tetrominoes.js' import { Mino, environment } from './Tetrominoes.js'
export class TetraGUI extends GUI { export class Menu extends GUI {
constructor(game, settings, stats, scene, controls, playfield) { constructor(game, settings, stats, scene, controls, playfield) {
super({title: "ᵀᴱTᴿᴬ"}) super({title: "ᵀᴱTᴿᴬ"})
@ -24,8 +23,8 @@ export class TetraGUI extends GUI {
this.stats.add(stats, "maxCombo").name("Combos max").disable().listen() this.stats.add(stats, "maxCombo").name("Combos max").disable().listen()
this.stats.add(stats, "maxB2B").name("BàB max").disable().listen() this.stats.add(stats, "maxB2B").name("BàB max").disable().listen()
this.settings = this.addFolder("Options").open()
this.settings = this.addFolder("Options")
this.settings.add(settings, "startLevel").name("Niveau initial").min(1).max(15).step(1) this.settings.add(settings, "startLevel").name("Niveau initial").min(1).max(15).step(1)
this.settings.add(settings, "theme", ["Plasma", "Espace", "Rétro"]).name("Thème").onChange(theme => { this.settings.add(settings, "theme", ["Plasma", "Espace", "Rétro"]).name("Thème").onChange(theme => {
@ -74,9 +73,9 @@ export class TetraGUI extends GUI {
scene.hardDropSound.setVolume(volume/100) scene.hardDropSound.setVolume(volume/100)
}) })
this.dev = window.location.search.includes("dev") this.settings.dev = window.location.search.includes("dev")
if (this.dev) { if (this.settings.dev) {
let dev = this.addFolder("dev") let dev = this.settings.addFolder("dev")
let cameraPosition = dev.addFolder("camera").close() let cameraPosition = dev.addFolder("camera").close()
cameraPosition.add(scene.camera.position, "x") cameraPosition.add(scene.camera.position, "x")
cameraPosition.add(scene.camera.position, "y") cameraPosition.add(scene.camera.position, "y")
@ -146,7 +145,7 @@ export class TetraGUI extends GUI {
if ("thickness" in Mino.meshes.material) material.add(Mino.meshes.material, "thickness" ).min(0).max(5).listen() if ("thickness" in Mino.meshes.material) material.add(Mino.meshes.material, "thickness" ).min(0).max(5).listen()
if ("transmission" in Mino.meshes.material) material.add(Mino.meshes.material, "transmission" ).min(0).max(1).listen() if ("transmission" in Mino.meshes.material) material.add(Mino.meshes.material, "transmission" ).min(0).max(1).listen()
} }
changeMaterial(this.materialType) changeMaterial(this.settings.materialType)
material.close() material.close()
controls.addEventListener("change", () => cameraPosition.controllersRecursive().forEach((control) => { controls.addEventListener("change", () => cameraPosition.controllersRecursive().forEach((control) => {
@ -154,15 +153,6 @@ export class TetraGUI extends GUI {
})) }))
} }
if (window.location.search.includes("fps")) {
let fps = new FPS.default()
document.body.appendChild(fps.dom)
this.update = function() {
fps.update()
}
}
} }
load() { load() {
@ -176,7 +166,7 @@ export class TetraGUI extends GUI {
} }
changeKey() { changeKey() {
let controller = this let controller = this.settings
let input = controller.domElement.getElementsByTagName("input")[0] let input = controller.domElement.getElementsByTagName("input")[0]
input.select() input.select()
input.onkeydown = function (event) { input.onkeydown = function (event) {
@ -184,6 +174,4 @@ export class TetraGUI extends GUI {
input.blur() input.blur()
} }
} }
update() {}
} }