Skip to content

Refactor Mirabuf Loading System [AARD-2060] #1273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fission/manifest.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type ManifestFileType = Record<"robots"|"private"|"fields", { filename: string, hash: string }[]>
4 changes: 2 additions & 2 deletions fission/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"fmt:fix": "bunx --bun biome format src --write",
"style": "bun run fmt && bun run lint",
"style:fix": "bun run fmt:fix && bun run lint:fix",
"assetpack": "git lfs pull && tar -xf public/assetpack.zip -C public/",
"assetpack:update": "cd public && zip -FS -r assetpack.zip Downloadables",
"assetpack": "git lfs pull && (rm -rf public/Downloadables;tar -xf public/assetpack.zip -C public/)",
"assetpack:update": "bun update_manifest.ts && cd public && zip -FS -r assetpack.zip Downloadables",
"playwright:install": "bun x playwright install",
"electron:start": "electron-forge start",
"electron:package": "electron-forge package",
Expand Down
4 changes: 2 additions & 2 deletions fission/public/assetpack.zip
Git LFS file not shown
54 changes: 54 additions & 0 deletions fission/src/mirabuf/DefaultAssetLoader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { type MirabufCacheInfo, MiraType } from "@/mirabuf/MirabufLoader.ts"
import type { ManifestFileType } from "../../manifest.d.ts"

export type DefaultAssetInfo = Required<Pick<MirabufCacheInfo, "hash" | "remotePath" | "miraType" | "name">>

class DefaultAssetLoader {
private static _assets: DefaultAssetInfo[] = []
private static _hasLoaded = false
static {
setTimeout(() => {
if (!this._hasLoaded) this.refresh().catch(console.error)
}, 1000)
}

public static async refresh() {
this._hasLoaded = true
this._assets = []

const isElectron = window.electronAPI != null
const host = isElectron ? "https://synthesis.autodesk.com" : ""
const baseUrl = `${host}/api/mira`

const manifest: ManifestFileType = await fetch(`${baseUrl}/manifest.json`).then(x => x.json())

const miraTypeMap: Partial<Record<keyof ManifestFileType, MiraType>> = {
robots: MiraType.ROBOT,
fields: MiraType.FIELD,
}

Object.entries(manifest).forEach(([dir, assets]) => {
const miraType = miraTypeMap[dir as keyof ManifestFileType]
if (miraType == undefined) return

assets.forEach(obj => {
this._assets.push({
remotePath: `${baseUrl}/${dir}/${obj.filename}`,
hash: obj.hash,
miraType,
name: obj.filename,
})
})
})
}

public static get robots() {
return this._assets.filter(obj => obj.miraType == MiraType.ROBOT)
}

public static get fields() {
return this._assets.filter(obj => obj.miraType == MiraType.FIELD)
}
}

export default DefaultAssetLoader
Loading