1
This commit is contained in:
@@ -109,6 +109,9 @@ pub(crate) fn generate_big_fish_asset_tx(
|
||||
last_assistant_reply: Some(reply.clone()),
|
||||
publish_ready: coverage.publish_ready,
|
||||
play_count: session.play_count,
|
||||
remix_count: session.remix_count,
|
||||
like_count: session.like_count,
|
||||
published_at: session.published_at,
|
||||
created_at: session.created_at,
|
||||
updated_at,
|
||||
};
|
||||
@@ -166,6 +169,9 @@ pub(crate) fn publish_big_fish_game_tx(
|
||||
last_assistant_reply: Some("玩法已发布,可以进入测试运行态。".to_string()),
|
||||
publish_ready: true,
|
||||
play_count: session.play_count,
|
||||
remix_count: session.remix_count,
|
||||
like_count: session.like_count,
|
||||
published_at: Some(published_at),
|
||||
created_at: session.created_at,
|
||||
updated_at: published_at,
|
||||
};
|
||||
|
||||
@@ -122,6 +122,25 @@ pub fn record_big_fish_play(
|
||||
}
|
||||
}
|
||||
|
||||
#[spacetimedb::procedure]
|
||||
pub fn remix_big_fish_work(
|
||||
ctx: &mut ProcedureContext,
|
||||
input: BigFishWorkRemixInput,
|
||||
) -> BigFishSessionProcedureResult {
|
||||
match ctx.try_with_tx(|tx| remix_big_fish_work_tx(tx, input.clone())) {
|
||||
Ok(session) => BigFishSessionProcedureResult {
|
||||
ok: true,
|
||||
session: Some(session),
|
||||
error_message: None,
|
||||
},
|
||||
Err(message) => BigFishSessionProcedureResult {
|
||||
ok: false,
|
||||
session: None,
|
||||
error_message: Some(message),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[spacetimedb::procedure]
|
||||
pub fn submit_big_fish_message(
|
||||
ctx: &mut ProcedureContext,
|
||||
@@ -224,6 +243,9 @@ pub(crate) fn create_big_fish_session_tx(
|
||||
last_assistant_reply: Some(input.welcome_message_text.clone()),
|
||||
publish_ready: false,
|
||||
play_count: 0,
|
||||
remix_count: 0,
|
||||
like_count: 0,
|
||||
published_at: None,
|
||||
created_at,
|
||||
updated_at: created_at,
|
||||
});
|
||||
@@ -414,6 +436,9 @@ pub(crate) fn submit_big_fish_message_tx(
|
||||
last_assistant_reply: session.last_assistant_reply.clone(),
|
||||
publish_ready: session.publish_ready,
|
||||
play_count: session.play_count,
|
||||
remix_count: session.remix_count,
|
||||
like_count: session.like_count,
|
||||
published_at: session.published_at,
|
||||
created_at: session.created_at,
|
||||
updated_at: submitted_at,
|
||||
};
|
||||
@@ -461,6 +486,9 @@ pub(crate) fn finalize_big_fish_agent_message_turn_tx(
|
||||
last_assistant_reply: session.last_assistant_reply.clone(),
|
||||
publish_ready: session.publish_ready,
|
||||
play_count: session.play_count,
|
||||
remix_count: session.remix_count,
|
||||
like_count: session.like_count,
|
||||
published_at: session.published_at,
|
||||
created_at: session.created_at,
|
||||
updated_at,
|
||||
};
|
||||
@@ -516,6 +544,9 @@ pub(crate) fn finalize_big_fish_agent_message_turn_tx(
|
||||
last_assistant_reply: Some(assistant_reply_text),
|
||||
publish_ready: session.publish_ready,
|
||||
play_count: session.play_count,
|
||||
remix_count: session.remix_count,
|
||||
like_count: session.like_count,
|
||||
published_at: session.published_at,
|
||||
created_at: session.created_at,
|
||||
updated_at,
|
||||
};
|
||||
@@ -570,6 +601,9 @@ pub(crate) fn compile_big_fish_draft_tx(
|
||||
last_assistant_reply: Some(reply.clone()),
|
||||
publish_ready: coverage.publish_ready,
|
||||
play_count: session.play_count,
|
||||
remix_count: session.remix_count,
|
||||
like_count: session.like_count,
|
||||
published_at: session.published_at,
|
||||
created_at: session.created_at,
|
||||
updated_at: compiled_at,
|
||||
};
|
||||
@@ -656,6 +690,9 @@ pub(crate) fn record_big_fish_play_tx(
|
||||
publish_ready: session.publish_ready,
|
||||
// 中文注释:正式进入已发布作品时同时累加作品播放数,用户侧去重由 profile_played_world 保证。
|
||||
play_count: session.play_count.saturating_add(1),
|
||||
remix_count: session.remix_count,
|
||||
like_count: session.like_count,
|
||||
published_at: session.published_at,
|
||||
created_at: session.created_at,
|
||||
updated_at: played_at,
|
||||
};
|
||||
@@ -670,6 +707,123 @@ pub(crate) fn record_big_fish_play_tx(
|
||||
)
|
||||
}
|
||||
|
||||
fn remix_big_fish_work_tx(
|
||||
ctx: &ReducerContext,
|
||||
input: BigFishWorkRemixInput,
|
||||
) -> Result<BigFishSessionSnapshot, String> {
|
||||
let source_session_id = input.source_session_id.trim();
|
||||
let target_session_id = input.target_session_id.trim();
|
||||
let target_owner_user_id = input.target_owner_user_id.trim();
|
||||
let welcome_message_id = input.welcome_message_id.trim();
|
||||
if source_session_id.is_empty()
|
||||
|| target_session_id.is_empty()
|
||||
|| target_owner_user_id.is_empty()
|
||||
|| welcome_message_id.is_empty()
|
||||
{
|
||||
return Err("big_fish remix 参数不能为空".to_string());
|
||||
}
|
||||
if ctx
|
||||
.db
|
||||
.big_fish_creation_session()
|
||||
.session_id()
|
||||
.find(&target_session_id.to_string())
|
||||
.is_some()
|
||||
{
|
||||
return Err("big_fish remix 目标 session 已存在".to_string());
|
||||
}
|
||||
if ctx
|
||||
.db
|
||||
.big_fish_agent_message()
|
||||
.message_id()
|
||||
.find(&welcome_message_id.to_string())
|
||||
.is_some()
|
||||
{
|
||||
return Err("big_fish remix 消息已存在".to_string());
|
||||
}
|
||||
|
||||
let source = ctx
|
||||
.db
|
||||
.big_fish_creation_session()
|
||||
.session_id()
|
||||
.find(&source_session_id.to_string())
|
||||
.filter(|row| row.stage == BigFishCreationStage::Published)
|
||||
.ok_or_else(|| "big_fish 已发布源作品不存在".to_string())?;
|
||||
let remixed_at = Timestamp::from_micros_since_unix_epoch(input.remixed_at_micros);
|
||||
let next_source = BigFishCreationSession {
|
||||
session_id: source.session_id.clone(),
|
||||
owner_user_id: source.owner_user_id.clone(),
|
||||
seed_text: source.seed_text.clone(),
|
||||
current_turn: source.current_turn,
|
||||
progress_percent: source.progress_percent,
|
||||
stage: source.stage,
|
||||
anchor_pack_json: source.anchor_pack_json.clone(),
|
||||
draft_json: source.draft_json.clone(),
|
||||
asset_coverage_json: source.asset_coverage_json.clone(),
|
||||
last_assistant_reply: source.last_assistant_reply.clone(),
|
||||
publish_ready: source.publish_ready,
|
||||
play_count: source.play_count,
|
||||
remix_count: source.remix_count.saturating_add(1),
|
||||
like_count: source.like_count,
|
||||
published_at: source.published_at,
|
||||
created_at: source.created_at,
|
||||
updated_at: remixed_at,
|
||||
};
|
||||
replace_big_fish_session(ctx, &source, next_source);
|
||||
|
||||
let target_session = BigFishCreationSession {
|
||||
session_id: target_session_id.to_string(),
|
||||
owner_user_id: target_owner_user_id.to_string(),
|
||||
seed_text: source.seed_text.clone(),
|
||||
current_turn: 1,
|
||||
progress_percent: 80,
|
||||
stage: BigFishCreationStage::DraftReady,
|
||||
anchor_pack_json: source.anchor_pack_json.clone(),
|
||||
draft_json: source.draft_json.clone(),
|
||||
asset_coverage_json: source.asset_coverage_json.clone(),
|
||||
last_assistant_reply: Some("已从公开作品 Remix 出新的大鱼吃小鱼草稿。".to_string()),
|
||||
publish_ready: source.publish_ready,
|
||||
play_count: 0,
|
||||
remix_count: 0,
|
||||
like_count: 0,
|
||||
published_at: None,
|
||||
created_at: remixed_at,
|
||||
updated_at: remixed_at,
|
||||
};
|
||||
ctx.db.big_fish_creation_session().insert(target_session);
|
||||
ctx.db.big_fish_agent_message().insert(BigFishAgentMessage {
|
||||
message_id: welcome_message_id.to_string(),
|
||||
session_id: target_session_id.to_string(),
|
||||
role: BigFishAgentMessageRole::Assistant,
|
||||
kind: BigFishAgentMessageKind::Summary,
|
||||
text: "已复制公开作品为你的草稿。".to_string(),
|
||||
created_at: remixed_at,
|
||||
});
|
||||
for slot in list_big_fish_asset_slots(ctx, &source.session_id) {
|
||||
upsert_big_fish_asset_slot(
|
||||
ctx,
|
||||
BigFishAssetSlotSnapshot {
|
||||
slot_id: slot.slot_id.replace(&source.session_id, target_session_id),
|
||||
session_id: target_session_id.to_string(),
|
||||
asset_kind: slot.asset_kind,
|
||||
level: slot.level,
|
||||
motion_key: slot.motion_key,
|
||||
status: slot.status,
|
||||
asset_url: slot.asset_url,
|
||||
prompt_snapshot: slot.prompt_snapshot,
|
||||
updated_at_micros: input.remixed_at_micros,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
get_big_fish_session_tx(
|
||||
ctx,
|
||||
BigFishSessionGetInput {
|
||||
session_id: target_session_id.to_string(),
|
||||
owner_user_id: target_owner_user_id.to_string(),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn build_big_fish_session_snapshot(
|
||||
ctx: &ReducerContext,
|
||||
row: &BigFishCreationSession,
|
||||
@@ -784,6 +938,12 @@ pub(crate) fn build_big_fish_work_summary(
|
||||
level_motion_ready_count: coverage.level_motion_ready_count,
|
||||
background_ready: coverage.background_ready,
|
||||
play_count: row.play_count,
|
||||
remix_count: row.remix_count,
|
||||
like_count: row.like_count,
|
||||
published_at_micros: row
|
||||
.published_at
|
||||
.or_else(|| (row.stage == BigFishCreationStage::Published).then_some(row.updated_at))
|
||||
.map(|value| value.to_micros_since_unix_epoch()),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -821,6 +981,13 @@ mod tests {
|
||||
last_assistant_reply: Some("欢迎来到大鱼吃小鱼共创。".to_string()),
|
||||
publish_ready: false,
|
||||
play_count: 0,
|
||||
remix_count: 0,
|
||||
like_count: 0,
|
||||
published_at: if stage == BigFishCreationStage::Published {
|
||||
Some(Timestamp::from_micros_since_unix_epoch(1))
|
||||
} else {
|
||||
None
|
||||
},
|
||||
created_at: Timestamp::from_micros_since_unix_epoch(1),
|
||||
updated_at: Timestamp::from_micros_since_unix_epoch(1),
|
||||
}
|
||||
|
||||
@@ -18,6 +18,9 @@ pub struct BigFishCreationSession {
|
||||
pub(crate) last_assistant_reply: Option<String>,
|
||||
pub(crate) publish_ready: bool,
|
||||
pub(crate) play_count: u32,
|
||||
pub(crate) remix_count: u32,
|
||||
pub(crate) like_count: u32,
|
||||
pub(crate) published_at: Option<Timestamp>,
|
||||
pub(crate) created_at: Timestamp,
|
||||
pub(crate) updated_at: Timestamp,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user