@antha/asset 0.5.0 → 0.6.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.
@@ -7,7 +7,7 @@ export type AnthaBootstrapModState = {
7
7
  hasStartedBootstrap: boolean;
8
8
  };
9
9
  /** Parameters passed to {@link AnthaBootstrapModOptions.bootstrap}. */
10
- export type AnthaBootstrapParams<Module, State extends AnyObject> = {
10
+ export type AnthaBootstrapParams<State extends AnyObject, Module> = {
11
11
  assetLoader: AssetLoader;
12
12
  engine: AnthaEngine;
13
13
  loadSession: AssetLoadSession;
@@ -20,12 +20,12 @@ export type AnthaBootstrapResult = {
20
20
  mods: ReadonlyArray<AnthaMod>;
21
21
  };
22
22
  /** Options for {@link createAnthaBootstrapMod}. */
23
- export type AnthaBootstrapModOptions<Module, State extends AnyObject> = {
23
+ export type AnthaBootstrapModOptions<State extends AnyObject, Module> = {
24
24
  /**
25
25
  * Bootstraps the loaded module and returns the mods that should be installed for it. Await any
26
26
  * initial asset loading here, using the provided load session, before returning.
27
27
  */
28
- bootstrap: (this: void, params: Readonly<AnthaBootstrapParams<Module, State>>) => MaybePromise<AnthaBootstrapResult>;
28
+ bootstrap: (this: void, params: Readonly<AnthaBootstrapParams<State, Module>>) => MaybePromise<AnthaBootstrapResult>;
29
29
  /** Lazily imports the code required to bootstrap the game. */
30
30
  loadModule: (this: void) => MaybePromise<Module>;
31
31
  } & PartialWithUndefined<{
@@ -38,4 +38,4 @@ export type AnthaBootstrapModOptions<Module, State extends AnyObject> = {
38
38
  *
39
39
  * @category Pre-Built Mods
40
40
  */
41
- export declare function createAnthaBootstrapMod<Module, State extends AnyObject = AnyObject>(options: Readonly<AnthaBootstrapModOptions<Module, State>>): AnthaMod<NoInfer<State & AnthaAssetModState & AnthaBootstrapModState>>;
41
+ export declare function createAnthaBootstrapMod<State extends AnyObject = AnyObject>(): <Module>(options: Readonly<AnthaBootstrapModOptions<NoInfer<State>, Module>>) => AnthaMod<NoInfer<NoInfer<State> & AnthaAssetModState & AnthaBootstrapModState>>;
@@ -1,54 +1,48 @@
1
1
  import { defineAnthaMod, SkipExecution } from '@antha/engine';
2
2
  import { ensureErrorAndPrependMessage, } from '@augment-vir/common';
3
- import { defineAsset } from './asset-loader.js';
4
3
  /**
5
4
  * Creates a mod that tracks a lazy game-module import on Antha's loading screen, then installs the
6
5
  * mods returned by the module's bootstrap callback.
7
6
  *
8
7
  * @category Pre-Built Mods
9
8
  */
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,
9
+ export function createAnthaBootstrapMod() {
10
+ return function createBootstrapMod(options) {
11
+ return defineAnthaMod({
12
+ modName: 'antha-bootstrap',
13
+ execute({ engine, state }) {
14
+ const assetLoader = state.assetLoader;
15
+ if (!assetLoader || state.hasStartedBootstrap) {
16
+ return SkipExecution;
17
+ }
18
+ state.hasStartedBootstrap = true;
19
+ const loadSession = assetLoader.createLoadSession();
20
+ loadSession.reportProgress({
21
+ current: 0,
22
+ currentResourceName: options.assetName || 'Game code',
23
+ total: 0,
24
+ });
25
+ void Promise.resolve()
26
+ .then(() => {
27
+ return options.loadModule();
28
+ })
29
+ .then(async (module) => {
30
+ const bootstrapResult = await options.bootstrap({
31
+ assetLoader,
32
+ engine,
33
+ loadSession,
34
+ module,
35
+ state,
36
+ });
37
+ engine.currentMods.push(...bootstrapResult.mods);
38
+ loadSession.complete();
39
+ })
40
+ .catch((error) => {
41
+ loadSession.complete();
42
+ engine.log.error(ensureErrorAndPrependMessage(error, 'Failed to bootstrap game.'));
43
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
- });
44
+ return SkipExecution;
45
+ },
46
+ });
47
+ };
54
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antha/asset",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "An Antha mod for handling asset loading.",
5
5
  "keywords": [
6
6
  "vir",
@@ -50,7 +50,7 @@
50
50
  "typedoc": "^0.28.20"
51
51
  },
52
52
  "peerDependencies": {
53
- "@antha/engine": "^0.5.0",
53
+ "@antha/engine": "^0.6.0",
54
54
  "element-vir": ">=26"
55
55
  },
56
56
  "engines": {