|
10 | 10 | }; |
11 | 11 |
|
12 | 12 | // state.js |
| 13 | + function resetBattleState() { |
| 14 | + state.gauntletChampion = null; |
| 15 | + state.gauntletWins = 0; |
| 16 | + state.gauntletDefeated = []; |
| 17 | + state.gauntletFalling = false; |
| 18 | + state.gauntletFallingItem = null; |
| 19 | + state.gauntletChampionRank = 0; |
| 20 | + } |
13 | 21 | var state; |
14 | 22 | var init_state = __esm({ |
15 | 23 | "state.js"() { |
|
1298 | 1306 | state.gauntletFalling = true; |
1299 | 1307 | state.gauntletFallingItem = loserItem; |
1300 | 1308 | state.gauntletDefeated = [winnerId]; |
| 1309 | + } else { |
| 1310 | + state.gauntletDefeated.push(winnerId); |
1301 | 1311 | } |
1302 | | - state.gauntletChampion = winnerItem; |
1303 | | - state.gauntletWins = 1; |
1304 | | - state.gauntletDefeated = [loserId]; |
1305 | 1312 | } |
1306 | 1313 | } |
1307 | 1314 | function updateChampionModeState(winnerId, winnerItem, loserId, newWinnerRating) { |
|
1316 | 1323 | } |
1317 | 1324 | } |
1318 | 1325 | async function handleSkip() { |
1319 | | - const leftPerformer = state.currentPair?.left; |
1320 | 1326 | const rightPerformer = state.currentPair?.right; |
1321 | | - if (!leftPerformer || !rightPerformer) { |
1322 | | - loadNewPair(); |
1323 | | - return; |
| 1327 | + if (state.currentMode === "gauntlet" && rightPerformer) { |
| 1328 | + state.skippedId = rightPerformer.id; |
| 1329 | + console.log(`[HotOrNot] Skipping Gauntlet opponent: ${rightPerformer.name}`); |
1324 | 1330 | } |
1325 | 1331 | if (state.currentMode === "swiss") { |
1326 | | - console.log(`[HotOrNot] Tying Swiss match: ${leftPerformer.name} vs ${rightPerformer.name}`); |
1327 | | - try { |
1328 | | - await handleComparison( |
1329 | | - leftPerformer.id, |
1330 | | - rightPerformer.id, |
1331 | | - leftPerformer.rating100, |
1332 | | - rightPerformer.rating100, |
1333 | | - null, |
1334 | | - leftPerformer, |
1335 | | - rightPerformer, |
1336 | | - true |
1337 | | - // <--- The isDraw flag |
1338 | | - ); |
1339 | | - } catch (err) { |
1340 | | - console.error("[HotOrNot] Tie failed:", err); |
1341 | | - } |
1342 | 1332 | } |
1343 | | - loadNewPair(); |
| 1333 | + const { loadNewPair: loadNewPair2 } = await Promise.resolve().then(() => (init_battle_engine(), battle_engine_exports)); |
| 1334 | + loadNewPair2(); |
1344 | 1335 | } |
1345 | 1336 | function applyVisualFeedback(winnerCard, loserCard, winnerRating, loserRating, outcome) { |
1346 | 1337 | winnerCard.classList.add("hon-winner"); |
|
1350 | 1341 | if (loserCard) { |
1351 | 1342 | showRatingAnimation(loserCard, loserRating, outcome.newLoserRating, outcome.loserChange, false); |
1352 | 1343 | } |
1353 | | - setTimeout(() => loadNewPair(), 1500); |
| 1344 | + setTimeout(() => { |
| 1345 | + const isVictoryVisible = document.querySelector(".hon-victory-screen"); |
| 1346 | + if (!isVictoryVisible) { |
| 1347 | + loadNewPair(); |
| 1348 | + } else { |
| 1349 | + console.log("[HotOrNot] Victory screen detected, cancelling next pair load."); |
| 1350 | + } |
| 1351 | + }, 1500); |
1354 | 1352 | } |
1355 | 1353 | var init_match_handler = __esm({ |
1356 | 1354 | "match-handler.js"() { |
|
1363 | 1361 | }); |
1364 | 1362 |
|
1365 | 1363 | // battle-engine.js |
| 1364 | + var battle_engine_exports = {}; |
| 1365 | + __export(battle_engine_exports, { |
| 1366 | + fetchChampionPairPerformers: () => fetchChampionPairPerformers, |
| 1367 | + fetchChampionPairScenes: () => fetchChampionPairScenes, |
| 1368 | + fetchGauntletPairPerformers: () => fetchGauntletPairPerformers, |
| 1369 | + fetchGauntletPairScenes: () => fetchGauntletPairScenes, |
| 1370 | + fetchPair: () => fetchPair, |
| 1371 | + fetchSwissPairImages: () => fetchSwissPairImages, |
| 1372 | + fetchSwissPairPerformers: () => fetchSwissPairPerformers, |
| 1373 | + fetchSwissPairScenes: () => fetchSwissPairScenes, |
| 1374 | + handleMatchmakingLogic: () => handleMatchmakingLogic, |
| 1375 | + isChampionVictory: () => isChampionVictory, |
| 1376 | + loadNewPair: () => loadNewPair |
| 1377 | + }); |
1366 | 1378 | async function fetchPair() { |
1367 | 1379 | const { battleType, currentMode, selectedGenders } = state; |
1368 | 1380 | if (currentMode === "swiss") { |
|
1815 | 1827 | document.removeEventListener("keydown", handleGlobalKeys); |
1816 | 1828 | return; |
1817 | 1829 | } |
1818 | | - const hotKeys = ["ArrowLeft", "ArrowRight", " ", "Space"]; |
1819 | | - if (hotKeys.includes(e.key) || hotKeys.includes(e.code)) { |
1820 | | - e.stopImmediatePropagation(); |
| 1830 | + const isSpace = e.key === " " || e.code === "Space"; |
| 1831 | + const hotKeys = ["ArrowLeft", "ArrowRight", ...isSpace ? [" ", "Space"] : []]; |
| 1832 | + if (hotKeys.includes(e.key) || e.code && hotKeys.includes(e.code)) { |
1821 | 1833 | e.preventDefault(); |
| 1834 | + e.stopImmediatePropagation(); |
1822 | 1835 | if (e.key === "ArrowLeft") { |
1823 | | - const leftCard = activeModal.querySelector('.hon-scene-card[data-side="left"]'); |
1824 | | - leftCard?.querySelector(".hon-scene-body")?.click(); |
1825 | | - } |
1826 | | - if (e.key === "ArrowRight") { |
1827 | | - const rightCard = activeModal.querySelector('.hon-scene-card[data-side="right"]'); |
1828 | | - rightCard?.querySelector(".hon-scene-body")?.click(); |
1829 | | - } |
1830 | | - if (e.key === " " || e.code === "Space") { |
1831 | | - document.getElementById("hon-skip-btn")?.click(); |
| 1836 | + activeModal.querySelector('.hon-scene-card[data-side="left"] .hon-scene-body')?.click(); |
| 1837 | + } else if (e.key === "ArrowRight") { |
| 1838 | + activeModal.querySelector('.hon-scene-card[data-side="right"] .hon-scene-body')?.click(); |
| 1839 | + } else if (isSpace) { |
| 1840 | + const skipBtn = document.getElementById("hon-skip-btn") || activeModal.querySelector(".hon-gauntlet-skip"); |
| 1841 | + if (skipBtn) { |
| 1842 | + skipBtn.click(); |
| 1843 | + } |
1832 | 1844 | } |
1833 | 1845 | } |
1834 | 1846 | } |
|
1873 | 1885 | console.error("CRASH in _buildAndOpenModal:", err); |
1874 | 1886 | } |
1875 | 1887 | } |
1876 | | - function openRankingModal() { |
| 1888 | + async function openRankingModal() { |
1877 | 1889 | try { |
1878 | 1890 | const path = window.location.pathname; |
1879 | | - state.battleType = path.includes("/images") ? "images" : "performers"; |
1880 | 1891 | const performerMatch = path.match(/\/performers\/(\d+)/); |
1881 | | - if (performerMatch && state.currentMode === "gauntlet") { |
| 1892 | + const isSinglePerformerPage = !!performerMatch; |
| 1893 | + if (isSinglePerformerPage) { |
1882 | 1894 | const performerId = performerMatch[1]; |
1883 | | - Promise.resolve().then(() => (init_api_client(), api_client_exports)).then(async ({ fetchPerformerById: fetchPerformerById2 }) => { |
1884 | | - try { |
1885 | | - const performer = await fetchPerformerById2(performerId); |
1886 | | - if (performer) { |
1887 | | - state.gauntletChampion = performer; |
1888 | | - state.gauntletWins = 0; |
1889 | | - state.gauntletDefeated = []; |
1890 | | - state.gauntletFalling = false; |
1891 | | - state.gauntletFallingItem = null; |
1892 | | - } |
1893 | | - } catch (e) { |
1894 | | - console.warn("[HotOrNot] Could not pre-seed performer for gauntlet:", e); |
1895 | | - } |
| 1895 | + if (state.currentMode === "gauntlet" && state.gauntletChampion && state.gauntletChampion.id.toString() === performerId) { |
| 1896 | + console.log("[HotOrNot] Resuming existing Gauntlet run."); |
1896 | 1897 | _buildAndOpenModal(); |
1897 | | - }); |
1898 | | - return; |
| 1898 | + return; |
| 1899 | + } |
| 1900 | + state.battleType = "performers"; |
| 1901 | + state.currentMode = "gauntlet"; |
| 1902 | + const { fetchPerformerById: fetchPerformerById2 } = await Promise.resolve().then(() => (init_api_client(), api_client_exports)); |
| 1903 | + try { |
| 1904 | + const performer = await fetchPerformerById2(performerId); |
| 1905 | + if (performer) { |
| 1906 | + state.gauntletChampion = performer; |
| 1907 | + state.gauntletWins = 0; |
| 1908 | + state.gauntletDefeated = []; |
| 1909 | + state.gauntletFalling = false; |
| 1910 | + state.gauntletFallingItem = null; |
| 1911 | + } |
| 1912 | + } catch (e) { |
| 1913 | + console.warn("[HotOrNot] Could not pre-seed performer:", e); |
| 1914 | + } |
| 1915 | + } else { |
| 1916 | + state.battleType = path.includes("/images") ? "images" : "performers"; |
| 1917 | + state.currentMode = "swiss"; |
| 1918 | + state.gauntletChampion = null; |
1899 | 1919 | } |
1900 | 1920 | _buildAndOpenModal(); |
1901 | 1921 | } catch (err) { |
|
1983 | 2003 | }); |
1984 | 2004 | const skipBtn = parent.querySelector("#hon-skip-btn"); |
1985 | 2005 | if (skipBtn) { |
1986 | | - skipBtn.style.display = state.currentMode === "swiss" ? "block" : "none"; |
| 2006 | + const isSkippableMode = state.currentMode === "swiss" || state.currentMode === "gauntlet"; |
| 2007 | + skipBtn.style.display = isSkippableMode ? "block" : "none"; |
1987 | 2008 | skipBtn.onclick = () => { |
1988 | | - if (state.currentMode === "swiss") |
| 2009 | + if (state.currentMode === "swiss" || state.currentMode === "gauntlet") { |
1989 | 2010 | handleSkip(); |
| 2011 | + } |
1990 | 2012 | }; |
1991 | 2013 | } |
1992 | 2014 | parent.querySelectorAll(".hon-gender-btn").forEach((btn) => { |
1993 | 2015 | btn.addEventListener("click", () => handleGenderToggle(btn.dataset.gender)); |
1994 | 2016 | }); |
1995 | 2017 | parent.querySelectorAll(".hon-mode-btn").forEach((btn) => { |
1996 | | - btn.addEventListener("click", () => { |
| 2018 | + btn.addEventListener("click", async () => { |
1997 | 2019 | const newMode = btn.dataset.mode; |
1998 | 2020 | if (state.currentMode === newMode) |
1999 | 2021 | return; |
2000 | 2022 | state.currentMode = newMode; |
2001 | | - state.gauntletChampion = null; |
2002 | | - state.gauntletFalling = false; |
2003 | | - state.gauntletWins = 0; |
2004 | | - state.gauntletDefeated = []; |
| 2023 | + const { getPerformerIdFromUrl: getPerformerIdFromUrl2 } = await Promise.resolve().then(() => (init_ui_modal(), ui_modal_exports)); |
| 2024 | + const urlPerformerId = getPerformerIdFromUrl2(); |
| 2025 | + if (!urlPerformerId || state.gauntletChampion && state.gauntletChampion.id.toString() !== urlPerformerId) { |
| 2026 | + state.gauntletChampion = null; |
| 2027 | + state.gauntletWins = 0; |
| 2028 | + state.gauntletDefeated = []; |
| 2029 | + state.gauntletFalling = false; |
| 2030 | + } |
2005 | 2031 | const modalContent = document.querySelector(".hon-modal-content"); |
2006 | | - const mainContainer = document.getElementById("stash-main-container"); |
2007 | 2032 | if (modalContent) { |
2008 | 2033 | modalContent.innerHTML = `<span class="hon-modal-close">\u2715</span>${createMainUI()}`; |
2009 | 2034 | attachEventListeners(modalContent); |
2010 | 2035 | modalContent.querySelector(".hon-modal-close").onclick = () => Promise.resolve().then(() => (init_ui_modal(), ui_modal_exports)).then((m) => m.closeRankingModal()); |
2011 | | - } else if (mainContainer) { |
2012 | | - mainContainer.innerHTML = createMainUI(); |
2013 | | - attachEventListeners(mainContainer); |
2014 | 2036 | } |
2015 | 2037 | if (newMode === "gauntlet") { |
2016 | | - window.showPerformerSelection(); |
| 2038 | + if (urlPerformerId && !state.gauntletChampion) { |
| 2039 | + const { fetchPerformerById: fetchPerformerById2 } = await Promise.resolve().then(() => (init_api_client(), api_client_exports)); |
| 2040 | + state.gauntletChampion = await fetchPerformerById2(urlPerformerId); |
| 2041 | + } |
| 2042 | + if (state.gauntletChampion) { |
| 2043 | + const selEl = document.getElementById("hon-performer-selection"); |
| 2044 | + const compEl = document.getElementById("hon-comparison-area"); |
| 2045 | + if (selEl) |
| 2046 | + selEl.style.display = "none"; |
| 2047 | + if (compEl) |
| 2048 | + compEl.style.display = ""; |
| 2049 | + loadNewPair(); |
| 2050 | + } else { |
| 2051 | + window.showPerformerSelection(); |
| 2052 | + } |
2017 | 2053 | } else { |
2018 | 2054 | loadNewPair(); |
2019 | 2055 | } |
|
0 commit comments