@antha/asset 0.4.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/antha-bootstrap.mod.d.ts +41 -0
- package/dist/antha-bootstrap.mod.js +54 -0
- package/dist/asset-loader.d.ts +1 -1
- package/dist/asset-loader.js +8 -8
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type AnthaEngine, type AnthaMod } from '@antha/engine';
|
|
2
|
+
import { type AnyObject, type MaybePromise, type PartialWithUndefined } from '@augment-vir/common';
|
|
3
|
+
import { type AnthaAssetModState } from './antha-asset.mod.js';
|
|
4
|
+
import { type AssetLoader, type AssetLoadSession } from './asset-loader.js';
|
|
5
|
+
/** State used internally by {@link createAnthaBootstrapMod}. */
|
|
6
|
+
export type AnthaBootstrapModState = {
|
|
7
|
+
hasStartedBootstrap: boolean;
|
|
8
|
+
};
|
|
9
|
+
/** Parameters passed to {@link AnthaBootstrapModOptions.bootstrap}. */
|
|
10
|
+
export type AnthaBootstrapParams<Module, State extends AnyObject> = {
|
|
11
|
+
assetLoader: AssetLoader;
|
|
12
|
+
engine: AnthaEngine;
|
|
13
|
+
loadSession: AssetLoadSession;
|
|
14
|
+
module: Module;
|
|
15
|
+
state: Partial<State & AnthaAssetModState & AnthaBootstrapModState>;
|
|
16
|
+
};
|
|
17
|
+
/** Result returned by {@link AnthaBootstrapModOptions.bootstrap}. */
|
|
18
|
+
export type AnthaBootstrapResult = {
|
|
19
|
+
/** Mods that Antha installs after bootstrapping finishes. */
|
|
20
|
+
mods: ReadonlyArray<AnthaMod>;
|
|
21
|
+
};
|
|
22
|
+
/** Options for {@link createAnthaBootstrapMod}. */
|
|
23
|
+
export type AnthaBootstrapModOptions<Module, State extends AnyObject> = {
|
|
24
|
+
/**
|
|
25
|
+
* Bootstraps the loaded module and returns the mods that should be installed for it. Await any
|
|
26
|
+
* initial asset loading here, using the provided load session, before returning.
|
|
27
|
+
*/
|
|
28
|
+
bootstrap: (this: void, params: Readonly<AnthaBootstrapParams<Module, State>>) => MaybePromise<AnthaBootstrapResult>;
|
|
29
|
+
/** Lazily imports the code required to bootstrap the game. */
|
|
30
|
+
loadModule: (this: void) => MaybePromise<Module>;
|
|
31
|
+
} & PartialWithUndefined<{
|
|
32
|
+
/** Label shown for the code-loading task. */
|
|
33
|
+
assetName: string;
|
|
34
|
+
}>;
|
|
35
|
+
/**
|
|
36
|
+
* Creates a mod that tracks a lazy game-module import on Antha's loading screen, then installs the
|
|
37
|
+
* mods returned by the module's bootstrap callback.
|
|
38
|
+
*
|
|
39
|
+
* @category Pre-Built Mods
|
|
40
|
+
*/
|
|
41
|
+
export declare function createAnthaBootstrapMod<Module, State extends AnyObject = AnyObject>(options: Readonly<AnthaBootstrapModOptions<Module, State>>): AnthaMod<NoInfer<State & AnthaAssetModState & AnthaBootstrapModState>>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { defineAnthaMod, SkipExecution } from '@antha/engine';
|
|
2
|
+
import { ensureErrorAndPrependMessage, } from '@augment-vir/common';
|
|
3
|
+
import { defineAsset } from './asset-loader.js';
|
|
4
|
+
/**
|
|
5
|
+
* Creates a mod that tracks a lazy game-module import on Antha's loading screen, then installs the
|
|
6
|
+
* mods returned by the module's bootstrap callback.
|
|
7
|
+
*
|
|
8
|
+
* @category Pre-Built Mods
|
|
9
|
+
*/
|
|
10
|
+
export function createAnthaBootstrapMod(options) {
|
|
11
|
+
const moduleAsset = defineAsset({
|
|
12
|
+
assetName: options.assetName || 'Game code',
|
|
13
|
+
maxProgress: 1,
|
|
14
|
+
async load({ incrementProgressCallback }) {
|
|
15
|
+
const module = await options.loadModule();
|
|
16
|
+
incrementProgressCallback();
|
|
17
|
+
return {
|
|
18
|
+
value: module,
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
return defineAnthaMod({
|
|
23
|
+
modName: 'antha-bootstrap',
|
|
24
|
+
execute({ engine, state }) {
|
|
25
|
+
const assetLoader = state.assetLoader;
|
|
26
|
+
if (!assetLoader || state.hasStartedBootstrap) {
|
|
27
|
+
return SkipExecution;
|
|
28
|
+
}
|
|
29
|
+
state.hasStartedBootstrap = true;
|
|
30
|
+
const loadSession = assetLoader.createLoadSession();
|
|
31
|
+
void assetLoader
|
|
32
|
+
.loadIndividualAsset({
|
|
33
|
+
asset: moduleAsset,
|
|
34
|
+
loadSession,
|
|
35
|
+
})
|
|
36
|
+
.then(async (module) => {
|
|
37
|
+
const bootstrapResult = await options.bootstrap({
|
|
38
|
+
assetLoader,
|
|
39
|
+
engine,
|
|
40
|
+
loadSession,
|
|
41
|
+
module,
|
|
42
|
+
state,
|
|
43
|
+
});
|
|
44
|
+
engine.currentMods.push(...bootstrapResult.mods);
|
|
45
|
+
loadSession.complete();
|
|
46
|
+
})
|
|
47
|
+
.catch((error) => {
|
|
48
|
+
loadSession.complete();
|
|
49
|
+
engine.log.error(ensureErrorAndPrependMessage(error, 'Failed to bootstrap game.'));
|
|
50
|
+
});
|
|
51
|
+
return SkipExecution;
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
package/dist/asset-loader.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ export type AssetValue<SpecificAsset extends Pick<Asset, 'load'>> = Awaited<Retu
|
|
|
50
50
|
* @category Asset
|
|
51
51
|
*/
|
|
52
52
|
export type Asset<AssetValue = any> = {
|
|
53
|
-
|
|
53
|
+
assetName: string;
|
|
54
54
|
maxProgress: number;
|
|
55
55
|
load: AssetLoaderCallback<AssetValue>;
|
|
56
56
|
};
|
package/dist/asset-loader.js
CHANGED
|
@@ -173,7 +173,7 @@ export class AssetLoader {
|
|
|
173
173
|
this.assetCache.set(asset, deferredLoadPromise.promise);
|
|
174
174
|
loadSession?.reportProgress({
|
|
175
175
|
current: 0,
|
|
176
|
-
currentResourceName: asset.
|
|
176
|
+
currentResourceName: asset.assetName,
|
|
177
177
|
total: asset.maxProgress,
|
|
178
178
|
});
|
|
179
179
|
const loadedAsset = await asset.load({
|
|
@@ -181,7 +181,7 @@ export class AssetLoader {
|
|
|
181
181
|
incrementProgressCallback?.(progressParams);
|
|
182
182
|
loadSession?.incrementProgress({
|
|
183
183
|
amount: progressParams,
|
|
184
|
-
currentResourceName: asset.
|
|
184
|
+
currentResourceName: asset.assetName,
|
|
185
185
|
});
|
|
186
186
|
},
|
|
187
187
|
});
|
|
@@ -197,7 +197,7 @@ export class AssetLoader {
|
|
|
197
197
|
await entry.cleanup();
|
|
198
198
|
}
|
|
199
199
|
catch (error) {
|
|
200
|
-
this.log.error(ensureErrorAndPrependMessage(error, `Failed to cleanup asset: ${asset.
|
|
200
|
+
this.log.error(ensureErrorAndPrependMessage(error, `Failed to cleanup asset: ${asset.assetName}`));
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
203
|
this.assetCache.delete(asset);
|
|
@@ -233,7 +233,7 @@ export class AssetLoader {
|
|
|
233
233
|
progress: {
|
|
234
234
|
current: currentProgress,
|
|
235
235
|
total: maxProgress,
|
|
236
|
-
currentResourceName: assetsToLoad[0]?.
|
|
236
|
+
currentResourceName: assetsToLoad[0]?.assetName,
|
|
237
237
|
},
|
|
238
238
|
});
|
|
239
239
|
}
|
|
@@ -247,7 +247,7 @@ export class AssetLoader {
|
|
|
247
247
|
progress: {
|
|
248
248
|
current: currentProgress,
|
|
249
249
|
total: maxProgress,
|
|
250
|
-
currentResourceName: assetsToLoad[0]?.
|
|
250
|
+
currentResourceName: assetsToLoad[0]?.assetName,
|
|
251
251
|
},
|
|
252
252
|
});
|
|
253
253
|
const chunkedAssets = options.maxParallelism
|
|
@@ -263,7 +263,7 @@ export class AssetLoader {
|
|
|
263
263
|
progress: {
|
|
264
264
|
current: currentProgress,
|
|
265
265
|
total: maxProgress,
|
|
266
|
-
currentResourceName: asset.
|
|
266
|
+
currentResourceName: asset.assetName,
|
|
267
267
|
},
|
|
268
268
|
});
|
|
269
269
|
};
|
|
@@ -278,7 +278,7 @@ export class AssetLoader {
|
|
|
278
278
|
progress: {
|
|
279
279
|
current: currentProgress,
|
|
280
280
|
total: maxProgress,
|
|
281
|
-
currentResourceName: asset.
|
|
281
|
+
currentResourceName: asset.assetName,
|
|
282
282
|
},
|
|
283
283
|
});
|
|
284
284
|
return await this.loadIndividualAsset({
|
|
@@ -293,7 +293,7 @@ export class AssetLoader {
|
|
|
293
293
|
currentProgress,
|
|
294
294
|
maxProgress,
|
|
295
295
|
assetCount: assetsToLoad.length,
|
|
296
|
-
assetNames: assetsToLoad.map((entry) => entry.
|
|
296
|
+
assetNames: assetsToLoad.map((entry) => entry.assetName).filter(Boolean),
|
|
297
297
|
},
|
|
298
298
|
tags: {
|
|
299
299
|
mod: '@antha/asset',
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antha/asset",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "An Antha mod for handling asset loading.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vir",
|
|
@@ -45,10 +45,12 @@
|
|
|
45
45
|
"@web/test-runner": "^1.0.0",
|
|
46
46
|
"@web/test-runner-playwright": "^1.0.0",
|
|
47
47
|
"istanbul-smart-text-reporter": "^1.1.5",
|
|
48
|
-
"
|
|
48
|
+
"markdown-code-example-inserter": "^3.0.6",
|
|
49
|
+
"pixi.js": "^8.19.0",
|
|
50
|
+
"typedoc": "^0.28.20"
|
|
49
51
|
},
|
|
50
52
|
"peerDependencies": {
|
|
51
|
-
"@antha/engine": "^0.
|
|
53
|
+
"@antha/engine": "^0.5.0",
|
|
52
54
|
"element-vir": ">=26"
|
|
53
55
|
},
|
|
54
56
|
"engines": {
|