update web, add clickable parts

This commit is contained in:
bridge
2025-11-22 15:07:09 +08:00
parent 8ae8b50e70
commit 99e4871a5d
18 changed files with 1085 additions and 13 deletions

View File

@@ -475,6 +475,45 @@ def get_hover_info(
"lines": serialize_hover_lines([str(line) for line in lines]),
}
@app.get("/api/detail")
def get_detail_info(
target_type: str = Query(alias="type"),
target_id: str = Query(alias="id")
):
"""获取结构化详情信息,替代/增强 hover info"""
world = game_instance.get("world")
if world is None:
raise HTTPException(status_code=503, detail="World not initialized")
target = None
if target_type == "avatar":
target = world.avatar_manager.avatars.get(target_id)
elif target_type == "region":
if world.map and hasattr(world.map, "regions"):
regions = world.map.regions
target = regions.get(target_id)
if target is None:
try:
target = regions.get(int(target_id))
except (ValueError, TypeError):
target = None
if target is None:
raise HTTPException(status_code=404, detail="Target not found")
if hasattr(target, "get_structured_info"):
return target.get_structured_info()
else:
# 回退到 hover info 如果没有结构化信息
if hasattr(target, "get_hover_info"):
lines = target.get_hover_info() or []
return {
"fallback": True,
"name": getattr(target, "name", target_id),
"lines": serialize_hover_lines([str(line) for line in lines])
}
return {"error": "No info available"}
class SetObjectiveRequest(BaseModel):
avatar_id: str
content: str