123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- import { JsonAsset } from "cc";
- export default class GameConfigManager
- {
- private static jsonMap:Map<string,JsonAsset>=new Map<string,JsonAsset>();
- /**
- * 武器配置
- */
- private static WeaponMap:Map<number,any>=new Map<number,any>();
- /**
- * 怪物模板配置
- */
- private static MonsterMap:Map<number,any>=new Map<number,any>();
- /**
- * 栅栏配置
- */
- private static FenceMap:Map<number,any>=new Map<number,any>();
- constructor(){
- }
- /**
- * 初始化
- * @param jsons
- */
- public static Init(jsons:JsonAsset[]):void{
- jsons.forEach(element => {
- jsons[element.name]=element;
- this.jsonMap.set(element.name,element);
- });
- this.InitWeaponConfig();
- this.InitMonsterConfig();
- this.InitFenceConfig();
- }
- /**
- * 初始化
- */
- private static InitWeaponConfig():void{
- if(this.jsonMap.has("Weapons")==false){
- return;
- }
- this.GetConfig("Weapons").forEach(element => {
- this.WeaponMap.set(element.id,element);
- });
- }
- private static InitMonsterConfig():void{
- if(this.jsonMap.has("Monsters")==false){
- return;
- }
- this.GetConfig("Monsters").forEach(element => {
- this.MonsterMap.set(element.id,element);
- });
- }
- private static InitFenceConfig():void{
- if(this.jsonMap.has("Fence")==false){
- return;
- }
- this.GetConfig("Fence").forEach(element => {
- this.FenceMap.set(element.id,element);
- });
- }
- /**
- * 获取配置数据
- * @param sheet
- * @param key
- */
- public static GetConfig(sheet:string):any{
- let jsonAsset:JsonAsset=this.jsonMap.get(sheet);
- let json:any=jsonAsset.json;
- return json.data;
- }
- /**
- * 获取武器ID
- * @param id
- */
- public static GetWeaponConfig(id:number):any{
- if(this.WeaponMap.has(id)==false){
- throw new Error("找不到ID为:"+id+"的武器!");
- }
- return this.WeaponMap.get(id);
- }
- /**
- * 获取关卡配置
- * @param id
- */
- public static GetLevelConfig(id:number):any{
- return this.GetConfig("Level"+id);
- }
- /**
- * 获取怪物模板配置
- * @param id
- */
- public static GetMonsterConfig(id:number):any{
- if(this.MonsterMap.has(id)==false){
- throw new Error("找不到ID为:"+id+"的怪物!");
- }
- return this.MonsterMap.get(id);
- }
-
- public static GetFenceConfig(id:number):any{
- if(this.FenceMap.has(id)==false){
- throw new Error("找不到ID为:"+id+"的栅栏!");
- }
- return this.FenceMap.get(id);
- }
- }
|