@antha/asset 0.5.0 → 0.6.1
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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/dist/asset-loader.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AnthaLogger } from '@antha/engine';
|
|
1
|
+
import { type AnthaLogger, type EngineTime } from '@antha/engine';
|
|
2
2
|
import { type MaybePromise, type PartialWithUndefined } from '@augment-vir/common';
|
|
3
3
|
import { ListenTarget } from 'typed-event-target';
|
|
4
4
|
/**
|
|
@@ -102,7 +102,7 @@ export type AssetLoadProgress = {
|
|
|
102
102
|
};
|
|
103
103
|
/** State of the active asset load. */
|
|
104
104
|
export type AssetLoadState = AssetLoadProgress & {
|
|
105
|
-
completedAt:
|
|
105
|
+
completedAt: EngineTime | undefined;
|
|
106
106
|
isLoading: boolean;
|
|
107
107
|
};
|
|
108
108
|
declare const AssetLoadSessionUpdateEvent_base: (new (eventInitDict: {
|
|
@@ -166,7 +166,7 @@ export declare class AssetLoadSessionController {
|
|
|
166
166
|
/** Advances asset-load completion after an engine render. */
|
|
167
167
|
advance({ currentTick, totalMs, }: Readonly<{
|
|
168
168
|
currentTick: number;
|
|
169
|
-
totalMs:
|
|
169
|
+
totalMs: EngineTime;
|
|
170
170
|
}>): void;
|
|
171
171
|
/** Stops tracking the active load session. */
|
|
172
172
|
destroy(): void;
|
|
@@ -193,7 +193,7 @@ export declare class AssetLoader {
|
|
|
193
193
|
/** Advances asset-load completion after an engine render. */
|
|
194
194
|
advanceLoadState({ currentTick, totalMs, }: Readonly<{
|
|
195
195
|
currentTick: number;
|
|
196
|
-
totalMs:
|
|
196
|
+
totalMs: EngineTime;
|
|
197
197
|
}>): void;
|
|
198
198
|
/** Loads a single asset, returning its cached value if already loaded. */
|
|
199
199
|
loadIndividualAsset<ThisAsset extends Asset>({ asset, incrementProgressCallback, loadSession, }: Readonly<{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antha/asset",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
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.
|
|
53
|
+
"@antha/engine": "^0.6.1",
|
|
54
54
|
"element-vir": ">=26"
|
|
55
55
|
},
|
|
56
56
|
"engines": {
|