@antha/entity-2d 0.13.0 → 0.14.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 +3 -2
- package/dist/antha-entity.mod.js +13 -15
- package/dist/entity-suite.d.ts +10 -10
- package/dist/entity.d.ts +4 -11
- package/package.json +10 -10
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type AnthaAssetModState } from '@antha/asset';
|
|
2
|
+
import { type AnthaMod } from '@antha/engine';
|
|
2
3
|
import { type AnthaGraphics2dModState } from '@antha/graphics-2d';
|
|
3
4
|
import { type AnyObject, type PartialWithUndefined } from '@augment-vir/common';
|
|
4
5
|
import { type EntityStore2d, type EntityStore2dConstructorParams } from './entity.js';
|
|
@@ -7,7 +8,7 @@ import { type EntityStore2d, type EntityStore2dConstructorParams } from './entit
|
|
|
7
8
|
*
|
|
8
9
|
* @category Internal
|
|
9
10
|
*/
|
|
10
|
-
export type AnthaEntity2dModState<State extends AnyObject =
|
|
11
|
+
export type AnthaEntity2dModState<State extends AnyObject = AnyObject> = {
|
|
11
12
|
entityStore: EntityStore2d<Partial<AnthaEntity2dModState<State>>>;
|
|
12
13
|
/** If true, entity updates and collision checks are skipped. */
|
|
13
14
|
disableEntityUpdates: boolean;
|
|
@@ -31,5 +32,5 @@ export declare function createAnthaEntityMod2d<ExtraState extends AnyObject>(opt
|
|
|
31
32
|
defineEntity: import("./entity-suite.js").DefineViewEntity2d<AnthaEntity2dModState<ExtraState>>;
|
|
32
33
|
defineLogicEntity: import("./entity-suite.js").DefineLogicEntity2d<AnthaEntity2dModState<ExtraState>>;
|
|
33
34
|
entityKeys: Set<string>;
|
|
34
|
-
mod:
|
|
35
|
+
mod: AnthaMod<AnthaEntity2dModState<ExtraState>>;
|
|
35
36
|
};
|
package/dist/antha-entity.mod.js
CHANGED
|
@@ -18,34 +18,32 @@ export function createAnthaEntityMod2d(options = {}) {
|
|
|
18
18
|
cleanup({ state }) {
|
|
19
19
|
state.entityStore?.destroy();
|
|
20
20
|
},
|
|
21
|
-
async execute(
|
|
21
|
+
async execute(executeParams) {
|
|
22
22
|
/**
|
|
23
23
|
* If we don't have a mod that is expected to create the asset loader, then we create
|
|
24
24
|
* one ourself.
|
|
25
25
|
*/
|
|
26
|
-
if (!state.assetLoader &&
|
|
27
|
-
!engine.currentMods.some((mod) => mod.modName === anthaAssetModName)) {
|
|
28
|
-
state.assetLoader = new AssetLoader();
|
|
26
|
+
if (!executeParams.state.assetLoader &&
|
|
27
|
+
!executeParams.engine.currentMods.some((mod) => mod.modName === anthaAssetModName)) {
|
|
28
|
+
executeParams.state.assetLoader = new AssetLoader();
|
|
29
29
|
}
|
|
30
|
-
const pixiApplication = state.pixi?.pixiApplication;
|
|
30
|
+
const pixiApplication = executeParams.state.pixi?.pixiApplication;
|
|
31
31
|
if (!pixiApplication) {
|
|
32
32
|
return SkipExecution;
|
|
33
33
|
}
|
|
34
|
-
if (state.entityStore) {
|
|
35
|
-
if (!state.disableEntityUpdates) {
|
|
36
|
-
await state.entityStore.updateAllEntities(
|
|
37
|
-
msSinceLastUpdate: msSinceLastExecute,
|
|
38
|
-
});
|
|
34
|
+
if (executeParams.state.entityStore) {
|
|
35
|
+
if (!executeParams.state.disableEntityUpdates) {
|
|
36
|
+
await executeParams.state.entityStore.updateAllEntities(executeParams);
|
|
39
37
|
}
|
|
40
38
|
}
|
|
41
|
-
else if (state.assetLoader) {
|
|
42
|
-
state.entityStore = new EntityStore(mergeDefinedProperties({
|
|
39
|
+
else if (executeParams.state.assetLoader) {
|
|
40
|
+
executeParams.state.entityStore = new EntityStore(mergeDefinedProperties({
|
|
43
41
|
pixi: pixiApplication,
|
|
44
|
-
state,
|
|
45
|
-
assetLoader: state.assetLoader,
|
|
42
|
+
state: executeParams.state,
|
|
43
|
+
assetLoader: executeParams.state.assetLoader,
|
|
46
44
|
}, options));
|
|
47
45
|
}
|
|
48
|
-
if (state.debugHitboxes) {
|
|
46
|
+
if (executeParams.state.debugHitboxes) {
|
|
49
47
|
return html `
|
|
50
48
|
<canvas class="hitbox-debug-canvas"></canvas>
|
|
51
49
|
`;
|
package/dist/entity-suite.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { BaseEntity2d, type BaseEntityAssetDefinitions, type Entity2dConstructor
|
|
|
6
6
|
*
|
|
7
7
|
* @category Internal
|
|
8
8
|
*/
|
|
9
|
-
export type DefineEntity2dArgs<ParamsShape extends Shape
|
|
9
|
+
export type DefineEntity2dArgs<ParamsShape extends Shape | undefined, EntityAssets extends BaseEntityAssetDefinitions | undefined> = {
|
|
10
10
|
/** Entity classes this entity observes collisions with. Omit to observe none. */
|
|
11
11
|
collidesWith?: EntityCollisionDefinition | undefined;
|
|
12
12
|
/**
|
|
@@ -89,7 +89,7 @@ export type DefineEntity2dArgs<ParamsShape extends Shape<AnyObject> | undefined,
|
|
|
89
89
|
*
|
|
90
90
|
* @default undefined // no mapping
|
|
91
91
|
*/
|
|
92
|
-
paramsMap?: ParamsMap<NoInfer<ParamsShape> extends Shape
|
|
92
|
+
paramsMap?: ParamsMap<NoInfer<ParamsShape> extends Shape ? NoInfer<ParamsShape>['runtimeType'] : undefined> | undefined;
|
|
93
93
|
assets?: EntityAssets;
|
|
94
94
|
};
|
|
95
95
|
/**
|
|
@@ -97,7 +97,7 @@ export type DefineEntity2dArgs<ParamsShape extends Shape<AnyObject> | undefined,
|
|
|
97
97
|
*
|
|
98
98
|
* @category Internal
|
|
99
99
|
*/
|
|
100
|
-
export type StaticEntity2dParts<State extends AnyObject = any, ParamsShape extends Shape
|
|
100
|
+
export type StaticEntity2dParts<State extends AnyObject = any, ParamsShape extends Shape | undefined = any, EntityAssets extends BaseEntityAssetDefinitions | undefined = any> = {
|
|
101
101
|
/** Entity classes this entity observes collisions with. Omit to observe none. */
|
|
102
102
|
collidesWith: EntityCollisionDefinition | undefined;
|
|
103
103
|
/** Cached entity classes this entity observes collisions with. */
|
|
@@ -117,11 +117,11 @@ export type StaticEntity2dParts<State extends AnyObject = any, ParamsShape exten
|
|
|
117
117
|
* Defines which properties from {@link BaseEntity2d.params} will be mapped to hitbox and/or view
|
|
118
118
|
* properties.
|
|
119
119
|
*/
|
|
120
|
-
paramsMap: IsAny<ParamsShape> extends true ? any : ParamsMap<ParamsShape extends Shape
|
|
120
|
+
paramsMap: IsAny<ParamsShape> extends true ? any : ParamsMap<ParamsShape extends Shape ? ParamsShape['runtimeType'] : undefined>;
|
|
121
121
|
/** Parses the serialized params generated by {@link BaseEntity2d.serialize}. */
|
|
122
122
|
deserialize(serialized: string | undefined): AnyObject | undefined;
|
|
123
123
|
assets: MappedEntityAssets<EntityAssets>;
|
|
124
|
-
ConstructorArgsType: Entity2dConstructorParams<State, ParamsShape extends Shape
|
|
124
|
+
ConstructorArgsType: Entity2dConstructorParams<State, ParamsShape extends Shape ? ParamsShape['runtimeType'] : undefined>;
|
|
125
125
|
};
|
|
126
126
|
/**
|
|
127
127
|
* ========================
|
|
@@ -143,13 +143,13 @@ export type DefinedViewEntity2dInstance<State extends AnyObject, ParamsShape ext
|
|
|
143
143
|
*
|
|
144
144
|
* @category Internal
|
|
145
145
|
*/
|
|
146
|
-
export type DefinedViewEntity2dConstructor<State extends AnyObject, ParamsShape extends Shape
|
|
146
|
+
export type DefinedViewEntity2dConstructor<State extends AnyObject, ParamsShape extends Shape | undefined, EntityAssets extends BaseEntityAssetDefinitions | undefined> = Constructor<DefinedViewEntity2dInstance<State, ParamsShape, EntityAssets>, ConstructorParameters<typeof ViewEntity2d<State, ParamsShape extends Shape ? ParamsShape['runtimeType'] : undefined>>> & StaticEntity2dParts<State, ParamsShape>;
|
|
147
147
|
/**
|
|
148
148
|
* Type for {@link EntitySuite2d.defineEntity}.
|
|
149
149
|
*
|
|
150
150
|
* @category Internal
|
|
151
151
|
*/
|
|
152
|
-
export type DefineViewEntity2d<State extends AnyObject> = <const ParamsShape extends Shape
|
|
152
|
+
export type DefineViewEntity2d<State extends AnyObject> = <const ParamsShape extends Shape | undefined, const EntityAssets extends BaseEntityAssetDefinitions | undefined>(params: DefineEntity2dArgs<ParamsShape, EntityAssets>) => DefinedViewEntity2dConstructor<State, NoInfer<ParamsShape>, NoInfer<EntityAssets>> & StaticEntity2dParts<NoInfer<State>, NoInfer<ParamsShape>>;
|
|
153
153
|
/**
|
|
154
154
|
* ========================
|
|
155
155
|
*
|
|
@@ -165,19 +165,19 @@ export type DefineViewEntity2d<State extends AnyObject> = <const ParamsShape ext
|
|
|
165
165
|
*
|
|
166
166
|
* @category Internal
|
|
167
167
|
*/
|
|
168
|
-
export type DefinedLogicEntity2dInstance<State extends AnyObject, ParamsShape extends Shape
|
|
168
|
+
export type DefinedLogicEntity2dInstance<State extends AnyObject, ParamsShape extends Shape | undefined> = BaseEntity2d<State, ParamsShape extends Shape ? ParamsShape['runtimeType'] : undefined>;
|
|
169
169
|
/**
|
|
170
170
|
* Output of {@link DefineLogicEntity2d}.
|
|
171
171
|
*
|
|
172
172
|
* @category Internal
|
|
173
173
|
*/
|
|
174
|
-
export type DefinedLogicEntity2dConstructor<State extends AnyObject, ParamsShape extends Shape
|
|
174
|
+
export type DefinedLogicEntity2dConstructor<State extends AnyObject, ParamsShape extends Shape | undefined> = Constructor<DefinedLogicEntity2dInstance<State, ParamsShape>, ConstructorParameters<typeof BaseEntity2d<State, ParamsShape extends Shape ? ParamsShape['runtimeType'] : undefined>>> & StaticEntity2dParts<State, ParamsShape>;
|
|
175
175
|
/**
|
|
176
176
|
* Type for `EntitySuite.defineEntity`.
|
|
177
177
|
*
|
|
178
178
|
* @category Internal
|
|
179
179
|
*/
|
|
180
|
-
export type DefineLogicEntity2d<State extends AnyObject> = <const ParamsShape extends Shape
|
|
180
|
+
export type DefineLogicEntity2d<State extends AnyObject> = <const ParamsShape extends Shape | undefined, const EntityAssets extends BaseEntityAssetDefinitions | undefined>(params: DefineEntity2dArgs<ParamsShape, EntityAssets>) => DefinedLogicEntity2dConstructor<NoInfer<State>, NoInfer<ParamsShape>>;
|
|
181
181
|
/**
|
|
182
182
|
* ========================
|
|
183
183
|
*
|
package/dist/entity.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Asset, type AssetLoader, type AssetValue } from '@antha/asset';
|
|
2
|
+
import { type ModExecuteParams } from '@antha/engine';
|
|
2
3
|
import { type PixiApplication } from '@antha/graphics-2d';
|
|
3
4
|
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
5
|
import { System as HitboxSystem, type Response as Collision, type Body as Hitbox } from 'detect-collisions';
|
|
@@ -141,7 +142,7 @@ export declare class EntityStore2d<State extends AnyObject = any> {
|
|
|
141
142
|
*
|
|
142
143
|
* @returns All detected hitbox collisions (if any).
|
|
143
144
|
*/
|
|
144
|
-
updateAllEntities(updateParams: Readonly<
|
|
145
|
+
updateAllEntities(updateParams: Readonly<ModExecuteParams<NoInfer<State>>>): Promise<void>;
|
|
145
146
|
/** Get all current instances of the given entity class constructor. */
|
|
146
147
|
getEntities<T>(entityClassConstructor: AbstractConstructor<T> | Constructor<T>): Set<T>;
|
|
147
148
|
/** Remove an entity from the store. */
|
|
@@ -298,14 +299,6 @@ export declare const position2dParamsMap: {
|
|
|
298
299
|
* @category Internal
|
|
299
300
|
*/
|
|
300
301
|
export type ReverseParamsMap = Record<string, Partial<Record<'hitbox' | 'view', string[]>>>;
|
|
301
|
-
/**
|
|
302
|
-
* The parameters given to entity update methods.
|
|
303
|
-
*
|
|
304
|
-
* @category Internal
|
|
305
|
-
*/
|
|
306
|
-
export type EntityUpdateParams = {
|
|
307
|
-
msSinceLastUpdate: number;
|
|
308
|
-
};
|
|
309
302
|
/**
|
|
310
303
|
* Base entity class, types, and functionality.
|
|
311
304
|
*
|
|
@@ -322,7 +315,7 @@ export declare abstract class BaseEntity2d<State extends AnyObject = any, Params
|
|
|
322
315
|
/** Cached entity classes this entity observes collisions with. */
|
|
323
316
|
static readonly collidesWithSet: ReadonlySet<Entity2dConstructor>;
|
|
324
317
|
/** Shape definition of this entity's parameters. */
|
|
325
|
-
static readonly paramsShape: Shape
|
|
318
|
+
static readonly paramsShape: Shape | undefined;
|
|
326
319
|
static readonly assets: MappedEntityAssets<BaseEntityAssetDefinitions | undefined> | undefined;
|
|
327
320
|
/**
|
|
328
321
|
* Defines which properties from {@link BaseEntity2d.params} will be mapped to hitbox and/or view
|
|
@@ -363,7 +356,7 @@ export declare abstract class BaseEntity2d<State extends AnyObject = any, Params
|
|
|
363
356
|
* Called every game tick. Run all entity updates in here. This should be overridden in all
|
|
364
357
|
* entity definition classes.
|
|
365
358
|
*/
|
|
366
|
-
abstract update(updateParams: Readonly<
|
|
359
|
+
abstract update(updateParams: Readonly<ModExecuteParams<NoInfer<State>>>): MaybePromise<void>;
|
|
367
360
|
/** Called after construction to perform async initialization (e.g. creating views). */
|
|
368
361
|
initInstance(): MaybePromise<void>;
|
|
369
362
|
/** The game's current state. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antha/entity-2d",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "An Antha mod for handling 2D entities.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vir",
|
|
@@ -35,13 +35,13 @@
|
|
|
35
35
|
"test:docs": "virmator docs check"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@augment-vir/assert": "^32.2.
|
|
39
|
-
"@augment-vir/common": "^32.2.
|
|
38
|
+
"@augment-vir/assert": "^32.2.4",
|
|
39
|
+
"@augment-vir/common": "^32.2.4"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@antha/engine": "^0.
|
|
43
|
-
"@antha/web-test-runner-plugin-pixi": "^0.
|
|
44
|
-
"@augment-vir/test": "^32.2.
|
|
42
|
+
"@antha/engine": "^0.14.0",
|
|
43
|
+
"@antha/web-test-runner-plugin-pixi": "^0.14.0",
|
|
44
|
+
"@augment-vir/test": "^32.2.4",
|
|
45
45
|
"@web/dev-server-esbuild": "^2.0.0",
|
|
46
46
|
"@web/test-runner": "^1.0.0",
|
|
47
47
|
"@web/test-runner-playwright": "^1.0.0",
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"typed-event-target": "^4.3.3"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@antha/asset": "^0.
|
|
56
|
-
"@antha/audio": "^0.
|
|
57
|
-
"@antha/engine": "^0.
|
|
58
|
-
"@antha/graphics-2d": "^0.
|
|
55
|
+
"@antha/asset": "^0.14.0",
|
|
56
|
+
"@antha/audio": "^0.14.0",
|
|
57
|
+
"@antha/engine": "^0.14.0",
|
|
58
|
+
"@antha/graphics-2d": "^0.14.0",
|
|
59
59
|
"detect-collisions": ">=10",
|
|
60
60
|
"element-vir": ">=26",
|
|
61
61
|
"object-shape-tester": ">=6",
|