添加字典表解析
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
// 武将羁绊表
|
||||
import { decodeArrayListStr, readJsonFile, parseNumberList } from '../util';
|
||||
import { FILENAME } from '../../consts/consts';
|
||||
|
||||
export interface DicFriendShip {
|
||||
// id
|
||||
readonly id: number;
|
||||
// 羁绊id
|
||||
readonly shipId: number;
|
||||
// 主武将ID
|
||||
readonly actorId: number;
|
||||
// 羁绊名称
|
||||
readonly name: string;
|
||||
// 羁绊等级
|
||||
readonly level: number;
|
||||
// 羁绊武将ID
|
||||
readonly hids: Array<number>;
|
||||
// 属性加成
|
||||
readonly attribute: Array<{id: number, number: number}>
|
||||
// 消耗铜币
|
||||
readonly costCoin: number;
|
||||
}
|
||||
|
||||
const str = readJsonFile(FILENAME.DIC_FRIEND_SHIP);
|
||||
let arr = JSON.parse(str);
|
||||
|
||||
export const friendShips = new Map<string, DicFriendShip>();
|
||||
export const friendShipHidAandIds = new Map<number, {actorId: number, level:number}>();
|
||||
arr.forEach(o => {
|
||||
o.attribute = parseAttribute(o.attribute);
|
||||
o.hids = parseNumberList(o.memberId);
|
||||
friendShips.set(o.shipId + '_' + o.level, o);
|
||||
let fiendShipHidAandId = friendShipHidAandIds.get(o.shipId);
|
||||
if (!fiendShipHidAandId || fiendShipHidAandId.level < o.level)
|
||||
friendShipHidAandIds.set(o.shipId, {actorId: o.actorId, level: o.level});
|
||||
});
|
||||
|
||||
function parseAttribute(str: string) {
|
||||
let result = new Array<{id: number, number: number}>();
|
||||
if(!str) return result;
|
||||
let decodeArr = decodeArrayListStr(str);
|
||||
for(let [id, number] of decodeArr) {
|
||||
if(isNaN(parseInt(id)) || isNaN(parseInt(number))) {
|
||||
throw new Error('data table format wrong');
|
||||
}
|
||||
result.push({id: parseInt(id), number: parseInt(number)});
|
||||
}
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user