Implement scoped memory graph and refresh defaults

This commit is contained in:
Youzini-afk
2026-04-03 20:48:07 +08:00
parent fbd8b00f1f
commit c60f60f349
21 changed files with 1706 additions and 352 deletions

View File

@@ -3,6 +3,7 @@
import { getNodeColors } from './themes.js';
import { getGraphNodeLabel, getNodeDisplayName } from './node-labels.js';
import { normalizeMemoryScope } from './memory-scope.js';
/**
* @typedef {Object} GraphNode
@@ -31,6 +32,12 @@ const DEFAULT_FORCE_CONFIG = {
gridColor: 'rgba(255,255,255,0.03)',
};
const SCOPE_OUTLINE_COLORS = {
objective: '#57c7ff',
character: '#ffb347',
user: '#7dff9b',
};
export class GraphRenderer {
/**
* @param {HTMLCanvasElement} canvas
@@ -236,6 +243,12 @@ export class GraphRenderer {
const color = this.colors[node.type] || this.colors.event;
const isSelected = node === this.selectedNode;
const isHovered = node === this.hoveredNode;
const scope = normalizeMemoryScope(node.raw?.scope);
const outlineColor = scope.layer === 'pov'
? (scope.ownerType === 'user'
? SCOPE_OUTLINE_COLORS.user
: SCOPE_OUTLINE_COLORS.character)
: SCOPE_OUTLINE_COLORS.objective;
// 发光效果
if (isSelected || isHovered) {
@@ -255,11 +268,9 @@ export class GraphRenderer {
ctx.fill();
// 边框
if (isSelected) {
ctx.strokeStyle = '#fff';
ctx.lineWidth = 2;
ctx.stroke();
}
ctx.strokeStyle = isSelected ? '#fff' : outlineColor;
ctx.lineWidth = isSelected ? 2.5 : 1.5;
ctx.stroke();
// 标签
ctx.fillStyle = `rgba(255,255,255,${isHovered || isSelected ? 0.95 : 0.65})`;