feat(诸子列传): 添加功能

This commit is contained in:
luying
2023-07-12 17:38:19 +08:00
parent b1af8ad204
commit 1eb6f76cce
25 changed files with 5475 additions and 71 deletions

View 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
}