添加字典表解析
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
// 时装表
|
||||
import { decodeArrayListStr, readJsonFile, parseNumberList } from '../util';
|
||||
import { FILENAME } from '../../consts/consts';
|
||||
|
||||
export interface DicFashions {
|
||||
// 时装id
|
||||
readonly id: number;
|
||||
// 增加的被动技能
|
||||
readonly seid: Array<number>;
|
||||
// 全局加成
|
||||
readonly globalAttr: Array<{type: number, value: number}>;
|
||||
// 单体加成
|
||||
readonly actorAttr: Array<{type: number, value: number}>;
|
||||
// 角色id
|
||||
readonly actorId: number;
|
||||
}
|
||||
|
||||
const str = readJsonFile(FILENAME.DIC_FASHIONS);
|
||||
let arr = JSON.parse(str);
|
||||
|
||||
export const dicFashions = new Map<number, DicFashions>();
|
||||
arr.forEach(o => {
|
||||
o.seid = parseNumberList(o.seid);
|
||||
o.globalAttr = parseAttr(o.globalAttr);
|
||||
o.actorAttr = parseAttr(o.actorAttr);
|
||||
dicFashions.set(o.id, o);
|
||||
});
|
||||
|
||||
function parseAttr(str: string) {
|
||||
let result = new Array<{type: number, value: number}>();
|
||||
if(!str) return result;
|
||||
let decodeArr = decodeArrayListStr(str);
|
||||
for(let [type, value] of decodeArr) {
|
||||
if(isNaN(parseInt(type)) || isNaN(parseInt(value))) {
|
||||
throw new Error('data table format wrong');
|
||||
}
|
||||
result.push({type: parseInt(type), value: parseInt(value)});
|
||||
}
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user