class ItemDB { private item_line = "^" + "(?[0-9]+),[ \t]*" + "(?[^ \t,]+),[ \t]*" + "(?[0-9]+),[ \t]*" + "(?[0-9]+),[ \t]*" + "(?[0-9]+),[ \t]*" + "(?[0-9]+),[ \t]*" + "(?[0-9]+),[ \t]*" + "(?[0-9]+),[ \t]*" + "(?[0-9]+),[ \t]*" + "(?[0-9-]+),[ \t]*" + "(?[0-9]+),[ \t]*" + "(?[0-9]+),[ \t]*" + "(?[0-9]+),[ \t]*" + "(?[0-9]+),[ \t]*" + "(?[0-9]+),[ \t]*" + "(?[0-9]+),[ \t]*" + "\{(?[^\}]*)\},[ \t]*" + "\{(?[^\}]*)\}[ \t]*" + "$"; private item_regex: RegExp; constructor () { this.item_regex = new RegExp(this.item_line); } private parseLine (line: string) { const match = this.item_regex.exec(line); if (!(match instanceof Object) || !Reflect.has(match, "groups")) { console.error("line does not match the item db regex:", line); throw new SyntaxError(); } return (match as any).groups; } public async * readDB () { const decoder = new TextDecoder("utf-8"); console.info("reading tmwa-map.conf..."); const file = await Deno.readFile("world/map/conf/tmwa-map.conf"); const data = decoder.decode(file).split("\n"); const db_regex = new RegExp("^item_db: *(?[A-Za-z0-9_\./]+)$"); for (const line of data) { const match = db_regex.exec(line); if (!(match instanceof Object)) continue; const path = (match as any).groups.path; console.info(`reading world/map/${path}...`) const db = await Deno.readFile(`world/map/${path}`); for (const item of decoder.decode(db).split("\n")) { if (item.startsWith("//") || item.length < 2) { continue; } yield this.parseLine(item); } } } } export { ItemDB }