Add public work read model and smooth puzzle transitions

This commit is contained in:
kdletters
2026-05-26 16:38:27 +08:00
parent 545f315cbc
commit aeee782fe0
47 changed files with 2679 additions and 79 deletions

View File

@@ -1789,6 +1789,18 @@ pub fn select_next_profiles<'a>(
available
}
pub fn select_runtime_next_profile<'a>(
same_work_next_profile: Option<&'a PuzzleWorkProfile>,
similar_work_profiles: &'a [&'a PuzzleWorkProfile],
prefer_similar_work: bool,
) -> Option<&'a PuzzleWorkProfile> {
if prefer_similar_work {
similar_work_profiles.first().copied().or(same_work_next_profile)
} else {
same_work_next_profile.or_else(|| similar_work_profiles.first().copied())
}
}
pub fn recommendation_score(
current_profile: &PuzzleWorkProfile,
candidate: &PuzzleWorkProfile,
@@ -3261,6 +3273,28 @@ mod tests {
assert_eq!(selected.profile_id, "b");
}
#[test]
fn select_runtime_next_profile_prefers_similar_work_when_requested() {
let same_work = build_published_profile("same", "owner-a", vec!["奇幻"]);
let similar_work = build_published_profile("similar", "owner-b", vec!["奇幻"]);
let similar_work_profiles = [&similar_work];
let selected = select_runtime_next_profile(
Some(&same_work),
&similar_work_profiles,
true,
)
.expect("should select similar work first");
assert_eq!(selected.profile_id, "similar");
}
#[test]
fn select_runtime_next_profile_falls_back_to_same_work_when_no_similar_candidate() {
let same_work = build_published_profile("same", "owner-a", vec!["奇幻"]);
let selected = select_runtime_next_profile(Some(&same_work), &[], true)
.expect("should fall back to same work");
assert_eq!(selected.profile_id, "same");
}
#[test]
fn restart_cleared_count_uses_selected_level_index() {
let mut profile = build_published_profile("entry", "owner-a", vec!["机关"]);

View File

@@ -228,6 +228,8 @@ pub struct PuzzleRunNextLevelInput {
pub owner_user_id: String,
#[serde(default)]
pub target_profile_id: Option<String>,
#[serde(default)]
pub prefer_similar_work: bool,
pub advanced_at_micros: i64,
}