添加持久化逻辑

This commit is contained in:
2025-05-13 20:31:44 +08:00
parent dcb12db40d
commit cbee313bb5
17 changed files with 512 additions and 213 deletions

80
src/types/DOBlock.ts Normal file
View File

@@ -0,0 +1,80 @@
import { StorageManager } from "../models/StorageManager"
export class DOBlock {
private data: any
private preset: boolean = false//预设格子
private correct: number = 0;
private checked: boolean = false//是否正确
constructor(dataBlock: any, preset: boolean, correct: number) {
this.data = dataBlock
this.preset = preset
this.correct = correct
this.checked = preset || (dataBlock.show == correct)
}
//====================================持久化数据
public get_index(): number {
return this.data.index
}
public get_show(): number {
return this.data.show
}
public set_show(show: number): void {
this.data.show = show
if (show == this.get_correct())
this.checked = true
if (this.get_checked() || show == 0)
this.clean_notes()//正确或者擦除
StorageManager.getInstance().saveStage()
}
public get_score(): number {
return this.data.score
}
public set_score(score: number): void {
this.data.score = score
StorageManager.getInstance().saveStage()
}
public get_notes(): Array<number> {
return this.data.notes
}
public add_note(noteNumber: number): boolean {
var b = false
if (this.data.notes.indexOf(noteNumber) < 0) {
this.data.notes.push(noteNumber)
StorageManager.getInstance().saveStage()
b = true
}
return b
}
public clean_notes(): void {
if (this.data.notes.length > 0) {
this.data.notes = new Array()
StorageManager.getInstance().saveStage()
}
}
//====================================持久化数据
public get_preset(): boolean {
return this.preset
}
public get_correct(): number {
return this.correct
}
public get_checked(): boolean {
return this.checked
}
}