@antha/entity-2d 0.0.8 → 0.1.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/README.md +47 -3
- package/dist/entity-suite.d.ts +1 -2
- package/dist/entity-suite.js +1 -1
- package/dist/entity.d.ts +4 -4
- package/dist/entity.js +1 -0
- package/package.json +13 -14
package/README.md
CHANGED
|
@@ -1,11 +1,55 @@
|
|
|
1
1
|
# @antha/entity-2d
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Demo: https://electrovir.github.io/antha/demo/basic-entities
|
|
3
|
+
This package provides a pre-built [Antha game engine](https://www.npmjs.com/package/@antha/engine) mod for creating, updating, rendering, and collision-checking 2D entities. It uses the PixiJS application supplied by [`@antha/graphics-2d`](https://npmjs.com/package/@antha/graphics-2d) to display entity views.
|
|
6
4
|
|
|
7
5
|
## Install
|
|
8
6
|
|
|
9
7
|
```sh
|
|
10
8
|
npm i @antha/entity-2d
|
|
11
9
|
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
<!-- example-link: src/readme-examples/creating-logic-entity.example.ts -->
|
|
14
|
+
|
|
15
|
+
```TypeScript
|
|
16
|
+
import {AnthaEngine, defineAnthaMod} from '@antha/engine';
|
|
17
|
+
import {createAnthaGraphics2dMod} from '@antha/graphics-2d';
|
|
18
|
+
import {type AnthaEntity2dModState, createAnthaEntityMod2d} from '@antha/entity-2d';
|
|
19
|
+
|
|
20
|
+
type GameState = AnthaEntity2dModState<{
|
|
21
|
+
hasCreatedScoreEntity: boolean;
|
|
22
|
+
}>;
|
|
23
|
+
|
|
24
|
+
const {defineLogicEntity, mod: entityMod} = createAnthaEntityMod2d<{
|
|
25
|
+
hasCreatedScoreEntity: boolean;
|
|
26
|
+
}>();
|
|
27
|
+
|
|
28
|
+
class ScoreEntity extends defineLogicEntity({
|
|
29
|
+
key: 'score',
|
|
30
|
+
paramsShape: undefined,
|
|
31
|
+
}) {
|
|
32
|
+
public override update() {}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const engine = new AnthaEngine<GameState>({
|
|
36
|
+
initState: {
|
|
37
|
+
hasCreatedScoreEntity: false,
|
|
38
|
+
},
|
|
39
|
+
mods: [
|
|
40
|
+
createAnthaGraphics2dMod(),
|
|
41
|
+
entityMod,
|
|
42
|
+
defineAnthaMod<GameState>({
|
|
43
|
+
modName: 'game-logic',
|
|
44
|
+
async execute({state}) {
|
|
45
|
+
if (state.entityStore && !state.hasCreatedScoreEntity) {
|
|
46
|
+
state.hasCreatedScoreEntity = true;
|
|
47
|
+
await state.entityStore.addEntity(ScoreEntity);
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
}),
|
|
51
|
+
],
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
engine.startLoop();
|
|
55
|
+
```
|
package/dist/entity-suite.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { type AnyObject } from '@augment-vir/common';
|
|
1
|
+
import { type AnyObject, type Constructor, type IsAny } from '@augment-vir/common';
|
|
2
2
|
import { type Shape } from 'object-shape-tester';
|
|
3
|
-
import { type Constructor, type IsAny } from 'type-fest';
|
|
4
3
|
import { BaseEntity2d, type BaseEntityAssetDefinitions, type Entity2dConstructorParams, EntityStore2d, type EntityStore2dConstructorParams, type MappedEntityAssets, type ParamsMap, type ReverseParamsMap, ViewEntity2d } from './entity.js';
|
|
5
4
|
/**
|
|
6
5
|
* Params for both {@link EntitySuite2d.defineEntity} and {@link EntitySuite2d.defineLogicEntity}.
|
package/dist/entity-suite.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { check } from '@augment-vir/assert';
|
|
2
|
-
import { getObjectTypedEntries, getOrSet } from '@augment-vir/common';
|
|
2
|
+
import { getObjectTypedEntries, getOrSet, } from '@augment-vir/common';
|
|
3
3
|
import { BaseEntity2d, EntityStore2d, ViewEntity2d, } from './entity.js';
|
|
4
4
|
/**
|
|
5
5
|
* This is the starting point of the @game-vir/entity package. Call this to produce the function
|
package/dist/entity.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { type Asset, type AssetBulkLoaderLoadOptions, type AssetLoader, type AssetValue } from '@antha/asset';
|
|
2
2
|
import { type PixiApplication } from '@antha/graphics-2d';
|
|
3
|
-
import { ConstructorInstanceMap, type AnyObject, type ExtractKeysWithMatchingValues, type MaybePromise, type PartialWithUndefined } from '@augment-vir/common';
|
|
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';
|
|
5
5
|
import { type Shape } from 'object-shape-tester';
|
|
6
6
|
import { type Container, type ViewContainer } from 'pixi.js';
|
|
7
|
-
import { type AbstractConstructor, type Constructor, type EmptyObject, type IsEqual, type IsNever, type WritableKeysOf } from 'type-fest';
|
|
8
7
|
import { GenericListenTarget } from 'typed-event-target';
|
|
9
8
|
import { type StaticEntity2dParts } from './entity-suite.js';
|
|
10
9
|
export { System as HitboxSystem, type Response as Collision } from 'detect-collisions';
|
|
@@ -322,7 +321,7 @@ export declare abstract class BaseEntity2d<State extends AnyObject = any, Params
|
|
|
322
321
|
dispatch(event: EntityEvent | EntityDestroyEvent): void;
|
|
323
322
|
/** If true, this entity should no longer be used or operated upon. */
|
|
324
323
|
readonly isDestroyed: boolean;
|
|
325
|
-
|
|
324
|
+
protected readonly abortController: AbortController;
|
|
326
325
|
/** An `AbortSignal` that triggers when the entity is destroyed. */
|
|
327
326
|
readonly abortSignal: AbortSignal;
|
|
328
327
|
hitbox: Hitbox<this> | undefined;
|
|
@@ -411,7 +410,8 @@ export declare abstract class ViewEntity2d<State extends AnyObject = any, Params
|
|
|
411
410
|
/** Creates the view and hitbox, adds the view to the stage, and sets up the params proxy. */
|
|
412
411
|
initInstance(): Promise<void>;
|
|
413
412
|
constructor(args: Readonly<Entity2dConstructorParams<NoInfer<State>, NoInfer<Params>>>);
|
|
414
|
-
|
|
413
|
+
/** Wrap entity params in a proxy that maps changes to the view and hitbox properties. */
|
|
414
|
+
protected wrapParamsInProxy(): void;
|
|
415
415
|
/**
|
|
416
416
|
* Creates the entity's PixiJS view. This will be called on entity construction and added to the
|
|
417
417
|
* PixiJS application stage.
|
package/dist/entity.js
CHANGED
|
@@ -404,6 +404,7 @@ export class ViewEntity2d extends BaseEntity2d {
|
|
|
404
404
|
constructor(args) {
|
|
405
405
|
super(args);
|
|
406
406
|
}
|
|
407
|
+
/** Wrap entity params in a proxy that maps changes to the view and hitbox properties. */
|
|
407
408
|
wrapParamsInProxy() {
|
|
408
409
|
const paramsMap = this.constructor.paramsMap;
|
|
409
410
|
const reverseParamsMap = this.constructor.reverseParamsMap;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antha/entity-2d",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "An Antha mod for handling 2D entities.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vir",
|
|
@@ -35,27 +35,26 @@
|
|
|
35
35
|
"test:docs": "virmator docs check"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@augment-vir/assert": "^
|
|
39
|
-
"@augment-vir/common": "^
|
|
40
|
-
"type-fest": "^5.7.0"
|
|
38
|
+
"@augment-vir/assert": "^32.2.2",
|
|
39
|
+
"@augment-vir/common": "^32.2.2"
|
|
41
40
|
},
|
|
42
41
|
"devDependencies": {
|
|
43
|
-
"@antha/engine": "^0.
|
|
44
|
-
"@
|
|
45
|
-
"@
|
|
46
|
-
"@web/
|
|
47
|
-
"@web/test-runner
|
|
42
|
+
"@antha/engine": "^0.1.1",
|
|
43
|
+
"@antha/web-test-runner-plugin-pixi": "^0.1.1",
|
|
44
|
+
"@augment-vir/test": "^32.2.2",
|
|
45
|
+
"@web/dev-server-esbuild": "^2.0.0",
|
|
46
|
+
"@web/test-runner": "^1.0.0",
|
|
47
|
+
"@web/test-runner-playwright": "^1.0.0",
|
|
48
48
|
"detect-collisions": "^10.10.2025",
|
|
49
49
|
"istanbul-smart-text-reporter": "^1.1.5",
|
|
50
|
-
"object-shape-tester": "^6.14.
|
|
50
|
+
"object-shape-tester": "^6.14.1",
|
|
51
51
|
"pixi.js": "^8.19.0",
|
|
52
|
-
"typed-event-target": "^4.3.
|
|
53
|
-
"web-test-runner-plugin-pixi": "^0.0.2"
|
|
52
|
+
"typed-event-target": "^4.3.3"
|
|
54
53
|
},
|
|
55
54
|
"peerDependencies": {
|
|
56
|
-
"@antha/asset": "^0.
|
|
55
|
+
"@antha/asset": "^0.1.1",
|
|
57
56
|
"@antha/engine": "*",
|
|
58
|
-
"@antha/graphics-2d": "^0.
|
|
57
|
+
"@antha/graphics-2d": "^0.1.1",
|
|
59
58
|
"detect-collisions": ">=10",
|
|
60
59
|
"element-vir": ">=26",
|
|
61
60
|
"object-shape-tester": ">=6",
|