import { levelList, bonusLevelList, mainMenuLevel } from "./levelList.js"

function preloadImage(path) {
  return new Promise(resolve => {
    const image = new Image()
    image.src = path
    image.onerror = (e) => {
      console.error('fuk', path, e)
      resolve()
    }
    image.onload = resolve(image)
  })
}

async function preloadEveryThing() {
  for (const level of levelList) {
    await level.loadLevel()
    console.log('Preloaded level:', level.title)
  }

  for (const level of bonusLevelList) {
    await level.loadLevel()
    console.log('Preloaded bonus level:', level.title)
  }
  await mainMenuLevel.loadLevel()
  console.log('Preloaded everything')
}

export { preloadImage, preloadEveryThing }