Improve the scene browser stuff a bit
This commit is contained in:
+8
-6
@@ -13,20 +13,21 @@ import {
|
|||||||
ZoomScanIcon,
|
ZoomScanIcon,
|
||||||
} from "./icons/index.ts";
|
} from "./icons/index.ts";
|
||||||
|
|
||||||
async function fetchScenes(): Promise<BrowserFolder> {
|
async function fetchBrowserData(dir: string): Promise<BrowserFolder> {
|
||||||
const indexRef: string[] = await (await fetch("/api/scenes")).json();
|
const indexRef: string[] = await (await fetch(`/api/${dir}`)).json();
|
||||||
|
|
||||||
const scenes = indexRef.reduce((root, entry) => {
|
const scenes = indexRef.reduce((root, entry) => {
|
||||||
const [name] = entry.substring(1).split("/");
|
const [name] = entry.substring(1).split("/");
|
||||||
root.set(name, `${name}/data.json`);
|
root.set(name, name);
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}, new Map() as BrowserFolder);
|
}, new Map() as BrowserFolder);
|
||||||
|
|
||||||
return new Map([["scenes", scenes]]);
|
return new Map([[dir, scenes]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const root = await fetchScenes();
|
const scenes = await fetchBrowserData("scenes");
|
||||||
|
const entites = await fetchBrowserData("entities");
|
||||||
|
|
||||||
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;`;
|
||||||
@@ -107,7 +108,8 @@ const DevTools: Component<{ gameContainer: HTMLElement }> = ({
|
|||||||
></InputField>
|
></InputField>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<FileBrowser root={root} handler={console.log} />
|
<FileBrowser root={scenes} handler={console.log} />
|
||||||
|
<FileBrowser root={entites} handler={console.log} />
|
||||||
</div>
|
</div>
|
||||||
<div class="tool-bar-resize" onMouseDown={startResizing}></div>
|
<div class="tool-bar-resize" onMouseDown={startResizing}></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -10,20 +10,21 @@ function buildBrowserIndex(dir: string): string[] {
|
|||||||
return dirents
|
return dirents
|
||||||
.filter((dirent) => dirent.isFile())
|
.filter((dirent) => dirent.isFile())
|
||||||
.map((dirent) => {
|
.map((dirent) => {
|
||||||
const path = dirent.parentPath.substring(dir.length - 2);
|
const path = dirent.parentPath.substring(dir.length);
|
||||||
return `${path}/${dirent.name}`;
|
return `${path}/${dirent.name}`;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function get(req: IncomingMessage, res: ServerResponse): void {
|
function get(req: IncomingMessage, res: ServerResponse): void {
|
||||||
console.log(req.url);
|
const match = req.url?.match(/^\/(\w+)$/);
|
||||||
const match = req.url?.match(/\/(\w+)$/);
|
|
||||||
if (!match) {
|
if (!match) {
|
||||||
|
console.error(req.url);
|
||||||
res.statusCode = 400;
|
res.statusCode = 400;
|
||||||
res.end();
|
res.end();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const sceneData = buildBrowserIndex(`.${req.url}`);
|
const sceneData = buildBrowserIndex(match[1]);
|
||||||
|
|
||||||
res.writeHead(200, { "Content-Type": "application/json" });
|
res.writeHead(200, { "Content-Type": "application/json" });
|
||||||
res.end(JSON.stringify(sceneData));
|
res.end(JSON.stringify(sceneData));
|
||||||
|
|||||||
Reference in New Issue
Block a user