✨ feat(诸子列传): 添加功能
This commit is contained in:
38
shared/pubUtils/dictionary/DicAuthorsBookPoint.ts
Normal file
38
shared/pubUtils/dictionary/DicAuthorsBookPoint.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
// 列传的进度节点
|
||||
import {decodeArrayListStr, readFileAndParse} from '../util'
|
||||
import { FILENAME } from '../../consts'
|
||||
|
||||
export interface DicAuthorsBookPoint {
|
||||
// 列传
|
||||
readonly bookId: number;
|
||||
// 进度节点
|
||||
readonly value: number;
|
||||
// 到这个节点可得的属性
|
||||
readonly attr: { id: number, val: number }[]
|
||||
}
|
||||
|
||||
export const dicAuthorsBookPoint = new Map<number, DicAuthorsBookPoint[]>();
|
||||
export function loadAuthorsBookPoint() {
|
||||
dicAuthorsBookPoint.clear();
|
||||
let arr = readFileAndParse(FILENAME.DIC_AUTHORS_BOOK_POINT);
|
||||
|
||||
arr.forEach(o => {
|
||||
o.attr = parseAttribute(o.attr);
|
||||
if(!dicAuthorsBookPoint.has(o.id)) dicAuthorsBookPoint.set(o.id, []);
|
||||
dicAuthorsBookPoint.get(o.id)?.push(o);
|
||||
});
|
||||
arr = undefined;
|
||||
}
|
||||
|
||||
function parseAttribute(str: string) {
|
||||
let result = new Array<{ id: number, val: number }>();
|
||||
if (!str) return result;
|
||||
let decodeArr = decodeArrayListStr(str);
|
||||
for (let [id, val] of decodeArr) {
|
||||
if (isNaN(parseInt(id)) || isNaN(parseInt(val))) {
|
||||
throw new Error('data table format wrong');
|
||||
}
|
||||
result.push({ id: parseInt(id), val: parseInt(val) });
|
||||
}
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user