收紧 AGC 资源 kind 类型边界并统一族判据

- 将 manifest 与本地导入回执的资源 kind 改为 ts-rs 生成绑定

- 集中音频与视觉资源族判据并复用 Rust 枚举方法

- 放宽 Unknown 未解析语义并清理上传类型墓碑注释

- 标记共享生成绑定并同步项目决策与实施计划
This commit is contained in:
2026-09-18 15:07:36 +08:00
parent 03d7bca9a5
commit e5fd454bb3
16 changed files with 175 additions and 47 deletions
@@ -45,8 +45,8 @@ macro_rules! game_creation_app_asset_kinds {
/// GameCreationApp manifest 资源 kind 的**唯一**类型,也是 TS 侧 kind union 的唯一真源
/// (经 ts-rs 生成,前端不再手写第二份列表)。
///
/// JSON 使用 kebab-case`Unknown` 表示解析边界遇到尚未登记的输入
/// 正常资源写入路径不应主动选择它
/// JSON 使用 kebab-case`Unknown` 表示当前边界无法解析输入
/// 写入方可以保留这个未解析结果,但必须由调用者决定是否拒绝写入或交给后续归类
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "ts-bindings", derive(ts_rs::TS))]
#[cfg_attr(
@@ -88,6 +88,29 @@ macro_rules! game_creation_app_asset_kinds {
}
}
/// 资源编辑器和摘要视图共用的音频资源族。
pub const fn is_audio(self) -> bool {
matches!(
self,
Self::Audio | Self::SoundEffect | Self::BackgroundMusic
)
}
/// 资源编辑器和摘要视图共用的视觉资源族。
pub const fn is_visual(self) -> bool {
matches!(
self,
Self::Image
| Self::Scene
| Self::Character
| Self::CharacterAnimation
| Self::Icon
| Self::IconSpritesheet
| Self::IconSpec
| Self::UiDesign
)
}
/// 严格解析:只认 canonical 值,其余(含大小写、空白变体)一律 `Unknown`。
///
/// 私有实现细节,**不是**解析入口:外部一律走 [`Self::parse_with_context`]
@@ -368,4 +391,40 @@ mod tests {
// 每个非 canonical 变体都要留痕(5 条大小写/空白/legacy 变体都算异常)。
assert_eq!(recorded_reports().len(), 5);
}
#[test]
fn media_family_helpers_cover_the_shared_kind_sets() {
let audio = GameCreationAppAssetKind::ALL
.iter()
.copied()
.filter(|kind| kind.is_audio())
.collect::<Vec<_>>();
assert_eq!(
audio,
vec![
GameCreationAppAssetKind::Audio,
GameCreationAppAssetKind::SoundEffect,
GameCreationAppAssetKind::BackgroundMusic,
]
);
let visual = GameCreationAppAssetKind::ALL
.iter()
.copied()
.filter(|kind| kind.is_visual())
.collect::<Vec<_>>();
assert_eq!(
visual,
vec![
GameCreationAppAssetKind::Image,
GameCreationAppAssetKind::Scene,
GameCreationAppAssetKind::Character,
GameCreationAppAssetKind::CharacterAnimation,
GameCreationAppAssetKind::Icon,
GameCreationAppAssetKind::IconSpritesheet,
GameCreationAppAssetKind::IconSpec,
GameCreationAppAssetKind::UiDesign,
]
);
}
}