// Learn TypeScript:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class GameData extends cc.Component {

    private static _instance: GameData = null;

    public selectedLevel: number = 1;

    public static get instance(): GameData {
        if (!this._instance) {
            this._instance = new GameData();
        }
        return this._instance;
    }

    public get enemyHealth(): number {
        return this.selectedLevel;
    }

    private levelConfig = {
        1: { shootingSpeed: 8, spawnInterval: 6, playerSpeed: 3 },
        2: { shootingSpeed: 6, spawnInterval: 8, playerSpeed: 4 },
        3: { shootingSpeed: 4, spawnInterval: 10, playerSpeed: 5 },
        4: { shootingSpeed: 2, spawnInterval: 12, playerSpeed: 6 },
    };

    public get playerShootingInterval(): number {
        return this.levelConfig[this.selectedLevel].shootingSpeed;
    }

    public get enemySpawnInterval(): number {
        return this.levelConfig[this.selectedLevel].spawnInterval;
    }

    public get enemyMoveTime(): number {
        return this.levelConfig[this.selectedLevel].playerSpeed;
    }
}
