feat: 结局AI改写支持pathHistory回放和完成通知
This commit is contained in:
@@ -164,12 +164,15 @@ export default class StoryManager {
|
||||
// 先标记之前的未读草稿为已读
|
||||
await this.markAllDraftsRead(userId);
|
||||
|
||||
console.log('[rewriteEndingAsync] pathHistory:', JSON.stringify(this.pathHistory));
|
||||
|
||||
const result = await post(`/drafts/ending`, {
|
||||
userId: userId,
|
||||
storyId: storyId,
|
||||
endingName: ending?.name || '未知结局',
|
||||
endingContent: ending?.content || '',
|
||||
prompt: prompt
|
||||
prompt: prompt,
|
||||
pathHistory: this.pathHistory || [] // 传递游玩路径
|
||||
}, { timeout: 30000 });
|
||||
|
||||
if (result && result.draftId) {
|
||||
@@ -195,7 +198,8 @@ export default class StoryManager {
|
||||
storyId: storyId,
|
||||
endingName: ending?.name || '未知结局',
|
||||
endingContent: ending?.content || '',
|
||||
prompt: prompt
|
||||
prompt: prompt,
|
||||
pathHistory: this.pathHistory || [] // 传递游玩路径
|
||||
}, { timeout: 30000 });
|
||||
|
||||
if (result && result.draftId) {
|
||||
|
||||
@@ -128,6 +128,12 @@ export default class Main {
|
||||
try {
|
||||
if (!this.userManager.isLoggedIn) return;
|
||||
|
||||
// 如果结局页正在轮询,跳过全局检查
|
||||
const currentScene = this.sceneManager.currentScene;
|
||||
if (currentScene && currentScene.draftPollTimer) {
|
||||
return;
|
||||
}
|
||||
|
||||
const result = await this.storyManager.checkNewDrafts(this.userManager.userId);
|
||||
|
||||
if (result && result.hasNew && result.count > 0) {
|
||||
|
||||
@@ -1080,6 +1080,9 @@ export default class EndingScene extends BaseScene {
|
||||
showCancel: false,
|
||||
confirmText: '知道了'
|
||||
});
|
||||
|
||||
// 启动专门的草稿检查(每5秒检查一次,持续2分钟)
|
||||
this.startDraftPolling(result.draftId);
|
||||
} else {
|
||||
wx.showToast({ title: '提交失败,请重试', icon: 'none' });
|
||||
}
|
||||
@@ -1130,6 +1133,9 @@ export default class EndingScene extends BaseScene {
|
||||
showCancel: false,
|
||||
confirmText: '知道了'
|
||||
});
|
||||
|
||||
// 启动专门的草稿检查(每5秒检查一次,持续2分钟)
|
||||
this.startDraftPolling(result.draftId);
|
||||
} else {
|
||||
wx.showToast({ title: '提交失败,请重试', icon: 'none' });
|
||||
}
|
||||
@@ -1189,4 +1195,69 @@ export default class EndingScene extends BaseScene {
|
||||
this.isCollected = !this.isCollected;
|
||||
this.main.userManager.collectStory(this.storyId, this.isCollected);
|
||||
}
|
||||
|
||||
// 启动草稿完成轮询(每5秒检查一次,持续2分钟)
|
||||
startDraftPolling(draftId) {
|
||||
// 清除之前的轮询
|
||||
if (this.draftPollTimer) {
|
||||
clearInterval(this.draftPollTimer);
|
||||
}
|
||||
|
||||
let pollCount = 0;
|
||||
const maxPolls = 24; // 2分钟 / 5秒 = 24次
|
||||
|
||||
console.log('[EndingScene] 启动草稿轮询, draftId:', draftId);
|
||||
|
||||
this.draftPollTimer = setInterval(async () => {
|
||||
pollCount++;
|
||||
|
||||
if (pollCount > maxPolls) {
|
||||
console.log('[EndingScene] 轮询超时,停止检查');
|
||||
clearInterval(this.draftPollTimer);
|
||||
this.draftPollTimer = null;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const userId = this.main.userManager.userId;
|
||||
if (!userId) return;
|
||||
|
||||
const result = await this.main.storyManager.checkNewDrafts(userId);
|
||||
|
||||
if (result && result.hasNew && result.count > 0) {
|
||||
console.log('[EndingScene] 检测到新草稿:', result.count);
|
||||
|
||||
// 停止轮询
|
||||
clearInterval(this.draftPollTimer);
|
||||
this.draftPollTimer = null;
|
||||
|
||||
// 标记为已读
|
||||
await this.main.storyManager.markAllDraftsRead(userId);
|
||||
|
||||
// 弹窗通知
|
||||
wx.showModal({
|
||||
title: 'AI改写完成',
|
||||
content: `您有 ${result.count} 个新的AI改写已完成,是否前往查看?`,
|
||||
confirmText: '查看',
|
||||
cancelText: '稍后',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
this.main.sceneManager.switchScene('profile', { tab: 1 });
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('[EndingScene] 草稿检查失败:', e);
|
||||
}
|
||||
}, 5000); // 每5秒检查一次
|
||||
}
|
||||
|
||||
// 场景销毁时清理轮询
|
||||
destroy() {
|
||||
if (this.draftPollTimer) {
|
||||
clearInterval(this.draftPollTimer);
|
||||
this.draftPollTimer = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,6 +128,14 @@ export default class StoryScene extends BaseScene {
|
||||
|
||||
const draft = await this.main.storyManager.getDraftDetail(this.draftId);
|
||||
|
||||
console.log('[StoryScene] 草稿详情:', JSON.stringify({
|
||||
hasDraft: !!draft,
|
||||
hasAiNodes: !!draft?.aiNodes,
|
||||
aiNodesKeys: draft?.aiNodes ? Object.keys(draft.aiNodes) : [],
|
||||
entryNodeKey: draft?.entryNodeKey,
|
||||
pathHistoryLength: draft?.pathHistory?.length
|
||||
}));
|
||||
|
||||
if (draft && draft.aiNodes && draft.storyId) {
|
||||
// 先加载原故事
|
||||
this.story = await this.main.storyManager.loadStoryDetail(draft.storyId);
|
||||
@@ -1197,8 +1205,8 @@ export default class StoryScene extends BaseScene {
|
||||
if (this.waitingForClick) {
|
||||
this.waitingForClick = false;
|
||||
|
||||
// AI改写内容 - 直接跳转到新结局
|
||||
if (this.aiContent && this.aiContent.is_ending) {
|
||||
// AI改写内容 - 直接跳转到新结局(但回放模式下先显示选项)
|
||||
if (this.aiContent && this.aiContent.is_ending && !this.isReplayMode) {
|
||||
console.log('AI改写内容:', JSON.stringify(this.aiContent));
|
||||
this.main.sceneManager.switchScene('ending', {
|
||||
storyId: this.storyId,
|
||||
|
||||
Reference in New Issue
Block a user