diff options
Diffstat (limited to 'viewer/resources.ts')
-rw-r--r-- | viewer/resources.ts | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/viewer/resources.ts b/viewer/resources.ts index 0e9162e..c0eaba3 100644 --- a/viewer/resources.ts +++ b/viewer/resources.ts @@ -1,3 +1,4 @@ +import { Loader } from "./loader.ts"; export class Resource<T> { constructor(public hash: Uint8Array) { } @@ -6,11 +7,7 @@ export class Resource<T> { .map(e => e.toString(16).padStart(2, "0")) .join("") } - async download_raw() { - const res = await fetch(`http://127.0.0.1:28556/${this.toString()}`) - if (!res.ok) throw new Error("aaaa"); - return await res.bytes() - } + } export function read_res_table(buffer: Uint8Array, cb: (key: string, value: Uint8Array) => void) { @@ -54,9 +51,9 @@ async function ob_cached<T>(r: Resource<T>, make: () => Promise<T>): Promise<T> return m } -export async function get_respackentry(r: Resource<RespackEntry>): Promise<RespackEntry> { +export async function get_respackentry(l: Loader, r: Resource<RespackEntry>): Promise<RespackEntry> { return await ob_cached(r, async () => { - const buf = await r.download_raw(); + const buf = await l.download(r); const o: RespackEntry = {} read_res_table(buf, (key, value) => { switch (key) { @@ -69,9 +66,9 @@ export async function get_respackentry(r: Resource<RespackEntry>): Promise<Respa return o }) } -export async function get_spatialindex(r: Resource<SpatialIndex>): Promise<SpatialIndex> { +export async function get_spatialindex(l: Loader, r: Resource<SpatialIndex>): Promise<SpatialIndex> { return await ob_cached(r, async () => { - const buf = await r.download_raw(); + const buf = await l.download(r); const o: SpatialIndex = { child: [] } read_res_table(buf, (key, value) => { switch (key) { @@ -90,9 +87,9 @@ export async function get_spatialindex(r: Resource<SpatialIndex>): Promise<Spati return o }) } -export async function get_prefab(r: Resource<Prefab>): Promise<Prefab> { +export async function get_prefab(l: Loader, r: Resource<Prefab>): Promise<Prefab> { return await ob_cached(r, async () => { - const buf = await r.download_raw(); + const buf = await l.download(r); const o: Prefab = { graphics: [] } read_res_table(buf, (key, value) => { let v, x = 0 @@ -123,9 +120,9 @@ export async function get_prefab(r: Resource<Prefab>): Promise<Prefab> { return o }) } -export async function get_graphics_part(r: Resource<GraphicsPart>): Promise<GraphicsPart> { +export async function get_graphics_part(l: Loader, r: Resource<GraphicsPart>): Promise<GraphicsPart> { return await ob_cached(r, async () => { - return new GraphicsPart(await r.download_raw()) + return new GraphicsPart(await l.download(r)) }) } @@ -192,4 +189,4 @@ export interface GraphicsCommand { stroke?: number stroke_width?: number point?: Vec3 -}
\ No newline at end of file +} |