feat: 完善分享模式
This commit is contained in:
@@ -11,7 +11,7 @@ import { ShareManager } from 'db://assets/scripts/utils/ShareManager';
|
||||
import { PassModal } from 'db://assets/prefabs/PassModal';
|
||||
import { WrongModal } from 'db://assets/prefabs/WrongModal';
|
||||
import { TimeoutModal } from 'db://assets/prefabs/TimeoutModal';
|
||||
import { StaminaInfo, NextLevelData } from 'db://assets/scripts/types/ApiTypes';
|
||||
import { StaminaInfo, NextLevelData, SubmitShareLevel } from 'db://assets/scripts/types/ApiTypes';
|
||||
import { AchievementTitleManager } from 'db://assets/scripts/utils/AchievementTitleManager';
|
||||
import { applyRoundedCorner } from 'db://assets/scripts/utils/roundedMaterial.utils';
|
||||
const { ccclass, property } = _decorator;
|
||||
@@ -286,6 +286,12 @@ export class PageLevel extends BaseView {
|
||||
/** 分享模式下的关卡索引(仅分享模式使用) */
|
||||
private _shareLevelIndex: number = 0;
|
||||
|
||||
/** 分享模式下每关最终提交内容,等整场结束后一次性提交 */
|
||||
private _shareSubmissions: Map<string, SubmitShareLevel> = new Map();
|
||||
|
||||
/** 是否正在提交分享挑战结果 */
|
||||
private _isSubmittingShareResult: boolean = false;
|
||||
|
||||
/**
|
||||
* 页面首次加载时调用
|
||||
*/
|
||||
@@ -300,6 +306,8 @@ export class PageLevel extends BaseView {
|
||||
|
||||
if (this._isShareMode) {
|
||||
this._shareLevelIndex = 0;
|
||||
this._shareSubmissions.clear();
|
||||
this._isSubmittingShareResult = false;
|
||||
console.log('[PageLevel] 进入分享挑战模式');
|
||||
} else {
|
||||
// 从 AuthManager 获取首关数据(由 PageLoading → game-data 提供)
|
||||
@@ -703,6 +711,7 @@ export class PageLevel extends BaseView {
|
||||
|
||||
private tryAutoSubmitAnswer(): void {
|
||||
if (!this._currentConfig || this._isTransitioning) return;
|
||||
if (this._isShareMode) return;
|
||||
|
||||
const values = this.getInputValues();
|
||||
const isFilled = values.length === Array.from(this._currentConfig.answer ?? '').length && values.every(value => value.length === 1);
|
||||
@@ -913,8 +922,15 @@ export class PageLevel extends BaseView {
|
||||
if (!this._isShareMode) {
|
||||
return;
|
||||
}
|
||||
if (this._isSubmittingShareResult) {
|
||||
return;
|
||||
}
|
||||
if (this._isTransitioning) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.playClickSound();
|
||||
this._recordCurrentShareSubmission();
|
||||
void this.goToNextLevel();
|
||||
}
|
||||
|
||||
@@ -1639,6 +1655,11 @@ export class PageLevel extends BaseView {
|
||||
const userAnswer = this.getAnswer();
|
||||
console.log(`[PageLevel] 提交答案: ${userAnswer}, 正确答案: ${this._currentConfig.answer}`);
|
||||
|
||||
if (this._isShareMode) {
|
||||
void this._submitShareAnswerAndContinue(userAnswer);
|
||||
return;
|
||||
}
|
||||
|
||||
if (userAnswer === this._currentConfig.answer) {
|
||||
// 答案正确,只播放成功音效(不播放点击音效,避免重合)
|
||||
this.showSuccess();
|
||||
@@ -1676,11 +1697,15 @@ export class PageLevel extends BaseView {
|
||||
|
||||
this.reportLevelCompleted(levelId, timeSpent);
|
||||
|
||||
// 不论是否有谐音梗,都停留固定时间再弹出通关弹窗,保证节奏一致
|
||||
// 不论是否有谐音梗,都停留固定时间,保证玩家能看到答案反馈
|
||||
await this.delay(PageLevel.PASS_MODAL_DELAY_MS);
|
||||
|
||||
if (this._isFinalShareLevel()) {
|
||||
this._showShareEndPage();
|
||||
if (this._isShareMode) {
|
||||
if (this._isFinalShareLevel()) {
|
||||
await this._showShareEndPage();
|
||||
} else {
|
||||
await this.goToNextLevel();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1688,6 +1713,24 @@ export class PageLevel extends BaseView {
|
||||
this._showPassModal();
|
||||
}
|
||||
|
||||
private async _submitShareAnswerAndContinue(userAnswer: string): Promise<void> {
|
||||
if (!this._currentConfig || this._isTransitioning || this._isSubmittingShareResult) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._isTransitioning = true;
|
||||
this.stopCountdown();
|
||||
this.hidePunchline();
|
||||
this._recordCurrentShareSubmission(userAnswer);
|
||||
|
||||
if (this._isFinalShareLevel()) {
|
||||
await this._showShareEndPage();
|
||||
return;
|
||||
}
|
||||
|
||||
await this.goToNextLevel();
|
||||
}
|
||||
|
||||
private getValidPunchline(punchline: string | null): string | null {
|
||||
if (!punchline?.trim()) {
|
||||
return null;
|
||||
@@ -1730,8 +1773,43 @@ export class PageLevel extends BaseView {
|
||||
|
||||
this._passModalCompletedLevelCount = null;
|
||||
this._passModalPreviousCompletedLevelCount = null;
|
||||
// fire-and-forget: errors are logged inside reportLevelProgress
|
||||
void ShareManager.instance.reportLevelProgress(levelId, true, timeSpent);
|
||||
this._recordCurrentShareSubmission(undefined, timeSpent);
|
||||
}
|
||||
|
||||
private _recordCurrentShareSubmission(answer?: string, timeSpent?: number): void {
|
||||
if (!this._isShareMode || !this._currentConfig?.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
const elapsedSeconds = Math.max(0, Math.round((Date.now() - this._levelStartTime) / 1000));
|
||||
const finalTimeSpent = Math.max(0, Math.round(timeSpent ?? elapsedSeconds));
|
||||
const finalAnswer = answer ?? this.getAnswer();
|
||||
|
||||
this._shareSubmissions.set(this._currentConfig.id, {
|
||||
levelId: this._currentConfig.id,
|
||||
answer: finalAnswer,
|
||||
timeSpent: finalTimeSpent,
|
||||
});
|
||||
|
||||
console.log(
|
||||
`[PageLevel] 记录分享挑战提交: ${this._currentConfig.id}, answer="${finalAnswer}", timeSpent=${finalTimeSpent}`,
|
||||
);
|
||||
}
|
||||
|
||||
private _buildShareSubmissionPayload(): SubmitShareLevel[] {
|
||||
const levelIds = ShareManager.instance.getShareLevelIds();
|
||||
const ids = levelIds.length > 0
|
||||
? levelIds
|
||||
: [...this._shareSubmissions.keys()];
|
||||
|
||||
return ids.map(levelId => {
|
||||
const submission = this._shareSubmissions.get(levelId);
|
||||
return submission ?? {
|
||||
levelId,
|
||||
answer: '',
|
||||
timeSpent: 0,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private delay(ms: number): Promise<void> {
|
||||
@@ -2021,7 +2099,7 @@ export class PageLevel extends BaseView {
|
||||
if (this._shareLevelIndex >= totalLevels) {
|
||||
console.log('[PageLevel] 分享关卡全部完成');
|
||||
this.stopCountdown();
|
||||
this._showShareEndPage();
|
||||
await this._showShareEndPage();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2056,9 +2134,41 @@ export class PageLevel extends BaseView {
|
||||
return totalLevels > 0 && this._shareLevelIndex >= totalLevels - 1;
|
||||
}
|
||||
|
||||
private _showShareEndPage(): void {
|
||||
private async _showShareEndPage(): Promise<void> {
|
||||
if (this._isSubmittingShareResult) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('[PageLevel] 分享关卡全部完成,进入 PK 结算页');
|
||||
this.stopCountdown();
|
||||
ViewManager.instance.replace('PagePKEnd');
|
||||
|
||||
if (this._currentConfig?.id && !this._shareSubmissions.has(this._currentConfig.id)) {
|
||||
this._recordCurrentShareSubmission();
|
||||
}
|
||||
|
||||
const payload = this._buildShareSubmissionPayload();
|
||||
if (payload.length === 0) {
|
||||
ToastManager.show('挑战数据异常,请重新进入');
|
||||
this._isTransitioning = false;
|
||||
return;
|
||||
}
|
||||
|
||||
this._isSubmittingShareResult = true;
|
||||
ToastManager.show('正在结算挑战...');
|
||||
|
||||
const result = await ShareManager.instance.submitShareChallenge(payload);
|
||||
this._isSubmittingShareResult = false;
|
||||
|
||||
if (!result) {
|
||||
ToastManager.show('提交挑战结果失败,请稍后重试');
|
||||
this._isTransitioning = false;
|
||||
return;
|
||||
}
|
||||
|
||||
ViewManager.instance.replace('PagePKEnd', {
|
||||
params: {
|
||||
result,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user