import { Component, sys, _decorator } from 'cc';
import GameConst from '../common/GameConst';
import Data from '../manager/Data';
import WindowManager from '../manager/WindowManager';
import levelsData from 'db://assets/data/levelsData';

const { ccclass, property } = _decorator;
@ccclass('DebugTools')
export default class DebugTools extends Component {
    start() {
        if (sys.platform === sys.Platform.DESKTOP_BROWSER) {
            return;
        }
        this.addBtn("清除数据", () => {
            localStorage.setItem(GameConst.local_data_key, "");
        })

        this.addBtn("金币+100", () => {
            Data.user.coin += 100
        })

        
        this.addBtn("Star+100", () => {
            Data.user.star += 100
            let OpenItems:Array<any> = levelsData.getNormModelDatas();
            if (Data.user.openIndex < OpenItems.length - 1) {
                //解锁新物品
                WindowManager.ins.open("NewPackOpenedLayer", Data.user.openIndex);
            }
        })

        this.addBtn("LV++", () => {
            Data.user.lv++
        })
    }

    addBtn(name: string, callback: Function) {
        let toolbar = document.getElementsByClassName("toolbar")[0];
        if (!toolbar) return;
        let div = document.createElement("div");
        div.className = "item";
        div.innerHTML = "<button id='" + name + "'>" + name + "</button>";
        toolbar.appendChild(div);

        document.getElementById(name).onclick = () => {
            callback()
        };
    }
}
