refactor: 重构无限关模式,移除章节概念,统一使用关卡-回合结构

This commit is contained in:
pan
2026-09-23 17:18:05 +08:00
parent 8f89dd11fa
commit 577a62193c
7 changed files with 56 additions and 85 deletions

View File

@@ -48,11 +48,9 @@ export interface GameDate {
talent_lv?: number,
/** 天赋当前等级已累计的经验值 */
talent_exp?: number,
/** 关卡进度存档:当前章节-关-节 */
/** 关卡进度存档:当前关卡号(无限关模式只记关卡号,回合恒从 1 开始) */
stage_progress?: {
chapter: number,
stage: number,
section: number,
},
/** 奖励领取状态:段位/闯关首达奖励的已领取标记(玩家点击领取) */
reward_claimed?: {
@@ -61,7 +59,7 @@ export interface GameDate {
/** 已领取的大关号 */
stage: number[],
},
/** 已通关大关的显式标记(覆盖存档停留场景,如第 10 关通关后进度停留 1-10-10) */
/** 已通关大关的显式标记(历史遗留字段,无限关模式不再写入;仅用于兼容读取旧存档) */
passed_stages?: number[],
}
export interface CloudData {
@@ -152,11 +150,9 @@ export class SingletonModuleComp extends ecs.Comp {
talent_lv: 0,
/** 当前等级已累计经验 */
talent_exp: 0,
/** 关卡进度存档:默认从 1-1-1 开始 */
/** 关卡进度存档:默认从第 1 关开始 */
stage_progress: {
chapter: 1,
stage: 1,
section: 1,
},
/** 奖励领取状态(玩家点击领取,跨局保留) */
reward_claimed: {
@@ -238,9 +234,7 @@ export class SingletonModuleComp extends ecs.Comp {
switch_music: true, // 音乐开关(MVVM绑定字段)
/** 关卡进度(MVVM绑定字段,镜像 data.stage_progress,供 HUD 实时显示) */
stage_progress: {
chapter: 1,
stage: 1,
section: 1,
},
};
@@ -352,26 +346,26 @@ export class SingletonModuleComp extends ecs.Comp {
* 将 data 层的关卡进度镜像到 vmdata 视图层(MVVM 绑定字段)。
* Why: data.stage_progress 为云端持久权威源,vmdata.stage_progress 仅供 HUD 绑定展示;
* 登录覆盖、关卡推进后都必须调用本方法保持镜像一致。
* 旧版三段存档(chapter/stage/section)在同步时归一化为 stage 单字段。
*/
public syncStageProgressToView(): void {
const p = this.data.stage_progress;
// 就地更新字段而非整体替换对象:oops VM(JsonOb)只通知被赋值属性的精确路径,
// 整体替换仅派发 VC:data.stage_progress,不会触发 HUD 绑定的
// data.stage_progress.section 等嵌套末端路径刷新,导致进度显示停留在老节
const view = this.vmdata.stage_progress;
view.chapter = p?.chapter ?? 1;
view.stage = p?.stage ?? 1;
view.section = p?.section ?? 1;
// 旧存档归一化:兼容历史 chapter/stage/section 三段结构,仅提取 stage
const stage = Math.max(1, Math.floor(p?.stage ?? 1));
if (p && (p.stage !== stage || (p as any).chapter !== undefined || (p as any).section !== undefined)) {
this.data.stage_progress = { stage };
}
this.vmdata.stage_progress.stage = stage;
}
/**
* 更新关卡进度(权威源 data + 视图镜像 vmdata),并派发事件刷新 UI。
* Why: 替代直接赋值 smc.data.stage_progress,保证视图层实时同步。
* @param progress 新的关卡进度(章节/大关/小节均从 1 开始)
* @param progress 新的关卡进度(仅关卡号,从 1 开始)
* @param is_sync 是否标记脏并触发云端/本地同步
*/
public updateStageProgress(progress: { chapter: number; stage: number; section: number }, is_sync: boolean = true): void {
this.data.stage_progress = { ...progress };
public updateStageProgress(progress: { stage: number }, is_sync: boolean = true): void {
this.data.stage_progress = { stage: Math.max(1, Math.floor(progress.stage)) };
this.syncStageProgressToView();
if (is_sync) {
gameDataSync.markDataDirty();
@@ -452,20 +446,18 @@ export class SingletonModuleComp extends ecs.Comp {
}
/**
* 标记大关已通关(通关点调用,覆盖存档停留场景)
* Why: 第 10 关通关后存档停留 1-10-10,无法从 stage_progress 推导已通状态,
* 需在通关时显式写入。
* @param stage 大关号
* 标记大关已通关(历史遗留入口)
* Why: 旧版本第 10 关通关后存档停留,无法从 stage_progress 推导已通状态,需显式标记;
* 无限关模式存档永远推进,判定已通可直接由 stage_progress 推导,无需再写入。
* 保留空实现以避免破坏外部调用方(若有旧存档读取场景走 passed_stages 兼容)。
* @param _stage 大关号(未使用,保留签名兼容)
* @deprecated 无限关模式无需调用,保留仅为兼容旧代码引用
*/
public markStagePassed(stage: number): void {
if (!this.data.passed_stages) this.data.passed_stages = [];
if (!this.data.passed_stages.includes(stage)) {
this.data.passed_stages.push(stage);
gameDataSync.markDataDirty();
}
public markStagePassed(_stage: number): void {
// 无限关模式不再写入 passed_stages
}
/** 判定大关是否已通关:显式标记优先,存档推进兜底(已进入后续关即已通关) */
/** 判定大关是否已通关:旧存档显式标记兼容,无限关以存档关卡号推导(已进入后续关即已通关) */
private isStagePassed(stage: number): boolean {
if ((this.data.passed_stages ?? []).includes(stage)) return true;
return (this.data.stage_progress?.stage ?? 1) > stage;

View File

@@ -104,15 +104,15 @@ export enum GameEvent {
STAGE_PROGRESS_UPDATE = "STAGE_PROGRESS_UPDATE",
/** 奖励领取完成(payload 为空,UI 刷新待领取列表/红点) */
REWARD_CLAIMED = "REWARD_CLAIMED",
/** 小节开始(payload: { chapter, stage, section },MissionMonComp 据此生成怪物) */
/** 回合开始(payload: { stage, section },MissionMonComp 据此生成怪物) */
SectionStart = "SectionStart",
/** 小节结束(payload: { chapter, stage, section },玩家点击"下一节"后推进) */
/** @deprecated 已废弃:无限关模式无节间结算,回合自动推进,勿再监听 */
SectionEnd = "SectionEnd",
/** 大关结束(payload: { chapter, stage },10 节打完) */
/** @deprecated 已废弃:无限关模式无大关结算,勿再监听 */
StageEnd = "StageEnd",
/** 章节结束(payload: { chapter },10 关打完) */
/** @deprecated 已废弃:无限关模式无章节概念,勿再监听 */
ChapterEnd = "ChapterEnd",
/** 结算弹窗点击"下一节"(payload 为空,MissionComp 据此推进到下一小节) */
/** @deprecated 已废弃:无限关模式无"下一节"手动推进,勿再监听 */
NextSection = "NextSection",
/** 结算弹窗点击"再来一次"(payload 为空,MissionComp 据此重开本关) */
RestartMission = "RestartMission",

View File

@@ -117,12 +117,11 @@ export function getSectionType(section: number): SectionType {
/**
* 获取回合配置(无限关:按需动态生成,不再依赖章节静态表)
* @param chapter 章节号(无限关模式已废弃章节概念,参数仅为兼容旧调用方,恒忽略)
* @param stage 关卡号(1~∞)
* @param section 回合号(1~SECTIONS_PER_STAGE)
* @returns 回合配置,回合号越界时返回 null
*/
export function getSectionConfig(chapter: number, stage: number, section: number): SectionConfig | null {
export function getSectionConfig(stage: number, section: number): SectionConfig | null {
if (section < 1 || section > SECTIONS_PER_STAGE) return null;
const type = getSectionType(section);
@@ -140,12 +139,11 @@ export function getSectionConfig(chapter: number, stage: number, section: number
}
/**
* 获取当前进度显示文本(无限关:只展示 关-回合,章节号恒忽略)
* @param chapter 章节号(兼容参数,恒忽略)
* 获取当前进度显示文本(无限关:只展示 关-回合)
* @param stage 关卡号
* @param section 回合号
* @returns 格式化文本,如 "5-3"
*/
export function getProgressText(chapter: number, stage: number, section: number): string {
export function getProgressText(stage: number, section: number): string {
return `${stage}-${section}`;
}