优化存档逻辑

This commit is contained in:
2025-05-14 10:14:55 +08:00
parent cbee313bb5
commit 2cc01c5570
11 changed files with 117 additions and 17 deletions

View File

@@ -18,5 +18,69 @@
"_$type": "cd70cd5e-b4cd-4277-ac0a-2224cfbe89ac",
"scriptPath": "../src/models/UIManager.ts"
}
],
"_$child": [
{
"_$id": "w805s9t9",
"_$type": "Box",
"name": "Box",
"width": 1080,
"height": 1920,
"left": 0,
"right": 0,
"top": 0,
"bottom": 0,
"_$child": [
{
"_$id": "c5b9d1x1",
"_$type": "Image",
"name": "bg",
"x": 118,
"y": 420,
"width": 844,
"height": 1080,
"centerX": 0,
"centerY": 0,
"skin": "res://6ad19646-ed7a-431c-a50e-65c2bcb40751",
"color": "#ffffff"
},
{
"_$id": "md4ipd8a",
"_$type": "Image",
"name": "score",
"x": 300,
"y": 449,
"width": 240,
"height": 181,
"scaleX": 2,
"scaleY": 2,
"centerX": 0,
"centerY": -330,
"skin": "res://9e3eb0ac-c410-40a7-b8c3-ae1316d04cfb",
"useSourceSize": true,
"color": "#ffffff",
"_$child": [
{
"_$id": "fkjymlk3",
"_$type": "Label",
"name": "Label",
"x": 20,
"y": 61,
"width": 200,
"height": 60,
"centerX": 0,
"centerY": 0,
"text": "99",
"font": "res://55f943ef-58d2-4b30-8498-271c4213cce4",
"fontSize": 60,
"color": "#FFFFFF",
"align": "center",
"valign": "middle",
"padding": "0,0,0,0"
}
]
}
]
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

View File

@@ -0,0 +1,13 @@
{
"uuid": "6ad19646-ed7a-431c-a50e-65c2bcb40751",
"importer": {
"textureType": 2,
"sizeGrid": [
20,
40,
31,
40,
0
]
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

View File

@@ -0,0 +1,6 @@
{
"uuid": "9e3eb0ac-c410-40a7-b8c3-ae1316d04cfb",
"importer": {
"textureType": 2
}
}

View File

@@ -102,8 +102,10 @@
"width": 400,
"height": 64,
"_mouseState": 2,
"left": 60,
"top": 60,
"left": null,
"top": null,
"centerX": -314,
"centerY": -888,
"_$child": [
{
"_$id": "l1ebdt6a",

View File

@@ -43,10 +43,13 @@ export class StorageManager {
}
private changed = false
private stageID: string = "";
private stageMap: Map<string, any> = new Map();
public init(): void {
this.changed = false
}
public loadStage(stageID: string): DOStage {
@@ -66,14 +69,22 @@ export class StorageManager {
this.stageMap.set(stageID, dataStage)
}
}
return new DOStage(dataStage)
var levelStr = "aBCeIGFhdEDFcAHBGIhigBdfecAgHDiFBCaeBEAGHCIdffcIdEAHbgcABfGEdiHIFHaCDGEBDGEHbiaFC"
return new DOStage(dataStage, levelStr)
}
public saveStage(): void {
if (this.stageMap.has(this.stageID)) {
var dataStage = this.stageMap.get(this.stageID)
var jsonStr = JSON.stringify(dataStage)
Laya.LocalStorage.setItem(this.stageID, jsonStr)
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)
}
}
}
public onChanged(): void {
this.changed = true
}
}

View File

@@ -37,4 +37,8 @@ export class UIManager extends Laya.Script {
})
}
onLateUpdate(): void {
StorageManager.getInstance().saveStage()
}
}

View File

@@ -32,7 +32,7 @@ export class DOBlock {
this.checked = true
if (this.get_checked() || show == 0)
this.clean_notes()//正确或者擦除
StorageManager.getInstance().saveStage()
StorageManager.getInstance().onChanged()
}
public get_score(): number {
@@ -40,7 +40,7 @@ export class DOBlock {
}
public set_score(score: number): void {
this.data.score = score
StorageManager.getInstance().saveStage()
StorageManager.getInstance().onChanged()
}
public get_notes(): Array<number> {
@@ -50,7 +50,7 @@ export class DOBlock {
var b = false
if (this.data.notes.indexOf(noteNumber) < 0) {
this.data.notes.push(noteNumber)
StorageManager.getInstance().saveStage()
StorageManager.getInstance().onChanged()
b = true
}
return b
@@ -58,7 +58,7 @@ export class DOBlock {
public clean_notes(): void {
if (this.data.notes.length > 0) {
this.data.notes = new Array()
StorageManager.getInstance().saveStage()
StorageManager.getInstance().onChanged()
}
}
//====================================持久化数据

View File

@@ -19,7 +19,7 @@ export class DOCandy {
}
public set_left(left: number): void {
this.data.left = left
StorageManager.getInstance().saveStage()
StorageManager.getInstance().onChanged()
}
//====================================持久化数据

View File

@@ -14,7 +14,7 @@ export class DOStage {
private letterToNumber: any;
private numberToLetter: any;
constructor(dataStage: any) {
constructor(dataStage: any, levelStr: string) {
this.data = dataStage
this.letterToNumber = new Map();
@@ -44,7 +44,7 @@ export class DOStage {
var dataBlock = this.data.blocks[i]
blockMap.set(dataBlock.index, dataBlock)
}
var levelStr = "aBCeIGFhdEDFcAHBGIhigBdfecAgHDiFBCaeBEAGHCIdffcIdEAHbgcABfGEdiHIFHaCDGEBDGEHbiaFC"
if (levelStr.length != 81) {
console.log("levelStr error", levelStr.length)
}
@@ -105,7 +105,7 @@ export class DOStage {
}
public set_mistake(mistake: number): void {
this.data.mistake = mistake
StorageManager.getInstance().saveStage()
StorageManager.getInstance().onChanged()
}
public get_difficulty(): number {
@@ -117,7 +117,7 @@ export class DOStage {
}
public set_duration(duration: number): void {//关卡计时
this.data.duration = duration
// StorageManager.getInstance().saveStage()
// StorageManager.getInstance().onChanged()
}
public get_note_open(): boolean {
@@ -125,7 +125,7 @@ export class DOStage {
}
public set_note_open(note_open: boolean): void {
this.data.note_open = note_open
StorageManager.getInstance().saveStage()
StorageManager.getInstance().onChanged()
}
//====================================持久化数据