Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions frontend/src/components/BotList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ let {
orangePlayers = $bindable(),
map,
duplicateAgentIds = new Set<string>(),
getLatestBotInfo,
getLatestScriptInfo,
}: {
bots: DraggablePlayer[];
scripts: ToggleableScript[];
Expand All @@ -43,6 +45,8 @@ let {
orangePlayers: DraggablePlayer[];
map: string;
duplicateAgentIds: Set<string>;
getLatestBotInfo?: (tomlPath: string) => Promise<BotInfo | null>;
getLatestScriptInfo?: (tomlPath: string) => Promise<BotInfo | null>;
} = $props();
const flipDurationMs = 100;

Expand Down Expand Up @@ -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;
}
Expand Down
30 changes: 30 additions & 0 deletions frontend/src/pages/Home.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,31 @@ async function updateScripts() {
loadingScripts = false;
}

async function getLatestBotInfo(tomlPath: string): Promise<BotInfo | null> {
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<ScriptInfo | null> {
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();
Expand Down Expand Up @@ -373,6 +398,9 @@ async function onMatchStart(randomizeMap: boolean) {
];
}

await updateBots();
await updateScripts();

const options: StartMatchOptions = {
map: $mapStore,
gameMode: mode,
Expand Down Expand Up @@ -476,6 +504,8 @@ function handleSearch(event: Event) {
selectedTeam={selectedTeam}
map={$mapStore}
{duplicateAgentIds}
getLatestBotInfo={getLatestBotInfo}
getLatestScriptInfo={getLatestScriptInfo}
/>
</div>

Expand Down