refactor: split large modules and normalize rust layout

This commit is contained in:
kdletters
2026-05-18 19:40:14 +08:00
parent 472a47eae7
commit 269f35cecf
51 changed files with 17492 additions and 17169 deletions

View File

@@ -0,0 +1,94 @@
use super::*;
pub(crate) fn map_bark_battle_draft_config_procedure_result(
result: BarkBattleProcedureResult,
) -> Result<BarkBattleDraftConfigRecord, SpacetimeClientError> {
if !result.ok {
return Err(SpacetimeClientError::procedure_failed(result.error_message));
}
result
.draft_config
.ok_or_else(|| SpacetimeClientError::missing_snapshot("Bark Battle draft config"))
.map(bark_battle_draft_config_to_value)
}
pub(crate) fn map_bark_battle_runtime_config_procedure_result(
result: BarkBattleProcedureResult,
) -> Result<BarkBattleRuntimeConfigRecord, SpacetimeClientError> {
if !result.ok {
return Err(SpacetimeClientError::procedure_failed(result.error_message));
}
result
.runtime_config
.ok_or_else(|| SpacetimeClientError::missing_snapshot("Bark Battle runtime config"))
.map(bark_battle_runtime_config_to_value)
}
pub(crate) fn map_bark_battle_run_procedure_result(
result: BarkBattleProcedureResult,
) -> Result<BarkBattleRunRecord, SpacetimeClientError> {
if !result.ok {
return Err(SpacetimeClientError::procedure_failed(result.error_message));
}
result
.run
.ok_or_else(|| SpacetimeClientError::missing_snapshot("Bark Battle run"))
.map(bark_battle_run_to_value)
}
fn bark_battle_draft_config_to_value(snapshot: BarkBattleDraftConfigSnapshot) -> serde_json::Value {
serde_json::json!({
"draftId": snapshot.draft_id,
"ownerUserId": snapshot.owner_user_id,
"workId": snapshot.work_id,
"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,
"updatedAtMicros": snapshot.updated_at_micros,
})
}
fn bark_battle_runtime_config_to_value(
snapshot: BarkBattleRuntimeConfigSnapshot,
) -> serde_json::Value {
serde_json::json!({
"workId": snapshot.work_id,
"ownerUserId": snapshot.owner_user_id,
"sourceDraftId": snapshot.source_draft_id,
"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,
"updatedAtMicros": snapshot.updated_at_micros,
})
}
fn bark_battle_run_to_value(snapshot: BarkBattleRunSnapshot) -> serde_json::Value {
serde_json::json!({
"runId": snapshot.run_id,
"ownerUserId": snapshot.owner_user_id,
"workId": snapshot.work_id,
"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,
"clientFinishedAtMicros": snapshot.client_finished_at_micros,
"serverFinishedAtMicros": snapshot.server_finished_at_micros,
"metricsJson": snapshot.metrics_json,
"serverResult": snapshot.server_result,
"validationStatus": snapshot.validation_status,
"antiCheatFlagsJson": snapshot.anti_cheat_flags_json,
"leaderboardScore": snapshot.leaderboard_score,
"scoreId": snapshot.score_id,
})
}