@antha/entity-2d 0.6.1 → 0.7.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/dist/antha-entity.mod.d.ts +2 -0
- package/dist/antha-entity.mod.js +5 -3
- package/dist/entity.d.ts +2 -8
- package/dist/entity.js +2 -12
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/load-antha-assets.d.ts +31 -0
- package/dist/load-antha-assets.js +37 -0
- package/package.json +7 -6
|
@@ -9,6 +9,8 @@ import { type EntityStore2d, type EntityStore2dConstructorParams } from './entit
|
|
|
9
9
|
*/
|
|
10
10
|
export type AnthaEntity2dModState<State extends AnyObject = any> = {
|
|
11
11
|
entityStore: EntityStore2d<Partial<AnthaEntity2dModState<State>>>;
|
|
12
|
+
/** If true, entity updates and collision checks are skipped. */
|
|
13
|
+
disableEntityUpdates: boolean;
|
|
12
14
|
/** If `true`, hit boxes are visually rendered for debugging purposes. */
|
|
13
15
|
debugHitboxes: boolean;
|
|
14
16
|
} & State & AnthaGraphics2dModState & AnthaAssetModState;
|
package/dist/antha-entity.mod.js
CHANGED
|
@@ -32,9 +32,11 @@ export function createAnthaEntityMod2d(options = {}) {
|
|
|
32
32
|
return SkipExecution;
|
|
33
33
|
}
|
|
34
34
|
if (state.entityStore) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
if (!state.disableEntityUpdates) {
|
|
36
|
+
await state.entityStore.updateAllEntities({
|
|
37
|
+
msSinceLastUpdate: msSinceLastExecute,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
38
40
|
}
|
|
39
41
|
else if (state.assetLoader) {
|
|
40
42
|
state.entityStore = new EntityStore(mergeDefinedProperties({
|
package/dist/entity.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Asset, type
|
|
1
|
+
import { type Asset, type AssetLoader, type AssetValue } from '@antha/asset';
|
|
2
2
|
import { type PixiApplication } from '@antha/graphics-2d';
|
|
3
3
|
import { ConstructorInstanceMap, type AbstractConstructor, type AnyObject, type Constructor, type EmptyObject, type ExtractKeysWithMatchingValues, type IsEqual, type IsNever, type MaybePromise, type PartialWithUndefined, type WritableKeysOf } from '@augment-vir/common';
|
|
4
4
|
import { System as HitboxSystem, type Response as Collision, type Body as Hitbox } from 'detect-collisions';
|
|
@@ -84,12 +84,6 @@ export type EntityCollisionDefinition = PartialWithUndefined<{
|
|
|
84
84
|
/** Other entity classes this entity observes collisions with. */
|
|
85
85
|
collidesWithOtherEntities: ReadonlyArray<Entity2dConstructor>;
|
|
86
86
|
}>;
|
|
87
|
-
/** Loads assets declared by the given entity classes. */
|
|
88
|
-
export declare function loadEntityAssets({ assetLoader, entities, otherAssets, }: Readonly<{
|
|
89
|
-
assetLoader: AssetLoader;
|
|
90
|
-
entities: ReadonlyArray<Entity2dConstructor>;
|
|
91
|
-
otherAssets?: ReadonlyArray<Readonly<Asset>> | undefined;
|
|
92
|
-
}>, options?: Readonly<AssetBulkLoaderLoadOptions> | undefined): Promise<readonly unknown[]>;
|
|
93
87
|
/** A collision system that skips pairs no entity observes before running SAT collision checks. */
|
|
94
88
|
export declare class EntityHitboxSystem extends HitboxSystem {
|
|
95
89
|
protected checkedHitboxPairs: WeakMap<Hitbox, WeakSet<Hitbox>> | undefined;
|
|
@@ -161,7 +155,7 @@ export declare class EntityStore2d<State extends AnyObject = any> {
|
|
|
161
155
|
/**
|
|
162
156
|
* Shape definition for {@link EntityPositionParams}.
|
|
163
157
|
*
|
|
164
|
-
* @category
|
|
158
|
+
* @category Main
|
|
165
159
|
*/
|
|
166
160
|
export declare const entityPositionParamsShape: Shape<{
|
|
167
161
|
x: number;
|
package/dist/entity.js
CHANGED
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
import { assert, check } from '@augment-vir/assert';
|
|
2
|
-
import { ConstructorInstanceMap, getObjectTypedEntries,
|
|
2
|
+
import { ConstructorInstanceMap, getObjectTypedEntries, makeWritable, mapObjectValues, } from '@augment-vir/common';
|
|
3
3
|
import { System as HitboxSystem, Response, } from 'detect-collisions';
|
|
4
4
|
import { assertValidShape, defineShape } from 'object-shape-tester';
|
|
5
5
|
import { ParticleContainer } from 'pixi.js';
|
|
6
6
|
import { defineTypedCustomEvent, GenericListenTarget } from 'typed-event-target';
|
|
7
7
|
export { System as HitboxSystem } from 'detect-collisions';
|
|
8
|
-
/** Loads assets declared by the given entity classes. */
|
|
9
|
-
export async function loadEntityAssets({ assetLoader, entities, otherAssets, }, options) {
|
|
10
|
-
const assets = [
|
|
11
|
-
...(otherAssets || []),
|
|
12
|
-
...entities.flatMap((entity) => {
|
|
13
|
-
return getObjectTypedValues(entity.assets);
|
|
14
|
-
}),
|
|
15
|
-
];
|
|
16
|
-
return await assetLoader.bulkLoadAssets(assets, options);
|
|
17
|
-
}
|
|
18
8
|
function extractEntityFromHitbox(hitbox) {
|
|
19
9
|
return hitbox.userData instanceof BaseEntity2d ? hitbox.userData : undefined;
|
|
20
10
|
}
|
|
@@ -306,7 +296,7 @@ export class EntityStore2d {
|
|
|
306
296
|
/**
|
|
307
297
|
* Shape definition for {@link EntityPositionParams}.
|
|
308
298
|
*
|
|
309
|
-
* @category
|
|
299
|
+
* @category Main
|
|
310
300
|
*/
|
|
311
301
|
export const entityPositionParamsShape = defineShape({
|
|
312
302
|
x: -1,
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type Asset, type AssetBulkLoaderLoadOptions, type AssetLoader } from '@antha/asset';
|
|
2
|
+
import { type AudioPlayer, type AudioSetupParams } from '@antha/audio';
|
|
3
|
+
import { type PartialWithUndefined } from '@augment-vir/common';
|
|
4
|
+
import { type Entity2dConstructor } from './entity.js';
|
|
5
|
+
/** Audio files and their player to include in {@link loadAnthaAssets}. */
|
|
6
|
+
export type AnthaAudioFilesToLoad = {
|
|
7
|
+
audioPlayer: Pick<AudioPlayer, 'loadFiles'>;
|
|
8
|
+
files: ReadonlyArray<Readonly<AudioSetupParams>>;
|
|
9
|
+
} & PartialWithUndefined<{
|
|
10
|
+
/** Label shown for this audio load on the loading screen. */
|
|
11
|
+
assetName: string;
|
|
12
|
+
/** Whether audio files should load sequentially. */
|
|
13
|
+
serial: boolean;
|
|
14
|
+
}>;
|
|
15
|
+
/** Inputs for {@link loadAnthaAssets}. */
|
|
16
|
+
export type LoadAnthaAssetsParams = {
|
|
17
|
+
assetLoader: AssetLoader;
|
|
18
|
+
} & PartialWithUndefined<{
|
|
19
|
+
/** Assets declared by these entity classes are loaded. */
|
|
20
|
+
entities: ReadonlyArray<Entity2dConstructor>;
|
|
21
|
+
/** Audio files to load through their audio player. */
|
|
22
|
+
audio: AnthaAudioFilesToLoad;
|
|
23
|
+
/** Additional assets to load. */
|
|
24
|
+
assets: ReadonlyArray<Readonly<Asset>>;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Loads assets declared by entities, audio files, and any additional assets in one load session.
|
|
28
|
+
*
|
|
29
|
+
* @category Main
|
|
30
|
+
*/
|
|
31
|
+
export declare function loadAnthaAssets({ assetLoader, assets, audio, entities }: Readonly<LoadAnthaAssetsParams>, options?: Readonly<AssetBulkLoaderLoadOptions> | undefined): Promise<readonly unknown[]>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { defineAsset, } from '@antha/asset';
|
|
2
|
+
import { getObjectTypedValues } from '@augment-vir/common';
|
|
3
|
+
function createAudioLoadAsset({ assetName = 'Audio files', audioPlayer, files, serial, }) {
|
|
4
|
+
return defineAsset({
|
|
5
|
+
assetName,
|
|
6
|
+
maxProgress: files.length,
|
|
7
|
+
async load({ incrementProgressCallback }) {
|
|
8
|
+
await audioPlayer.loadFiles(files, {
|
|
9
|
+
progressCallback() {
|
|
10
|
+
incrementProgressCallback();
|
|
11
|
+
},
|
|
12
|
+
serial: !!serial,
|
|
13
|
+
});
|
|
14
|
+
return {
|
|
15
|
+
value: undefined,
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Loads assets declared by entities, audio files, and any additional assets in one load session.
|
|
22
|
+
*
|
|
23
|
+
* @category Main
|
|
24
|
+
*/
|
|
25
|
+
export async function loadAnthaAssets({ assetLoader, assets, audio, entities }, options) {
|
|
26
|
+
return await assetLoader.bulkLoadAssets([
|
|
27
|
+
...(audio
|
|
28
|
+
? [
|
|
29
|
+
createAudioLoadAsset(audio),
|
|
30
|
+
]
|
|
31
|
+
: []),
|
|
32
|
+
...(assets || []),
|
|
33
|
+
...(entities || []).flatMap((entity) => {
|
|
34
|
+
return getObjectTypedValues(entity.assets);
|
|
35
|
+
}),
|
|
36
|
+
], options);
|
|
37
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antha/entity-2d",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "An Antha mod for handling 2D entities.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vir",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"@augment-vir/common": "^32.2.3"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@antha/engine": "^0.
|
|
43
|
-
"@antha/web-test-runner-plugin-pixi": "^0.
|
|
42
|
+
"@antha/engine": "^0.7.0",
|
|
43
|
+
"@antha/web-test-runner-plugin-pixi": "^0.7.0",
|
|
44
44
|
"@augment-vir/test": "^32.2.3",
|
|
45
45
|
"@web/dev-server-esbuild": "^2.0.0",
|
|
46
46
|
"@web/test-runner": "^1.0.0",
|
|
@@ -52,9 +52,10 @@
|
|
|
52
52
|
"typed-event-target": "^4.3.3"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@antha/asset": "^0.
|
|
56
|
-
"@antha/
|
|
57
|
-
"@antha/
|
|
55
|
+
"@antha/asset": "^0.7.0",
|
|
56
|
+
"@antha/audio": "^0.7.0",
|
|
57
|
+
"@antha/engine": "^0.7.0",
|
|
58
|
+
"@antha/graphics-2d": "^0.7.0",
|
|
58
59
|
"detect-collisions": ">=10",
|
|
59
60
|
"element-vir": ">=26",
|
|
60
61
|
"object-shape-tester": ">=6",
|