mirror of
https://github.com/xmanrui/OpenClaw-bot-review.git
synced 2026-07-27 22:25:52 +00:00
fix: restore pixel office characters on page switch
This commit is contained in:
@@ -462,8 +462,8 @@ export default function PixelOfficePage() {
|
||||
if (!officeReady || !office || cachedAgents.length === 0) return
|
||||
|
||||
for (const [agentId, charId] of agentIdMapRef.current) {
|
||||
office.removeAllSubagents(charId)
|
||||
office.removeAgent(charId)
|
||||
office.removeAllSubagentsImmediately(charId)
|
||||
office.removeAgentImmediately(charId)
|
||||
agentIdMapRef.current.delete(agentId)
|
||||
}
|
||||
nextIdRef.current.current = 1
|
||||
|
||||
@@ -57,6 +57,10 @@ export function syncAgentsToOffice(
|
||||
}
|
||||
|
||||
let charId = agentIdMap.get(activity.agentId)
|
||||
if (charId !== undefined && !office.characters.has(charId)) {
|
||||
agentIdMap.delete(activity.agentId)
|
||||
charId = undefined
|
||||
}
|
||||
if (charId === undefined) {
|
||||
charId = nextIdRef.current++
|
||||
agentIdMap.set(activity.agentId, charId)
|
||||
|
||||
@@ -1082,6 +1082,18 @@ export class OfficeState {
|
||||
ch.bubbleType = null
|
||||
}
|
||||
|
||||
removeAgentImmediately(id: number): void {
|
||||
const ch = this.characters.get(id)
|
||||
if (!ch) return
|
||||
if (ch.seatId) {
|
||||
const seat = this.seats.get(ch.seatId)
|
||||
if (seat) seat.assigned = false
|
||||
}
|
||||
if (this.selectedAgentId === id) this.selectedAgentId = null
|
||||
if (this.cameraFollowId === id) this.cameraFollowId = null
|
||||
this.characters.delete(id)
|
||||
}
|
||||
|
||||
/** Find seat uid at a given tile position, or null */
|
||||
getSeatAtTile(col: number, row: number): string | null {
|
||||
for (const [uid, seat] of this.seats) {
|
||||
@@ -1346,6 +1358,31 @@ export class OfficeState {
|
||||
}
|
||||
}
|
||||
|
||||
removeAllSubagentsImmediately(parentAgentId: number): void {
|
||||
const toRemove: string[] = []
|
||||
const toDeleteIds: number[] = []
|
||||
for (const [key, id] of this.subagentIdMap) {
|
||||
const meta = this.subagentMeta.get(id)
|
||||
if (!meta || meta.parentAgentId !== parentAgentId) continue
|
||||
const ch = this.characters.get(id)
|
||||
if (ch?.seatId) {
|
||||
const seat = this.seats.get(ch.seatId)
|
||||
if (seat) seat.assigned = false
|
||||
}
|
||||
if (this.selectedAgentId === id) this.selectedAgentId = null
|
||||
if (this.cameraFollowId === id) this.cameraFollowId = null
|
||||
this.subagentMeta.delete(id)
|
||||
toRemove.push(key)
|
||||
toDeleteIds.push(id)
|
||||
}
|
||||
for (const key of toRemove) {
|
||||
this.subagentIdMap.delete(key)
|
||||
}
|
||||
for (const id of toDeleteIds) {
|
||||
this.characters.delete(id)
|
||||
}
|
||||
}
|
||||
|
||||
/** Look up the sub-agent character ID for a given parent+toolId, or null */
|
||||
getSubagentId(parentAgentId: number, parentToolId: string): number | null {
|
||||
return this.subagentIdMap.get(`${parentAgentId}:${parentToolId}`) ?? null
|
||||
|
||||
Reference in New Issue
Block a user