活动:支持礼包兑换
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
// 礼包奖励表
|
||||
import { decodeArrayListStr, readJsonFile } from '../util';
|
||||
import { FILENAME } from '../../consts';
|
||||
import { RewardParam } from '../../domain/activityField/rewardField';
|
||||
|
||||
export interface DicGiftPackage {
|
||||
// 礼包id
|
||||
readonly id: number;
|
||||
// 礼包类型 GIFT_PACKAGE_TYPE 1.全部;2.选择;3.随机
|
||||
readonly type: number;
|
||||
// 个数 type=1时,无效
|
||||
readonly count: number;
|
||||
// 礼包内容
|
||||
readonly reward: Array<RewardParam>;
|
||||
// 描述
|
||||
readonly des: string;
|
||||
|
||||
}
|
||||
|
||||
const str = readJsonFile(FILENAME.DIC_GIFT_PACKAGE);
|
||||
let arr = JSON.parse(str);
|
||||
|
||||
export const dicGiftPackage = new Map<number, DicGiftPackage>();
|
||||
arr.forEach(o => {
|
||||
o.reward = parseAttr(o.reward);
|
||||
dicGiftPackage.set(o.id, o);
|
||||
});
|
||||
|
||||
function parseAttr(str: string) {
|
||||
let result = new Array<{ type: number, id: number, count: number }>();
|
||||
if (!str) return result;
|
||||
let decodeArr = decodeArrayListStr(str);
|
||||
for (let [type, id, count] of decodeArr) {
|
||||
if (isNaN(parseInt(type)) || isNaN(parseInt(id)) || isNaN(parseInt(count))) {
|
||||
throw new Error('data table format wrong');
|
||||
}
|
||||
result.push({ type: parseInt(type), id: parseInt(id), count: parseInt(count) });
|
||||
}
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user