整理持久化数据结构
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { config } from "../constants/config"
|
||||
import { DataStage } from "../types/global"
|
||||
import { DOStage } from "./DOStage"
|
||||
|
||||
|
||||
@@ -12,41 +13,10 @@ export class StorageManager {
|
||||
return StorageManager.instance
|
||||
}
|
||||
|
||||
|
||||
public static createDataBlock(index: number, show: number, score: number=0, notes: Array<number>=new Array()): any {//格子
|
||||
var dataBlock = {
|
||||
index: index,
|
||||
show: show,
|
||||
score: score,
|
||||
notes: notes,
|
||||
}
|
||||
return dataBlock
|
||||
}
|
||||
|
||||
public static createDataCandy(left: number): any {//可选数字
|
||||
var dataCandy = {
|
||||
left: left,
|
||||
}
|
||||
return dataCandy
|
||||
}
|
||||
|
||||
public static createDataStage(mistake: number, difficulty: number, duration: number=0, blocks: Array<any>=new Array(), candys: Array<any>=new Array()): any {//关卡数据
|
||||
var dataStage = {
|
||||
mistake: mistake,
|
||||
difficulty: difficulty,
|
||||
duration: duration,
|
||||
note_open: false,
|
||||
blocks: blocks,
|
||||
candys: candys,
|
||||
}
|
||||
return dataStage
|
||||
}
|
||||
|
||||
|
||||
private changed = false
|
||||
|
||||
private stageID: string = "";
|
||||
private stageMap: Map<string, any> = new Map();
|
||||
private stageMap: Map<string, DataStage> = new Map();
|
||||
|
||||
public init(): void {
|
||||
this.changed = false
|
||||
@@ -54,7 +24,7 @@ export class StorageManager {
|
||||
|
||||
public loadStage(stageID: string): DOStage {
|
||||
this.stageID = stageID
|
||||
var dataStage
|
||||
var dataStage: DataStage
|
||||
if (this.stageMap.has(stageID)) {
|
||||
dataStage = this.stageMap.get(stageID)
|
||||
}
|
||||
@@ -65,7 +35,7 @@ export class StorageManager {
|
||||
this.stageMap.set(stageID, dataStage)
|
||||
}
|
||||
else {
|
||||
dataStage = StorageManager.createDataStage(0, config.DIFFICULTY_TYPE.Easy)
|
||||
dataStage = {mistake: 0, difficulty: config.DIFFICULTY_TYPE.Easy, duration: 0, note_open: false, blocks: new Array(), candys: new Array()}
|
||||
this.stageMap.set(stageID, dataStage)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user