implements PR-016 asset codec NONE in runtime

This commit is contained in:
2026-03-24 13:40:56 +00:00
parent a024e199fb
commit ecc1a864bb
6 changed files with 31 additions and 75 deletions
+25 -9
View File
@@ -180,6 +180,10 @@ impl AssetBridge for AssetManager {
}
impl AssetManager {
fn codec_is_none_or_legacy_raw(codec: &str) -> bool {
matches!(codec, "NONE" | "RAW")
}
fn decode_tile_bank_layout(
entry: &AssetEntry,
) -> Result<(TileSize, usize, usize, usize), String> {
@@ -246,9 +250,13 @@ impl AssetManager {
}
fn op_mode_for(entry: &AssetEntry) -> Result<AssetOpMode, String> {
match (entry.bank_type, entry.codec.as_str()) {
(BankType::TILES, "RAW") => Ok(AssetOpMode::StageInMemory),
(BankType::SOUNDS, "RAW") => Ok(AssetOpMode::DirectFromSlice),
match entry.bank_type {
BankType::TILES if Self::codec_is_none_or_legacy_raw(entry.codec.as_str()) => {
Ok(AssetOpMode::StageInMemory)
}
BankType::SOUNDS if Self::codec_is_none_or_legacy_raw(entry.codec.as_str()) => {
Ok(AssetOpMode::DirectFromSlice)
}
_ => Err(format!("Unsupported codec: {}", entry.codec)),
}
}
@@ -914,7 +922,7 @@ mod tests {
offset: 0,
size: expected_tile_payload_size(width, height) as u64,
decoded_size: expected_tile_decoded_size(width, height) as u64,
codec: "RAW".to_string(),
codec: "NONE".to_string(),
metadata: serde_json::json!({
"tile_size": 16,
"width": width,
@@ -966,14 +974,22 @@ mod tests {
}
#[test]
fn test_op_mode_for_tiles_raw_stages_in_memory() {
fn test_op_mode_for_tiles_none_stages_in_memory() {
let entry = test_tile_asset_entry("tiles", 16, 16);
assert_eq!(AssetManager::op_mode_for(&entry), Ok(AssetOpMode::StageInMemory));
}
#[test]
fn test_op_mode_for_sounds_raw_reads_direct_from_slice() {
fn test_op_mode_for_tiles_raw_is_legacy_alias() {
let mut entry = test_tile_asset_entry("tiles", 16, 16);
entry.codec = "RAW".to_string();
assert_eq!(AssetManager::op_mode_for(&entry), Ok(AssetOpMode::StageInMemory));
}
#[test]
fn test_op_mode_for_sounds_none_reads_direct_from_slice() {
let entry = AssetEntry {
asset_id: 1,
asset_name: "sound".to_string(),
@@ -981,7 +997,7 @@ mod tests {
offset: 0,
size: 8,
decoded_size: 8,
codec: "RAW".to_string(),
codec: "NONE".to_string(),
metadata: serde_json::json!({
"sample_rate": 44100
}),
@@ -1077,7 +1093,7 @@ mod tests {
offset: 0,
size: data.len() as u64,
decoded_size: data.len() as u64,
codec: "RAW".to_string(),
codec: "NONE".to_string(),
metadata: serde_json::json!({
"sample_rate": 44100
}),
@@ -1122,7 +1138,7 @@ mod tests {
offset: 0,
size: data.len() as u64,
decoded_size: data.len() as u64,
codec: "RAW".to_string(),
codec: "NONE".to_string(),
metadata: serde_json::json!({
"sample_rate": 44100
}),
+1 -1
View File
@@ -20,7 +20,7 @@ pub struct AssetEntry {
pub offset: u64,
pub size: u64,
pub decoded_size: u64,
pub codec: String, // e.g., "RAW"
pub codec: String, // e.g., "NONE" (legacy alias: "RAW")
pub metadata: serde_json::Value,
}
@@ -369,7 +369,7 @@ mod tests {
offset,
size,
decoded_size: 16 * 16 + (TILE_BANK_PALETTE_COUNT_V1 as u64 * 16 * 2),
codec: "RAW".to_string(),
codec: "NONE".to_string(),
metadata: json!({
"tile_size": 16,
"width": 16,
@@ -451,7 +451,7 @@ mod tests {
offset: 4,
size: 4,
decoded_size: 16 * 16 + (TILE_BANK_PALETTE_COUNT_V1 as u64 * 16 * 2),
codec: "RAW".to_string(),
codec: "NONE".to_string(),
metadata: json!({
"tile_size": 16,
"width": 16,
@@ -109,7 +109,7 @@ fn test_tile_asset_entry(asset_name: &str, data_len: usize) -> AssetEntry {
offset: 0,
size: data_len as u64,
decoded_size: test_tile_decoded_size(16, 16) as u64,
codec: "RAW".to_string(),
codec: "NONE".to_string(),
metadata: serde_json::json!({
"tile_size": 16,
"width": 16,