import Tilorswift from "./Tilorswift.js";
import Level from "../../js/Level.js";
import ImageLoader from "../../js/ImageLoader.js";
import GraphicSet from "../../js/GraphicSet.js";
import Setting from "../../js/Setting.js";

const imageLoader = new ImageLoader();

window.addEventListener(
    'beforeunload',
    (event) => {
        event.preventDefault();
    }
);

for (const graphicSet of GraphicSet) {
    imageLoader.addImage('../' + Setting.TILESET_LOCATION + graphicSet.tileset);

    if (graphicSet.tilesetBackground !== null) {
        imageLoader.addImage('../' + Setting.TILESET_LOCATION + graphicSet.tilesetBackground.path);
    }
}

imageLoader.onLoad = () => {
    Level.createFromFile(
        '../levels/moonbase.json',
        (level) => {
            const tilorswift = new Tilorswift(level);
            tilorswift.loadLevel();
            tilorswift.init();
        }
    );
}
imageLoader.load();
