mainmenuui.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import gsap from "gsap"
  2. import { showNavigationUI } from "./navigationui.js"
  3. import { clearSaveData, loadSaveData } from "../game.js"
  4. import { showGameStatusUI } from "./gamestatusui.js"
  5. export function brewTutorialPrompt(stageData) {
  6. if(stageData.brewTutorial1.alreadySeen) {
  7. return
  8. }
  9. stageData.brewInactivityHandle = setTimeout(() => {
  10. gsap.to(stageData.brewTutorial1.material, {duration: 1.5, opacity: 1, onStart: () => {
  11. stageData.brewTutorial1.castShadow = true
  12. }})
  13. }, 5000)
  14. }
  15. export async function mainMenuUI(game, stageData) {
  16. const container = document.getElementById('main-menu-container')
  17. document.getElementById("play-button").addEventListener('click', () => {
  18. brewTutorialPrompt(stageData)
  19. closeMainMenuUI(game, stageData)
  20. showNavigationUI(game, stageData)
  21. showGameStatusUI(game, stageData)
  22. const camPosition = stageData.cameraPositions[1]
  23. gsap.to(game.camera.position, {duration: 2.5, x: camPosition.camera.x, y:camPosition.camera.y, z:camPosition.camera.z})
  24. gsap.to(game.lookAtFocus, { duration: 2.5, x: camPosition.focus.x, y: camPosition.focus.y, z: camPosition.focus.z })
  25. stageData.musicLoop.play()
  26. })
  27. document.getElementById("reset-save-button").addEventListener('click', () => {
  28. let shouldDelete = confirm("Are you sure you want to delete your Spookonomics save data? This cannot be undone.")
  29. if(shouldDelete) {
  30. clearSaveData(stageData)
  31. loadSaveData(stageData)
  32. }
  33. })
  34. container.addEventListener('click', (event) => {
  35. event.stopPropagation()
  36. })
  37. }
  38. export async function openMainMenuUI(game, stageData) {
  39. const container = document.getElementById("main-menu-container")
  40. container.style.display = "block"
  41. const display = document.getElementById("main-menu-display")
  42. display.style.opacity = 0
  43. gsap.to(display, {opacity: 1, duration: 0.8})
  44. }
  45. export async function closeMainMenuUI(game, stageData) {
  46. const container = document.getElementById("main-menu-container")
  47. const display = document.getElementById("main-menu-display")
  48. gsap.to(display, {
  49. opacity: 0, duration: 0.8, onComplete: () => {
  50. container.style.display = "none"
  51. }
  52. })
  53. }