diff --git a/frontend/src/components/BotList.svelte b/frontend/src/components/BotList.svelte index 7086e6a..50a19c2 100644 --- a/frontend/src/components/BotList.svelte +++ b/frontend/src/components/BotList.svelte @@ -32,6 +32,8 @@ let { orangePlayers = $bindable(), map, duplicateAgentIds = new Set(), + getLatestBotInfo, + getLatestScriptInfo, }: { bots: DraggablePlayer[]; scripts: ToggleableScript[]; @@ -43,6 +45,8 @@ let { orangePlayers: DraggablePlayer[]; map: string; duplicateAgentIds: Set; + getLatestBotInfo?: (tomlPath: string) => Promise; + getLatestScriptInfo?: (tomlPath: string) => Promise; } = $props(); const flipDurationMs = 100; @@ -250,14 +254,42 @@ function toggleScript(id: string) { enabledScripts[id] = !enabledScripts[id]; } -function handleBotInfoClick(bot: DraggablePlayer) { +async function handleBotInfoClick(bot: DraggablePlayer) { if (bot.info instanceof BotInfo) { + + try { + if (getLatestBotInfo) { + const refreshed = await getLatestBotInfo(bot.info.tomlPath); + if (refreshed) { + selectedAgent = [refreshed, refreshed.config?.settings?.name ?? bot.displayName, (refreshed as any).icon ?? bot.icon]; + showInfoModal = true; + return; + } + } + } catch (err) { + toast.error("Failed to get latest bot info: " + err, { duration: 10000 }); + } + selectedAgent = [bot.info, bot.displayName, bot.icon]; showInfoModal = true; } } -function handleScriptInfoClick(script: ToggleableScript) { +async function handleScriptInfoClick(script: ToggleableScript) { + + try { + if (getLatestScriptInfo) { + const refreshed = await getLatestScriptInfo(script.info.tomlPath); + if (refreshed) { + selectedAgent = [refreshed, refreshed.config?.settings?.name ?? script.displayName, (refreshed as any).icon ?? script.icon]; + showInfoModal = true; + return; + } + } + } catch (err) { + toast.error("Failed to get latest script info: " + err, { duration: 10000 }); + } + selectedAgent = [script.info, script.displayName, script.icon]; showInfoModal = true; } diff --git a/frontend/src/pages/Home.svelte b/frontend/src/pages/Home.svelte index 435f7bb..dab1410 100644 --- a/frontend/src/pages/Home.svelte +++ b/frontend/src/pages/Home.svelte @@ -317,6 +317,31 @@ async function updateScripts() { loadingScripts = false; } +async function getLatestBotInfo(tomlPath: string): Promise { + try { + await updateBots(); + const found = players.find( + (p) => p.info instanceof BotInfo && p.info.tomlPath === tomlPath, + ); + return found ? (found.info as BotInfo) : null; + } catch (err) { + console.error("Failed to get latest bot info: ", err); + return null; + } +} + +async function getLatestScriptInfo(tomlPath: string): Promise { + try { + await updateScripts(); + const found = scripts.find((s) => s.info.tomlPath === tomlPath); + return found ? (found.info as BotInfo) : null; + } catch (err) { + console.error("Failed to get latest script info: ", err); + return null; + } +} + + $effect(() => { localStorage.setItem("BOT_SEARCH_PATHS", JSON.stringify(paths)); updateBots(); @@ -373,6 +398,9 @@ async function onMatchStart(randomizeMap: boolean) { ]; } + await updateBots(); + await updateScripts(); + const options: StartMatchOptions = { map: $mapStore, gameMode: mode, @@ -476,6 +504,8 @@ function handleSearch(event: Event) { selectedTeam={selectedTeam} map={$mapStore} {duplicateAgentIds} + getLatestBotInfo={getLatestBotInfo} + getLatestScriptInfo={getLatestScriptInfo} />