gameoverui.js 1.2 KB

123456789101112131415161718192021222324252627282930
  1. import gsap from "gsap"
  2. import { clearSaveData, returnToMainMenu } from "../game.js"
  3. export function gameOverUI(game, stageData) {
  4. document.getElementById("play-again").addEventListener('click', event => {
  5. hideGameOverUI(game, stageData)
  6. clearSaveData(stageData)
  7. returnToMainMenu(game, stageData)
  8. })
  9. }
  10. export function showGameOverUI(game, stageData) {
  11. document.getElementById("game-over-container").style.display = "block"
  12. const blackoutContainer = document.getElementById("game-over-blackout")
  13. gsap.to(blackoutContainer, { duration: 2, opacity: 1 })
  14. const gameOverPanel = document.getElementById("game-over-panel")
  15. gameOverPanel.getElementsByTagName("p")[0].innerHTML = `You made ${stageData.currency} gold in:`
  16. gameOverPanel.getElementsByTagName("h2")[0].innerHTML = `${stageData.currentDay - 1} days`
  17. }
  18. export function hideGameOverUI(game, stageData) {
  19. const blackoutContainer = document.getElementById("game-over-blackout")
  20. gsap.to(blackoutContainer, {
  21. duration: 2, opacity: 0, onComplete: () => {
  22. document.getElementById("game-over-container").style.display = "none"
  23. }
  24. })
  25. }