119 lines
2.7 KiB
TypeScript
119 lines
2.7 KiB
TypeScript
|
/************************************************************************************
|
||
|
|
||
|
* FileName : PropDataManager.ts
|
||
|
* Description : 道具数据管理器
|
||
|
* Version : v1.0.0
|
||
|
* CreateTime : 2024-10-29 10:38:27
|
||
|
* Author :
|
||
|
* Copyright (c) since 2024
|
||
|
* ==============================================================
|
||
|
* Method Description:
|
||
|
*
|
||
|
* ==============================================================
|
||
|
************************************************************************************/
|
||
|
|
||
|
import {Logger} from "db://assets/core_tgx/base/utils/Logger";
|
||
|
import {IPropCfg} from "db://assets/module_basic/shared/configs/interface/IPropCfg";
|
||
|
export default class PropDataManager
|
||
|
{
|
||
|
private _data: Array<IPropCfg> | undefined;
|
||
|
private _dataMap: Map<number, IPropCfg> | undefined;
|
||
|
init(data?: any): void
|
||
|
{
|
||
|
if (data){
|
||
|
this._data = data;
|
||
|
this._dataMap = new Map<number, IPropCfg>();
|
||
|
for (let i = 0; i < this._data.length; i++){
|
||
|
let element = this._data[i];
|
||
|
this._dataMap.set(element.id, element);
|
||
|
}
|
||
|
Logger.info(`配置数据(IPropCfg)加载完毕...`);
|
||
|
}
|
||
|
console.log("所有道具的信息 === ",this._data);
|
||
|
}
|
||
|
|
||
|
|
||
|
getData(id: number):IPropCfg
|
||
|
{
|
||
|
if (this._dataMap)
|
||
|
{
|
||
|
// return this._data.find(p=>p.id == id);
|
||
|
return this._dataMap.get(id);
|
||
|
}
|
||
|
console.log("配置数据(IPropCfg)不存在"+id);
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 根据类型获取道具
|
||
|
* @param type 道具类型
|
||
|
* @returns
|
||
|
*/
|
||
|
public getDataByType(type: number):Array<IPropCfg>{
|
||
|
let list = this._data.filter(p=>p.type == type);
|
||
|
return list;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 推荐位数据获取
|
||
|
* @param type 推荐类型
|
||
|
* @returns
|
||
|
*/
|
||
|
public getRecommendData(type: RecommendType):IPropCfg{
|
||
|
let item = this._data.find(p=>p.recommend == type);
|
||
|
if (item==null){
|
||
|
Logger.warning(`推荐类型没找到..`+type);
|
||
|
}
|
||
|
return item;
|
||
|
}
|
||
|
|
||
|
getAllData() : IPropCfg[]{
|
||
|
return this._data;
|
||
|
}
|
||
|
|
||
|
getAllDataMap() : Map<number, IPropCfg>{
|
||
|
return this._dataMap;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
export enum RecommendType{
|
||
|
/**
|
||
|
* 英雄推荐
|
||
|
*/
|
||
|
HeroType= 1,
|
||
|
/**
|
||
|
* 推荐皮肤
|
||
|
*/
|
||
|
SkinType = 2,
|
||
|
/**
|
||
|
* 推荐礼包1
|
||
|
*/
|
||
|
BoxType1 = 31,
|
||
|
/**
|
||
|
* 推荐礼包2
|
||
|
* */
|
||
|
BoxType2 = 32,
|
||
|
/**
|
||
|
* 推荐礼包3
|
||
|
* */
|
||
|
BoxType3 = 33,
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 上架类型
|
||
|
*/
|
||
|
export enum ShelvesType{
|
||
|
/**
|
||
|
* 上架
|
||
|
*/
|
||
|
Shelves = 1,
|
||
|
/**
|
||
|
* 下架
|
||
|
*/
|
||
|
UnShelves = 2,
|
||
|
}
|
||
|
|