mainmenuui.js 2.8 KB

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