refactor: split large modules and normalize rust layout
This commit is contained in:
94
server-rs/crates/spacetime-client/src/mapper/bark_battle.rs
Normal file
94
server-rs/crates/spacetime-client/src/mapper/bark_battle.rs
Normal 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,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user