|
1 | 1 | import { LevelDB } from "leveldb-zlib";
|
2 |
| -import { DimensionID } from "../Region-Types/dist/bedrock/index.js"; |
3 | 2 | import { readEntry } from "./entry.js";
|
4 | 3 |
|
5 |
| -import type { ChunkKeyNameMap, WorldKeyNameMap, SuffixKeyNameMap } from "../Region-Types/dist/bedrock/index.js"; |
6 |
| - |
7 |
| -export type Entries = { |
8 |
| - overworld: Chunk[]; |
9 |
| - nether: Chunk[]; |
10 |
| - end: Chunk[]; |
11 |
| -} & { |
12 |
| - [K in keyof WorldKeyNameMap]?: WorldKeyNameMap[K]; |
13 |
| -} & { |
14 |
| - [K in keyof SuffixKeyNameMap as `${K}${string}`]?: SuffixKeyNameMap[K]; |
15 |
| -} |
16 |
| - |
17 |
| -export type Chunk = { |
18 |
| - x: number; |
19 |
| - y: number; |
20 |
| - subchunks: Buffer[]; |
21 |
| -} & { |
22 |
| - [K in keyof ChunkKeyNameMap]?: ChunkKeyNameMap[K]; |
23 |
| -} |
| 4 | +import type { Key } from "../Region-Types/dist/bedrock/index.js"; |
24 | 5 |
|
25 | 6 | // not sure about the indexing here yet, still messy with these fancy types now
|
26 |
| -export async function readDatabase(path: string): Promise<Entries> { |
| 7 | +export async function readDatabase(path: string): Promise<Key[]> { |
27 | 8 | const db = new LevelDB(path,{ createIfMissing: false });
|
28 | 9 | await db.open();
|
29 | 10 |
|
30 |
| - const entries: Entries = { |
31 |
| - overworld: [], |
32 |
| - nether: [], |
33 |
| - end: [], |
34 |
| - }; |
| 11 | + const entries: Key[] = []; |
35 | 12 |
|
36 | 13 | // for await (const [keyBuffer] of db.getIterator({ keys: true, values: false })){
|
37 | 14 | // const key = (await import("./entry.js")).readKey(keyBuffer);
|
38 | 15 | // console.log(key);
|
39 | 16 | // }
|
40 | 17 |
|
41 |
| - for await (const entry of (db.getIterator() as AsyncIterable<[Buffer, Buffer]>)){ |
42 |
| - const result = await readEntry(entry); |
43 |
| - // console.log(result); |
| 18 | + // for await (const entry of (db.getIterator() as AsyncIterable<[Buffer, Buffer]>)){ |
| 19 | + // const result = await readEntry(entry); |
| 20 | + // // console.log(result); |
44 | 21 |
|
45 |
| - const [key, value] = result; |
| 22 | + // const [key, value] = result; |
46 | 23 |
|
47 |
| - if (typeof key !== "object"){ |
48 |
| - entries[key] = value as any; |
49 |
| - // console.log(key,value); |
50 |
| - continue; |
51 |
| - } |
| 24 | + // if (typeof key !== "object"){ |
| 25 | + // entries[key] = value as any; |
| 26 | + // // console.log(key,value); |
| 27 | + // continue; |
| 28 | + // } |
52 | 29 |
|
53 |
| - // continue; |
| 30 | + // // continue; |
54 | 31 |
|
55 |
| - if (!("x" in key) || !("y" in key)){ |
56 |
| - entries[key.key.toString() as `${keyof SuffixKeyNameMap}${string}`] = value as any; |
57 |
| - continue; |
58 |
| - } |
| 32 | + // if (!("x" in key) || !("y" in key)){ |
| 33 | + // entries[key.key.toString() as `${keyof SuffixKeyNameMap}${string}`] = value as any; |
| 34 | + // continue; |
| 35 | + // } |
59 | 36 |
|
60 |
| - const { x, y, type, dimension, subchunk } = key; |
61 |
| - let chunk: Chunk | undefined = entries[DimensionID[dimension] as keyof typeof DimensionID].find(entry => entry.x === x && entry.y === y); |
| 37 | + // const { x, y, type, dimension, subchunk } = key; |
| 38 | + // let chunk: Chunk | undefined = entries[DimensionID[dimension] as keyof typeof DimensionID].find(entry => entry.x === x && entry.y === y); |
62 | 39 |
|
63 |
| - if (chunk === undefined){ |
64 |
| - chunk = { x, y, subchunks: [] }; |
65 |
| - entries[DimensionID[dimension] as keyof typeof DimensionID].push(chunk); |
66 |
| - } |
| 40 | + // if (chunk === undefined){ |
| 41 | + // chunk = { x, y, subchunks: [] }; |
| 42 | + // entries[DimensionID[dimension] as keyof typeof DimensionID].push(chunk); |
| 43 | + // } |
67 | 44 |
|
68 |
| - if (type === "SubChunkPrefix"){ |
69 |
| - chunk.subchunks[subchunk!] = value as Buffer; |
70 |
| - continue; |
71 |
| - } |
| 45 | + // if (type === "SubChunkPrefix"){ |
| 46 | + // chunk.subchunks[subchunk!] = value as Buffer; |
| 47 | + // continue; |
| 48 | + // } |
72 | 49 |
|
73 |
| - chunk[type] = value as any; |
| 50 | + // chunk[type] = value as any; |
| 51 | + // } |
| 52 | + |
| 53 | + for await (const entry of (db.getIterator() as AsyncIterable<[Buffer, Buffer]>)){ |
| 54 | + const result = await readEntry(entry); |
| 55 | + // console.log(result); |
| 56 | + entries.push(result); |
74 | 57 | }
|
75 | 58 |
|
76 | 59 | await db.close();
|
|
0 commit comments