function loadAssets (scene, basepath, dataname) {
  const scenedata = scene.cache.json.get(dataname)

  for (const name in scenedata) {
    if (scenedata[name].type === 'image') {
      scene.load.image(
        name,
        basepath + scenedata[name].asset
      )
    } else if (scenedata[name].type === 'sprite') {
      scene.load.spritesheet(
        name,
        basepath + scenedata[name].asset,
        {
          frameWidth: scenedata[name].frame[0],
          frameHeight: scenedata[name].frame[1]
        }
      )
    }
  }
}

function initScene (scene, sceneData, skip) {
  for (const name in sceneData) {
    if (skip !== undefined && skip.indexOf(name) >= 0) {
      continue
    }

    if (sceneData[name].type === 'image') {
      scene[name] = scene.add.image(
        sceneData[name].x, sceneData[name].y, name
      ).setOrigin(0, 0)
    } else if (sceneData[name].type === 'sprite') {
      scene[name] = scene.add.sprite(
        sceneData[name].x, sceneData[name].y, name
      ).setOrigin(0, 0)
    }
  }
}

export { loadAssets, initScene }
