This commit is contained in:
kolaflash
2025-12-16 23:19:04 +01:00
parent 1dc9c803b3
commit 539ea78fbb
2 changed files with 11 additions and 31 deletions
+7 -27
View File
@@ -13,40 +13,20 @@ import {
ZoomScanIcon, ZoomScanIcon,
} from "./icons/index.ts"; } from "./icons/index.ts";
function sceneTreeBuilder( async function fetchScenes(): Promise<BrowserFolder> {
current: BrowserFolder,
entries: string[],
index: number,
ref: string[],
): void {
console.log(entries);
const next = current.has(entries[0])
? (current.get(entries[0]) as BrowserFolder)
: (new Map() as BrowserFolder);
if (entries.length > 1) {
current.set(entries.shift() as string, next);
sceneTreeBuilder(next, entries, index, ref);
} else {
// if (entries[0] !== "index.ts") {
// return;
// }
current.set(entries[0], entries[0]);
}
}
async function fetchSceneIndex(): Promise<BrowserFolder> {
const indexRef: string[] = await (await fetch("/api/scenes")).json(); const indexRef: string[] = await (await fetch("/api/scenes")).json();
return indexRef.reduce((root, entry, index) => { const scenes = indexRef.reduce((root, entry) => {
const entries = `scenes${entry}`.split("/"); const [name] = entry.substring(1).split("/");
sceneTreeBuilder(root, entries, index, indexRef); root.set(name, `${name}/data.json`);
return root; return root;
}, new Map() as BrowserFolder); }, new Map() as BrowserFolder);
return new Map([["scenes", scenes]]);
} }
const root = await fetchSceneIndex(); const root = await fetchScenes();
function adjustGameContainer(gameContainer: HTMLElement, width: number): void { function adjustGameContainer(gameContainer: HTMLElement, width: number): void {
gameContainer.style = `position: relative; top: 0; left: ${width}px; width: ${document.body.offsetWidth - width}px;`; gameContainer.style = `position: relative; top: 0; left: ${width}px; width: ${document.body.offsetWidth - width}px;`;
+4 -4
View File
@@ -1,16 +1,16 @@
import { readdirSync, writeFileSync } from "node:fs"; import { readdirSync, writeFileSync } from "node:fs";
import type { IncomingMessage, ServerResponse } from "node:http"; import type { IncomingMessage, ServerResponse } from "node:http";
function buildBrowserIndex(name: string, dir: string): string[] { function buildBrowserIndex(dir: string): string[] {
const dirents = readdirSync(dir, { const dirents = readdirSync(dir, {
withFileTypes: true, withFileTypes: true,
recursive: true, recursive: true,
}); });
return dirents return dirents
.filter((dirent) => dirent.isFile() && dirent.name !== name) .filter((dirent) => dirent.isFile())
.map((dirent) => { .map((dirent) => {
const path = dirent.parentPath.substring(dir.length); const path = dirent.parentPath.substring(dir.length - 2);
return `${path}/${dirent.name}`; return `${path}/${dirent.name}`;
}); });
} }
@@ -23,7 +23,7 @@ function get(req: IncomingMessage, res: ServerResponse): void {
res.end(); res.end();
} }
const sceneData = buildBrowserIndex("scenes", "scenes"); // FIXME const sceneData = buildBrowserIndex(`.${req.url}`);
res.writeHead(200, { "Content-Type": "application/json" }); res.writeHead(200, { "Content-Type": "application/json" });
res.end(JSON.stringify(sceneData)); res.end(JSON.stringify(sceneData));