UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

49 lines (45 loc) 1.35 kB
import { computeFileExtension } from "../../core/path/computeFileExtension.js"; /** * * @param {string} url * @returns {string|null} */ export function guessAssetType(url) { const ext = computeFileExtension(url); const assetRootPath = 'data/'; let assetDirectory = url.substring(url.indexOf(assetRootPath) + assetRootPath.length); while (assetDirectory.charAt(0) === "/") { assetDirectory = assetDirectory.substr(1); } let iSlash = assetDirectory.indexOf("/"); if (iSlash === -1) { assetDirectory = ""; } else { assetDirectory = assetDirectory.substr(0, iSlash); } switch (ext) { case "json": switch (assetDirectory) { case "models": return "three.js"; case "levels": return "level"; default: return "json"; } case 'gltf': return 'model/gltf+json'; case 'glb': return 'model/gltf'; case "jpg": case "jpeg": case "png": return "image"; case "ogg": case "mp3": //NOTE currently chrome doesn't seem to load these // return "sound"; default : return null; } }