@caperjs/plugin-crunch 0.1.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/lib/types.d.ts ADDED
@@ -0,0 +1,246 @@
1
+ import { PointLike, SizeLike } from '@caperjs/core';
2
+ import { Container } from 'pixi.js';
3
+ import { Actor } from './Actor';
4
+ import { Entity } from './Entity';
5
+ import { Group } from './Group';
6
+ import { Sensor } from './Sensor';
7
+ import { Solid } from './Solid';
8
+ export interface Vector2 {
9
+ x: number;
10
+ y: number;
11
+ }
12
+ export interface Rectangle {
13
+ x: number;
14
+ y: number;
15
+ width: number;
16
+ height: number;
17
+ }
18
+ export type CollisionShape = 'rectangle';
19
+ export type EntityData = {
20
+ [key: string]: any;
21
+ };
22
+ export type PhysicsEntityClass = new (config?: PhysicsEntityConfig) => Actor | Solid | Sensor;
23
+ /**
24
+ * Collision layers using bitwise flags
25
+ * Each entity can belong to multiple layers (using bitwise OR)
26
+ * and can collide with multiple layers (using bitwise AND)
27
+ */
28
+ export declare enum CollisionLayer {
29
+ NONE = 0,
30
+ DEFAULT = 1,
31
+ PLAYER = 2,
32
+ ENEMY = 4,
33
+ PROJECTILE = 8,
34
+ PLATFORM = 16,
35
+ TRIGGER = 32,
36
+ ITEM = 64,
37
+ WALL = 128,
38
+ FX = 256,
39
+ ALL = 4294967295
40
+ }
41
+ /**
42
+ * Interface for a registered collision layer
43
+ */
44
+ export interface RegisteredCollisionLayer {
45
+ /** Name of the collision layer */
46
+ name: string;
47
+ /** Numeric value of the collision layer (bitwise) */
48
+ value: number;
49
+ /** Description of the collision layer (optional) */
50
+ description?: string;
51
+ }
52
+ /**
53
+ * Registry for tracking custom collision layers
54
+ */
55
+ export declare class CollisionLayerRegistry {
56
+ private static _instance;
57
+ private _layers;
58
+ private _usedIndices;
59
+ /**
60
+ * Get the singleton instance of the registry
61
+ */
62
+ static get instance(): CollisionLayerRegistry;
63
+ /**
64
+ * Register a new collision layer
65
+ *
66
+ * @param name Name of the collision layer
67
+ * @param index Index from 0-15 representing which user bit to use (gets shifted to bits 16-31)
68
+ * @param description Optional description of the layer
69
+ * @returns The registered collision layer
70
+ */
71
+ register(name: string, index: number, description?: string): RegisteredCollisionLayer;
72
+ /**
73
+ * Get a registered collision layer by name
74
+ *
75
+ * @param name Name of the collision layer
76
+ * @returns The registered collision layer or undefined if not found
77
+ */
78
+ get(name: string): RegisteredCollisionLayer | undefined;
79
+ /**
80
+ * Get all registered collision layers
81
+ *
82
+ * @returns Array of all registered collision layers
83
+ */
84
+ getAll(): RegisteredCollisionLayer[];
85
+ /**
86
+ * Check if a collision layer with the given name exists
87
+ *
88
+ * @param name Name of the collision layer
89
+ * @returns True if the layer exists
90
+ */
91
+ has(name: string): boolean;
92
+ /**
93
+ * Remove a registered collision layer
94
+ *
95
+ * @param name Name of the collision layer to remove
96
+ * @returns True if the layer was removed, false if it didn't exist
97
+ */
98
+ remove(name: string): boolean;
99
+ /**
100
+ * Clear all registered collision layers
101
+ */
102
+ clear(): void;
103
+ /**
104
+ * Get the next available index for a custom collision layer
105
+ *
106
+ * @returns The next available index or -1 if all indices are used
107
+ */
108
+ getNextAvailableIndex(): number;
109
+ }
110
+ /**
111
+ * Utility functions for working with collision layers
112
+ */
113
+ export declare const CollisionLayers: {
114
+ /**
115
+ * Creates a custom collision layer using bits 16-31 (user space)
116
+ *
117
+ * @param index Index from 0-15 representing which user bit to use (gets shifted to bits 16-31)
118
+ * @returns A unique collision layer value
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * // Create custom collision layers
123
+ * const WATER_LAYER = CollisionLayers.createLayer(0); // 1 << 16
124
+ * const LAVA_LAYER = CollisionLayers.createLayer(1); // 1 << 17
125
+ * const CLOUD_LAYER = CollisionLayers.createLayer(2); // 1 << 18
126
+ *
127
+ * // Use in entity creation
128
+ * const waterEntity = physics.createActor({
129
+ * type: 'Water',
130
+ * position: [100, 400],
131
+ * size: [800, 100],
132
+ * collisionLayer: WATER_LAYER,
133
+ * collisionMask: CollisionLayer.PLAYER | CollisionLayer.ENEMY
134
+ * });
135
+ * ```
136
+ */
137
+ createLayer(index: number): number;
138
+ /**
139
+ * Creates a collision mask from multiple layers
140
+ *
141
+ * @param layers Array of collision layers to combine
142
+ * @returns A combined collision mask
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * // Create a mask that collides with players, enemies and projectiles
147
+ * const mask = CollisionLayers.createMask([
148
+ * CollisionLayer.PLAYER,
149
+ * CollisionLayer.ENEMY,
150
+ * CollisionLayer.PROJECTILE
151
+ * ]);
152
+ * ```
153
+ */
154
+ createMask(layers: number[]): number;
155
+ /**
156
+ * Checks if a layer is included in a mask
157
+ *
158
+ * @param layer The layer to check
159
+ * @param mask The mask to check against
160
+ * @returns True if the layer is included in the mask
161
+ *
162
+ * @example
163
+ * ```typescript
164
+ * // Check if player layer is in the mask
165
+ * if (CollisionLayers.isLayerInMask(CollisionLayer.PLAYER, entity.collisionMask)) {
166
+ * console.log('Entity can collide with players');
167
+ * }
168
+ * ```
169
+ */
170
+ isLayerInMask(layer: number, mask: number): boolean;
171
+ /**
172
+ * Get the registry for custom collision layers
173
+ *
174
+ * @returns The collision layer registry
175
+ */
176
+ getRegistry(): CollisionLayerRegistry;
177
+ };
178
+ export interface PhysicsEntityConfig<D extends EntityData = EntityData> {
179
+ id?: string;
180
+ class?: PhysicsEntityClass;
181
+ type?: PhysicsEntityType;
182
+ position?: PointLike;
183
+ size?: SizeLike;
184
+ x?: number;
185
+ y?: number;
186
+ width?: number;
187
+ height?: number;
188
+ restitution?: number;
189
+ view?: PhysicsEntityView;
190
+ data?: Partial<D>;
191
+ group?: Group;
192
+ groupOffset?: PointLike;
193
+ follows?: Entity;
194
+ followOffset?: PointLike;
195
+ /** Collision layer this entity belongs to (bitwise) */
196
+ collisionLayer?: number;
197
+ /** Collision mask defining which layers this entity collides with (bitwise) */
198
+ collisionMask?: number;
199
+ /** Whether to disable actor-to-actor collisions for this entity */
200
+ disableActorCollisions?: boolean;
201
+ }
202
+ export interface CollisionResult {
203
+ collided: boolean;
204
+ normal?: Vector2;
205
+ penetration?: number;
206
+ solid: Solid;
207
+ }
208
+ export interface SensorOverlap {
209
+ type: `${PhysicsEntityType}|${PhysicsEntityType}`;
210
+ actor: Actor;
211
+ sensor: Sensor;
212
+ }
213
+ export interface CollisionResult {
214
+ collided: boolean;
215
+ normal?: Vector2;
216
+ penetration?: number;
217
+ solid: Solid;
218
+ pushingSolid?: Solid;
219
+ }
220
+ /**
221
+ * Result of an actor-to-actor collision
222
+ */
223
+ export interface ActorCollisionResult {
224
+ collided: boolean;
225
+ normal?: Vector2;
226
+ penetration?: number;
227
+ actor: Actor;
228
+ }
229
+ export interface Collision {
230
+ type: `${PhysicsEntityType}|${PhysicsEntityType}`;
231
+ entity1: Actor | Sensor;
232
+ entity2: Actor | Solid;
233
+ result: CollisionResult;
234
+ }
235
+ /**
236
+ * Represents a collision between two actors
237
+ */
238
+ export interface ActorCollision {
239
+ type: `${PhysicsEntityType}|${PhysicsEntityType}`;
240
+ actor1: Actor;
241
+ actor2: Actor;
242
+ result: ActorCollisionResult;
243
+ }
244
+ export type PhysicsEntityView = Container;
245
+ export type PhysicsEntityType = 'Actor' | 'Solid' | 'Sensor' | 'Group' | string;
246
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,SAA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IACd,MAAM,EAAE,oBAAoB,CAAC;CAC9B;AAED,MAAM,MAAM,iBAAiB,GAAG,SAAS,CAAC;AAC1C,MAAM,MAAM,iBAAiB,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC"}
package/lib/utils.d.ts ADDED
@@ -0,0 +1,63 @@
1
+ import { PhysicsEntityConfig } from './types';
2
+ /**
3
+ * Utility functions for resolving entity positions and sizes from various input formats.
4
+ * These functions handle the conversion of different coordinate and size specifications
5
+ * into standardized formats used by the physics system.
6
+ */
7
+ /**
8
+ * Resolves an entity's position from various input formats.
9
+ * Supports direct x/y values or a position object/array.
10
+ *
11
+ * @param config - Entity configuration containing position information
12
+ * @returns Resolved {x, y} coordinates
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * // Using direct x/y values
17
+ * resolveEntityPosition({ x: 100, y: 200 })
18
+ * // → { x: 100, y: 200 }
19
+ *
20
+ * // Using position array
21
+ * resolveEntityPosition({ position: [100, 200] })
22
+ * // → { x: 100, y: 200 }
23
+ *
24
+ * // Using position object
25
+ * resolveEntityPosition({ position: { x: 100, y: 200 } })
26
+ * // → { x: 100, y: 200 }
27
+ * ```
28
+ */
29
+ export declare function resolveEntityPosition(config: PhysicsEntityConfig): {
30
+ x: number;
31
+ y: number;
32
+ };
33
+ /**
34
+ * Resolves an entity's size from various input formats.
35
+ * Supports direct width/height values or a size object/array.
36
+ *
37
+ * @param config - Entity configuration containing size information
38
+ * @returns Resolved {width, height} dimensions
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * // Using direct width/height values
43
+ * resolveEntitySize({ width: 100, height: 200 })
44
+ * // → { width: 100, height: 200 }
45
+ *
46
+ * // Using size array
47
+ * resolveEntitySize({ size: [100, 200] })
48
+ * // → { width: 100, height: 200 }
49
+ *
50
+ * // Using size object
51
+ * resolveEntitySize({ size: { width: 100, height: 200 } })
52
+ * // → { width: 100, height: 200 }
53
+ *
54
+ * // Using defaults
55
+ * resolveEntitySize({})
56
+ * // → { width: 32, height: 32 }
57
+ * ```
58
+ */
59
+ export declare function resolveEntitySize(config: PhysicsEntityConfig): {
60
+ width: number;
61
+ height: number;
62
+ };
63
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,mBAAmB,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAK3F;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,mBAAmB,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAOhG"}
@@ -0,0 +1,2 @@
1
+ export declare const version = "0.1.0";
2
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,UAAU,CAAC"}
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@caperjs/plugin-crunch",
3
+ "description": "Crunch Physics",
4
+ "keywords": [
5
+ "physics",
6
+ "crunch",
7
+ "physics-crunch",
8
+ "@caperjs/core",
9
+ "caper"
10
+ ],
11
+ "version": "0.1.0",
12
+ "files": [
13
+ "lib",
14
+ "src"
15
+ ],
16
+ "main": "lib/caper-plugin-crunch.mjs",
17
+ "types": "lib/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "default": "./lib/caper-plugin-crunch.mjs",
21
+ "types": "./lib/index.d.ts"
22
+ }
23
+ },
24
+ "sideEffects": false,
25
+ "author": "",
26
+ "license": "MIT",
27
+ "devDependencies": {
28
+ "vite": "^8.0.7",
29
+ "vite-plugin-dts": "^4.5.3",
30
+ "@caperjs/core": "0.1.0"
31
+ },
32
+ "peerDependencies": {
33
+ "gsap": "^3.15.0",
34
+ "pixi.js": "8.19.0",
35
+ "@caperjs/core": "0.1.0"
36
+ },
37
+ "scripts": {
38
+ "build": "pnpm run generate-version && vite build",
39
+ "test": "echo \"Error: no test specified\" && exit 1",
40
+ "generate-version": "node generateVersion.mjs"
41
+ }
42
+ }