ConfigManager.ts 766 Bytes
import { ResUtils } from "../../utils/ResUtils";
import { DeepReadonly } from "simba-utils";

export namespace ConfigManager {
    let configData: DeepReadonly<{ [key: string]: { [key: string]: {} } }>;

    export async function initConfigData() {
        configData = await ResUtils.loadRes<any>("config/config", cc.JsonAsset);
        ResUtils.releaseRes("config/config");
    }

    export function getConfig<T>(config: { name: string, type?: T }, id: number): DeepReadonly<T> {
        return configData[config.name][id] as DeepReadonly<T>;
    }

    export function getAllConfig<T>(config: { name: string, type?: T }): DeepReadonly<{ [key: number]: T }> {
        return configData[config.name] as DeepReadonly<{ [key: number]: T }>;
    }
}