fix: polish bark battle creation flow
This commit is contained in:
@@ -36,6 +36,70 @@ pub(crate) fn map_bark_battle_run_procedure_result(
|
||||
.map(bark_battle_run_to_value)
|
||||
}
|
||||
|
||||
pub(crate) fn map_bark_battle_draft_config_row(
|
||||
row: BarkBattleDraftConfigRow,
|
||||
) -> BarkBattleDraftConfigRecord {
|
||||
serde_json::json!({
|
||||
"draftId": row.draft_id,
|
||||
"ownerUserId": row.owner_user_id,
|
||||
"workId": row.work_id,
|
||||
"configVersion": row.config_version,
|
||||
"rulesetVersion": row.ruleset_version,
|
||||
"difficultyPreset": row.difficulty_preset,
|
||||
"configJson": row.config_json,
|
||||
"editorStateJson": row.editor_state_json,
|
||||
"createdAtMicros": row.created_at.to_micros_since_unix_epoch(),
|
||||
"updatedAtMicros": row.updated_at.to_micros_since_unix_epoch(),
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn map_bark_battle_published_config_row(
|
||||
row: BarkBattlePublishedConfigRow,
|
||||
) -> BarkBattleRuntimeConfigRecord {
|
||||
serde_json::json!({
|
||||
"workId": row.work_id,
|
||||
"ownerUserId": row.owner_user_id,
|
||||
"sourceDraftId": row.source_draft_id,
|
||||
"configVersion": row.config_version,
|
||||
"rulesetVersion": row.ruleset_version,
|
||||
"difficultyPreset": row.difficulty_preset,
|
||||
"configJson": row.config_json,
|
||||
"publishedSnapshotJson": row.published_snapshot_json,
|
||||
"publishedAtMicros": row.published_at.to_micros_since_unix_epoch(),
|
||||
"updatedAtMicros": row.updated_at.to_micros_since_unix_epoch(),
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn map_bark_battle_gallery_view_row(
|
||||
row: BarkBattleGalleryViewRow,
|
||||
recent_play_count_7d: u32,
|
||||
) -> serde_json::Value {
|
||||
serde_json::json!({
|
||||
"workId": row.work_id,
|
||||
"ownerUserId": row.owner_user_id,
|
||||
"sourceDraftId": row.source_draft_id,
|
||||
"configVersion": row.config_version,
|
||||
"rulesetVersion": row.ruleset_version,
|
||||
"difficultyPreset": row.difficulty_preset,
|
||||
"title": row.title,
|
||||
"description": row.description,
|
||||
"themeDescription": row.theme_description,
|
||||
"playerImageDescription": row.player_image_description,
|
||||
"opponentImageDescription": row.opponent_image_description,
|
||||
"onomatopoeia": row.onomatopoeia,
|
||||
"playerCharacterImageSrc": row.player_character_image_src,
|
||||
"opponentCharacterImageSrc": row.opponent_character_image_src,
|
||||
"uiBackgroundImageSrc": row.ui_background_image_src,
|
||||
"status": "published",
|
||||
"publishReady": true,
|
||||
"playCount": row.play_count,
|
||||
"finishCount": row.finish_count,
|
||||
"recentPlayCount7d": recent_play_count_7d,
|
||||
"updatedAtMicros": row.updated_at_micros,
|
||||
"publishedAtMicros": row.published_at_micros,
|
||||
})
|
||||
}
|
||||
|
||||
fn bark_battle_draft_config_to_value(snapshot: BarkBattleDraftConfigSnapshot) -> serde_json::Value {
|
||||
serde_json::json!({
|
||||
"draftId": snapshot.draft_id,
|
||||
@@ -44,7 +108,6 @@ fn bark_battle_draft_config_to_value(snapshot: BarkBattleDraftConfigSnapshot) ->
|
||||
"configVersion": snapshot.config_version,
|
||||
"rulesetVersion": snapshot.ruleset_version,
|
||||
"difficultyPreset": snapshot.difficulty_preset,
|
||||
"leaderboardEnabled": snapshot.leaderboard_enabled,
|
||||
"configJson": snapshot.config_json,
|
||||
"editorStateJson": snapshot.editor_state_json,
|
||||
"createdAtMicros": snapshot.created_at_micros,
|
||||
@@ -62,7 +125,6 @@ fn bark_battle_runtime_config_to_value(
|
||||
"configVersion": snapshot.config_version,
|
||||
"rulesetVersion": snapshot.ruleset_version,
|
||||
"difficultyPreset": snapshot.difficulty_preset,
|
||||
"leaderboardEnabled": snapshot.leaderboard_enabled,
|
||||
"configJson": snapshot.config_json,
|
||||
"publishedSnapshotJson": snapshot.published_snapshot_json,
|
||||
"publishedAtMicros": snapshot.published_at_micros,
|
||||
@@ -78,7 +140,6 @@ fn bark_battle_run_to_value(snapshot: BarkBattleRunSnapshot) -> serde_json::Valu
|
||||
"configVersion": snapshot.config_version,
|
||||
"rulesetVersion": snapshot.ruleset_version,
|
||||
"difficultyPreset": snapshot.difficulty_preset,
|
||||
"leaderboardEnabled": snapshot.leaderboard_enabled,
|
||||
"status": snapshot.status,
|
||||
"clientStartedAtMicros": snapshot.client_started_at_micros,
|
||||
"serverStartedAtMicros": snapshot.server_started_at_micros,
|
||||
@@ -92,3 +153,38 @@ fn bark_battle_run_to_value(snapshot: BarkBattleRunSnapshot) -> serde_json::Valu
|
||||
"scoreId": snapshot.score_id,
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn bark_battle_gallery_mapper_keeps_custom_onomatopoeia() {
|
||||
let row = BarkBattleGalleryViewRow {
|
||||
work_id: "BB-33333333".to_string(),
|
||||
owner_user_id: "user-3".to_string(),
|
||||
source_draft_id: Some("bark-battle-draft-3".to_string()),
|
||||
config_version: 1,
|
||||
ruleset_version: "bark-battle-ruleset-v1".to_string(),
|
||||
difficulty_preset: "normal".to_string(),
|
||||
title: "声浪公开赛".to_string(),
|
||||
description: "画廊映射测试".to_string(),
|
||||
theme_description: "霓虹竞技场".to_string(),
|
||||
player_image_description: "星际猫骑士".to_string(),
|
||||
opponent_image_description: "机器人拳手".to_string(),
|
||||
onomatopoeia: vec!["轰!".to_string(), "炸场!".to_string()],
|
||||
player_character_image_src: Some("/assets/player.png".to_string()),
|
||||
opponent_character_image_src: Some("/assets/opponent.png".to_string()),
|
||||
ui_background_image_src: Some("/assets/background.png".to_string()),
|
||||
play_count: 8,
|
||||
finish_count: 5,
|
||||
updated_at_micros: 1_713_686_401_234_567,
|
||||
published_at_micros: 1_713_686_401_234_000,
|
||||
};
|
||||
|
||||
let value = map_bark_battle_gallery_view_row(row, 3);
|
||||
|
||||
assert_eq!(value["onomatopoeia"], serde_json::json!(["轰!", "炸场!"]));
|
||||
assert_eq!(value["recentPlayCount7d"], serde_json::json!(3));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user