fix: restore pixel office characters on page switch

This commit is contained in:
xmanrui
2026-03-17 03:23:49 +08:00
parent 3af09fbbfb
commit 030bd4c8f5
3 changed files with 43 additions and 2 deletions
+2 -2
View File
@@ -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
+4
View File
@@ -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)
+37
View File
@@ -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