Add shared-scene 2D authoring, sprite animation and Rapier2D physics
CI / validate (push) Canceled after 0s
CI / validate (push) Canceled after 0s
This commit is contained in:
+23
-3
@@ -1,7 +1,17 @@
|
||||
import { zipSync, unzipSync, strToU8, strFromU8 } from "fflate";
|
||||
import { type Project, clone, validateProject } from "./schema.ts";
|
||||
export const assetExtension = (name: string) =>
|
||||
/\.(gltf|png|jpg|jpeg|webp)$/i.exec(name)?.[0].toLowerCase() || ".glb";
|
||||
export const mimeFor = (n: string) =>
|
||||
n.toLowerCase().endsWith(".gltf") ? "model/gltf+json" : "model/gltf-binary";
|
||||
(
|
||||
({
|
||||
".gltf": "model/gltf+json",
|
||||
".png": "image/png",
|
||||
".jpg": "image/jpeg",
|
||||
".jpeg": "image/jpeg",
|
||||
".webp": "image/webp",
|
||||
}) as Record<string, string>
|
||||
)[assetExtension(n)] || "model/gltf-binary";
|
||||
export function base64(a: Uint8Array) {
|
||||
let s = "";
|
||||
for (let i = 0; i < a.length; i += 16384)
|
||||
@@ -14,7 +24,10 @@ export function decodeData(uri: string) {
|
||||
throw Error("Ожидался data URI base64");
|
||||
return Uint8Array.from(atob(uri.slice(i + 1)), (c) => c.charCodeAt(0));
|
||||
}
|
||||
export function engineResource(path: string, base = typeof document === "undefined" ? undefined : document.baseURI) {
|
||||
export function engineResource(
|
||||
path: string,
|
||||
base = typeof document === "undefined" ? undefined : document.baseURI,
|
||||
) {
|
||||
return base ? new URL(path.replace(/^\//, ""), base).href : path;
|
||||
}
|
||||
export async function readBytes(uri: string) {
|
||||
@@ -35,7 +48,14 @@ async function pack(
|
||||
const file =
|
||||
"assets/" +
|
||||
a.id +
|
||||
(a.name.toLowerCase().endsWith(".gltf") ? ".gltf" : ".glb");
|
||||
(a.kind === "image"
|
||||
? a.uri.startsWith("data:")
|
||||
? "." +
|
||||
(
|
||||
/^data:image\/(png|jpeg|webp);/i.exec(a.uri)?.[1] || "png"
|
||||
).replace("jpeg", "jpg")
|
||||
: assetExtension(a.uri)
|
||||
: assetExtension(a.name));
|
||||
files[file] = await read(a.uri);
|
||||
a.uri = file;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user