迁移后端认证与拆分 Spacetime 客户端
This commit is contained in:
72
server-rs/crates/spacetime-client/src/combat.rs
Normal file
72
server-rs/crates/spacetime-client/src/combat.rs
Normal file
@@ -0,0 +1,72 @@
|
||||
use super::*;
|
||||
|
||||
impl SpacetimeClient {
|
||||
pub async fn create_battle_state(
|
||||
&self,
|
||||
input: DomainBattleStateInput,
|
||||
) -> Result<BattleStateRecord, SpacetimeClientError> {
|
||||
validate_battle_state_input(&input)
|
||||
.map_err(|error| SpacetimeClientError::Runtime(error.to_string()))?;
|
||||
let procedure_input = map_battle_state_input(input);
|
||||
|
||||
self.call_after_connect(move |connection, sender| {
|
||||
connection.procedures().create_battle_state_and_return_then(
|
||||
procedure_input,
|
||||
move |_, result| {
|
||||
let mapped = result
|
||||
.map_err(|error| SpacetimeClientError::Procedure(error.to_string()))
|
||||
.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 = map_battle_state_query_input(
|
||||
build_battle_state_query_input(battle_state_id)
|
||||
.map_err(|error| SpacetimeClientError::Runtime(error.to_string()))?,
|
||||
);
|
||||
|
||||
self.call_after_connect(move |connection, sender| {
|
||||
connection
|
||||
.procedures()
|
||||
.get_battle_state_then(procedure_input, move |_, result| {
|
||||
let mapped = result
|
||||
.map_err(|error| SpacetimeClientError::Procedure(error.to_string()))
|
||||
.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(|error| SpacetimeClientError::Runtime(error.to_string()))?;
|
||||
let procedure_input = map_resolve_combat_action_input(input);
|
||||
|
||||
self.call_after_connect(move |connection, sender| {
|
||||
connection
|
||||
.procedures()
|
||||
.resolve_combat_action_and_return_then(procedure_input, move |_, result| {
|
||||
let mapped = result
|
||||
.map_err(|error| SpacetimeClientError::Procedure(error.to_string()))
|
||||
.and_then(map_resolve_combat_action_procedure_result);
|
||||
send_once(&sender, mapped);
|
||||
});
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user