Asset Entry Metadata Normalization Contract

This commit is contained in:
2026-04-09 08:25:37 +01:00
parent 9228fb1e29
commit 52d4a91c71
6 changed files with 110 additions and 138 deletions
+37
View File
@@ -24,6 +24,43 @@ pub struct AssetEntry {
pub metadata: serde_json::Value,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct TilesMetadata {
pub tile_size: u32,
pub width: u32,
pub height: u32,
pub palette_count: u32,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct SoundsMetadata {
pub sample_rate: u32,
}
impl AssetEntry {
pub fn metadata_as_tiles(&self) -> Result<TilesMetadata, String> {
if self.bank_type != BankType::TILES {
return Err(format!(
"Asset {} is not a TILES bank (type: {:?})",
self.asset_id, self.bank_type
));
}
serde_json::from_value(self.metadata.clone())
.map_err(|e| format!("Invalid TILES metadata for asset {}: {}", self.asset_id, e))
}
pub fn metadata_as_sounds(&self) -> Result<SoundsMetadata, String> {
if self.bank_type != BankType::SOUNDS {
return Err(format!(
"Asset {} is not a SOUNDS bank (type: {:?})",
self.asset_id, self.bank_type
));
}
serde_json::from_value(self.metadata.clone())
.map_err(|e| format!("Invalid SOUNDS metadata for asset {}: {}", self.asset_id, e))
}
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct PreloadEntry {
pub asset_id: AssetId,