diff --git a/src/constants/config.ts b/src/constants/config.ts index 9f400d6..68c8884 100644 --- a/src/constants/config.ts +++ b/src/constants/config.ts @@ -24,12 +24,8 @@ export const config = { BLUE: "#2559c0", }, - UNDO_TYPE: { - NORMAL: 1, - NOTE: 2, - }, - + } diff --git a/src/models/DOBlock.ts b/src/models/DOBlock.ts index 051d14d..72ce850 100644 --- a/src/models/DOBlock.ts +++ b/src/models/DOBlock.ts @@ -28,8 +28,7 @@ export class DOBlock { } public set_show(show: number): void { this.data.show = show - if (show == this.get_correct()) - this.checked = true + this.checked = show == this.get_correct() StorageManager.getInstance().onChanged() } diff --git a/src/models/DOStage.ts b/src/models/DOStage.ts index 9e8fa5c..cf2c6d8 100644 --- a/src/models/DOStage.ts +++ b/src/models/DOStage.ts @@ -129,8 +129,14 @@ export class DOStage { public get_undos(): Array { return this.data.undos } - public add_undo(type: number, index: number, value: number): void { - var dataUndo: DataUndo = {type: type, index: index, value: value} + public add_undo(index: number, show: number=0, notes: Array=new Array()): void { + var _notes: Array + if (notes) { + _notes = new Array() + for (var i=0; i>>>>>>>>>>>>>>>>>>>>>>>>>>>", JSON.stringify(dataUndo)) this.data.undos.push(dataUndo) StorageManager.getInstance().onChanged() diff --git a/src/types/global.ts b/src/types/global.ts index ac55e8a..653d349 100644 --- a/src/types/global.ts +++ b/src/types/global.ts @@ -10,9 +10,9 @@ export interface DataBlock { //撤回数据结构 export interface DataUndo { - type: number, index: number, - value: number, + show: number, + notes?: Array, } //关卡数据 diff --git a/src/views/Block.ts b/src/views/Block.ts index a5c7474..19351c8 100644 --- a/src/views/Block.ts +++ b/src/views/Block.ts @@ -119,20 +119,18 @@ export class Block extends Laya.Script { } public setShowNumber(showNumber: number): boolean { - if (this.data.get_checked() == false) { - this.data.set_show(showNumber) - var score: number = 0 - if (this.newSelect) { - this.newSelect = false - if (this.data.get_checked()) { - score = 150 - this.data.set_score(score) - G_ShowScoreTips(score.toString(), this.label_show) - } - } - this.data.clean_notes() - this.updateBlock() - } + this.data.set_show(showNumber) + // var score: number = 0 + // if (this.newSelect) { + // this.newSelect = false + // if (this.data.get_checked()) { + // score = 150 + // this.data.set_score(score) + // G_ShowScoreTips(score.toString(), this.label_show) + // } + // } + this.data.clean_notes() + this.updateBlock() return this.data.get_checked() } @@ -149,6 +147,14 @@ export class Block extends Laya.Script { } this.updateBlock() } + public setNotes(notes: Array): void { + this.data.set_show(0) + this.data.clean_notes() + for (var i=0; i{ @@ -209,32 +210,28 @@ export class Stage extends Laya.Script { this.onApplyBlock(block) } - - onApplyUndo(undo: DataUndo): void { - - } onClickUndo(evt: Laya.Event): void { var undo = this.data.pop_undo() if (undo) { - // console.log("onClickUndo>>>>", JSON.stringify(undo)) - // this.selectedBlock = this.blocks[undo.index] - // this.onApplyBlock(this.selectedBlock) - // if (undo.type == config.UNDO_TYPE.NORMAL) { - // var block = this.blocks[undo.index] - - // this.selectedBlock.setShowNumber(undo.value) - // this.onSetBlock(this.selectedBlock) - // } - // else if (undo.type == config.UNDO_TYPE.NOTE) { - - // } + console.log("onClickUndo>>>>", JSON.stringify(undo)) + this.selectedBlock = this.blocks[undo.index] + this.onApplyBlock(this.selectedBlock) + if (undo.notes && undo.notes.length > 0) { + this.selectedBlock.setNotes(undo.notes) + } + else { + this.selectedBlock.setShowNumber(undo.show) + } + this.onSetBlock(this.selectedBlock) } } onClickErase(evt: Laya.Event): void { - if (this.selectedBlock.getData().get_checked() == false) {//未完成切有数字或者笔记才可以使用橡皮 - if (this.selectedBlock.getData().get_show() > 0 || this.selectedBlock.getData().get_notes().length > 0) { - this.data.add_undo(config.UNDO_TYPE.NORMAL, this.selectedBlock.getData().get_index(), 0) + if (this.selectedBlock.getData().get_checked() == false) {//未完成且有数字或者笔记才可以使用橡皮 + var show = this.selectedBlock.getData().get_show() + var notes = this.selectedBlock.getData().get_notes() + if (show > 0 || notes.length > 0) { + this.data.add_undo(this.selectedBlock.getData().get_index(), show, notes) this.selectedBlock.setShowNumber(0) this.onUpdateScore() this.onSetBlock(this.selectedBlock) @@ -288,6 +285,7 @@ export class Stage extends Laya.Script { this.data.set_hint(9) this.onUpdateHintStatus() } + } onUpdateHintStatus(): void { var hint = this.data.get_hint() @@ -297,6 +295,8 @@ export class Stage extends Laya.Script { } public onApplyCandy(showNumber: number): void { + var show = this.selectedBlock.getData().get_show() + var notes = this.selectedBlock.getData().get_notes() if (this.selectedBlock.getData().get_checked() == false) { if (this.data.get_note_open()) { var relateds = this.findRelatedBlocks(this.selectedBlock) @@ -308,25 +308,26 @@ export class Stage extends Laya.Script { } } if (find == false) { + this.data.add_undo(this.selectedBlock.getData().get_index(), show, notes) this.selectedBlock.addNoteNumber(showNumber) + this.onSetBlock(this.selectedBlock) } else { for (var i=0; i