添加撤回逻辑
This commit is contained in:
@@ -1,33 +1,27 @@
|
||||
|
||||
|
||||
import { DataCandy } from "../types/global"
|
||||
import { StorageManager } from "./StorageManager"
|
||||
|
||||
|
||||
export class DOCandy {
|
||||
|
||||
private data: DataCandy
|
||||
private show: number
|
||||
|
||||
constructor(dataCandy: DataCandy, show: number) {
|
||||
this.data = dataCandy
|
||||
this.show = show
|
||||
}
|
||||
private left: number
|
||||
|
||||
//====================================持久化数据
|
||||
public get_left(): number {
|
||||
return this.data.left
|
||||
constructor(show: number, left: number) {
|
||||
this.show = show
|
||||
this.left = left
|
||||
}
|
||||
public set_left(left: number): void {
|
||||
this.data.left = left
|
||||
StorageManager.getInstance().onChanged()
|
||||
}
|
||||
//====================================持久化数据
|
||||
|
||||
public get_show(): number {
|
||||
return this.show
|
||||
}
|
||||
|
||||
public get_left(): number {
|
||||
return this.left
|
||||
}
|
||||
public set_left(left: number): void {
|
||||
this.left = left
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,15 +2,13 @@
|
||||
|
||||
import { StorageManager } from "./StorageManager"
|
||||
import { DOBlock } from "./DOBlock"
|
||||
import { DOCandy } from "./DOCandy"
|
||||
import { DataBlock, DataStage } from "../types/global"
|
||||
import { DataBlock, DataUndo, DataStage } from "../types/global"
|
||||
|
||||
|
||||
export class DOStage {
|
||||
|
||||
private data: DataStage
|
||||
private blocks: Array<DOBlock> = new Array()
|
||||
private candys: Array<DOCandy> = new Array()
|
||||
|
||||
private letterToNumber: Map<string, number>;
|
||||
private numberToLetter: Map<number, string>;
|
||||
@@ -80,27 +78,14 @@ export class DOStage {
|
||||
}
|
||||
}
|
||||
}
|
||||
for (var i=1; i<=9; i++) {
|
||||
var dataCandy = this.data.candys[i]
|
||||
if (dataCandy) {
|
||||
var doCandy = new DOCandy(dataCandy, i)
|
||||
this.candys.push(doCandy)
|
||||
}
|
||||
else {
|
||||
var left = 0;
|
||||
var c = this.numberToLetter.get(i)
|
||||
if (list.has(c))
|
||||
left = list.get(c);
|
||||
dataCandy = {left: left}
|
||||
this.data.candys.push(dataCandy)
|
||||
var doCandy = new DOCandy(dataCandy, i)
|
||||
this.candys.push(doCandy)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//====================================持久化数据
|
||||
public get_difficulty(): number {
|
||||
return this.data.difficulty
|
||||
}
|
||||
|
||||
public get_mistake(): number {
|
||||
return this.data.mistake
|
||||
}
|
||||
@@ -109,10 +94,6 @@ export class DOStage {
|
||||
StorageManager.getInstance().onChanged()
|
||||
}
|
||||
|
||||
public get_difficulty(): number {
|
||||
return this.data.difficulty
|
||||
}
|
||||
|
||||
public get_duration(): number {
|
||||
return this.data.duration
|
||||
}
|
||||
@@ -129,6 +110,14 @@ export class DOStage {
|
||||
StorageManager.getInstance().onChanged()
|
||||
}
|
||||
|
||||
public get_select_index(): number {
|
||||
return this.data.select_index
|
||||
}
|
||||
public set_select_index(select_index: number): void {//当前选中
|
||||
this.data.select_index = select_index
|
||||
StorageManager.getInstance().onChanged()
|
||||
}
|
||||
|
||||
public get_hint(): number {
|
||||
return this.data.hint
|
||||
}
|
||||
@@ -136,13 +125,28 @@ export class DOStage {
|
||||
this.data.hint = hint
|
||||
StorageManager.getInstance().onChanged()
|
||||
}
|
||||
|
||||
public get_undos(): Array<DataUndo> {
|
||||
return this.data.undos
|
||||
}
|
||||
public add_undo(type: number, index: number, value: number): void {
|
||||
var dataUndo: DataUndo = {type: type, index: index, value: value}
|
||||
console.log("add_undo >>>>>>>>>>>>>>>>>>>>>>>>>>>>", JSON.stringify(dataUndo))
|
||||
this.data.undos.push(dataUndo)
|
||||
StorageManager.getInstance().onChanged()
|
||||
}
|
||||
public pop_undo(): DataUndo {
|
||||
var dataUndo: DataUndo
|
||||
if (this.data.undos.length > 0) {
|
||||
dataUndo = this.data.undos[this.data.undos.length-1]
|
||||
this.data.undos.splice(this.data.undos.length-1, 1)
|
||||
StorageManager.getInstance().onChanged()
|
||||
}
|
||||
return dataUndo
|
||||
}
|
||||
//====================================持久化数据
|
||||
|
||||
public get_blocks(): Array<DOBlock> {
|
||||
return this.blocks
|
||||
}
|
||||
|
||||
public get_candys(): Array<DOCandy> {
|
||||
return this.candys
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { config } from "../constants/config"
|
||||
import { DataStage } from "../types/global"
|
||||
import { DataStage, createDataStage } from "../types/global"
|
||||
import { DOStage } from "./DOStage"
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ export class StorageManager {
|
||||
this.stageMap.set(stageID, dataStage)
|
||||
}
|
||||
else {
|
||||
dataStage = {mistake: 0, difficulty: config.DIFFICULTY_TYPE.Easy, duration: 0, note_open: false, hint: 2, blocks: new Array(), candys: new Array()}
|
||||
dataStage = createDataStage(config.DIFFICULTY_TYPE.Easy)
|
||||
this.stageMap.set(stageID, dataStage)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user