// compiled from ../ts/main.ts
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
function sleep(ms) {
    return new Promise(res => setTimeout(res, ms));
}
function getCoords() {
    const coordsElms = [...document.querySelectorAll('[data-coords]')];
    const coordsArr = coordsElms.map((el) => {
        return { 'el': el, 'initCoords': el.dataset.coords.split(',').map(coord => Number(coord)) };
    });
    return coordsArr;
}
function getScenes() {
    const scenesElms = [...document.querySelectorAll('[data-scene-name]')];
    const scenesArr = scenesElms.map(el => {
        return { 'id': el.dataset.sceneName, 'el': el };
    });
    return scenesArr;
}
function getInventoryItems() {
    const inventoryElement = document.querySelector('[data-inventory]');
    const inventoryElms = [...inventoryElement.children];
    const inventoryItemsArr = inventoryElms.map(el => {
        return { 'id': el.dataset.inventoryItemId, 'el': el };
    });
    return inventoryItemsArr;
}
var appCache = {
    'coords': getCoords(),
    'wrapperElement': document.querySelector('[data-wrapper]'),
    'scenes': getScenes(),
    'inventoryElement': document.querySelector('[data-inventory]'),
    'inventoryItems': getInventoryItems(),
    'clickDisablerElement': document.querySelector('[data-click-disabler-active]'),
    'imgLoadingScreen': document.querySelector('[data-img-loading-screen-active]'),
    'coordsCalculationScreen': document.querySelector('[data-coords-calculation-screen-active]'),
    'titulkyNegativ': document.querySelector('[data-id="titulky-negativ"]')
};
var appState = {
    'debounceUpdateCoordsActive': false,
    'debounceUpdateCoordsTimeout': 0,
    'grabbedInventoryItem': '',
    'grabbedInventoryItemSrc': '',
    'activeScene': 'nazev',
    'sklepUnlocked': false,
    'nabojePicked': false,
    'puskaUnlocked': false,
    'lozniceUnlocked': false,
    'listActive': false
};
function checkCssCompatibility() {
    const el = document.querySelector('[data-css-check]');
    return getComputedStyle(el).getPropertyValue('display') === 'none';
}
function hideCompatibilityInfo() {
    const el = document.querySelector('[data-compatibility]');
    el.style.display = 'none';
}
function updateCoords() {
    return __awaiter(this, void 0, void 0, function* () {
        showCoordsCalculationScreen(true);
        const coords = appCache.coords;
        for (const coord of coords) {
            const ratio = appCache.wrapperElement.clientWidth / 1920;
            const calculatedCoordsArr = coord.initCoords.map(value => Math.floor(value * ratio).toString());
            coord.el.setAttribute('coords', calculatedCoordsArr.join(','));
        }
        showCoordsCalculationScreen(false);
    });
}
function switchScene(sceneName) {
    function finishSceneLoading(sceneElement) {
        const containedImgs = sceneElement.querySelectorAll('.base-img, .decoration-img');
        const containedImgsURLs = [...containedImgs].map(img => img.src);
        showImgLoadingScreen(true);
        let imgsNotLoadedCount = containedImgsURLs.length;
        for (const imgURL of containedImgsURLs) {
            const imgObject = new Image();
            imgObject.onerror = () => {
                console.error(`Image '${imgURL}' was not found.`);
                alert(`Obrázek ${imgURL} nemohl být načten.`);
            };
            imgObject.onload = () => {
                if (imgsNotLoadedCount > 1)
                    --imgsNotLoadedCount;
                else {
                    showImgLoadingScreen(false);
                    sceneElement.dataset.hideScene = 'false';
                }
            };
            imgObject.src = imgURL;
        }
    }
    const scenes = appCache.scenes;
    const scenesCount = scenes.length;
    let found = false;
    for (let i = 0; i < scenesCount; ++i) {
        const sceneI = scenes[i];
        if (sceneI.id === sceneName) {
            found = true;
            for (++i; i < scenesCount; ++i)
                scenes[i].el.dataset.hideScene = 'true';
            finishSceneLoading(sceneI.el);
            appState.activeScene = sceneName;
            break;
        }
        sceneI.el.dataset.hideScene = 'true';
    }
    if (!found)
        console.warn(`Scene [${sceneName}] was not found.`);
}
function addSceneLinksFunctionality() {
    const elms = document.querySelectorAll('[data-scene-link]');
    for (const el of elms) {
        el.addEventListener('click', () => __awaiter(this, void 0, void 0, function* () {
            if (appState.grabbedInventoryItem !== '')
                return;
            disableSceneClick(true);
            switchScene(el.dataset.sceneLink);
            yield sleep(1400);
            disableSceneClick(false);
        }));
    }
}
function showInventory(show) {
    if (show)
        appCache.inventoryElement.dataset.inventoryOpen = 'true';
    else
        appCache.inventoryElement.dataset.inventoryOpen = 'false';
}
function addInventoryItem(itemId) {
    const items = appCache.inventoryItems;
    const itemsCount = items.length;
    let found = false;
    for (let i = 0; i < itemsCount; ++i) {
        const itemI = items[i];
        if (itemI.id === itemId) {
            found = true;
            itemI.el.dataset.inventoryItemShow = 'true';
            showInventory(true);
            return;
        }
    }
    if (!found)
        console.warn(`Item [${itemId}] was not found.`);
}
function removeInventoryItem(itemId) {
    const items = appCache.inventoryItems;
    const itemsCount = items.length;
    let found = false;
    let isInventoryEmpty = true;
    for (let i = 0; i < itemsCount; ++i) {
        const itemI = items[i];
        if (itemI.id === itemId) {
            found = true;
            itemI.el.dataset.inventoryItemShow = 'false';
        }
        else if (itemI.el.dataset.inventoryItemShow === 'true')
            isInventoryEmpty = false;
    }
    if (isInventoryEmpty)
        showInventory(false);
    if (!found)
        console.warn(`Item [${itemId}] was not found.`);
}
function grabInventoryItem(itemId) {
    function continueWithGrabbing(itemId, itemElement) {
        itemElement.dataset.inventoryItemShow = 'false';
        appState.grabbedInventoryItem = itemId;
        appState.grabbedInventoryItemSrc = itemElement.src;
        document.body.classList.add('force-cursor');
        document.body.style.cursor = `url('${itemElement.src}'), help`;
    }
    const items = appCache.inventoryItems;
    const itemsCount = items.length;
    let found = false;
    let available = false;
    for (let i = 0; i < itemsCount; ++i) {
        const itemI = items[i];
        if (itemI.id === itemId) {
            found = true;
            if (itemI.el.dataset.inventoryItemShow === 'true')
                available = true;
            continueWithGrabbing(itemI.id, itemI.el);
            break;
        }
    }
    if (!found) {
        console.warn(`Item [${itemId}] was not found.`);
        return;
    }
    if (!available) {
        console.warn(`Item [${itemId}] is not available for grabbing.`);
        return;
    }
}
function freezeCursor(cursorPath) {
    return __awaiter(this, void 0, void 0, function* () {
        disableSceneClick(true);
        document.body.classList.add('force-cursor');
        document.body.style.cursor = `url('${cursorPath}'), help`;
        yield sleep(1200);
        if (appState.grabbedInventoryItem !== '')
            document.body.style.cursor = `url('${appState.grabbedInventoryItemSrc}'), help`;
        else {
            document.body.style.cursor = '';
            document.body.classList.remove('force-cursor');
        }
        disableSceneClick(false);
    });
}
function freezeQuestioning() {
    freezeCursor('./img/misc/kurzor-otaznik.png');
}
function playAngryTeta() {
    return __awaiter(this, void 0, void 0, function* () {
        disableSceneClick(true);
        yield sleep(800);
        switchScene('obyvak');
        const obyvakTeta = document.querySelector('[data-id="obyvak-teta"]');
        yield sleep(2000);
        switchScene('BLANK');
        yield sleep(500);
        const chodbaTetaLeva = document.querySelector('[data-id="chodba-teta-leva"]');
        const chodbaTetaSukne = document.querySelector('[data-id="chodba-teta-sukne"]');
        const chodbaTetaTelo = document.querySelector('[data-id="chodba-teta-telo"]');
        const chodbaTetaPrava = document.querySelector('[data-id="chodba-teta-prava"]');
        chodbaTetaLeva.style.animationName = 'teta-leva-ruka';
        chodbaTetaSukne.style.animationName = 'teta-pohyb, teta-sukne-houp';
        chodbaTetaTelo.style.animationName = 'teta-pohyb, teta-telo-houp';
        chodbaTetaPrava.style.animationName = 'teta-prava-ruka';
        switchScene('spoj-chodba');
        yield sleep(6000);
        const kuchyneTeta = document.querySelector('[data-id="kuchyne-teta"]');
        kuchyneTeta.style.opacity = '1';
        yield sleep(750);
        switchScene('kuchyne');
        yield sleep(2000);
        chodbaTetaLeva.style.animationName = '';
        chodbaTetaSukne.style.animationName = '';
        chodbaTetaTelo.style.animationName = '';
        chodbaTetaPrava.style.animationName = '';
        yield sleep(1500);
        switchScene('spoj-chodba');
        yield sleep(750);
        obyvakTeta.style.opacity = '0';
        disableSceneClick(false);
    });
}
function angryTetaCheck() {
    const drivkaKamnaElm = document.querySelector('[data-id="kuchyne-drivka"]');
    const hrnecCizrnaElm = document.querySelector('[data-id="kuchyne-hrnec-cizrna"]');
    if (drivkaKamnaElm.style.opacity === '1' && hrnecCizrnaElm.style.opacity === '1')
        playAngryTeta();
}
var specialActions = [
    {
        name: 'start',
        fn: () => __awaiter(void 0, void 0, void 0, function* () {
            disableSceneClick(true);
            switchScene('komiks-prolog');
            yield sleep(5000);
            for (let i = 1; i <= 7; ++i) {
                switchScene(`komiks-${i}`);
                yield sleep(4000);
            }
            switchScene('BLANK');
            yield sleep(1000);
            disableSceneClick(false);
            switchScene('vchod');
        })
    },
    {
        name: 'obyvak',
        fn: () => __awaiter(void 0, void 0, void 0, function* () {
            if (appState.grabbedInventoryItem !== '')
                return;
            const tetaElm = document.querySelector('[data-id="obyvak-teta"]');
            if (tetaElm.style.opacity === '1') {
                const originalScene = appState.activeScene;
                disableSceneClick(true);
                switchScene('obyvak');
                yield sleep(2000);
                for (let i = 0; i < 3; ++i) {
                    tetaElm.style.filter = 'drop-shadow(-4rem -4rem 2rem #d50000)';
                    yield sleep(400);
                    tetaElm.style.filter = '';
                    yield sleep(400);
                }
                switchScene(originalScene);
                yield sleep(1000);
                disableSceneClick(false);
            }
            else {
                disableSceneClick(true);
                switchScene('obyvak');
                yield sleep(1400);
                disableSceneClick(false);
            }
        })
    },
    {
        name: 'jidelna-kniha',
        fn: () => __awaiter(void 0, void 0, void 0, function* () {
            const grabbedItem = appState.grabbedInventoryItem;
            if (grabbedItem === 'kniha-1') {
                releaseGrabbedItem();
                removeInventoryItem('kniha-1');
                const jidelniKniha = document.querySelector('[data-id="jidelna-kniha"]');
                jidelniKniha.style.opacity = '1';
            }
            else if (grabbedItem == '') {
                const jidelniKniha = document.querySelector('[data-id="jidelna-kniha"]');
                if (jidelniKniha.style.opacity !== '0') {
                    disableSceneClick(true);
                    jidelniKniha.style.opacity = '0';
                    yield sleep(500);
                    addInventoryItem('kniha-1');
                    disableSceneClick(false);
                }
                else {
                    freezeQuestioning();
                }
            }
            else
                freezeQuestioning();
        })
    },
    {
        name: 'zahrada-sklep',
        fn: () => __awaiter(void 0, void 0, void 0, function* () {
            const grabbedItem = appState.grabbedInventoryItem;
            if (grabbedItem === 'klic-sklep') {
                disableSceneClick(true);
                appState.sklepUnlocked = true;
                releaseGrabbedItem();
                removeInventoryItem('klic-sklep');
                switchScene('sklep');
                yield sleep(1400);
                disableSceneClick(false);
            }
            else if (grabbedItem === '') {
                if (appState.sklepUnlocked) {
                    disableSceneClick(true);
                    switchScene('sklep');
                    yield sleep(1400);
                    disableSceneClick(false);
                }
                else {
                    freezeCursor('./img/misc/sklep-zamek.png');
                }
            }
            else {
                freezeQuestioning();
            }
        })
    },
    {
        name: 'altanek-drivka',
        fn: () => __awaiter(void 0, void 0, void 0, function* () {
            const grabbedItem = appState.grabbedInventoryItem;
            if (grabbedItem === 'drivka') {
                releaseGrabbedItem();
                removeInventoryItem('drivka');
                const drivkaElm = document.querySelector('[data-id="altanek-drivka"]');
                drivkaElm.style.opacity = '1';
            }
            else if (grabbedItem === '') {
                const drivkaElm = document.querySelector('[data-id="altanek-drivka"]');
                if (drivkaElm.style.opacity !== '0') {
                    disableSceneClick(true);
                    drivkaElm.style.opacity = '0';
                    yield sleep(500);
                    addInventoryItem('drivka');
                    disableSceneClick(false);
                }
                else {
                    freezeQuestioning();
                }
            }
            else {
                freezeQuestioning();
            }
        })
    },
    {
        name: 'sklep-naboje',
        fn: () => {
            if (appState.grabbedInventoryItem === '') {
                if (!appState.nabojePicked) {
                    appState.nabojePicked = true;
                    addInventoryItem('naboje');
                }
                else {
                    freezeQuestioning();
                }
            }
            else {
                freezeQuestioning();
            }
        }
    },
    {
        name: 'kuchyne-hrnec',
        fn: () => __awaiter(void 0, void 0, void 0, function* () {
            const grabbedItem = appState.grabbedInventoryItem;
            if (grabbedItem === 'hrnec-prazdny') {
                releaseGrabbedItem();
                removeInventoryItem('hrnec-prazdny');
                const hrnecPrazdnyElm = document.querySelector('[data-id="kuchyne-hrnec-prazdny"]');
                hrnecPrazdnyElm.style.opacity = '1';
            }
            else if (grabbedItem === 'hrnec-voda') {
                releaseGrabbedItem();
                removeInventoryItem('hrnec-voda');
                const hrnecVodaElm = document.querySelector('[data-id="kuchyne-hrnec-voda"]');
                hrnecVodaElm.style.opacity = '1';
            }
            else if (grabbedItem === 'cizrna') {
                const hrnecVodaElm = document.querySelector('[data-id="kuchyne-hrnec-voda"]');
                if (hrnecVodaElm.style.opacity === '1') {
                    releaseGrabbedItem();
                    removeInventoryItem('cizrna');
                    hrnecVodaElm.style.opacity = '0';
                    const hrnecCizrnaElm = document.querySelector('[data-id="kuchyne-hrnec-cizrna"]');
                    hrnecCizrnaElm.style.opacity = '1';
                    const hrnecArea = document.querySelector('[data-id="kuchyne-hrnec-area"]');
                    hrnecArea.remove();
                    angryTetaCheck();
                }
                else {
                    freezeQuestioning();
                }
            }
            else if (grabbedItem === '') {
                const hrnecPrazdnyElm = document.querySelector('[data-id="kuchyne-hrnec-prazdny"]');
                const hrnecVodaElm = document.querySelector('[data-id="kuchyne-hrnec-voda"]');
                if (hrnecPrazdnyElm.style.opacity === '1') {
                    disableSceneClick(true);
                    hrnecPrazdnyElm.style.opacity = '0';
                    yield sleep(500);
                    addInventoryItem('hrnec-prazdny');
                    disableSceneClick(false);
                }
                else if (hrnecVodaElm.style.opacity === '1') {
                    disableSceneClick(true);
                    hrnecVodaElm.style.opacity = '0';
                    yield sleep(500);
                    addInventoryItem('hrnec-voda');
                    disableSceneClick(false);
                }
                else {
                    freezeQuestioning();
                }
            }
            else {
                freezeQuestioning();
            }
        })
    },
    {
        name: 'kuchyne-kamna',
        fn: () => {
            if (appState.grabbedInventoryItem === 'drivka') {
                releaseGrabbedItem();
                removeInventoryItem('drivka');
                const drivkaElm = document.querySelector('[data-id="kuchyne-drivka"]');
                drivkaElm.style.opacity = '1';
                const drivkaArea = document.querySelector('[data-id="kuchyne-vnitrek-kamen"]');
                drivkaArea.remove();
                angryTetaCheck();
            }
            else {
                freezeQuestioning();
            }
        }
    },
    {
        name: 'kuchyne',
        fn: () => __awaiter(void 0, void 0, void 0, function* () {
            const tetaKuchyneElm = document.querySelector('[data-id="kuchyne-teta"]');
            if (tetaKuchyneElm.style.opacity === '0') {
                disableSceneClick(true);
                switchScene('kuchyne');
                yield sleep(1400);
                disableSceneClick(false);
            }
            else {
                const originalScene = appState.activeScene;
                disableSceneClick(true);
                switchScene('kuchyne');
                yield sleep(2000);
                for (let i = 0; i < 3; ++i) {
                    tetaKuchyneElm.style.filter = 'drop-shadow(-4rem -4rem 2rem #d50000)';
                    yield sleep(400);
                    tetaKuchyneElm.style.filter = '';
                    yield sleep(400);
                }
                switchScene(originalScene);
                yield sleep(1000);
                disableSceneClick(false);
            }
        })
    },
    {
        name: 'pristenek-hrnec',
        fn: () => __awaiter(void 0, void 0, void 0, function* () {
            const grabbedItem = appState.grabbedInventoryItem;
            if (grabbedItem === 'hrnec-prazdny') {
                releaseGrabbedItem();
                removeInventoryItem('hrnec-prazdny');
                const hrnecElm = document.querySelector('[data-id="hrnec-pristenek"]');
                hrnecElm.style.opacity = '1';
            }
            else if (grabbedItem === '') {
                const hrnecElm = document.querySelector('[data-id="hrnec-pristenek"]');
                if (hrnecElm.style.opacity !== '0') {
                    disableSceneClick(true);
                    hrnecElm.style.opacity = '0';
                    yield sleep(500);
                    addInventoryItem('hrnec-prazdny');
                    disableSceneClick(false);
                }
                else
                    freezeQuestioning();
            }
            else
                freezeQuestioning();
        })
    },
    {
        name: 'koupelna-voda',
        fn: () => {
            if (appState.grabbedInventoryItem === 'hrnec-prazdny') {
                releaseGrabbedItem();
                removeInventoryItem('hrnec-prazdny');
                addInventoryItem('hrnec-voda');
            }
            else
                freezeQuestioning();
        }
    },
    {
        name: 'spiz-sklenice',
        fn: () => __awaiter(void 0, void 0, void 0, function* () {
            const skleniceElm = document.querySelector('[data-id="spiz-sklenice"]');
            if (skleniceElm.style.opacity === '1') {
                freezeQuestioning();
            }
            else {
                if (appState.grabbedInventoryItem === '') {
                    disableSceneClick(true);
                    skleniceElm.style.opacity = '1';
                    yield sleep(500);
                    addInventoryItem('cizrna');
                    disableSceneClick(false);
                }
                else
                    freezeQuestioning();
            }
        })
    },
    {
        name: 'kumbal-prachovka',
        fn: () => __awaiter(void 0, void 0, void 0, function* () {
            const grabbedItem = appState.grabbedInventoryItem;
            const prachovkaElm = document.querySelector('[data-id="kumbal-prachovka"]');
            if (grabbedItem === '') {
                if (prachovkaElm.style.opacity === '1') {
                    disableSceneClick(true);
                    prachovkaElm.style.opacity = '0';
                    yield sleep(500);
                    addInventoryItem('prachovka');
                    disableSceneClick(false);
                }
                else
                    freezeQuestioning();
            }
            else if (grabbedItem === 'prachovka') {
                releaseGrabbedItem();
                removeInventoryItem('prachovka');
                prachovkaElm.style.opacity = '1';
            }
            else {
                freezeQuestioning();
            }
        })
    },
    {
        name: 'lovec-puska',
        fn: () => __awaiter(void 0, void 0, void 0, function* () {
            const grabbedItem = appState.grabbedInventoryItem;
            if (appState.puskaUnlocked) {
                if (grabbedItem === '') {
                    const puskaElm = document.querySelector('[data-id="lovec-puska"]');
                    if (puskaElm.style.opacity !== '0') {
                        disableSceneClick(true);
                        puskaElm.style.opacity = '0';
                        yield sleep(500);
                        addInventoryItem('puska');
                        disableSceneClick(false);
                    }
                    else
                        freezeQuestioning();
                }
                else if (grabbedItem === 'puska') {
                    releaseGrabbedItem();
                    removeInventoryItem('puska');
                    const puskaElm = document.querySelector('[data-id="lovec-puska"]');
                    puskaElm.style.opacity = '1';
                }
                else {
                    freezeQuestioning();
                }
            }
            else {
                if (grabbedItem === 'naboje') {
                    appState.puskaUnlocked = true;
                    releaseGrabbedItem();
                    removeInventoryItem('naboje');
                }
                else
                    freezeQuestioning();
            }
        })
    },
    {
        name: 'obrazy-ram',
        fn: () => __awaiter(void 0, void 0, void 0, function* () {
            const ramPrazdnyElm = document.querySelector('[data-id="obrazy-ram-prazdny"]');
            const ramObrazElm = document.querySelector('[data-id="obrazy-ram-plny"]');
            const grabbedItem = appState.grabbedInventoryItem;
            if (ramPrazdnyElm.style.opacity !== '0') {
                if (grabbedItem === 'obraz') {
                    disableSceneClick(true);
                    releaseGrabbedItem();
                    removeInventoryItem('obraz');
                    ramPrazdnyElm.style.opacity = '0';
                    yield sleep(100);
                    ramObrazElm.style.opacity = '1';
                    disableSceneClick(false);
                }
                else {
                    freezeQuestioning();
                }
            }
            else if (ramObrazElm.style.opacity !== '0') {
                if (grabbedItem === '') {
                    disableSceneClick(true);
                    ramObrazElm.style.opacity = '0';
                    const obrazStenaElm = document.querySelector('[data-id="obrazy-stena"]');
                    yield sleep(700);
                    obrazStenaElm.style.opacity = '1';
                    const obrazyRamArea = document.querySelector('[data-id="obrazy-ram-area"]');
                    obrazyRamArea.remove();
                    disableSceneClick(false);
                }
                else
                    freezeQuestioning();
            }
            else {
                freezeQuestioning();
            }
        })
    },
    {
        name: 'vchody',
        fn: () => __awaiter(void 0, void 0, void 0, function* () {
            const grabbedItem = appState.grabbedInventoryItem;
            if (grabbedItem === '') {
                const obrazStenaElm = document.querySelector('[data-id="obrazy-stena"]');
                if (obrazStenaElm.style.opacity !== '0') {
                    disableSceneClick(true);
                    switchScene('vchody');
                    yield sleep(1400);
                    disableSceneClick(false);
                }
                else
                    freezeQuestioning();
            }
        })
    },
    {
        name: 'knihovna-1',
        fn: () => {
            const grabbedItem = appState.grabbedInventoryItem;
            if (grabbedItem === 'kniha-1') {
                releaseGrabbedItem();
                removeInventoryItem('kniha-1');
                const knihaElm = document.querySelector('[data-id="knihovna-kniha-1"]');
                knihaElm.style.opacity = '1';
                const knihaArea = document.querySelector('[data-id="kniha-1-area"]');
                knihaArea.remove();
                zebrikCheck();
            }
            else
                freezeQuestioning();
        }
    },
    {
        name: 'knihovna-2',
        fn: () => {
            const grabbedItem = appState.grabbedInventoryItem;
            if (grabbedItem === 'kniha-2') {
                releaseGrabbedItem();
                removeInventoryItem('kniha-2');
                const knihaElm = document.querySelector('[data-id="knihovna-kniha-2"]');
                knihaElm.style.opacity = '1';
                const knihaArea = document.querySelector('[data-id="kniha-2-area"]');
                knihaArea.remove();
                zebrikCheck();
            }
            else
                freezeQuestioning();
        }
    },
    {
        name: 'puda',
        fn: () => __awaiter(void 0, void 0, void 0, function* () {
            const zebrikElm = document.querySelector('[data-id="vchody-zebrik"]');
            if (zebrikElm.style.opacity !== '0' && appState.grabbedInventoryItem === '') {
                disableSceneClick(true);
                switchScene('puda');
                yield sleep(1400);
                disableSceneClick(false);
            }
            else
                freezeQuestioning();
        })
    },
    {
        name: 'cestovatel-klic',
        fn: () => {
            const grabbedItem = appState.grabbedInventoryItem;
            const klicElm = document.querySelector('[data-id="cestovatel-klic"]');
            if (grabbedItem === '' && klicElm.style.opacity !== '0') {
                klicElm.style.opacity = '0';
                addInventoryItem('klic-loznice');
                const klicArea = document.querySelector('[data-id="cestovatel-klic-area"]');
                klicArea.remove();
            }
            else {
                freezeQuestioning();
            }
        }
    },
    {
        name: 'cestovatel-globus',
        fn: () => __awaiter(void 0, void 0, void 0, function* () {
            const grabbedItem = appState.grabbedInventoryItem;
            const globusCelyElm = document.querySelector('[data-id="cestovatel-globus-cely"]');
            if (globusCelyElm.style.opacity !== '0') {
                if (grabbedItem === 'puska') {
                    disableSceneClick(true);
                    releaseGrabbedItem();
                    removeInventoryItem('puska');
                    const dymElm = document.querySelector('[data-id="cestovatel-dym"]');
                    dymElm.style.opacity = '1';
                    const globusRozbityElm = document.querySelector('[data-id="cestovatel-globus-rozbity"]');
                    const klicElm = document.querySelector('[data-id="cestovatel-klic"]');
                    yield sleep(750);
                    globusCelyElm.style.opacity = '0';
                    globusRozbityElm.style.opacity = '1';
                    klicElm.style.opacity = '1';
                    yield sleep(750);
                    dymElm.style.transition = 'all 10s linear';
                    dymElm.style.transform = 'translateY(-40%) scale(110%)';
                    dymElm.style.opacity = '0';
                    disableSceneClick(false);
                }
                else
                    freezeQuestioning();
            }
            else {
                freezeQuestioning();
            }
        })
    },
    {
        name: 'epilog',
        fn: () => __awaiter(void 0, void 0, void 0, function* () {
            const malaRucickaElm = document.querySelector('[data-id="hodinky-kratka"]');
            const velkaRucickaElm = document.querySelector('[data-id="hodinky-dlouha"]');
            disableSceneClick(true);
            releaseGrabbedItem();
            showInventory(false);
            switchScene('BLANK');
            yield sleep(2000);
            switchScene('komiks-epilog');
            yield sleep(6000);
            switchScene('komiks-8');
            yield sleep(4000);
            switchScene('komiks-9');
            yield sleep(4000);
            malaRucickaElm.classList.add('anim1');
            velkaRucickaElm.classList.add('anim1');
            switchScene('komiks-10');
            yield sleep(11500);
            malaRucickaElm.classList.add('anim2');
            velkaRucickaElm.classList.add('anim2');
            yield sleep(18500);
            for (let i = 9; i >= 0; i--) {
                switchScene(`komiks-${i}`);
                yield sleep(1500);
            }
            yield sleep(8000);
            switchScene('titulky');
            yield sleep(10000);
            setInterval(() => generateNewTitulkyPath(), 2000);
        })
    },
    {
        name: 'relax-klic',
        fn: () => __awaiter(void 0, void 0, void 0, function* () {
            const grabbedItem = appState.grabbedInventoryItem;
            if (grabbedItem === '') {
                const klicElem = document.querySelector('[data-id="relax-klic"]');
                if (klicElem.style.opacity !== '0') {
                    disableSceneClick(true);
                    klicElem.style.opacity = '0';
                    yield sleep(500);
                    addInventoryItem('klic-sklep');
                    disableSceneClick(false);
                }
                else
                    freezeQuestioning();
            }
            else if (grabbedItem === 'klic-sklep') {
                releaseGrabbedItem();
                removeInventoryItem('klic-sklep');
                const klicElem = document.querySelector('[data-id="relax-klic"]');
                klicElem.style.opacity = '1';
            }
            else {
                freezeQuestioning();
            }
        })
    },
    {
        name: 'loznice',
        fn: () => __awaiter(void 0, void 0, void 0, function* () {
            const grabbedItem = appState.grabbedInventoryItem;
            if (grabbedItem === '') {
                if (appState.lozniceUnlocked) {
                    disableSceneClick(true);
                    switchScene('loznice');
                    yield sleep(1400);
                    disableSceneClick(false);
                }
                else {
                    freezeCursor('./img/misc/loznice-zamek.png');
                }
            }
            else if (grabbedItem === 'klic-loznice') {
                appState.lozniceUnlocked = true;
                releaseGrabbedItem();
                removeInventoryItem('klic-loznice');
                disableSceneClick(true);
                switchScene('loznice');
                yield sleep(1400);
                disableSceneClick(false);
            }
            else
                freezeQuestioning();
        })
    },
    {
        name: '2-patro-list',
        fn: () => __awaiter(void 0, void 0, void 0, function* () {
            const grabbedItem = appState.grabbedInventoryItem;
            if (grabbedItem === '') {
                if (appState.listActive) {
                    freezeQuestioning();
                }
                else {
                    const listElem = document.querySelector('[data-id="2-patro-list"]');
                    appState.listActive = true;
                    listElem.classList.add('rotate');
                    setTimeout(() => {
                        appState.listActive = false;
                        listElem.classList.remove('rotate');
                    }, 4000);
                }
            }
            else {
                freezeQuestioning();
            }
        })
    },
    {
        name: '2-patro-kumbal',
        fn: () => __awaiter(void 0, void 0, void 0, function* () {
            if (appState.grabbedInventoryItem === '') {
                if (appState.listActive) {
                    disableSceneClick(true);
                    switchScene('kumbal-2');
                    yield sleep(1400);
                    disableSceneClick(false);
                }
                else
                    freezeQuestioning();
            }
            else
                freezeQuestioning();
        })
    },
    {
        name: 'kumbal-2-obraz',
        fn: () => __awaiter(void 0, void 0, void 0, function* () {
            const grabbedItem = appState.grabbedInventoryItem;
            const obrazZaprasenyElem = document.querySelector('[data-id="kumbal-2-obraz-zapraseny"]');
            const obrazOcistenyElem = document.querySelector('[data-id="kumbal-2-obraz-ocisteny"]');
            if (obrazZaprasenyElem.style.opacity !== '0') {
                if (grabbedItem === 'prachovka') {
                    disableSceneClick(true);
                    releaseGrabbedItem();
                    removeInventoryItem('prachovka');
                    obrazOcistenyElem.style.opacity = '1';
                    yield sleep(450);
                    obrazZaprasenyElem.style.opacity = '0';
                    disableSceneClick(false);
                }
                else
                    freezeQuestioning();
            }
            else if (obrazOcistenyElem.style.opacity !== '0') {
                if (grabbedItem === '') {
                    const obrazArea = document.querySelector('[data-id="kumbal-2-obraz-area"]');
                    disableSceneClick(true);
                    obrazOcistenyElem.style.opacity = '0';
                    obrazArea.remove();
                    yield sleep(500);
                    addInventoryItem('obraz');
                    disableSceneClick(false);
                }
                else
                    freezeQuestioning();
            }
            else
                freezeQuestioning();
        })
    },
    {
        name: 'loznice-kniha',
        fn: () => __awaiter(void 0, void 0, void 0, function* () {
            const grabbedItem = appState.grabbedInventoryItem;
            if (grabbedItem === '') {
                const knihaElm = document.querySelector('[data-id="loznice-kniha"]');
                if (knihaElm.style.opacity !== '0') {
                    disableSceneClick(true);
                    knihaElm.style.opacity = '0';
                    yield sleep(500);
                    addInventoryItem('kniha-2');
                    disableSceneClick(false);
                }
                else
                    freezeQuestioning();
            }
            else if (grabbedItem == 'kniha-2') {
                const knihaElm = document.querySelector('[data-id="loznice-kniha"]');
                releaseGrabbedItem();
                removeInventoryItem('kniha-2');
                knihaElm.style.opacity = '1';
            }
            else
                freezeQuestioning();
        })
    }
];
function zebrikCheck() {
    const kniha1Elm = document.querySelector('[data-id="knihovna-kniha-1"]');
    const kniha2Elm = document.querySelector('[data-id="knihovna-kniha-2"]');
    if (kniha1Elm.style.opacity !== '0' &&
        kniha2Elm.style.opacity !== '0') {
        const zebrikElm = document.querySelector('[data-id="vchody-zebrik"]');
        zebrikElm.style.opacity = '1';
    }
}
function addSpecialActionsFunctionality() {
    const elms = document.querySelectorAll('[data-special-action]');
    for (const el of elms) {
        const actionName = el.dataset.specialAction;
        const actionFound = specialActions.find(action => action.name === actionName);
        if (actionFound === undefined)
            console.error(`Action [${actionName}] was not found in the specialActions array.`);
        else {
            el.addEventListener('click', () => actionFound.fn());
        }
    }
}
function releaseGrabbedItem() {
    const grabbedItemId = appState.grabbedInventoryItem;
    document.body.style.cursor = '';
    document.body.classList.remove('force-cursor');
    addInventoryItem(grabbedItemId);
    appState.grabbedInventoryItem = '';
    appState.grabbedInventoryItemSrc = '';
}
function handleInventoryClick(e) {
    if (appState.grabbedInventoryItem !== '') {
        releaseGrabbedItem();
    }
    else {
        const target = e.target;
        if (target !== appCache.inventoryElement) {
            const ItemId = target.dataset.inventoryItemId;
            grabInventoryItem(ItemId);
        }
    }
}
function disableSceneClick(disable) {
    if (disable)
        appCache.clickDisablerElement.dataset.clickDisablerActive = 'true';
    else
        appCache.clickDisablerElement.dataset.clickDisablerActive = 'false';
}
function showCoordsCalculationScreen(show) {
    if (show)
        appCache.coordsCalculationScreen.dataset.coordsCalculationScreenActive = 'true';
    else
        appCache.coordsCalculationScreen.dataset.coordsCalculationScreenActive = 'false';
}
function showImgLoadingScreen(show) {
    if (show)
        appCache.imgLoadingScreen.dataset.imgLoadingScreenActive = 'true';
    else
        appCache.imgLoadingScreen.dataset.imgLoadingScreenActive = 'false';
}
function debounceUpdateCoords() {
    if (appState.debounceUpdateCoordsActive)
        clearTimeout(appState.debounceUpdateCoordsTimeout);
    appState.debounceUpdateCoordsTimeout = setTimeout(() => {
        updateCoords();
        appState.debounceUpdateCoordsActive = true;
    }, 1000);
    appState.debounceUpdateCoordsActive = true;
}
function generateNewTitulkyPath() {
    const radius = Math.floor(Math.random() * 20) + 10;
    const x = Math.floor(Math.random() * (100 - 2 * (15 + radius))) + 15 + radius;
    const y = Math.floor(Math.random() * (100 - 2 * (10 + radius))) + 10 + radius;
    appCache.titulkyNegativ.style.clipPath = `circle(${radius}% at ${x}% ${y}%)`;
}
function main() {
    // compatibility check
    const cssAllowed = checkCssCompatibility();
    if (!cssAllowed)
        return;
    else
        hideCompatibilityInfo();
    // initial setting up
    addSceneLinksFunctionality();
    addSpecialActionsFunctionality();
    appCache.inventoryElement.addEventListener('click', e => handleInventoryClick(e));
    onresize = () => debounceUpdateCoords();
    // pre-loading
    const preloadImgsList = ['./img/misc/drivka-inventar.png', './img/misc/hrnec-prazdny-inventar.png', './img/misc/hrnec-voda-inventar.png', './img/misc/cizrna-inventar.png', './img/misc/prachovka-inventar.png', './img/misc/obraz-inventar.png', './img/misc/klick-sklep-inventar.png', './img/misc/naboje-inventar.png', './img/misc/puska-inventar.png', './img/misc/loznice-klic-inventar.png', './img/misc/kniha-2-inventar.png', './img/misc/kniha-1-inventar.png', './img/misc/drivka-inventar.png', './img/misc/hrnec-prazdny-inventar.png', './img/misc/hrnec-voda-inventar.png', './img/misc/klick-sklep-inventar.png', './img/misc/kniha-1-inventar.png', './img/misc/kniha-2-inventar.png', './img/misc/kurzor-doleva.png', './img/misc/kurzor-dolu.png', './img/misc/kurzor-doprava.png', './img/misc/kurzor-nahoru.png', './img/misc/kurzor-otaznik.png', './img/misc/kurzor-rukavice.png', './img/misc/kurzor-vychozi.png', './img/misc/loznice-klic-inventar.png', './img/misc/loznice-zamek.png', './img/misc/naboje-inventar.png', './img/misc/obraz-inventar.png', './img/misc/prachovka-inventar.png', './img/misc/puska-inventar.png', './img/misc/sklep-zamek.png'];
    let preloadImgsCount = preloadImgsList.length;
    let preloadImgsLoaded = 0;
    for (const url of preloadImgsList) {
        const imgObject = new Image();
        imgObject.onerror = () => alert(`Obrázek ${url} nebyl načten.`);
        imgObject.onload = () => {
            preloadImgsLoaded++;
            if (preloadImgsLoaded >= preloadImgsCount) {
                startTheGame();
            }
        };
        imgObject.src = url;
    }
}
function startTheGame() {
    updateCoords();
    switchScene('nazev');
}
main();
