From b7e3dac6619bdf5e2f1e5257989f83d5d3044031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Mon, 14 Sep 2026 21:36:43 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E5=BC=95=E7=94=A8=20UI=20?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E8=B5=84=E4=BA=A7=E7=B1=BB=E5=9E=8B=E5=B8=B8?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 前端入口、资源桥接与引用预览统一使用共享常量 Rust 持久化与测试复用共享契约常量 补齐 UI 编辑器入口 fixture 的新资产类型 --- .../src-tauri/src/tests/project.rs | 25 +++++++++------ .../src-tauri/src/ui_editor/persistence.rs | 6 ++-- .../ResourceReferenceInput.tsx | 6 +++- .../ui-editor/uiDesignResourceBridge.ts | 8 +++-- .../src/view/project-development/index.tsx | 14 +++++--- .../appSurface/project-development.suite.ts | 8 +++-- .../tests/assetKindCanonicalMapping.test.ts | 13 +++++--- .../tests/uiDesignResourceBridge.test.ts | 32 +++++++++++-------- .../shared/src/contracts/gameCreationApp.ts | 4 +-- .../shared-contracts/src/game_creation_app.rs | 9 ++++-- 10 files changed, 81 insertions(+), 44 deletions(-) diff --git a/apps/ai-game-creator-shell/src-tauri/src/tests/project.rs b/apps/ai-game-creator-shell/src-tauri/src/tests/project.rs index 52ad3d47d..839132da7 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/tests/project.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/tests/project.rs @@ -2031,8 +2031,8 @@ fn register_local_asset_keeps_explicit_category_when_kind_is_unchanged() { let registered = register_local_asset_at( &root, "ui/UI 设计 1.json", - "UI", - "application/json", + shared_contracts::game_creation_app::GAME_CREATION_APP_UI_DESIGN_DOC_ASSET_KIND, + shared_contracts::game_creation_app::GAME_CREATION_APP_UI_DESIGN_DOC_MEDIA_TYPE, "ui-workflow", source(), ) @@ -2053,8 +2053,8 @@ fn register_local_asset_keeps_explicit_category_when_kind_is_unchanged() { register_local_asset_at( &root, "ui/UI 设计 1.json", - "UI", - "application/json", + shared_contracts::game_creation_app::GAME_CREATION_APP_UI_DESIGN_DOC_ASSET_KIND, + shared_contracts::game_creation_app::GAME_CREATION_APP_UI_DESIGN_DOC_MEDIA_TYPE, "ui-workflow", source(), ) @@ -2063,7 +2063,10 @@ fn register_local_asset_keeps_explicit_category_when_kind_is_unchanged() { let manifest: Value = serde_json::from_str(&fs::read_to_string(root.join(".agent/manifest.json")).unwrap()) .expect("manifest json"); - assert_eq!(manifest["assets"][0]["kind"], "UI"); + assert_eq!( + manifest["assets"][0]["kind"], + shared_contracts::game_creation_app::GAME_CREATION_APP_UI_DESIGN_DOC_ASSET_KIND + ); assert_eq!(manifest["assets"][0]["category"], "audio"); assert_eq!(manifest["assets"][0]["tags"], serde_json::json!(["界面"])); @@ -2074,7 +2077,7 @@ fn register_local_asset_keeps_explicit_category_when_kind_is_unchanged() { /// /// 这里的字面量与写入侧逐字一致:UI 设计资产是 /// `ui_editor/resource_bridge.rs` / `workflow.rs` / `persistence.rs` 的 -/// `register_local_asset_at(root, path, "UI", "application/json", ...)`, +/// `register_local_asset_at` 使用 UI 文档 kind/media 常量, /// 字体是 `commands.rs` 字体上传的 `register_local_asset_entry(root, path, "font", ...)`。 /// 只要别名表漏掉它们,真机资产就会永远停在「待归类」且读时自愈也救不回来。 #[test] @@ -2099,8 +2102,8 @@ fn register_local_asset_derives_category_from_real_write_side_kinds() { register_local_asset_at( &root, "ui/UI 设计 1.json", - "UI", - "application/json", + shared_contracts::game_creation_app::GAME_CREATION_APP_UI_DESIGN_DOC_ASSET_KIND, + shared_contracts::game_creation_app::GAME_CREATION_APP_UI_DESIGN_DOC_MEDIA_TYPE, "ui-workflow", source(), ) @@ -2133,7 +2136,11 @@ fn register_local_asset_derives_category_from_real_write_side_kinds() { assert_eq!( categories, vec![ - ("UI".to_string(), "ui-interaction".to_string()), + ( + shared_contracts::game_creation_app::GAME_CREATION_APP_UI_DESIGN_DOC_ASSET_KIND + .to_string(), + "ui-interaction".to_string(), + ), ("font".to_string(), "document".to_string()), ] ); diff --git a/apps/ai-game-creator-shell/src-tauri/src/ui_editor/persistence.rs b/apps/ai-game-creator-shell/src-tauri/src/ui_editor/persistence.rs index 7755cdbd3..f9f1a018a 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/ui_editor/persistence.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/ui_editor/persistence.rs @@ -19,8 +19,10 @@ use std::time::{SystemTime, UNIX_EPOCH}; use typed_floats::tf32::StrictlyPositiveFinite; const UI_DESIGN_STATE_SCHEMA_VERSION: &str = "game-creator-ui-design-state.v1"; -pub(crate) const UI_DESIGN_DOC_ASSET_KIND: &str = "ui-design-doc"; -pub(crate) const UI_DESIGN_DOC_MEDIA_TYPE: &str = "application/json"; +pub(crate) use shared_contracts::game_creation_app::{ + GAME_CREATION_APP_UI_DESIGN_DOC_ASSET_KIND as UI_DESIGN_DOC_ASSET_KIND, + GAME_CREATION_APP_UI_DESIGN_DOC_MEDIA_TYPE as UI_DESIGN_DOC_MEDIA_TYPE, +}; const UI_DESIGN_STATE_MAX_BYTES: usize = 2 * 1024 * 1024; const UI_DESIGN_CODE_MAX_BYTES: usize = UI_DESIGN_STATE_MAX_BYTES * 8; const UI_DESIGN_STATE_MAX_IMAGES: usize = 4; diff --git a/apps/ai-game-creator-shell/src/features/project-workspace/ResourceReferenceInput.tsx b/apps/ai-game-creator-shell/src/features/project-workspace/ResourceReferenceInput.tsx index 1971660b5..591cc3830 100644 --- a/apps/ai-game-creator-shell/src/features/project-workspace/ResourceReferenceInput.tsx +++ b/apps/ai-game-creator-shell/src/features/project-workspace/ResourceReferenceInput.tsx @@ -53,6 +53,7 @@ import { createPortal, flushSync } from 'react-dom'; import { PlatformResourceFilterBar } from '../../../../../packages/shared/src/components/PlatformResourceFilterBar'; import { PlatformSegmentedTabs } from '../../../../../packages/shared/src/components/PlatformSegmentedTabs'; import { + GAME_CREATION_APP_UI_DESIGN_DOC_MEDIA_TYPE, type GameCreationAppAssetManifestEntry, gameCreationAppAssetTags, type GameIterationVersion, @@ -1253,7 +1254,10 @@ function ResourcePickerThumbnail({ if (mediaType.startsWith('image/')) { return