mainmenuui.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. })
  26. document.getElementById("reset-save-button").addEventListener('click', () => {
  27. let shouldDelete = confirm("Are you sure you want to delete your Spookonomics save data? This cannot be undone.")
  28. if(shouldDelete) {
  29. clearSaveData(stageData)
  30. loadSaveData(stageData)
  31. }
  32. })
  33. container.addEventListener('click', (event) => {
  34. event.stopPropagation()
  35. })
  36. }
  37. export async function openMainMenuUI(game, stageData) {
  38. const container = document.getElementById("main-menu-container")
  39. container.style.display = "block"
  40. const display = document.getElementById("main-menu-display")
  41. display.style.opacity = 0
  42. gsap.to(display, {opacity: 1, duration: 0.8})
  43. }
  44. export async function closeMainMenuUI(game, stageData) {
  45. const container = document.getElementById("main-menu-container")
  46. const display = document.getElementById("main-menu-display")
  47. gsap.to(display, {
  48. opacity: 0, duration: 0.8, onComplete: () => {
  49. container.style.display = "none"
  50. }
  51. })
  52. }