

import { DataBlock } from "../types/global";
import { StorageManager } from "./StorageManager"

export class DOBlock {

    private data: DataBlock
    private preset: boolean = false//预设格子
    private correct: number = 0;
    private checked: boolean = false//是否正确
    

    constructor(dataBlock: DataBlock, 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
        this.checked = show == this.get_correct()
        StorageManager.getInstance().onStageChanged()
    }

    public get_score(): number {
        return this.data.score
    }
    public set_score(score: number): void {
        this.data.score = score
        StorageManager.getInstance().onStageChanged()
    }

    public get_notes(): Array<number> {
        return this.data.notes
    }
    public add_note(noteNumber: number): void {
        if (this.data.notes.indexOf(noteNumber) < 0) {
            this.data.notes.push(noteNumber)
            StorageManager.getInstance().onStageChanged()
        }
    }
    public remove_note(noteNumber: number): void {
        var find = this.data.notes.indexOf(noteNumber)
        if (find >= 0) {
            this.data.notes.splice(find, 1)
            StorageManager.getInstance().onStageChanged()
        }
    }
    public clean_notes(): void {
        if (this.data.notes.length > 0) {
            this.data.notes = new Array()
            StorageManager.getInstance().onStageChanged()
        }
    }
    //====================================持久化数据

    public get_preset(): boolean {
        return this.preset
    }

    public get_correct(): number {
        return this.correct
    }

    public get_checked(): boolean {
        return this.checked
    }



}