@antha/entity-2d 0.0.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/LICENSE-CC0 +121 -0
- package/LICENSE-MIT +21 -0
- package/README.md +11 -0
- package/dist/antha-entity.mod.d.ts +33 -0
- package/dist/antha-entity.mod.js +60 -0
- package/dist/entity-suite.d.ts +223 -0
- package/dist/entity-suite.js +77 -0
- package/dist/entity.d.ts +436 -0
- package/dist/entity.js +464 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/package.json +71 -0
package/dist/entity.js
ADDED
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
import { assert, check } from '@augment-vir/assert';
|
|
2
|
+
import { ConstructorInstanceMap, getObjectTypedEntries, makeWritable, mapObjectValues, } from '@augment-vir/common';
|
|
3
|
+
import { System as HitboxSystem, } from 'detect-collisions';
|
|
4
|
+
import { assertValidShape, defineShape } from 'object-shape-tester';
|
|
5
|
+
import { ParticleContainer } from 'pixi.js';
|
|
6
|
+
import { defineTypedCustomEvent, GenericListenTarget } from 'typed-event-target';
|
|
7
|
+
export { System as HitboxSystem } from 'detect-collisions';
|
|
8
|
+
/**
|
|
9
|
+
* The top level storage class of all entities. Add entities with {@link EntityStore2d.addEntity}.
|
|
10
|
+
*
|
|
11
|
+
* @category Internal
|
|
12
|
+
*/
|
|
13
|
+
export class EntityStore2d {
|
|
14
|
+
/**
|
|
15
|
+
* All current child entities.
|
|
16
|
+
*
|
|
17
|
+
* Instead of modifying this set, use {@link EntityStore2d.addEntity} or
|
|
18
|
+
* {@link EntityStore2d.removeEntity}. If you must manually modify this set directly, you'll also
|
|
19
|
+
* need to modify {@link EntityStore2d.entityInstanceMap}.
|
|
20
|
+
*/
|
|
21
|
+
currentEntityInstances = new Set();
|
|
22
|
+
/** If true, this entity store should no longer be used or operated upon. */
|
|
23
|
+
isDestroyed = false;
|
|
24
|
+
/** An internal mapping of all entity constructors to their current instances. */
|
|
25
|
+
entityInstanceMap = new ConstructorInstanceMap();
|
|
26
|
+
/** Original pixi app. */
|
|
27
|
+
pixi;
|
|
28
|
+
/** Collision detection system. */
|
|
29
|
+
hitboxSystem;
|
|
30
|
+
/** A map of all entity keys to their registered Entity constructors. */
|
|
31
|
+
entityKeyConstructorMap = {};
|
|
32
|
+
/** Listen target for events emitted from any child entities. */
|
|
33
|
+
listenTarget = new GenericListenTarget();
|
|
34
|
+
state;
|
|
35
|
+
assetLoader;
|
|
36
|
+
constructor(args) {
|
|
37
|
+
this.pixi = args.pixi;
|
|
38
|
+
this.assetLoader = args.assetLoader;
|
|
39
|
+
this.hitboxSystem = args.customHitboxSystem || new HitboxSystem();
|
|
40
|
+
this.state = args.state;
|
|
41
|
+
if (args.preregisteredEntities) {
|
|
42
|
+
this.registerEntities({
|
|
43
|
+
entities: args.preregisteredEntities,
|
|
44
|
+
clearPreviousRegistrations: true,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Load all the assets for all the given entities. Without this, assets will be loaded on demand
|
|
50
|
+
* only.
|
|
51
|
+
*/
|
|
52
|
+
async loadEntityAssets({ entities, otherAssets, }, options) {
|
|
53
|
+
const assets = [
|
|
54
|
+
...(otherAssets || []),
|
|
55
|
+
...entities.flatMap((entity) => {
|
|
56
|
+
return Object.values(entity.assets).map((asset) => {
|
|
57
|
+
return asset;
|
|
58
|
+
});
|
|
59
|
+
}),
|
|
60
|
+
];
|
|
61
|
+
return await this.assetLoader.bulkLoadAssets(assets, options);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Register a set of entities so that they can be deserialized (for example, when transferring
|
|
65
|
+
* game state in across the network for multilayer).
|
|
66
|
+
*/
|
|
67
|
+
registerEntities({ clearPreviousRegistrations, entities, }) {
|
|
68
|
+
if (clearPreviousRegistrations) {
|
|
69
|
+
this.entityKeyConstructorMap = {};
|
|
70
|
+
}
|
|
71
|
+
entities.forEach((entity) => {
|
|
72
|
+
this.entityKeyConstructorMap[entity.entityKey] = entity;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Runs `.update()` on all current entities and runs collision detection for all hitboxes. If
|
|
77
|
+
* any entities get marked as destroyed during their update, then they will be removed from the
|
|
78
|
+
* set of entities.
|
|
79
|
+
*
|
|
80
|
+
* @returns All detected hitbox collisions (if any).
|
|
81
|
+
*/
|
|
82
|
+
async updateAllEntities(updateParams) {
|
|
83
|
+
if (this.isDestroyed) {
|
|
84
|
+
throw new Error('Cannot operate on a destroyed entity store.');
|
|
85
|
+
}
|
|
86
|
+
for (const entity of this.currentEntityInstances) {
|
|
87
|
+
/** Check if the entity was destroyed outside of an update cycle. */
|
|
88
|
+
if (entity.isDestroyed) {
|
|
89
|
+
entity.immediatelyDestroy();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
await entity.update(updateParams);
|
|
93
|
+
/** Check if the entity was destroyed while updating. */
|
|
94
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
95
|
+
if (entity.isDestroyed) {
|
|
96
|
+
entity.immediatelyDestroy();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
this.hitboxSystem.update();
|
|
100
|
+
const collisionPromises = [];
|
|
101
|
+
/**
|
|
102
|
+
* This `checkAll` method is synchronous, so even though its using a callback it'll still
|
|
103
|
+
* finish before this `updateAllEntities` method exits.
|
|
104
|
+
*/
|
|
105
|
+
this.hitboxSystem.checkAll((response) => {
|
|
106
|
+
const primaryEntity = response.a.userData instanceof BaseEntity2d ? response.a.userData : undefined;
|
|
107
|
+
const secondaryEntity = response.b.userData instanceof BaseEntity2d ? response.b.userData : undefined;
|
|
108
|
+
if (!primaryEntity ||
|
|
109
|
+
!secondaryEntity ||
|
|
110
|
+
primaryEntity.isDestroyed ||
|
|
111
|
+
secondaryEntity.isDestroyed) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const result = primaryEntity.collide(secondaryEntity, response);
|
|
115
|
+
if (result instanceof Promise) {
|
|
116
|
+
collisionPromises.push(result);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
await Promise.all(collisionPromises);
|
|
120
|
+
}
|
|
121
|
+
/** Get all current instances of the given entity class constructor. */
|
|
122
|
+
getEntities(entityClassConstructor) {
|
|
123
|
+
return this.entityInstanceMap.getInstances(entityClassConstructor);
|
|
124
|
+
}
|
|
125
|
+
/** Remove an entity from the store. */
|
|
126
|
+
removeEntity(entity) {
|
|
127
|
+
if (this.isDestroyed) {
|
|
128
|
+
throw new Error('Cannot operate on a destroyed entity store.');
|
|
129
|
+
}
|
|
130
|
+
this.currentEntityInstances.delete(entity);
|
|
131
|
+
this.entityInstanceMap.remove(entity);
|
|
132
|
+
if (entity instanceof ViewEntity2d && !entity.isDestroyed) {
|
|
133
|
+
// eslint-disable-next-line unicorn/prefer-dom-node-remove
|
|
134
|
+
this.pixi.stage.removeChild(entity.view);
|
|
135
|
+
if (entity.hitbox) {
|
|
136
|
+
this.hitboxSystem.remove(entity.hitbox);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Create an entity instance by finding the registered constructor with the given `entityKey`
|
|
142
|
+
* and then deserializing and passing the given `serializedParams` to that constructor.
|
|
143
|
+
*/
|
|
144
|
+
async deserializeEntity(entityKey, serializedParams) {
|
|
145
|
+
if (this.isDestroyed) {
|
|
146
|
+
throw new Error('Cannot operate on a destroyed entity store.');
|
|
147
|
+
}
|
|
148
|
+
const entityConstructor = this.entityKeyConstructorMap[entityKey];
|
|
149
|
+
if (!entityConstructor) {
|
|
150
|
+
throw new Error(`No entity registered for key '${entityKey}'`);
|
|
151
|
+
}
|
|
152
|
+
return await this.addEntity(entityConstructor, entityConstructor.deserialize(serializedParams));
|
|
153
|
+
}
|
|
154
|
+
/** Create a new instance of the given entity class and add it to this entity store. */
|
|
155
|
+
async addEntity(entityClass, ...params) {
|
|
156
|
+
if (this.isDestroyed) {
|
|
157
|
+
throw new Error('Cannot operate on a destroyed entity store.');
|
|
158
|
+
}
|
|
159
|
+
if (!(entityClass.entityKey in this.entityKeyConstructorMap)) {
|
|
160
|
+
this.entityKeyConstructorMap[entityClass.entityKey] = entityClass;
|
|
161
|
+
}
|
|
162
|
+
const child = new entityClass({
|
|
163
|
+
entityStore: this,
|
|
164
|
+
pixi: this.pixi,
|
|
165
|
+
state: this.state,
|
|
166
|
+
params: params[0],
|
|
167
|
+
hitboxSystem: this.hitboxSystem,
|
|
168
|
+
});
|
|
169
|
+
await child.initInstance();
|
|
170
|
+
this.currentEntityInstances.add(child);
|
|
171
|
+
this.entityInstanceMap.add(child);
|
|
172
|
+
return child;
|
|
173
|
+
}
|
|
174
|
+
/** Destroys the entity store and all entities contained inside it. */
|
|
175
|
+
destroy() {
|
|
176
|
+
if (this.isDestroyed) {
|
|
177
|
+
throw new Error('Entity store is already destroyed.');
|
|
178
|
+
}
|
|
179
|
+
this.currentEntityInstances.forEach((entity) => entity.destroy());
|
|
180
|
+
makeWritable(this).isDestroyed = true;
|
|
181
|
+
this.listenTarget.destroy();
|
|
182
|
+
this.currentEntityInstances.clear();
|
|
183
|
+
this.entityInstanceMap.destroy();
|
|
184
|
+
delete this.pixi;
|
|
185
|
+
delete this.hitboxSystem;
|
|
186
|
+
delete this.listenTarget;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Shape definition for {@link EntityPositionParams}.
|
|
191
|
+
*
|
|
192
|
+
* @category Util
|
|
193
|
+
*/
|
|
194
|
+
export const entityPositionParamsShape = defineShape({
|
|
195
|
+
x: -1,
|
|
196
|
+
y: -1,
|
|
197
|
+
});
|
|
198
|
+
/**
|
|
199
|
+
* The bse of all entity-specific events.
|
|
200
|
+
*
|
|
201
|
+
* @category Internal
|
|
202
|
+
*/
|
|
203
|
+
export class EntityEvent extends defineTypedCustomEvent()('antha-entity-event') {
|
|
204
|
+
constructor(detail) {
|
|
205
|
+
super({
|
|
206
|
+
detail,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Event emitted by all entities when they are destroyed.
|
|
212
|
+
*
|
|
213
|
+
* @category Internal
|
|
214
|
+
*/
|
|
215
|
+
export class EntityDestroyEvent extends EntityEvent {
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Default params shape for x, y position coordinates.
|
|
219
|
+
*
|
|
220
|
+
* Use with {@link position2dParamsMap}, or something similar.
|
|
221
|
+
*
|
|
222
|
+
* @category Internal
|
|
223
|
+
*/
|
|
224
|
+
export const position2dParamsShape = defineShape({
|
|
225
|
+
x: -1,
|
|
226
|
+
y: -1,
|
|
227
|
+
});
|
|
228
|
+
/**
|
|
229
|
+
* Default value for the optional {@link ParamsMap}. This maps the top level params of `x` and `y` to
|
|
230
|
+
* both `x` and `y` in the hitbox and view.
|
|
231
|
+
*
|
|
232
|
+
* Use with {@link position2dParamsShape}, or something similar.
|
|
233
|
+
*
|
|
234
|
+
* @category Internal
|
|
235
|
+
*/
|
|
236
|
+
export const position2dParamsMap = {
|
|
237
|
+
hitbox: {
|
|
238
|
+
x: true,
|
|
239
|
+
y: true,
|
|
240
|
+
},
|
|
241
|
+
view: {
|
|
242
|
+
x: true,
|
|
243
|
+
y: true,
|
|
244
|
+
},
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* Base entity class, types, and functionality.
|
|
248
|
+
*
|
|
249
|
+
* @category Internal
|
|
250
|
+
*/
|
|
251
|
+
export class BaseEntity2d {
|
|
252
|
+
/**
|
|
253
|
+
* This key is used for deserialization of entities to track which class needs to be
|
|
254
|
+
* constructed. You cannot have duplicate keys loaded at the same time.
|
|
255
|
+
*/
|
|
256
|
+
static entityKey = 'BaseEntity';
|
|
257
|
+
/** Shape definition of this entity's parameters. */
|
|
258
|
+
static paramsShape;
|
|
259
|
+
static assets;
|
|
260
|
+
/**
|
|
261
|
+
* Defines which properties from {@link BaseEntity2d.params} will be mapped to hitbox and/or view
|
|
262
|
+
* properties.
|
|
263
|
+
*/
|
|
264
|
+
static paramsMap;
|
|
265
|
+
/**
|
|
266
|
+
* A mapping from params properties to hitbox or view properties, making it easy to map params
|
|
267
|
+
* values.
|
|
268
|
+
*/
|
|
269
|
+
static reverseParamsMap;
|
|
270
|
+
/** Parses the serialized params generated by {@link BaseEntity2d.serialize}. */
|
|
271
|
+
static deserialize(serialized) {
|
|
272
|
+
const deserialized = serialized ? JSON.parse(serialized) : undefined;
|
|
273
|
+
if (this.paramsShape) {
|
|
274
|
+
assertValidShape(deserialized, this.paramsShape);
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
assert.isUndefined(deserialized);
|
|
278
|
+
}
|
|
279
|
+
return deserialized;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Dispatch an event. This will be dispatched through this entity's entity store (so listen for
|
|
283
|
+
* the event on the store).
|
|
284
|
+
*/
|
|
285
|
+
dispatch(event) {
|
|
286
|
+
/** Cast to optionally undefined to account for destruction. */
|
|
287
|
+
this.entityStore?.listenTarget.dispatch(event);
|
|
288
|
+
}
|
|
289
|
+
/** If true, this entity should no longer be used or operated upon. */
|
|
290
|
+
isDestroyed = false;
|
|
291
|
+
abortController = new AbortController();
|
|
292
|
+
/** An `AbortSignal` that triggers when the entity is destroyed. */
|
|
293
|
+
abortSignal = this.abortController.signal;
|
|
294
|
+
hitbox;
|
|
295
|
+
/** The entity store to add all entities to. */
|
|
296
|
+
entityStore;
|
|
297
|
+
/** Writable entity params. These should be serializable. */
|
|
298
|
+
params;
|
|
299
|
+
/** Original pixi app. */
|
|
300
|
+
pixi;
|
|
301
|
+
/** Collision detection system. */
|
|
302
|
+
hitboxSystem;
|
|
303
|
+
getAsset;
|
|
304
|
+
constructor(args) {
|
|
305
|
+
this.entityStore = args.entityStore;
|
|
306
|
+
this.params = args.params;
|
|
307
|
+
this.pixi = args.pixi;
|
|
308
|
+
this.hitboxSystem = args.hitboxSystem;
|
|
309
|
+
this.state = args.state;
|
|
310
|
+
const assets = this.constructor.assets;
|
|
311
|
+
this.getAsset = createEntityAssetAccessor({
|
|
312
|
+
assetLoader: args.entityStore.assetLoader,
|
|
313
|
+
entityAssets: assets,
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
/** Called after construction to perform async initialization (e.g. creating views). */
|
|
317
|
+
initInstance() {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
/** The game's current state. */
|
|
321
|
+
state;
|
|
322
|
+
/** Add a new entity to the entity store. */
|
|
323
|
+
async addEntity(entityClass, ...params) {
|
|
324
|
+
if (this.isDestroyed) {
|
|
325
|
+
throw new Error('Cannot add entity through destroyed entity.');
|
|
326
|
+
}
|
|
327
|
+
return await this.entityStore.addEntity(entityClass, ...params);
|
|
328
|
+
}
|
|
329
|
+
/** Marks the entity for destruction in the next entity store update. */
|
|
330
|
+
destroy() {
|
|
331
|
+
this.abortController.abort();
|
|
332
|
+
makeWritable(this).isDestroyed = true;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Immediately destroy the current entity, stop its updates.
|
|
336
|
+
*
|
|
337
|
+
* This is probably not what you want to use! See {@link BaseEntity2d.destroy} instead.
|
|
338
|
+
*/
|
|
339
|
+
immediatelyDestroy() {
|
|
340
|
+
this.abortController.abort();
|
|
341
|
+
makeWritable(this).isDestroyed = true;
|
|
342
|
+
this.entityStore?.removeEntity(this);
|
|
343
|
+
this.dispatch(new EntityDestroyEvent({
|
|
344
|
+
entityInstance: this,
|
|
345
|
+
}));
|
|
346
|
+
delete this.entityStore;
|
|
347
|
+
delete this.hitboxSystem;
|
|
348
|
+
delete this.params;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* This method is call whenever this entity's hitbox (if it has one) collides with another
|
|
352
|
+
* hitbox. It will be called for each individual collision. Override this to do something about
|
|
353
|
+
* it.
|
|
354
|
+
*/
|
|
355
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
356
|
+
collide(otherEntity, collision) { }
|
|
357
|
+
/**
|
|
358
|
+
* Serialize the entity params for sharing across the network (for multiplayer play). By default
|
|
359
|
+
* this simply calls `JSON.stringify` on `this.params`. This method must be overridden if your
|
|
360
|
+
* entity has params that are not JSON compatible.
|
|
361
|
+
*/
|
|
362
|
+
serialize() {
|
|
363
|
+
return this.params ? JSON.stringify(this.params) : undefined;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
function createEntityAssetAccessor({ assetLoader, entityAssets, }) {
|
|
367
|
+
if (!entityAssets || check.isEmpty(entityAssets)) {
|
|
368
|
+
return {};
|
|
369
|
+
}
|
|
370
|
+
return mapObjectValues(entityAssets, (key, asset) => {
|
|
371
|
+
return async () => {
|
|
372
|
+
return assetLoader.loadIndividualAsset({
|
|
373
|
+
asset,
|
|
374
|
+
});
|
|
375
|
+
};
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Base view entity class, types, and functionality.
|
|
380
|
+
*
|
|
381
|
+
* @category Internal
|
|
382
|
+
*/
|
|
383
|
+
export class ViewEntity2d extends BaseEntity2d {
|
|
384
|
+
/** The entity's PixiJS view. */
|
|
385
|
+
view;
|
|
386
|
+
/** Creates the view and hitbox, adds the view to the stage, and sets up the params proxy. */
|
|
387
|
+
async initInstance() {
|
|
388
|
+
const { view, hitbox } = await this.createView();
|
|
389
|
+
if (view) {
|
|
390
|
+
this.view = view;
|
|
391
|
+
this.pixi.stage.addChild(this.view);
|
|
392
|
+
}
|
|
393
|
+
else {
|
|
394
|
+
this.view = new ParticleContainer();
|
|
395
|
+
this.view.visible = false;
|
|
396
|
+
}
|
|
397
|
+
if (hitbox) {
|
|
398
|
+
this.hitbox = hitbox;
|
|
399
|
+
this.hitbox.userData = this;
|
|
400
|
+
this.hitboxSystem.insert(this.hitbox);
|
|
401
|
+
}
|
|
402
|
+
this.wrapParamsInProxy();
|
|
403
|
+
}
|
|
404
|
+
constructor(args) {
|
|
405
|
+
super(args);
|
|
406
|
+
}
|
|
407
|
+
wrapParamsInProxy() {
|
|
408
|
+
const paramsMap = this.constructor.paramsMap;
|
|
409
|
+
const reverseParamsMap = this.constructor.reverseParamsMap;
|
|
410
|
+
const params = this.params;
|
|
411
|
+
if (!params || !paramsMap || !reverseParamsMap) {
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
makeWritable(this).params = new Proxy(params, {
|
|
415
|
+
set: (target, propertyKey, value, receiver) => {
|
|
416
|
+
if (propertyKey in params && check.hasKey(reverseParamsMap, propertyKey)) {
|
|
417
|
+
const mappings = reverseParamsMap[propertyKey];
|
|
418
|
+
if (this.hitbox && mappings?.hitbox) {
|
|
419
|
+
mappings.hitbox.forEach((mapToKey) => {
|
|
420
|
+
this.hitbox[mapToKey] = value;
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
if (mappings?.view) {
|
|
424
|
+
mappings.view.forEach((mapToKey) => {
|
|
425
|
+
this.view[mapToKey] = value;
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
return Reflect.set(target, propertyKey, value, receiver);
|
|
430
|
+
},
|
|
431
|
+
});
|
|
432
|
+
/** Propagate initial params. */
|
|
433
|
+
getObjectTypedEntries(this.params).forEach(([key, value,]) => {
|
|
434
|
+
this.params[key] = value;
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
/** Detects if the current entity is still within the bounds of the render canvas. */
|
|
438
|
+
isInBounds(options = {}) {
|
|
439
|
+
if (this.isDestroyed) {
|
|
440
|
+
throw new Error('Cannot check bounds on destroyed entity.');
|
|
441
|
+
}
|
|
442
|
+
else if (options.entirely) {
|
|
443
|
+
return this.pixi.screen.containsRect(this.view.getBounds().rectangle);
|
|
444
|
+
}
|
|
445
|
+
else {
|
|
446
|
+
return this.pixi.screen.intersects(this.view.getBounds().rectangle);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Immediately destroy the current entity, stop its updates, and remove it from the view.
|
|
451
|
+
*
|
|
452
|
+
* This is probably not what you want to use! See {@link BaseEntity2d.destroy} instead.
|
|
453
|
+
*/
|
|
454
|
+
immediatelyDestroy() {
|
|
455
|
+
this.view?.destroy({
|
|
456
|
+
children: true,
|
|
457
|
+
});
|
|
458
|
+
if (this.hitbox) {
|
|
459
|
+
this.hitboxSystem.remove(this.hitbox);
|
|
460
|
+
}
|
|
461
|
+
super.immediatelyDestroy();
|
|
462
|
+
delete this.view;
|
|
463
|
+
}
|
|
464
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@antha/entity-2d",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "An Antha mod for handling 2D entities.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"vir",
|
|
7
|
+
"antha",
|
|
8
|
+
"render",
|
|
9
|
+
"entity",
|
|
10
|
+
"2d"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/electrovir/antha",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/electrovir/antha/issues"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/electrovir/antha.git"
|
|
19
|
+
},
|
|
20
|
+
"license": "(MIT OR CC0-1.0)",
|
|
21
|
+
"author": {
|
|
22
|
+
"name": "electrovir",
|
|
23
|
+
"url": "https://github.com/electrovir"
|
|
24
|
+
},
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"type": "module",
|
|
27
|
+
"main": "dist/index.js",
|
|
28
|
+
"module": "dist/index.js",
|
|
29
|
+
"types": "dist/index.d.ts",
|
|
30
|
+
"scripts": {
|
|
31
|
+
"compile": "virmator compile",
|
|
32
|
+
"docs": "virmator docs",
|
|
33
|
+
"test": "virmator test web",
|
|
34
|
+
"test:coverage": "npm test coverage",
|
|
35
|
+
"test:docs": "virmator docs check"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@augment-vir/assert": "^31.73.1",
|
|
39
|
+
"@augment-vir/common": "^31.73.1",
|
|
40
|
+
"type-fest": "^5.7.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@antha/engine": "*",
|
|
44
|
+
"@augment-vir/test": "^31.73.1",
|
|
45
|
+
"@web/dev-server-esbuild": "^1.0.5",
|
|
46
|
+
"@web/test-runner": "^0.20.2",
|
|
47
|
+
"@web/test-runner-playwright": "^0.11.1",
|
|
48
|
+
"detect-collisions": "^10.10.2025",
|
|
49
|
+
"istanbul-smart-text-reporter": "^1.1.5",
|
|
50
|
+
"object-shape-tester": "^6.14.0",
|
|
51
|
+
"pixi.js": "^8.19.0",
|
|
52
|
+
"typed-event-target": "^4.3.1",
|
|
53
|
+
"web-test-runner-plugin-pixi": "^0.0.2"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"@antha/asset": "*",
|
|
57
|
+
"@antha/engine": "*",
|
|
58
|
+
"@antha/graphics-2d": "*",
|
|
59
|
+
"detect-collisions": ">=10",
|
|
60
|
+
"element-vir": ">=26",
|
|
61
|
+
"object-shape-tester": ">=6",
|
|
62
|
+
"pixi.js": ">=8",
|
|
63
|
+
"typed-event-target": ">=4.3"
|
|
64
|
+
},
|
|
65
|
+
"engines": {
|
|
66
|
+
"node": ">=22"
|
|
67
|
+
},
|
|
68
|
+
"publishConfig": {
|
|
69
|
+
"access": "public"
|
|
70
|
+
}
|
|
71
|
+
}
|