68 lines
2.4 KiB
Rust
68 lines
2.4 KiB
Rust
use super::*;
|
|
use crate::mapper::*;
|
|
|
|
impl SpacetimeClient {
|
|
pub async fn create_battle_state(
|
|
&self,
|
|
input: DomainBattleStateInput,
|
|
) -> Result<BattleStateRecord, SpacetimeClientError> {
|
|
validate_battle_state_input(&input).map_err(SpacetimeClientError::validation_failed)?;
|
|
let procedure_input = input.into();
|
|
|
|
self.call_after_connect(move |connection, sender| {
|
|
connection.procedures().create_battle_state_and_return_then(
|
|
procedure_input,
|
|
move |_, result| {
|
|
let mapped = result
|
|
.map_err(SpacetimeClientError::from_sdk_error)
|
|
.and_then(map_battle_state_procedure_result);
|
|
send_once(&sender, mapped);
|
|
},
|
|
);
|
|
})
|
|
.await
|
|
}
|
|
|
|
pub async fn get_battle_state(
|
|
&self,
|
|
battle_state_id: String,
|
|
) -> Result<BattleStateRecord, SpacetimeClientError> {
|
|
let procedure_input = build_battle_state_query_input(battle_state_id)
|
|
.map_err(SpacetimeClientError::validation_failed)?
|
|
.into();
|
|
|
|
self.call_after_connect(move |connection, sender| {
|
|
connection
|
|
.procedures()
|
|
.get_battle_state_then(procedure_input, move |_, result| {
|
|
let mapped = result
|
|
.map_err(SpacetimeClientError::from_sdk_error)
|
|
.and_then(map_battle_state_procedure_result);
|
|
send_once(&sender, mapped);
|
|
});
|
|
})
|
|
.await
|
|
}
|
|
|
|
pub async fn resolve_combat_action(
|
|
&self,
|
|
input: DomainResolveCombatActionInput,
|
|
) -> Result<ResolveCombatActionRecord, SpacetimeClientError> {
|
|
validate_resolve_combat_action_input(&input)
|
|
.map_err(SpacetimeClientError::validation_failed)?;
|
|
let procedure_input = input.into();
|
|
|
|
self.call_after_connect(move |connection, sender| {
|
|
connection
|
|
.procedures()
|
|
.resolve_combat_action_and_return_then(procedure_input, move |_, result| {
|
|
let mapped = result
|
|
.map_err(SpacetimeClientError::from_sdk_error)
|
|
.and_then(map_resolve_combat_action_procedure_result);
|
|
send_once(&sender, mapped);
|
|
});
|
|
})
|
|
.await
|
|
}
|
|
}
|