Skip to content

Commit dec000d

Browse files
authored
Refactor Mirabuf Loading System [AARD-2060] (#1273)
2 parents 39ae674 + b6dac0a commit dec000d

27 files changed

+784
-809
lines changed

.github/workflows/FissionUnitTest.yml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runUnitTests:
1212
name: Playwright Unit Tests
1313
container:
14-
image: mcr.microsoft.com/playwright:v1.54.0-noble
14+
image: mcr.microsoft.com/playwright:v1.54.2-noble
1515
runs-on: ubuntu-latest
1616
defaults:
1717
run:
@@ -57,3 +57,41 @@ jobs:
5757

5858
- name: Run Tests
5959
run: HOME=/root npm run test
60+
61+
runAssetpackTests:
62+
name: Assetpack Tests
63+
needs: runUnitTests
64+
container:
65+
image: mcr.microsoft.com/playwright:v1.54.2-noble
66+
runs-on: ubuntu-latest
67+
defaults:
68+
run:
69+
working-directory: "fission"
70+
steps:
71+
- name: Checkout Code
72+
uses: actions/checkout@v4
73+
- name: JavaScript Setup
74+
uses: actions/setup-node@v4
75+
with:
76+
node-version: 20
77+
78+
- name: Cache Unzipped Synthesis Assets
79+
id: cache-assets
80+
uses: actions/cache@v3
81+
with:
82+
path: fission/public/Downloadables
83+
key: ${{ runner.os }}-assets-${{hashFiles('fission/public/assetpack.zip')}}
84+
85+
- name: Cache Node Dependencies
86+
uses: actions/cache@v3
87+
with:
88+
key: "${{runner.os}}-npm-fission-${{hashFiles('fission/package.json')}}"
89+
path: "fission/node_modules"
90+
restore-keys: |
91+
${{runner.os}}-npm-fission-
92+
${{runner.os}}-npm
93+
94+
- name: Run Assetpack Tests
95+
run: HOME=/root npm run test src/test/mirabuf/DefaultAssets.test.ts
96+
env:
97+
VITE_RUN_ASSETPACK_TEST: true

fission/manifest.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type ManifestFileType = Record<"robots"|"private"|"fields", { filename: string, hash: string }[]>

fission/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"fmt:fix": "bunx biome format src --write",
2222
"style": "bunx biome check src",
2323
"style:fix": "bunx biome check src --write",
24-
"assetpack": "git lfs pull && tar -xf public/assetpack.zip -C public/",
25-
"assetpack:update": "cd public && zip -FS -r assetpack.zip Downloadables",
24+
"assetpack": "git lfs pull && (rm -rf public/Downloadables;tar -xf public/assetpack.zip -C public/)",
25+
"assetpack:update": "bun update_manifest.ts && cd public && zip -FS -r assetpack.zip Downloadables",
2626
"playwright:install": "bun x playwright install",
2727
"electron:start": "electron-forge start",
2828
"electron:package": "electron-forge package",

fission/public/assetpack.zip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:ea7be96ce500ebef474d55314ad0e547dac7015763664574978417016d64a6f6
3-
size 193148563
2+
oid sha256:bc65215352491eacaf6090792280cfe8d3a4be4cf48100583d4044af7f54e12e
3+
size 72047181
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { type MirabufCacheInfo, MiraType } from "@/mirabuf/MirabufLoader.ts"
2+
import type { ManifestFileType } from "../../manifest.d.ts"
3+
import { API_URL } from "@/util/Consts.ts"
4+
5+
export type DefaultAssetInfo = Required<Pick<MirabufCacheInfo, "hash" | "remotePath" | "miraType" | "name">>
6+
7+
class DefaultAssetLoader {
8+
private static _assets: DefaultAssetInfo[] = []
9+
private static _hasLoaded = false
10+
static {
11+
setTimeout(() => {
12+
if (!this._hasLoaded) this.refresh().catch(console.error)
13+
}, 1000)
14+
}
15+
16+
public static async refresh() {
17+
this._hasLoaded = true
18+
this._assets = []
19+
const baseUrl = `${API_URL}/mira`
20+
const manifest: ManifestFileType = await fetch(`${baseUrl}/manifest.json`).then(x => x.json())
21+
22+
const miraTypeMap: Partial<Record<keyof ManifestFileType, MiraType>> = {
23+
robots: MiraType.ROBOT,
24+
fields: MiraType.FIELD,
25+
}
26+
27+
Object.entries(manifest).forEach(([dir, assets]) => {
28+
const miraType = miraTypeMap[dir as keyof ManifestFileType]
29+
if (miraType == undefined) return
30+
31+
assets.forEach(obj => {
32+
this._assets.push({
33+
remotePath: `${baseUrl}/${dir}/${obj.filename}`,
34+
hash: obj.hash,
35+
miraType,
36+
name: obj.filename,
37+
})
38+
})
39+
})
40+
}
41+
42+
public static get robots() {
43+
return this._assets.filter(obj => obj.miraType == MiraType.ROBOT)
44+
}
45+
46+
public static get fields() {
47+
return this._assets.filter(obj => obj.miraType == MiraType.FIELD)
48+
}
49+
}
50+
51+
export default DefaultAssetLoader

0 commit comments

Comments
 (0)