2025-05-13 20:31:44 +08:00
|
|
|
import { config } from "../constants/config"
|
|
|
|
|
import { DOStage } from "../types/DOStage"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class StorageManager {
|
|
|
|
|
|
|
|
|
|
private static instance: StorageManager
|
|
|
|
|
public static getInstance(): StorageManager {
|
|
|
|
|
if (!StorageManager.instance) {
|
|
|
|
|
StorageManager.instance = new 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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-05-14 10:14:55 +08:00
|
|
|
private changed = false
|
|
|
|
|
|
2025-05-13 20:31:44 +08:00
|
|
|
private stageID: string = "";
|
|
|
|
|
private stageMap: Map<string, any> = new Map();
|
|
|
|
|
|
|
|
|
|
public init(): void {
|
2025-05-14 10:14:55 +08:00
|
|
|
this.changed = false
|
2025-05-13 20:31:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public loadStage(stageID: string): DOStage {
|
|
|
|
|
this.stageID = stageID
|
|
|
|
|
var dataStage
|
|
|
|
|
if (this.stageMap.has(stageID)) {
|
|
|
|
|
dataStage = this.stageMap.get(stageID)
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
var jsonStr = Laya.LocalStorage.getItem(stageID)
|
|
|
|
|
if (jsonStr) {
|
|
|
|
|
dataStage = JSON.parse(jsonStr)
|
|
|
|
|
this.stageMap.set(stageID, dataStage)
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
dataStage = StorageManager.createDataStage(0, config.DIFFICULTY_TYPE.Easy)
|
|
|
|
|
this.stageMap.set(stageID, dataStage)
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-05-14 10:14:55 +08:00
|
|
|
var levelStr = "aBCeIGFhdEDFcAHBGIhigBdfecAgHDiFBCaeBEAGHCIdffcIdEAHbgcABfGEdiHIFHaCDGEBDGEHbiaFC"
|
|
|
|
|
return new DOStage(dataStage, levelStr)
|
2025-05-13 20:31:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public saveStage(): void {
|
2025-05-14 10:14:55 +08:00
|
|
|
if (this.changed) {
|
|
|
|
|
this.changed = false
|
|
|
|
|
if (this.stageMap.has(this.stageID)) {
|
|
|
|
|
var dataStage = this.stageMap.get(this.stageID)
|
|
|
|
|
var jsonStr = JSON.stringify(dataStage)
|
|
|
|
|
Laya.LocalStorage.setItem(this.stageID, jsonStr)
|
|
|
|
|
}
|
2025-05-13 20:31:44 +08:00
|
|
|
}
|
|
|
|
|
}
|
2025-05-14 10:14:55 +08:00
|
|
|
|
|
|
|
|
public onChanged(): void {
|
|
|
|
|
this.changed = true
|
|
|
|
|
}
|
2025-05-13 20:31:44 +08:00
|
|
|
}
|