Merge pull request #64 from liaoandi/fix/guest-agent-overlap

fix: prevent guest agents from overlapping when >3 in same area
This commit is contained in:
ringhyacinth 2026-03-06 16:13:54 +08:00 committed by GitHub
commit e5f3fc9247
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 44 additions and 14 deletions

View file

@ -225,22 +225,35 @@ const AREA_POSITIONS = {
breakroom: [
{ x: 620, y: 180 },
{ x: 560, y: 220 },
{ x: 680, y: 210 }
{ x: 680, y: 210 },
{ x: 540, y: 170 },
{ x: 700, y: 240 },
{ x: 600, y: 250 },
{ x: 650, y: 160 },
{ x: 580, y: 200 }
],
writing: [
{ x: 760, y: 320 },
{ x: 830, y: 280 },
{ x: 690, y: 350 }
{ x: 690, y: 350 },
{ x: 770, y: 260 },
{ x: 850, y: 340 },
{ x: 720, y: 300 },
{ x: 800, y: 370 },
{ x: 750, y: 240 }
],
error: [
{ x: 180, y: 260 },
{ x: 120, y: 220 },
{ x: 240, y: 230 }
{ x: 240, y: 230 },
{ x: 160, y: 200 },
{ x: 220, y: 270 },
{ x: 140, y: 250 },
{ x: 200, y: 210 },
{ x: 260, y: 260 }
]
};
let areaPositionCounters = { breakroom: 0, writing: 0, error: 0 };
// 状态控制栏函数(用于测试)
function setState(state, detail) {
@ -904,9 +917,12 @@ function fetchAgents() {
.then(data => {
if (!Array.isArray(data)) return;
// 重置位置计数器
areaPositionCounters = { breakroom: 0, writing: 0, error: 0 };
// 处理每个 agent
// 按区域分配不同位置索引,避免重叠
const areaSlots = { breakroom: 0, writing: 0, error: 0 };
for (let agent of data) {
const area = agent.area || 'breakroom';
agent._slotIndex = areaSlots[area] || 0;
areaSlots[area] = (areaSlots[area] || 0) + 1;
renderAgent(agent);
}
// 移除不再存在的 agent
@ -925,10 +941,9 @@ function fetchAgents() {
});
}
function getAreaPosition(area) {
function getAreaPosition(area, slotIndex) {
const positions = AREA_POSITIONS[area] || AREA_POSITIONS.breakroom;
const idx = areaPositionCounters[area] || 0;
areaPositionCounters[area] = (idx + 1) % positions.length;
const idx = (slotIndex || 0) % positions.length;
return positions[idx];
}
@ -940,7 +955,7 @@ function renderAgent(agent) {
const isMain = !!agent.isMain;
// 获取这个 agent 在区域里的位置
const pos = getAreaPosition(area);
const pos = getAreaPosition(area, agent._slotIndex || 0);
const baseX = pos.x;
const baseY = pos.y;

View file

@ -3493,17 +3493,32 @@ function toggleBrokerPanel() {
breakroom: [
{ x: 511, y: 262 },
{ x: 841, y: 621 },
{ x: 690, y: 470 }
{ x: 690, y: 470 },
{ x: 600, y: 340 },
{ x: 770, y: 540 },
{ x: 550, y: 420 },
{ x: 720, y: 310 },
{ x: 650, y: 580 }
],
writing: [
{ x: 190, y: 526 },
{ x: 380, y: 683 },
{ x: 300, y: 610 }
{ x: 300, y: 610 },
{ x: 240, y: 570 },
{ x: 350, y: 640 },
{ x: 160, y: 600 },
{ x: 420, y: 560 },
{ x: 280, y: 660 }
],
error: [
{ x: 932, y: 275 },
{ x: 1109, y: 327 },
{ x: 1020, y: 305 }
{ x: 1020, y: 305 },
{ x: 960, y: 340 },
{ x: 1070, y: 280 },
{ x: 990, y: 260 },
{ x: 1050, y: 350 },
{ x: 940, y: 310 }
]
};
const arr = map[area] || map.breakroom;