@antha/entity-2d 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.
- package/dist/entity-suite.d.ts +4 -4
- package/dist/entity-suite.js +2 -2
- package/dist/entity.d.ts +20 -11
- package/dist/entity.js +17 -23
- package/package.json +6 -6
package/dist/entity-suite.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type AnyObject, type Constructor, type IsAny } from '@augment-vir/common';
|
|
2
2
|
import { type Shape } from 'object-shape-tester';
|
|
3
|
-
import { BaseEntity2d, type BaseEntityAssetDefinitions, type Entity2dConstructor, type Entity2dConstructorParams, EntityStore2d, type EntityStore2dConstructorParams, type MappedEntityAssets, type ParamsMap, type ReverseParamsMap, ViewEntity2d } from './entity.js';
|
|
3
|
+
import { BaseEntity2d, type BaseEntityAssetDefinitions, type Entity2dConstructor, type Entity2dConstructorParams, type EntityCollisionDefinition, EntityStore2d, type EntityStore2dConstructorParams, type MappedEntityAssets, type ParamsMap, type ReverseParamsMap, ViewEntity2d } from './entity.js';
|
|
4
4
|
/**
|
|
5
5
|
* Params for both {@link EntitySuite2d.defineEntity} and {@link EntitySuite2d.defineLogicEntity}.
|
|
6
6
|
*
|
|
@@ -8,7 +8,7 @@ import { BaseEntity2d, type BaseEntityAssetDefinitions, type Entity2dConstructor
|
|
|
8
8
|
*/
|
|
9
9
|
export type DefineEntity2dArgs<ParamsShape extends Shape<AnyObject> | undefined, EntityAssets extends BaseEntityAssetDefinitions | undefined> = {
|
|
10
10
|
/** Entity classes this entity observes collisions with. Omit to observe none. */
|
|
11
|
-
collidesWith?:
|
|
11
|
+
collidesWith?: EntityCollisionDefinition | undefined;
|
|
12
12
|
/**
|
|
13
13
|
* This key is used for deserialization of entities to track which class needs to be
|
|
14
14
|
* constructed. Do not use duplicate key strings across multiple entity classes.
|
|
@@ -99,9 +99,9 @@ export type DefineEntity2dArgs<ParamsShape extends Shape<AnyObject> | undefined,
|
|
|
99
99
|
*/
|
|
100
100
|
export type StaticEntity2dParts<State extends AnyObject = any, ParamsShape extends Shape<AnyObject> | undefined = any, EntityAssets extends BaseEntityAssetDefinitions | undefined = any> = {
|
|
101
101
|
/** Entity classes this entity observes collisions with. Omit to observe none. */
|
|
102
|
-
collidesWith:
|
|
102
|
+
collidesWith: EntityCollisionDefinition | undefined;
|
|
103
103
|
/** Cached entity classes this entity observes collisions with. */
|
|
104
|
-
collidesWithSet: ReadonlySet<Entity2dConstructor
|
|
104
|
+
collidesWithSet: ReadonlySet<Entity2dConstructor>;
|
|
105
105
|
/**
|
|
106
106
|
* This key is used for deserialization of entities to track which class needs to be
|
|
107
107
|
* constructed. You cannot have duplicate keys loaded at the same time.
|
package/dist/entity-suite.js
CHANGED
|
@@ -31,10 +31,10 @@ export function defineEntitySuite2d() {
|
|
|
31
31
|
// @ts-expect-error: abstract methods are intentionally not implemented here
|
|
32
32
|
[key]: class extends entityParent {
|
|
33
33
|
static collidesWith = collidesWith;
|
|
34
|
-
static collidesWithSet = new Set(collidesWith);
|
|
34
|
+
static collidesWithSet = new Set(collidesWith?.collidesWithOtherEntities);
|
|
35
35
|
static entityKey = key;
|
|
36
36
|
static paramsShape = paramsShape;
|
|
37
|
-
static assets = assets;
|
|
37
|
+
static assets = assets || {};
|
|
38
38
|
static paramsMap = paramsMap;
|
|
39
39
|
static reverseParamsMap = reverseParamsMap(paramsMap);
|
|
40
40
|
},
|
package/dist/entity.d.ts
CHANGED
|
@@ -72,7 +72,24 @@ export type EntityStore2dConstructorParams<State extends AnyObject = any> = {
|
|
|
72
72
|
*
|
|
73
73
|
* @category Internal
|
|
74
74
|
*/
|
|
75
|
-
export type Entity2dConstructor = Constructor<BaseEntity2d> & StaticEntity2dParts
|
|
75
|
+
export type Entity2dConstructor = Constructor<BaseEntity2d> & StaticEntity2dParts<any, any, BaseEntityAssetDefinitions>;
|
|
76
|
+
/**
|
|
77
|
+
* Defines which entity classes this entity observes collisions with.
|
|
78
|
+
*
|
|
79
|
+
* @category Internal
|
|
80
|
+
*/
|
|
81
|
+
export type EntityCollisionDefinition = PartialWithUndefined<{
|
|
82
|
+
/** Whether this entity observes collisions with instances of its own class. */
|
|
83
|
+
collidesWithSelf: boolean;
|
|
84
|
+
/** Other entity classes this entity observes collisions with. */
|
|
85
|
+
collidesWithOtherEntities: ReadonlyArray<Entity2dConstructor>;
|
|
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[]>;
|
|
76
93
|
/** A collision system that skips pairs no entity observes before running SAT collision checks. */
|
|
77
94
|
export declare class EntityHitboxSystem extends HitboxSystem {
|
|
78
95
|
protected checkedHitboxPairs: WeakMap<Hitbox, WeakSet<Hitbox>> | undefined;
|
|
@@ -109,14 +126,6 @@ export declare class EntityStore2d<State extends AnyObject = any> {
|
|
|
109
126
|
readonly state: State;
|
|
110
127
|
readonly assetLoader: AssetLoader;
|
|
111
128
|
constructor(args: Readonly<EntityStore2dConstructorParams>);
|
|
112
|
-
/**
|
|
113
|
-
* Load all the assets for all the given entities. Without this, assets will be loaded on demand
|
|
114
|
-
* only.
|
|
115
|
-
*/
|
|
116
|
-
loadEntityAssets({ entities, otherAssets, }: Readonly<{
|
|
117
|
-
entities: ReadonlyArray<Entity2dConstructor>;
|
|
118
|
-
otherAssets?: ReadonlyArray<Readonly<Asset>> | undefined;
|
|
119
|
-
}>, options?: Readonly<AssetBulkLoaderLoadOptions> | undefined): Promise<readonly unknown[]>;
|
|
120
129
|
/**
|
|
121
130
|
* Register a set of entities so that they can be deserialized (for example, when transferring
|
|
122
131
|
* game state in across the network for multilayer).
|
|
@@ -307,9 +316,9 @@ export declare abstract class BaseEntity2d<State extends AnyObject = any, Params
|
|
|
307
316
|
*/
|
|
308
317
|
static readonly entityKey: string;
|
|
309
318
|
/** Entity classes this entity observes collisions with. Omit to observe none. */
|
|
310
|
-
static readonly collidesWith:
|
|
319
|
+
static readonly collidesWith: EntityCollisionDefinition | undefined;
|
|
311
320
|
/** Cached entity classes this entity observes collisions with. */
|
|
312
|
-
static readonly collidesWithSet: ReadonlySet<Entity2dConstructor
|
|
321
|
+
static readonly collidesWithSet: ReadonlySet<Entity2dConstructor>;
|
|
313
322
|
/** Shape definition of this entity's parameters. */
|
|
314
323
|
static readonly paramsShape: Shape<AnyObject> | undefined;
|
|
315
324
|
static readonly assets: MappedEntityAssets<BaseEntityAssetDefinitions | undefined> | undefined;
|
package/dist/entity.js
CHANGED
|
@@ -1,22 +1,31 @@
|
|
|
1
1
|
import { assert, check } from '@augment-vir/assert';
|
|
2
|
-
import { ConstructorInstanceMap, getObjectTypedEntries, makeWritable, mapObjectValues, } from '@augment-vir/common';
|
|
2
|
+
import { ConstructorInstanceMap, getObjectTypedEntries, getObjectTypedValues, 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
|
+
}
|
|
8
18
|
function extractEntityFromHitbox(hitbox) {
|
|
9
19
|
return hitbox.userData instanceof BaseEntity2d ? hitbox.userData : undefined;
|
|
10
20
|
}
|
|
11
21
|
function hasCollisionTargets(entity) {
|
|
12
|
-
return (
|
|
13
|
-
entity.entityDefinition.
|
|
14
|
-
0) > 0);
|
|
22
|
+
return (!!entity.entityDefinition.collidesWith?.collidesWithSelf ||
|
|
23
|
+
entity.entityDefinition.collidesWithSet.size > 0);
|
|
15
24
|
}
|
|
16
25
|
function doesEntityCollideWith({ entity, otherEntity, }) {
|
|
17
|
-
return (entity.entityDefinition.
|
|
18
|
-
entity.entityDefinition
|
|
19
|
-
|
|
26
|
+
return ((entity.entityDefinition.collidesWith?.collidesWithSelf &&
|
|
27
|
+
entity.entityDefinition === otherEntity.entityDefinition) ||
|
|
28
|
+
entity.entityDefinition.collidesWithSet.has(otherEntity.entityDefinition));
|
|
20
29
|
}
|
|
21
30
|
function shouldCheckEntityCollision({ firstEntity, secondEntity, }) {
|
|
22
31
|
return (doesEntityCollideWith({
|
|
@@ -155,21 +164,6 @@ export class EntityStore2d {
|
|
|
155
164
|
});
|
|
156
165
|
}
|
|
157
166
|
}
|
|
158
|
-
/**
|
|
159
|
-
* Load all the assets for all the given entities. Without this, assets will be loaded on demand
|
|
160
|
-
* only.
|
|
161
|
-
*/
|
|
162
|
-
async loadEntityAssets({ entities, otherAssets, }, options) {
|
|
163
|
-
const assets = [
|
|
164
|
-
...(otherAssets || []),
|
|
165
|
-
...entities.flatMap((entity) => {
|
|
166
|
-
return Object.values(entity.assets).map((asset) => {
|
|
167
|
-
return asset;
|
|
168
|
-
});
|
|
169
|
-
}),
|
|
170
|
-
];
|
|
171
|
-
return await this.assetLoader.bulkLoadAssets(assets, options);
|
|
172
|
-
}
|
|
173
167
|
/**
|
|
174
168
|
* Register a set of entities so that they can be deserialized (for example, when transferring
|
|
175
169
|
* game state in across the network for multilayer).
|
|
@@ -380,7 +374,7 @@ export class BaseEntity2d {
|
|
|
380
374
|
/** Entity classes this entity observes collisions with. Omit to observe none. */
|
|
381
375
|
static collidesWith;
|
|
382
376
|
/** Cached entity classes this entity observes collisions with. */
|
|
383
|
-
static collidesWithSet;
|
|
377
|
+
static collidesWithSet = new Set();
|
|
384
378
|
/** Shape definition of this entity's parameters. */
|
|
385
379
|
static paramsShape;
|
|
386
380
|
static assets;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antha/entity-2d",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
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.6.1",
|
|
43
|
+
"@antha/web-test-runner-plugin-pixi": "^0.6.1",
|
|
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,9 @@
|
|
|
52
52
|
"typed-event-target": "^4.3.3"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@antha/asset": "^0.
|
|
56
|
-
"@antha/engine": "^0.
|
|
57
|
-
"@antha/graphics-2d": "^0.
|
|
55
|
+
"@antha/asset": "^0.6.1",
|
|
56
|
+
"@antha/engine": "^0.6.1",
|
|
57
|
+
"@antha/graphics-2d": "^0.6.1",
|
|
58
58
|
"detect-collisions": ">=10",
|
|
59
59
|
"element-vir": ">=26",
|
|
60
60
|
"object-shape-tester": ">=6",
|