Merge branch 'master' into feat/create_entrance
This commit is contained in:
@@ -5458,6 +5458,31 @@ iframe.preview-frame {
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
.game-resource-card-type-badge {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 8px;
|
||||
z-index: 2;
|
||||
display: inline-flex;
|
||||
max-width: calc(100% - 16px);
|
||||
align-items: center;
|
||||
min-width: 0;
|
||||
padding: 4px 8px;
|
||||
overflow: hidden;
|
||||
border: 1px solid rgb(255 255 255 / 72%);
|
||||
border-radius: 999px;
|
||||
background: rgb(75 48 38 / 84%);
|
||||
color: #fff;
|
||||
font-size: 10px;
|
||||
font-weight: 900;
|
||||
line-height: 1;
|
||||
letter-spacing: 0.02em;
|
||||
pointer-events: none;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
box-shadow: 0 8px 18px rgb(96 62 47 / 20%);
|
||||
}
|
||||
|
||||
.game-resource-card-open {
|
||||
position: absolute;
|
||||
z-index: 1;
|
||||
|
||||
@@ -82,10 +82,10 @@ import {
|
||||
normalizeInfiniteResourceCanvasViewport,
|
||||
RESOURCE_CANVAS_DRAG_THRESHOLD,
|
||||
RESOURCE_CANVAS_FIT_PADDING,
|
||||
RESOURCE_CANVAS_INITIAL_FIT_MAX_SCALE,
|
||||
RESOURCE_CANVAS_SECTION_MIN_HEIGHT,
|
||||
RESOURCE_CANVAS_SECTION_MIN_WIDTH,
|
||||
RESOURCE_CANVAS_SECTION_ORDER,
|
||||
RESOURCE_CANVAS_VISIBLE_SECTION_ORDER,
|
||||
type ResourceCanvasCardSize,
|
||||
resourceCanvasCardSize,
|
||||
resourceCanvasContentBounds,
|
||||
@@ -123,6 +123,7 @@ import {
|
||||
type ProjectResource,
|
||||
type ProjectResourceCategory,
|
||||
projectResourcesFromReadModels,
|
||||
projectResourceTypeLabel,
|
||||
} from './resourceProjectionModel';
|
||||
import {
|
||||
clampProjectResourceSectionZoom,
|
||||
@@ -393,6 +394,7 @@ export type ProjectDevelopmentViewProps = {
|
||||
};
|
||||
|
||||
const categoryOrder = RESOURCE_CANVAS_SECTION_ORDER;
|
||||
const visibleCategoryOrder = RESOURCE_CANVAS_VISIBLE_SECTION_ORDER;
|
||||
|
||||
const categoryLabels: Record<ResourceCategory, string> = {
|
||||
code: '游戏代码',
|
||||
@@ -592,6 +594,7 @@ const ResourceCard = memo(function ResourceCard({
|
||||
const [decodedIdentity, setDecodedIdentity] = useState<string | null>(null);
|
||||
const Icon = categoryIcons[resource.category];
|
||||
const kind = projectResourceCardPreviewKind(resource);
|
||||
const resourceTypeLabel = projectResourceTypeLabel(resource);
|
||||
const isMedia = kind === 'video' || kind === 'audio';
|
||||
const mediaActive = activeMediaIdentity === previewIdentity;
|
||||
const sourceUrl =
|
||||
@@ -797,6 +800,13 @@ const ResourceCard = memo(function ResourceCard({
|
||||
<span className="game-resource-card-visual" aria-hidden="true">
|
||||
{visual}
|
||||
</span>
|
||||
<span
|
||||
className="game-resource-card-type-badge"
|
||||
data-resource-type={resourceTypeLabel}
|
||||
title={resourceTypeLabel}
|
||||
>
|
||||
{resourceTypeLabel}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
className="game-resource-card-open"
|
||||
@@ -1243,6 +1253,10 @@ export default function ProjectDevelopmentView({
|
||||
}),
|
||||
[manifestTaskById, projectedResources, resourceGraph],
|
||||
);
|
||||
const canvasResources = useMemo(
|
||||
() => resources.filter((resource) => resource.category !== 'code'),
|
||||
[resources],
|
||||
);
|
||||
// 做方案在拿到第一个产物之前,左边的资源画布是空的(文档 0 项、项目版本 0 项),而澄清
|
||||
// 问答、决定卡和 GDD 审批全挤在右边那一列里。这段时间先把画布收掉让对话铺满,一旦有第
|
||||
// 一个已登记资源就自动恢复双栏。用 CSS 收而不是不渲染:画布里的页签、缩放和选中状态都
|
||||
@@ -1288,7 +1302,7 @@ export default function ProjectDevelopmentView({
|
||||
projectPath,
|
||||
projectId: manifest.projectId,
|
||||
mode: sortMode,
|
||||
resources,
|
||||
resources: canvasResources,
|
||||
canvasRef: resourceCanvasRef,
|
||||
eagerPreviewLimit: 12,
|
||||
previewVersionByResourceId: resourcePreviewVersionByResourceId,
|
||||
@@ -1382,7 +1396,7 @@ export default function ProjectDevelopmentView({
|
||||
const normalizedSearch = searchText.trim().toLowerCase();
|
||||
const visibleResources = useMemo(
|
||||
() =>
|
||||
resources.filter((resource) =>
|
||||
canvasResources.filter((resource) =>
|
||||
normalizedSearch
|
||||
? [
|
||||
resource.label,
|
||||
@@ -1392,7 +1406,7 @@ export default function ProjectDevelopmentView({
|
||||
].some((value) => value.toLowerCase().includes(normalizedSearch))
|
||||
: true,
|
||||
),
|
||||
[normalizedSearch, resources],
|
||||
[canvasResources, normalizedSearch],
|
||||
);
|
||||
const visibleResourceIds = useMemo(
|
||||
() => new Set(visibleResources.map((resource) => resource.id)),
|
||||
@@ -1401,7 +1415,7 @@ export default function ProjectDevelopmentView({
|
||||
const visibleResourcesByCategory = useMemo(
|
||||
() =>
|
||||
new Map(
|
||||
categoryOrder.map((category) => [
|
||||
visibleCategoryOrder.map((category) => [
|
||||
category,
|
||||
visibleResources.filter((resource) => resource.category === category),
|
||||
]),
|
||||
@@ -1411,17 +1425,17 @@ export default function ProjectDevelopmentView({
|
||||
const projectResourcesByCategory = useMemo(
|
||||
() =>
|
||||
new Map(
|
||||
categoryOrder.map((category) => [
|
||||
visibleCategoryOrder.map((category) => [
|
||||
category,
|
||||
resources.filter((resource) => resource.category === category),
|
||||
canvasResources.filter((resource) => resource.category === category),
|
||||
]),
|
||||
),
|
||||
[resources],
|
||||
[canvasResources],
|
||||
);
|
||||
const resourceIdsByCategory = useMemo(
|
||||
() =>
|
||||
new Map(
|
||||
categoryOrder.map((category) => [
|
||||
visibleCategoryOrder.map((category) => [
|
||||
category,
|
||||
new Set(
|
||||
(projectResourcesByCategory.get(category) ?? []).map(
|
||||
@@ -1437,8 +1451,8 @@ export default function ProjectDevelopmentView({
|
||||
[manifest.projectId, projectPath],
|
||||
);
|
||||
const resourcePageCategories = useMemo(
|
||||
() => (resources.length > 0 ? categoryOrder : []),
|
||||
[resources.length],
|
||||
() => (canvasResources.length > 0 ? visibleCategoryOrder : []),
|
||||
[canvasResources.length],
|
||||
);
|
||||
const activePageCategory =
|
||||
resourcePageCategories.find(
|
||||
@@ -1468,16 +1482,18 @@ export default function ProjectDevelopmentView({
|
||||
return;
|
||||
}
|
||||
|
||||
const categoriesWithNewResources = categoryOrder.filter((category) => {
|
||||
if (category === viewedResourceCategory) {
|
||||
return false;
|
||||
}
|
||||
const previousIds =
|
||||
previousSnapshot.resourceIdsByCategory.get(category) ?? new Set();
|
||||
return Array.from(resourceIdsByCategory.get(category) ?? []).some(
|
||||
(resourceId) => !previousIds.has(resourceId),
|
||||
);
|
||||
});
|
||||
const categoriesWithNewResources = visibleCategoryOrder.filter(
|
||||
(category) => {
|
||||
if (category === viewedResourceCategory) {
|
||||
return false;
|
||||
}
|
||||
const previousIds =
|
||||
previousSnapshot.resourceIdsByCategory.get(category) ?? new Set();
|
||||
return Array.from(resourceIdsByCategory.get(category) ?? []).some(
|
||||
(resourceId) => !previousIds.has(resourceId),
|
||||
);
|
||||
},
|
||||
);
|
||||
resourceCategorySnapshotRef.current = {
|
||||
scopeKey: resourceCategoryScopeKey,
|
||||
resourceIdsByCategory,
|
||||
@@ -1683,9 +1699,11 @@ export default function ProjectDevelopmentView({
|
||||
}
|
||||
}, [activePageCategory, activeResourceCanvasViewport]);
|
||||
const selectedResource =
|
||||
resources.find((resource) => resource.id === selectedResourceId) ?? null;
|
||||
canvasResources.find((resource) => resource.id === selectedResourceId) ??
|
||||
null;
|
||||
const focusedResource =
|
||||
resources.find((resource) => resource.id === focusedResourceId) ?? null;
|
||||
canvasResources.find((resource) => resource.id === focusedResourceId) ??
|
||||
null;
|
||||
const focusedResourceDependencyDetails = useMemo(() => {
|
||||
if (!focusedResource) {
|
||||
return {
|
||||
@@ -2245,10 +2263,6 @@ export default function ProjectDevelopmentView({
|
||||
bounds: resourceCanvasFitBounds,
|
||||
canvasSize: { width: measuredWidth, height: measuredHeight },
|
||||
padding: RESOURCE_CANVAS_FIT_PADDING,
|
||||
maxScale:
|
||||
activePageCategory === 'art'
|
||||
? RESOURCE_CANVAS_INITIAL_FIT_MAX_SCALE
|
||||
: undefined,
|
||||
}),
|
||||
);
|
||||
return;
|
||||
@@ -2853,10 +2867,6 @@ export default function ProjectDevelopmentView({
|
||||
bounds: resourceCanvasFitBounds,
|
||||
canvasSize,
|
||||
padding: RESOURCE_CANVAS_FIT_PADDING,
|
||||
maxScale:
|
||||
activePageCategory === 'art'
|
||||
? RESOURCE_CANVAS_INITIAL_FIT_MAX_SCALE
|
||||
: undefined,
|
||||
}),
|
||||
);
|
||||
}, [activePageCategory, resourceCanvasFitBounds, setResourceCanvasViewport]);
|
||||
@@ -5035,7 +5045,7 @@ export default function ProjectDevelopmentView({
|
||||
</div>
|
||||
) : (
|
||||
<div className="game-resource-section-stack">
|
||||
{categoryOrder.map((category) => {
|
||||
{visibleCategoryOrder.map((category) => {
|
||||
const Icon = categoryIcons[category];
|
||||
const sectionHeight =
|
||||
resourceSectionHeights.sectionStates.get(category);
|
||||
|
||||
+9
-1
@@ -44,6 +44,14 @@ export const RESOURCE_CANVAS_FIT_PADDING = 16;
|
||||
export const RESOURCE_CANVAS_SECTION_ORDER: readonly ProjectResourceCanvasSection[] =
|
||||
['document', 'art', 'audio', 'code', 'version'];
|
||||
|
||||
/**
|
||||
* Ordinary resource-canvas navigation intentionally omits game code. The
|
||||
* complete five-section order above remains the internal layout/sidecar
|
||||
* contract so existing code-resource coordinates are not rewritten.
|
||||
*/
|
||||
export const RESOURCE_CANVAS_VISIBLE_SECTION_ORDER: readonly ProjectResourceCanvasSection[] =
|
||||
['document', 'art', 'audio', 'version'];
|
||||
|
||||
export type ResourceCanvasCardSize = {
|
||||
width: number;
|
||||
height: number;
|
||||
@@ -1345,7 +1353,7 @@ export function fitResourceCanvasViewportToContent({
|
||||
bounds,
|
||||
canvasSize,
|
||||
padding = RESOURCE_CANVAS_FIT_PADDING,
|
||||
maxScale = MAX_SCALE,
|
||||
maxScale = RESOURCE_CANVAS_INITIAL_FIT_MAX_SCALE,
|
||||
}: {
|
||||
bounds: { x: number; y: number; width: number; height: number };
|
||||
canvasSize: { width: number; height: number };
|
||||
|
||||
@@ -55,6 +55,18 @@ export type ProjectResource = {
|
||||
imageSequenceDurationMs?: number | null;
|
||||
};
|
||||
|
||||
export type ProjectResourceTypeLabel =
|
||||
| '图片'
|
||||
| 'SVG'
|
||||
| '视频'
|
||||
| '音频'
|
||||
| '文档'
|
||||
| '任务产物'
|
||||
| 'Agent 回执'
|
||||
| '项目版本'
|
||||
| '游戏代码'
|
||||
| '未知';
|
||||
|
||||
const documentExtension =
|
||||
/\.(md|markdown|mdx|txt|json|ya?ml|toml|csv|ini|conf|xml)$/iu;
|
||||
const gameCodeExtension =
|
||||
@@ -116,6 +128,55 @@ export function classifyProjectedResource(input: {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an already projected resource into short user-facing type text.
|
||||
* This is deliberately display-only: it derives from existing projection
|
||||
* fields and does not add a backend/read-model attribute.
|
||||
*/
|
||||
export function projectResourceTypeLabel(
|
||||
resource: Pick<
|
||||
ProjectResource,
|
||||
'category' | 'subtype' | 'path' | 'mediaType'
|
||||
>,
|
||||
): ProjectResourceTypeLabel {
|
||||
const subtype = resource.subtype.trim().toLowerCase();
|
||||
const path = resource.path.trim().toLowerCase();
|
||||
const mediaType = resource.mediaType.trim().toLowerCase();
|
||||
|
||||
if (resource.category === 'version' || subtype === 'project-version') {
|
||||
return '项目版本';
|
||||
}
|
||||
if (subtype === 'agent-result') {
|
||||
return 'Agent 回执';
|
||||
}
|
||||
if (resource.category === 'code') {
|
||||
return '游戏代码';
|
||||
}
|
||||
if (mediaType === 'image/svg+xml' || /\.svg$/iu.test(path)) {
|
||||
return 'SVG';
|
||||
}
|
||||
if (
|
||||
resource.category === 'audio' ||
|
||||
mediaType.startsWith('audio/') ||
|
||||
audioExtension.test(path)
|
||||
) {
|
||||
return '音频';
|
||||
}
|
||||
if (mediaType.startsWith('video/') || /\.(mp4|webm|mov)$/iu.test(path)) {
|
||||
return '视频';
|
||||
}
|
||||
if (resource.category === 'document' || mediaType.startsWith('text/')) {
|
||||
return '文档';
|
||||
}
|
||||
if (resource.category === 'art' || mediaType.startsWith('image/')) {
|
||||
return '图片';
|
||||
}
|
||||
if (subtype === 'task-artifact') {
|
||||
return '任务产物';
|
||||
}
|
||||
return '未知';
|
||||
}
|
||||
|
||||
function resourcePriority(resource: ProjectResource) {
|
||||
if (resource.manifestAssetId) {
|
||||
return 4;
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
RESOURCE_CANVAS_CARD_WIDTH,
|
||||
RESOURCE_CANVAS_COLUMN_GAP,
|
||||
RESOURCE_CANVAS_DEPENDENCY_COLUMN_GAP,
|
||||
RESOURCE_CANVAS_INITIAL_FIT_MAX_SCALE,
|
||||
} from '../../src/view/project-development/resourceCanvasLayoutModel';
|
||||
import { normalizeProjectResourceGraph } from '../../src/view/project-development/resourceDependencyGraphModel';
|
||||
import { ResourceDependencyOverlay } from '../../src/view/project-development/ResourceDependencyOverlay';
|
||||
@@ -429,6 +430,13 @@ export function registerProjectWorkbenchFoundationTests() {
|
||||
localPath: 'assets/section.mp3',
|
||||
source: { kind: 'generated', taskId: 'audio-asset-plan' },
|
||||
},
|
||||
{
|
||||
id: 'section-code',
|
||||
kind: 'game-code',
|
||||
mediaType: 'text/javascript',
|
||||
localPath: 'game/section.js',
|
||||
source: { kind: 'generated', taskId: 'code-prototype' },
|
||||
},
|
||||
];
|
||||
manifest.versions = [
|
||||
{
|
||||
@@ -448,9 +456,13 @@ export function registerProjectWorkbenchFoundationTests() {
|
||||
);
|
||||
addSectionResources(manifest);
|
||||
let layoutRevision = 0;
|
||||
let graphResourceIds: string[] = [];
|
||||
const invoke = vi.fn(
|
||||
async (command: string, args?: Record<string, unknown>) => {
|
||||
if (command === 'read_local_project_resource_graph') {
|
||||
graphResourceIds = (
|
||||
(args?.resources as Array<{ resourceId: string }> | undefined) ?? []
|
||||
).map(({ resourceId }) => resourceId);
|
||||
return resourceGraphForInputs(args);
|
||||
}
|
||||
if (command === 'read_local_project_resource_canvas_layout') {
|
||||
@@ -529,7 +541,12 @@ export function registerProjectWorkbenchFoundationTests() {
|
||||
Array.from(outline.querySelectorAll('strong')).map(
|
||||
(item) => item.textContent,
|
||||
),
|
||||
).toEqual(['设计文档', '美术资源', '音乐音效', '游戏代码', '项目版本']);
|
||||
).toEqual(['设计文档', '美术资源', '音乐音效', '项目版本']);
|
||||
expect(graphResourceIds).toContain('asset:section-code');
|
||||
expect(screen.queryByRole('button', { name: /section\.js/ })).toBeNull();
|
||||
expect(
|
||||
screen.queryByRole('region', { name: '游戏代码资源画布' }),
|
||||
).toBeNull();
|
||||
expect(outline.querySelectorAll('small')).toHaveLength(0);
|
||||
expect(
|
||||
screen.getByRole('region', { name: '设计文档资源画布' }),
|
||||
@@ -541,11 +558,12 @@ export function registerProjectWorkbenchFoundationTests() {
|
||||
screen.getByRole('button', { name: /下一页\s*美术资源/ }),
|
||||
).not.toBeNull();
|
||||
|
||||
fireEvent.click(within(outline).getByRole('button', { name: /游戏代码/ }));
|
||||
expect(
|
||||
screen.getByRole('region', { name: '游戏代码资源画布' }),
|
||||
).not.toBeNull();
|
||||
expect(screen.getByText('没有匹配资源')).not.toBeNull();
|
||||
within(outline).queryByRole('button', { name: /游戏代码/ }),
|
||||
).toBeNull();
|
||||
expect(
|
||||
screen.queryByRole('region', { name: '游戏代码资源画布' }),
|
||||
).toBeNull();
|
||||
fireEvent.click(within(outline).getByRole('button', { name: /文档/ }));
|
||||
|
||||
const dispatchPageWheel = (target: Element, deltaY = 160) => {
|
||||
@@ -606,10 +624,12 @@ export function registerProjectWorkbenchFoundationTests() {
|
||||
.map(Number);
|
||||
const fittedViewport = readViewport();
|
||||
const fittedBounds = readFitBounds();
|
||||
expect(
|
||||
Math.abs(fittedBounds[2]! * fittedViewport[2]! - 468) < 1 ||
|
||||
Math.abs(fittedBounds[3]! * fittedViewport[2]! - 268) < 1,
|
||||
).toBe(true);
|
||||
const expectedDocumentFitScale = Math.min(
|
||||
RESOURCE_CANVAS_INITIAL_FIT_MAX_SCALE,
|
||||
468 / fittedBounds[2]!,
|
||||
268 / fittedBounds[3]!,
|
||||
);
|
||||
expect(fittedViewport[2]).toBeCloseTo(expectedDocumentFitScale, 8);
|
||||
|
||||
const viewportBeforeZoom = fittedViewport;
|
||||
const zoomWheel = new WheelEvent('wheel', {
|
||||
@@ -626,6 +646,15 @@ export function registerProjectWorkbenchFoundationTests() {
|
||||
});
|
||||
expect(zoomWheelResult).toBe(false);
|
||||
expect(readViewport()[2]).toBeGreaterThan(viewportBeforeZoom[2]!);
|
||||
const documentViewportAfterZoom = readViewport();
|
||||
fireEvent.click(within(outline).getByRole('button', { name: /美术资源/ }));
|
||||
expect(
|
||||
screen.getByRole('region', { name: '美术资源资源画布' }),
|
||||
).not.toBeNull();
|
||||
fireEvent.click(within(outline).getByRole('button', { name: /设计文档/ }));
|
||||
await waitFor(() =>
|
||||
expect(readViewport()).toEqual(documentViewportAfterZoom),
|
||||
);
|
||||
expect(
|
||||
screen.getByRole('region', { name: '设计文档资源画布' }),
|
||||
).not.toBeNull();
|
||||
@@ -1051,10 +1080,16 @@ export function registerProjectWorkbenchFoundationTests() {
|
||||
}),
|
||||
);
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByLabelText('资源栏目大纲')).toBeNull();
|
||||
expect(screen.getAllByText('暂无已登记资源')).toHaveLength(4);
|
||||
expect(
|
||||
within(screen.getByLabelText('资源栏目大纲')).queryByRole('button', {
|
||||
name: /有新资源/,
|
||||
}),
|
||||
screen
|
||||
.getByLabelText(/资源(?:依赖|类型)视图/)
|
||||
.classList.contains('game-resource-canvas--paged'),
|
||||
).toBe(false);
|
||||
expect(screen.queryByRole('button', { name: /game\.js/ })).toBeNull();
|
||||
expect(
|
||||
screen.queryByRole('region', { name: '游戏代码资源画布' }),
|
||||
).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -1224,14 +1259,8 @@ export function registerProjectWorkbenchFoundationTests() {
|
||||
.getByLabelText(/资源(?:依赖|类型)视图/)
|
||||
.classList.contains('game-resource-canvas--dependency'),
|
||||
).toBe(false);
|
||||
expect(screen.getAllByText('暂无已登记资源')).toHaveLength(5);
|
||||
for (const label of [
|
||||
'设计文档',
|
||||
'美术资源',
|
||||
'音乐音效',
|
||||
'游戏代码',
|
||||
'项目版本',
|
||||
]) {
|
||||
expect(screen.getAllByText('暂无已登记资源')).toHaveLength(4);
|
||||
for (const label of ['设计文档', '美术资源', '音乐音效', '项目版本']) {
|
||||
expect(screen.getByRole('region', { name: label })).not.toBeNull();
|
||||
}
|
||||
};
|
||||
@@ -1394,6 +1423,9 @@ export function registerProjectWorkbenchFoundationTests() {
|
||||
expect(heroCard?.textContent).not.toContain('hero.png');
|
||||
expect(heroCard?.textContent).not.toContain('assets/hero.png');
|
||||
expect(heroCard?.textContent).not.toContain('Agent 生成');
|
||||
expect(
|
||||
heroCard?.querySelector('[data-resource-type="图片"]')?.textContent,
|
||||
).toBe('图片');
|
||||
expect(
|
||||
heroCard?.querySelector('.game-resource-card-open button'),
|
||||
).toBeNull();
|
||||
@@ -1411,7 +1443,12 @@ export function registerProjectWorkbenchFoundationTests() {
|
||||
});
|
||||
showResourcePage('设计文档');
|
||||
act(() => observer.triggerVisible());
|
||||
await screen.findByText(/这是安全的卡片正文摘要。/);
|
||||
const documentSummary = await screen.findByText(/这是安全的卡片正文摘要。/);
|
||||
expect(
|
||||
documentSummary
|
||||
.closest('.game-resource-card')
|
||||
?.querySelector('[data-resource-type="文档"]'),
|
||||
).not.toBeNull();
|
||||
showResourcePage('美术资源');
|
||||
expect(
|
||||
invoke.mock.calls.some(
|
||||
@@ -1425,6 +1462,9 @@ export function registerProjectWorkbenchFoundationTests() {
|
||||
name: '播放 intro.mp4',
|
||||
});
|
||||
const videoCard = videoControl.closest('.game-resource-card');
|
||||
expect(
|
||||
videoCard?.querySelector('[data-resource-type="视频"]'),
|
||||
).not.toBeNull();
|
||||
const video = videoCard?.querySelector('video');
|
||||
expect(video).not.toBeNull();
|
||||
expect(video?.preload).toBe('auto');
|
||||
@@ -1475,7 +1515,13 @@ export function registerProjectWorkbenchFoundationTests() {
|
||||
expect(document.activeElement).toBe(stableVideoControl);
|
||||
|
||||
showResourcePage('音乐音效');
|
||||
fireEvent.click(screen.getByRole('button', { name: '播放 theme.mp3' }));
|
||||
const audioControl = screen.getByRole('button', { name: '播放 theme.mp3' });
|
||||
expect(
|
||||
audioControl
|
||||
.closest('.game-resource-card')
|
||||
?.querySelector('[data-resource-type="音频"]'),
|
||||
).not.toBeNull();
|
||||
fireEvent.click(audioControl);
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
invoke.mock.calls.some(
|
||||
@@ -2800,6 +2846,82 @@ export function registerProjectWorkbenchFoundationTests() {
|
||||
});
|
||||
});
|
||||
|
||||
it('hides dependency edges whose code endpoint is not visible while preserving visible edges', async () => {
|
||||
const visibleEdgeId = 'asset-reference:["art-a","art-b"]';
|
||||
const hiddenEdgeId = 'asset-reference:["code","art-a"]';
|
||||
const graph = normalizeProjectResourceGraph({
|
||||
resourceIds: ['code', 'art-a', 'art-b'],
|
||||
referenceEdges: [
|
||||
{
|
||||
id: visibleEdgeId,
|
||||
kind: 'asset-reference',
|
||||
sourceResourceId: 'art-a',
|
||||
targetResourceId: 'art-b',
|
||||
cyclic: false,
|
||||
},
|
||||
{
|
||||
id: hiddenEdgeId,
|
||||
kind: 'asset-reference',
|
||||
sourceResourceId: 'code',
|
||||
targetResourceId: 'art-a',
|
||||
cyclic: false,
|
||||
},
|
||||
],
|
||||
taskFlows: [],
|
||||
connectionIndex: [],
|
||||
producerAssignments: [],
|
||||
dependencyDepths: [],
|
||||
unresolvedReferenceResourceIds: [],
|
||||
cyclicResourceIds: [],
|
||||
cyclicTaskIds: [],
|
||||
producerMappingTruncated: false,
|
||||
});
|
||||
const positions: ProjectResourceCanvasPosition[] = [
|
||||
{
|
||||
resourceId: 'code',
|
||||
section: 'code',
|
||||
x: 0,
|
||||
y: 0,
|
||||
manuallyPlaced: false,
|
||||
},
|
||||
{
|
||||
resourceId: 'art-a',
|
||||
section: 'art',
|
||||
x: 0,
|
||||
y: 0,
|
||||
manuallyPlaced: false,
|
||||
},
|
||||
{
|
||||
resourceId: 'art-b',
|
||||
section: 'art',
|
||||
x: 0,
|
||||
y: 144,
|
||||
manuallyPlaced: false,
|
||||
},
|
||||
];
|
||||
|
||||
render(
|
||||
React.createElement(ResourceDependencyOverlay, {
|
||||
graph,
|
||||
positions,
|
||||
section: 'art',
|
||||
visibleResourceIds: new Set(['art-a', 'art-b']),
|
||||
}),
|
||||
);
|
||||
|
||||
const overlay = await screen.findByTestId(
|
||||
'resource-dependency-overlay-art',
|
||||
);
|
||||
await waitFor(() => {
|
||||
const edgeById = (edgeId: string) =>
|
||||
Array.from(
|
||||
overlay.querySelectorAll<SVGPathElement>('[data-edge-id]'),
|
||||
).find((edge) => edge.getAttribute('data-edge-id') === edgeId);
|
||||
expect(edgeById(visibleEdgeId)).not.toBeNull();
|
||||
expect(edgeById(hiddenEdgeId)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
it('coalesces section scroll geometry, keeps partial endpoints stable, and cleans one dependency observer', async () => {
|
||||
const referenceId = 'asset-reference:["resource-a","resource-b"]';
|
||||
const graph = normalizeProjectResourceGraph({
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { createGameCreationAppManifest } from '../../../packages/shared/src/contracts/gameCreationApp';
|
||||
import { projectResourcesFromReadModels } from '../src/view/project-development/resourceProjectionModel';
|
||||
import {
|
||||
projectResourcesFromReadModels,
|
||||
projectResourceTypeLabel,
|
||||
} from '../src/view/project-development/resourceProjectionModel';
|
||||
|
||||
describe('项目资源投影', () => {
|
||||
it('只把明确资源投影到固定分类,未知任务产物不会伪装成项目版本', () => {
|
||||
@@ -225,4 +228,119 @@ describe('项目资源投影', () => {
|
||||
expect(versions[0]?.version?.childVersionIds).toEqual(['version-child']);
|
||||
expect(versions[1]?.version?.parentVersionId).toBe('version-root');
|
||||
});
|
||||
|
||||
it('按稳定优先级推导资源卡类型标识并为未知类型兜底', () => {
|
||||
expect(
|
||||
projectResourceTypeLabel({
|
||||
category: 'version',
|
||||
subtype: 'project-version',
|
||||
path: 'versions/v1',
|
||||
mediaType: '正式项目版本',
|
||||
}),
|
||||
).toBe('项目版本');
|
||||
expect(
|
||||
projectResourceTypeLabel({
|
||||
category: 'document',
|
||||
subtype: 'agent-result',
|
||||
path: '专业 Agent 文本回执',
|
||||
mediaType: 'Agent 历史文本回执',
|
||||
}),
|
||||
).toBe('Agent 回执');
|
||||
expect(
|
||||
projectResourceTypeLabel({
|
||||
category: 'document',
|
||||
subtype: 'task-artifact',
|
||||
path: 'memory/plan.md',
|
||||
mediaType: '项目文档',
|
||||
}),
|
||||
).toBe('文档');
|
||||
expect(
|
||||
projectResourceTypeLabel({
|
||||
category: 'audio',
|
||||
subtype: 'task-artifact',
|
||||
path: 'audio/theme.wav',
|
||||
mediaType: '音乐音效产物',
|
||||
}),
|
||||
).toBe('音频');
|
||||
expect(
|
||||
projectResourceTypeLabel({
|
||||
category: 'art',
|
||||
subtype: 'task-artifact',
|
||||
path: 'assets/hero.svg',
|
||||
mediaType: '美术产物',
|
||||
}),
|
||||
).toBe('SVG');
|
||||
expect(
|
||||
projectResourceTypeLabel({
|
||||
category: 'art',
|
||||
subtype: 'task-artifact',
|
||||
path: 'assets/unknown',
|
||||
mediaType: '美术产物',
|
||||
}),
|
||||
).toBe('图片');
|
||||
expect(
|
||||
projectResourceTypeLabel({
|
||||
category: 'art',
|
||||
subtype: 'character',
|
||||
path: 'assets/hero.svg',
|
||||
mediaType: 'image/svg+xml',
|
||||
}),
|
||||
).toBe('SVG');
|
||||
expect(
|
||||
projectResourceTypeLabel({
|
||||
category: 'art',
|
||||
subtype: 'video',
|
||||
path: 'assets/intro.mp4',
|
||||
mediaType: 'video/mp4',
|
||||
}),
|
||||
).toBe('视频');
|
||||
expect(
|
||||
projectResourceTypeLabel({
|
||||
category: 'art',
|
||||
subtype: 'character',
|
||||
path: 'assets/hero.png',
|
||||
mediaType: 'image/png',
|
||||
}),
|
||||
).toBe('图片');
|
||||
expect(
|
||||
projectResourceTypeLabel({
|
||||
category: 'document',
|
||||
subtype: 'attachment',
|
||||
path: 'docs/rules.yaml',
|
||||
mediaType: 'application/yaml',
|
||||
}),
|
||||
).toBe('文档');
|
||||
expect(
|
||||
projectResourceTypeLabel({
|
||||
category: 'document',
|
||||
subtype: 'unknown',
|
||||
path: 'data/blob',
|
||||
mediaType: 'application/octet-stream',
|
||||
}),
|
||||
).toBe('文档');
|
||||
expect(
|
||||
projectResourceTypeLabel({
|
||||
category: 'code',
|
||||
subtype: 'source',
|
||||
path: 'game/main.ts',
|
||||
mediaType: 'text/typescript',
|
||||
}),
|
||||
).toBe('游戏代码');
|
||||
expect(
|
||||
projectResourceTypeLabel({
|
||||
category: 'art',
|
||||
subtype: 'unknown',
|
||||
path: 'assets/blob',
|
||||
mediaType: 'application/octet-stream',
|
||||
}),
|
||||
).toBe('图片');
|
||||
expect(
|
||||
projectResourceTypeLabel({
|
||||
category: 'unsupported' as never,
|
||||
subtype: 'unknown',
|
||||
path: 'data/blob',
|
||||
mediaType: 'application/octet-stream',
|
||||
}),
|
||||
).toBe('未知');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
RESOURCE_CANVAS_COLUMN_GAP,
|
||||
RESOURCE_CANVAS_DEPENDENCY_COLUMN_GAP,
|
||||
RESOURCE_CANVAS_DEPENDENCY_ROW_GAP,
|
||||
RESOURCE_CANVAS_INITIAL_FIT_MAX_SCALE,
|
||||
type ResourceCanvasCardSize,
|
||||
resourceCanvasContentBounds,
|
||||
resourceCanvasImageCardSize,
|
||||
@@ -831,15 +832,23 @@ describe('resource canvas variable card geometry', () => {
|
||||
expect(viewport.x + bounds.x * viewport.scale).toBeCloseTo(16, 8);
|
||||
});
|
||||
|
||||
it('caps the initial fit without limiting explicit canvas zoom', () => {
|
||||
const viewport = fitResourceCanvasViewportToContent({
|
||||
bounds: { x: 0, y: 0, width: 180, height: 128 },
|
||||
canvasSize: { width: 800, height: 600 },
|
||||
maxScale: 1.5,
|
||||
});
|
||||
it.each(['document', 'art', 'audio', 'code', 'version'])(
|
||||
'caps the initial fit for every resource category (%s) while keeping explicit zoom overrides available',
|
||||
() => {
|
||||
const viewport = fitResourceCanvasViewportToContent({
|
||||
bounds: { x: 0, y: 0, width: 180, height: 128 },
|
||||
canvasSize: { width: 800, height: 600 },
|
||||
});
|
||||
const explicitViewport = fitResourceCanvasViewportToContent({
|
||||
bounds: { x: 0, y: 0, width: 180, height: 128 },
|
||||
canvasSize: { width: 800, height: 600 },
|
||||
maxScale: 2.5,
|
||||
});
|
||||
|
||||
expect(viewport.scale).toBe(1.5);
|
||||
});
|
||||
expect(viewport.scale).toBe(RESOURCE_CANVAS_INITIAL_FIT_MAX_SCALE);
|
||||
expect(explicitViewport.scale).toBe(2.5);
|
||||
},
|
||||
);
|
||||
|
||||
it('accepts card sizes directly on resource items for hook integration', () => {
|
||||
const wide = {
|
||||
|
||||
Reference in New Issue
Block a user