IntroTableMgr.ts 1.21 KB
import { tMgr } from "../../Global";
import { IntroTable, TableName } from "./TableDefine";

export class IntroTableMgr {

    private _levelList: number[] = [];
    private _idList: number[] = [];

    private static _ins: IntroTableMgr = null;
    static get ins(): IntroTableMgr {

        if (this._ins == null) {
            this._ins = new IntroTableMgr();
            let all = tMgr.map[TableName.INTRO];

            for (const key in all) {
                if (Object.prototype.hasOwnProperty.call(all, key)) {

                    if (!Number(key)) {
                        continue;
                    }

                    const element = all[key] as IntroTable;

                    if (element.Level > 0) {
                        this._ins._levelList.push(element.Level);
                        this._ins._idList.push(element.ID);
                    }
                }
            }
        }

        return this._ins;
    }

    getTableByLevel(level: number): IntroTable {

        let index = this._levelList.indexOf(level);

        if (index > -1) {
            let id = this._idList[index];
            return tMgr.getConfig(TableName.INTRO, id) as IntroTable;
        }
        
        return null;
    }
}