43 lines
1.4 KiB
Rust
43 lines
1.4 KiB
Rust
//! runtime story 应用编排落位。
|
|
//!
|
|
//! 这里组合纯领域规则并返回后端投影;真实保存、SSE 和模型调用由外层完成。
|
|
|
|
use serde_json::Value;
|
|
use shared_contracts::runtime_story::RuntimeStoryPatch;
|
|
|
|
use crate::{StoryResolution, read_bool_field, read_optional_string_field};
|
|
|
|
pub fn simple_story_resolution(
|
|
game_state: &Value,
|
|
action_text: String,
|
|
result_text: &str,
|
|
) -> StoryResolution {
|
|
StoryResolution {
|
|
action_text,
|
|
result_text: result_text.to_string(),
|
|
story_text: None,
|
|
presentation_options: None,
|
|
saved_current_story: None,
|
|
patches: vec![build_status_patch(game_state)],
|
|
battle: None,
|
|
toast: None,
|
|
}
|
|
}
|
|
|
|
pub fn build_status_patch(game_state: &Value) -> RuntimeStoryPatch {
|
|
RuntimeStoryPatch::StatusChanged {
|
|
in_battle: read_bool_field(game_state, "inBattle").unwrap_or(false),
|
|
npc_interaction_active: read_bool_field(game_state, "npcInteractionActive")
|
|
.unwrap_or(false),
|
|
current_npc_battle_mode: read_optional_string_field(game_state, "currentNpcBattleMode"),
|
|
current_npc_battle_outcome: read_optional_string_field(
|
|
game_state,
|
|
"currentNpcBattleOutcome",
|
|
),
|
|
}
|
|
}
|
|
|
|
pub fn current_world_type(game_state: &Value) -> Option<String> {
|
|
read_optional_string_field(game_state, "worldType")
|
|
}
|