nexus-2d 0.0.1 → 0.0.3
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 +2 -2
- package/dist/cjs/index.cjs +19917 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +19853 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/types/engine/Charactercontrollerv2.d.ts +112 -0
- package/dist/types/engine/audio.d.ts +183 -0
- package/dist/types/engine/cam.d.ts +94 -0
- package/dist/types/engine/camera.d.ts +142 -0
- package/dist/types/engine/charactercontroller.d.ts +235 -0
- package/dist/types/engine/controllers.d.ts +179 -0
- package/dist/types/engine/core.d.ts +17 -0
- package/dist/types/engine/lerp.d.ts +104 -0
- package/dist/types/engine/lib.d.ts +119 -0
- package/dist/types/engine/particles.d.ts +131 -0
- package/dist/types/engine/physics.d.ts +294 -0
- package/dist/types/engine/physicsv2.d.ts +154 -0
- package/dist/types/engine/sprite.d.ts +158 -0
- package/dist/types/engine/tiled.d.ts +21 -0
- package/dist/types/engine/vec2pool.d.ts +17 -0
- package/dist/types/index.d.ts +10 -0
- package/package.json +6 -3
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CharacterController2D - Kinematic character with tight controls
|
|
3
|
+
*
|
|
4
|
+
* Why kinematic not dynamic:
|
|
5
|
+
* - Physics forces feel floaty (acceleration, momentum)
|
|
6
|
+
* - We want instant response (press right → move right)
|
|
7
|
+
* - Still get collision detection from physics
|
|
8
|
+
*
|
|
9
|
+
* Game feel features:
|
|
10
|
+
* - Coyote time (jump grace period)
|
|
11
|
+
* - Jump buffering (early jump input)
|
|
12
|
+
* - Variable jump height
|
|
13
|
+
* - Acceleration curves
|
|
14
|
+
* - Air control
|
|
15
|
+
*
|
|
16
|
+
* Common use case: 2D platformer character
|
|
17
|
+
*/
|
|
18
|
+
export class CharacterController2D extends RigidBody2D {
|
|
19
|
+
constructor(name: any, options?: {});
|
|
20
|
+
activeCollisions: Set<any>;
|
|
21
|
+
collisionData: Map<any, any>;
|
|
22
|
+
onCollisionEnter: (other: any, pair: any) => void;
|
|
23
|
+
onCollisionStay: (other: any, pair: any) => void;
|
|
24
|
+
onCollisionExit: (other: any, pair: any) => void;
|
|
25
|
+
speed: any;
|
|
26
|
+
acceleration: any;
|
|
27
|
+
friction: any;
|
|
28
|
+
airAcceleration: any;
|
|
29
|
+
airFriction: any;
|
|
30
|
+
jumpForce: any;
|
|
31
|
+
gravity: any;
|
|
32
|
+
maxFallSpeed: any;
|
|
33
|
+
jumpCutMultiplier: any;
|
|
34
|
+
coyoteTime: any;
|
|
35
|
+
jumpBufferTime: any;
|
|
36
|
+
coyoteTimer: number;
|
|
37
|
+
jumpBufferTimer: number;
|
|
38
|
+
velocity: {
|
|
39
|
+
x: number;
|
|
40
|
+
y: number;
|
|
41
|
+
};
|
|
42
|
+
grounded: boolean;
|
|
43
|
+
wasGrounded: boolean;
|
|
44
|
+
jumping: boolean;
|
|
45
|
+
state: string;
|
|
46
|
+
moveInput: number;
|
|
47
|
+
jumpPressed: boolean;
|
|
48
|
+
jumpHeld: boolean;
|
|
49
|
+
jumpReleased: boolean;
|
|
50
|
+
groundCheckDistance: number;
|
|
51
|
+
wallCheckDistance: number;
|
|
52
|
+
onJump: any;
|
|
53
|
+
onLand: any;
|
|
54
|
+
onWallHit: any;
|
|
55
|
+
spriteNode: Sprite | AnimatedSprite;
|
|
56
|
+
animatedSprite: any;
|
|
57
|
+
collisionWidth: any;
|
|
58
|
+
collisionHeight: any;
|
|
59
|
+
collisionPaddingX: any;
|
|
60
|
+
collisionPaddingY: any;
|
|
61
|
+
debugDraw: any;
|
|
62
|
+
debugColor: {
|
|
63
|
+
r: number;
|
|
64
|
+
g: number;
|
|
65
|
+
b: number;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Setup sprite and auto-configure collision from sprite dimensions
|
|
69
|
+
*
|
|
70
|
+
* @param {Sprite|AnimatedSprite} sprite - Sprite to attach
|
|
71
|
+
*/
|
|
72
|
+
setupSprite(sprite: Sprite | AnimatedSprite): void;
|
|
73
|
+
/**
|
|
74
|
+
* Create collision box
|
|
75
|
+
*
|
|
76
|
+
* Uses collisionWidth/Height which are either:
|
|
77
|
+
* - Auto-calculated from sprite
|
|
78
|
+
* - Manually specified in options
|
|
79
|
+
*/
|
|
80
|
+
setupCollision(): void;
|
|
81
|
+
/**
|
|
82
|
+
* Setup animation state machine hooks
|
|
83
|
+
*
|
|
84
|
+
* Automatically plays animations based on controller state
|
|
85
|
+
*/
|
|
86
|
+
setupAnimations(animatedSprite: any): void;
|
|
87
|
+
prevState: any;
|
|
88
|
+
/**
|
|
89
|
+
* Update animations based on state
|
|
90
|
+
*
|
|
91
|
+
* Called automatically in _process if sprite is AnimatedSprite
|
|
92
|
+
*/
|
|
93
|
+
updateAnimations(): void;
|
|
94
|
+
/**
|
|
95
|
+
* Map controller state to animation name
|
|
96
|
+
*
|
|
97
|
+
* Override this in subclasses for custom animation mappings
|
|
98
|
+
*/
|
|
99
|
+
getAnimationForState(state: any): any;
|
|
100
|
+
/**
|
|
101
|
+
* Manually check collisions using Matter.Query
|
|
102
|
+
*
|
|
103
|
+
* Since kinematic (static) bodies don't fire collision events with other static bodies,
|
|
104
|
+
* we need to manually query the physics world
|
|
105
|
+
*/
|
|
106
|
+
checkCollisionsManually(): any;
|
|
107
|
+
/**
|
|
108
|
+
* Resolve collisions using manual query results
|
|
109
|
+
*/
|
|
110
|
+
resolveCollisions(): void;
|
|
111
|
+
/**
|
|
112
|
+
* Slide velocity along collision surface
|
|
113
|
+
*/
|
|
114
|
+
slideVelocity(normal: any, pushDir: any): void;
|
|
115
|
+
/**
|
|
116
|
+
* Check grounded using manual collision detection
|
|
117
|
+
*/
|
|
118
|
+
checkGrounded(): void;
|
|
119
|
+
/**
|
|
120
|
+
* Update game feel timers
|
|
121
|
+
*/
|
|
122
|
+
updateTimers(delta: any): void;
|
|
123
|
+
handleCollisionEnter(other: any, pair: any): void;
|
|
124
|
+
handleCollisionStay(other: any, pair: any): void;
|
|
125
|
+
handleCollisionExit(other: any, pair: any): void;
|
|
126
|
+
/**
|
|
127
|
+
* Handle horizontal movement
|
|
128
|
+
*
|
|
129
|
+
* Features:
|
|
130
|
+
* - Instant direction change (no momentum)
|
|
131
|
+
* - Smooth acceleration to max speed
|
|
132
|
+
* - Different air/ground acceleration
|
|
133
|
+
*/
|
|
134
|
+
handleMovement(delta: any): void;
|
|
135
|
+
/**
|
|
136
|
+
* Handle jump input with game feel tricks
|
|
137
|
+
*
|
|
138
|
+
* Coyote time: Can jump slightly after leaving platform
|
|
139
|
+
* Jump buffer: Jump input remembered for short time
|
|
140
|
+
* Variable height: Release jump early = shorter jump
|
|
141
|
+
*/
|
|
142
|
+
handleJump(delta: any): void;
|
|
143
|
+
/**
|
|
144
|
+
* Apply gravity
|
|
145
|
+
*/
|
|
146
|
+
applyGravity(delta: any): void;
|
|
147
|
+
/**
|
|
148
|
+
* Update state machine
|
|
149
|
+
*
|
|
150
|
+
* States: idle, walk, jump, fall
|
|
151
|
+
* Used for animation selection
|
|
152
|
+
*/
|
|
153
|
+
updateState(): void;
|
|
154
|
+
/**
|
|
155
|
+
* Set move input from external system
|
|
156
|
+
*
|
|
157
|
+
* @param {number} direction - -1 (left), 0 (none), 1 (right)
|
|
158
|
+
*/
|
|
159
|
+
setMoveInput(direction: number): void;
|
|
160
|
+
/**
|
|
161
|
+
* Set jump input from external system
|
|
162
|
+
*
|
|
163
|
+
* @param {boolean} pressed - Jump pressed this frame
|
|
164
|
+
* @param {boolean} held - Jump held
|
|
165
|
+
* @param {boolean} released - Jump released this frame
|
|
166
|
+
*/
|
|
167
|
+
setJumpInput(pressed: boolean, held: boolean, released: boolean): void;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* InputController - bridges tessera.js InputMap to CharacterController2D
|
|
171
|
+
*
|
|
172
|
+
* Why separate:
|
|
173
|
+
* - CharacterController doesn't know about input systems
|
|
174
|
+
* - Can swap input sources (keyboard, gamepad, AI, replay)
|
|
175
|
+
* - Easier to test (mock input)
|
|
176
|
+
*/
|
|
177
|
+
export class CharacterInputController {
|
|
178
|
+
constructor(character: any, inputMap: any);
|
|
179
|
+
character: any;
|
|
180
|
+
inputMap: any;
|
|
181
|
+
prevJumpHeld: boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Update character from input - call every frame
|
|
184
|
+
*/
|
|
185
|
+
update(): void;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* TopDownController - 8-directional movement (no jumping)
|
|
189
|
+
*
|
|
190
|
+
* For: top-down action games, twin-stick shooters
|
|
191
|
+
*/
|
|
192
|
+
export class TopDownController extends RigidBody2D {
|
|
193
|
+
constructor(name: any, options?: {});
|
|
194
|
+
speed: any;
|
|
195
|
+
acceleration: any;
|
|
196
|
+
friction: any;
|
|
197
|
+
velocity: {
|
|
198
|
+
x: number;
|
|
199
|
+
y: number;
|
|
200
|
+
};
|
|
201
|
+
moveInput: {
|
|
202
|
+
x: number;
|
|
203
|
+
y: number;
|
|
204
|
+
};
|
|
205
|
+
canDash: any;
|
|
206
|
+
dashSpeed: any;
|
|
207
|
+
dashDuration: any;
|
|
208
|
+
dashCooldown: any;
|
|
209
|
+
isDashing: boolean;
|
|
210
|
+
dashTimer: number;
|
|
211
|
+
dashCooldownTimer: number;
|
|
212
|
+
dashDirection: {
|
|
213
|
+
x: number;
|
|
214
|
+
y: number;
|
|
215
|
+
};
|
|
216
|
+
handleMovement(delta: any): void;
|
|
217
|
+
/**
|
|
218
|
+
* Execute dash
|
|
219
|
+
*/
|
|
220
|
+
dash(): boolean;
|
|
221
|
+
setMoveInput(x: any, y: any): void;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* TopDownInputController - for TopDownController
|
|
225
|
+
*/
|
|
226
|
+
export class TopDownInputController {
|
|
227
|
+
constructor(character: any, inputMap: any);
|
|
228
|
+
character: any;
|
|
229
|
+
inputMap: any;
|
|
230
|
+
prevDashHeld: boolean;
|
|
231
|
+
update(): void;
|
|
232
|
+
}
|
|
233
|
+
import { RigidBody2D } from './physics.js';
|
|
234
|
+
import { Sprite } from './sprite.js';
|
|
235
|
+
import { AnimatedSprite } from './sprite.js';
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Controller - all camera behaviors inherit from this
|
|
3
|
+
* Why a base class: provides common lifecycle methods and state management
|
|
4
|
+
*/
|
|
5
|
+
export class CameraController {
|
|
6
|
+
constructor(name?: string);
|
|
7
|
+
name: string;
|
|
8
|
+
enabled: boolean;
|
|
9
|
+
priority: number;
|
|
10
|
+
camera: any;
|
|
11
|
+
weight: number;
|
|
12
|
+
attach(camera: any): void;
|
|
13
|
+
detach(): void;
|
|
14
|
+
onAttach(): void;
|
|
15
|
+
onDetach(): void;
|
|
16
|
+
onUpdate(delta: any): boolean;
|
|
17
|
+
preUpdate(delta: any): void;
|
|
18
|
+
postUpdate(delta: any): void;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* FollowController - smoothly follows a target
|
|
22
|
+
* Key features:
|
|
23
|
+
* - Lag/smoothing with lerp
|
|
24
|
+
* - Deadzone (camera only moves when target leaves center area)
|
|
25
|
+
* - Look-ahead (predictive movement)
|
|
26
|
+
* - Boundaries (clamp to level limits)
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Optimized FollowController with smooth lerping
|
|
30
|
+
*
|
|
31
|
+
* Key improvements:
|
|
32
|
+
* - Smooth lerp towards target center (no harsh deadzone snapping)
|
|
33
|
+
* - Optional soft deadzone for reduced movement near center
|
|
34
|
+
* - Simplified calculations, fewer conversions
|
|
35
|
+
* - Better performance with early exits
|
|
36
|
+
*/
|
|
37
|
+
export class FollowController extends CameraController {
|
|
38
|
+
constructor(target: any, options?: {});
|
|
39
|
+
target: any;
|
|
40
|
+
smoothing: any;
|
|
41
|
+
softDeadzoneRadius: any;
|
|
42
|
+
softDeadzoneFalloff: any;
|
|
43
|
+
offset: any;
|
|
44
|
+
bounds: any;
|
|
45
|
+
smoothingX: any;
|
|
46
|
+
smoothingY: any;
|
|
47
|
+
minMovement: any;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* ShakeController - screen shake for impacts, explosions, etc.
|
|
51
|
+
* Key features:
|
|
52
|
+
* - Perlin-like noise for natural shaking
|
|
53
|
+
* - Decay over time
|
|
54
|
+
* - Configurable intensity and frequency
|
|
55
|
+
* - Can shake position, rotation, or both
|
|
56
|
+
*/
|
|
57
|
+
export class ShakeController extends CameraController {
|
|
58
|
+
constructor(options?: {});
|
|
59
|
+
intensity: any;
|
|
60
|
+
decay: any;
|
|
61
|
+
frequency: any;
|
|
62
|
+
shakePosition: boolean;
|
|
63
|
+
shakeRotation: any;
|
|
64
|
+
maxRotation: any;
|
|
65
|
+
time: number;
|
|
66
|
+
seed: number;
|
|
67
|
+
currentIntensity: number;
|
|
68
|
+
offset: {
|
|
69
|
+
x: number;
|
|
70
|
+
y: number;
|
|
71
|
+
};
|
|
72
|
+
rotationOffset: number;
|
|
73
|
+
octaves: any;
|
|
74
|
+
persistence: any;
|
|
75
|
+
shake(intensity?: any): void;
|
|
76
|
+
_perlinNoise(seed: any, t: any): number;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* ZoomController - smooth zoom interpolation
|
|
80
|
+
* Key features:
|
|
81
|
+
* - Animated zoom to target level
|
|
82
|
+
* - Zoom to fit specific bounds
|
|
83
|
+
* - Zoom with pivot point (mouse position)
|
|
84
|
+
*/
|
|
85
|
+
export class ZoomController extends CameraController {
|
|
86
|
+
constructor(options?: {});
|
|
87
|
+
targetZoom: any;
|
|
88
|
+
smoothing: any;
|
|
89
|
+
minZoom: any;
|
|
90
|
+
maxZoom: any;
|
|
91
|
+
zoomToFitPadding: any;
|
|
92
|
+
isZooming: boolean;
|
|
93
|
+
zoomStart: number;
|
|
94
|
+
zoomTime: number;
|
|
95
|
+
zoomDuration: number;
|
|
96
|
+
easingFunc: (t: any) => any;
|
|
97
|
+
pivot: any;
|
|
98
|
+
zoomTo(zoomLevel: any, duration?: number, easing?: string, pivot?: any): void;
|
|
99
|
+
zoomToFit(bounds: any, duration?: number, easing?: string): void;
|
|
100
|
+
zoomBy(factor: any, duration?: number, easing?: string, pivot?: any): void;
|
|
101
|
+
_getEasingFunction(name: any): (t: any) => any;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* PathController - follow a Bézier path for cinematic sequences
|
|
105
|
+
* Key features:
|
|
106
|
+
* - Follow sequence of control points
|
|
107
|
+
* - Configurable speed and easing
|
|
108
|
+
* - Loop or one-shot playback
|
|
109
|
+
* - Callbacks at waypoints
|
|
110
|
+
*/
|
|
111
|
+
export class PathController extends CameraController {
|
|
112
|
+
constructor(path?: any[], options?: {});
|
|
113
|
+
path: any[];
|
|
114
|
+
speed: any;
|
|
115
|
+
easing: any;
|
|
116
|
+
loop: any;
|
|
117
|
+
autoStart: any;
|
|
118
|
+
isPlaying: boolean;
|
|
119
|
+
currentTime: number;
|
|
120
|
+
totalDistance: number;
|
|
121
|
+
segmentDistances: any[];
|
|
122
|
+
currentSegment: number;
|
|
123
|
+
t: number;
|
|
124
|
+
onComplete: any;
|
|
125
|
+
onWaypoint: any;
|
|
126
|
+
play(): void;
|
|
127
|
+
pause(): void;
|
|
128
|
+
stop(): void;
|
|
129
|
+
_calculatePathDistances(): void;
|
|
130
|
+
onUpdate(delta: any): any;
|
|
131
|
+
_applyEasing(t: any, easing: any): any;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* ControllerManager - manages multiple controllers on a camera
|
|
135
|
+
* Why needed: handles controller priority, blending, and update order
|
|
136
|
+
*/
|
|
137
|
+
export class ControllerManager {
|
|
138
|
+
constructor(camera: any);
|
|
139
|
+
camera: any;
|
|
140
|
+
controllers: Map<any, any>;
|
|
141
|
+
updateOrder: any[];
|
|
142
|
+
_originalUpdate: any;
|
|
143
|
+
add(controller: any): any;
|
|
144
|
+
remove(name: any): void;
|
|
145
|
+
get(name: any): any;
|
|
146
|
+
_update(delta: any): void;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Integrated Camera2D with controller support
|
|
150
|
+
* Extends the base Camera2D to include controller management
|
|
151
|
+
*/
|
|
152
|
+
export class ControlledCamera extends Camera2D {
|
|
153
|
+
controllerManager: ControllerManager;
|
|
154
|
+
_controllers: ControllerManager;
|
|
155
|
+
addController(controller: any): any;
|
|
156
|
+
removeController(name: any): void;
|
|
157
|
+
getController(name: any): any;
|
|
158
|
+
follow(target: any, options: any): FollowController;
|
|
159
|
+
shake(options: any): ShakeController;
|
|
160
|
+
zoom(options: any): ZoomController;
|
|
161
|
+
path(path: any, options: any): PathController;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* CameraRig - parent node for camera with additional control points
|
|
165
|
+
* Useful for: camera shake that doesn't affect child objects, complex camera setups
|
|
166
|
+
*/
|
|
167
|
+
export class CameraRig extends Node {
|
|
168
|
+
camera: ControlledCamera;
|
|
169
|
+
pivot: Node;
|
|
170
|
+
cameraOffset: {
|
|
171
|
+
x: number;
|
|
172
|
+
y: number;
|
|
173
|
+
};
|
|
174
|
+
shakeCamera(intensity?: number): ShakeController;
|
|
175
|
+
moveRig(x: any, y: any): void;
|
|
176
|
+
setCameraOffset(x: any, y: any): void;
|
|
177
|
+
}
|
|
178
|
+
import { Camera2D } from "./cam.js";
|
|
179
|
+
import { Node } from "./core.js";
|
|
@@ -50,10 +50,13 @@ export class Node {
|
|
|
50
50
|
x: number;
|
|
51
51
|
y: number;
|
|
52
52
|
};
|
|
53
|
+
worldCos: number;
|
|
54
|
+
worldSin: number;
|
|
53
55
|
transformDirty: boolean;
|
|
54
56
|
visible: boolean;
|
|
55
57
|
active: boolean;
|
|
56
58
|
ready: boolean;
|
|
59
|
+
physicsWorld: any;
|
|
57
60
|
/**
|
|
58
61
|
*
|
|
59
62
|
* @param {Node} node
|
|
@@ -78,6 +81,18 @@ export class Node {
|
|
|
78
81
|
* This gives proper transform inheritance (child orbits parent)
|
|
79
82
|
*/
|
|
80
83
|
updateWorldTransform(): void;
|
|
84
|
+
getWorldPosition(): {
|
|
85
|
+
x: number;
|
|
86
|
+
y: number;
|
|
87
|
+
};
|
|
88
|
+
worldToLocal(wx: any, wy: any): {
|
|
89
|
+
x: any;
|
|
90
|
+
y: any;
|
|
91
|
+
};
|
|
92
|
+
localToWorld(lx: any, ly: any): {
|
|
93
|
+
x: number;
|
|
94
|
+
y: number;
|
|
95
|
+
};
|
|
81
96
|
_ready(): void;
|
|
82
97
|
_process(delta: any): void;
|
|
83
98
|
_draw(canvas: any, camera: any): void;
|
|
@@ -116,7 +131,9 @@ export class Scene {
|
|
|
116
131
|
paused: boolean;
|
|
117
132
|
timeScale: number;
|
|
118
133
|
camera: any;
|
|
134
|
+
set physicsWorld(world: any);
|
|
119
135
|
addChild(node: any): Node;
|
|
136
|
+
start(): void;
|
|
120
137
|
process(delta: any): void;
|
|
121
138
|
draw(): void;
|
|
122
139
|
/**
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* - `t = 0` → returns `a`
|
|
3
|
+
- `t = 0.5` → returns midpoint
|
|
4
|
+
- `t = 1` → returns `b`
|
|
5
|
+
- Single multiplication, single addition
|
|
6
|
+
- No branching (fast)
|
|
7
|
+
- Works for ANY numeric type (positions, colors, angles, scales)
|
|
8
|
+
|
|
9
|
+
* @param {*} a
|
|
10
|
+
* @param {*} b
|
|
11
|
+
* @param {*} t
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
export function lerp(a: any, b: any, t: any): any;
|
|
15
|
+
export function lerp2D(p0: any, p1: any, t: any): {
|
|
16
|
+
x: any;
|
|
17
|
+
y: any;
|
|
18
|
+
};
|
|
19
|
+
export function inverseLerp(a: any, b: any, value: any): number;
|
|
20
|
+
export function remap(inMin: any, inMax: any, outMin: any, outMax: any, value: any): any;
|
|
21
|
+
/**
|
|
22
|
+
* in quadratic interpolation (or "quadratic lerp" in programming contexts), the resulting line is a parabolic curve that is determined by the three points. It is not a direct, piecewise linear connection of the points.
|
|
23
|
+
Quadratic interpolation fits a second-degree polynomial (a parabola) through the three given points (e.g., A, B, and C).
|
|
24
|
+
When used as a Bézier curve, the three points define the start point, an end point, and a control point that shapes the curve.
|
|
25
|
+
The curve is generated by a continuous process of linear interpolations (lerps) between intermediate points, resulting in a smooth arc.
|
|
26
|
+
* @param {*} p0
|
|
27
|
+
* @param {*} p1
|
|
28
|
+
* @param {*} p2
|
|
29
|
+
* @param {*} t
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
export function quadraticBezier(p0: any, p1: any, p2: any, t: any): {
|
|
33
|
+
x: any;
|
|
34
|
+
y: any;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* the tangent vector of a quadratic Bézier curve is directly related to a linear interpolation (LERP). Specifically, the first derivative of a quadratic Bézier curve equation is a LERP function that defines the curve's velocity and direction (tangent) at any given parameter \(t\). A quadratic Bézier curve is defined as \(B(t)=(1-t)^{2}P_{0}+2(1-t)tP_{1}+t^{2}P_{2}\).The first derivative (rate of change with respect to \(t\)) is \(B^{\prime }(t)=2(1-t)(P_{1}-P_{0})+2t(P_{2}-P_{1})\).This derivative can be expressed as a LERP between the vectors \((P_{1}-P_{0})\) and \((P_{2}-P_{1})\), scaled by 2.
|
|
38
|
+
* @param {*} p0
|
|
39
|
+
* @param {*} p1
|
|
40
|
+
* @param {*} p2
|
|
41
|
+
* @param {*} t
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
export function quadraticBezierTangent(p0: any, p1: any, p2: any, t: any): {
|
|
45
|
+
x: number;
|
|
46
|
+
y: number;
|
|
47
|
+
};
|
|
48
|
+
export function cubicBezier(p0: any, p1: any, p2: any, p3: any, t: any): {
|
|
49
|
+
x: any;
|
|
50
|
+
y: any;
|
|
51
|
+
};
|
|
52
|
+
export function cubicBezierTangent(p0: any, p1: any, p2: any, p3: any, t: any): {
|
|
53
|
+
x: number;
|
|
54
|
+
y: number;
|
|
55
|
+
magnitude: number;
|
|
56
|
+
};
|
|
57
|
+
export function distance2D(p1: any, p2: any): number;
|
|
58
|
+
/**
|
|
59
|
+
* **The insight:** We don't change lerp. We change **t**.
|
|
60
|
+
|
|
61
|
+
```javascript
|
|
62
|
+
// Linear (boring)
|
|
63
|
+
const x = lerp(a, b, t);
|
|
64
|
+
|
|
65
|
+
// Beautiful
|
|
66
|
+
const easedT = easeOutCubic(t);
|
|
67
|
+
const x = lerp(a, b, easedT);
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Easing functions transform `t` from a straight line into a curve. Same lerp, different feel.
|
|
71
|
+
*/
|
|
72
|
+
export function easeInQuad(t: any): number;
|
|
73
|
+
export function easeOutQuad(t: any): number;
|
|
74
|
+
export function easeInOutQuad(t: any): number;
|
|
75
|
+
export function easeInCubic(t: any): number;
|
|
76
|
+
export function easeOutCubic(t: any): number;
|
|
77
|
+
export function easeInOutCubic(t: any): number;
|
|
78
|
+
/**
|
|
79
|
+
*
|
|
80
|
+
- **EaseIn**: Slow start, fast end (accelerate)
|
|
81
|
+
- **EaseOut**: Fast start, slow end (decelerate)
|
|
82
|
+
- **EaseInOut**: Slow both ends, fast middle (S-curve)
|
|
83
|
+
|
|
84
|
+
*/
|
|
85
|
+
export function easeInQuart(t: any): number;
|
|
86
|
+
export function easeOutQuart(t: any): number;
|
|
87
|
+
export function easeInOutQuart(t: any): number;
|
|
88
|
+
export function easeOutElastic(t: any): number;
|
|
89
|
+
export function easeInElastic(t: any): number;
|
|
90
|
+
export function easeOutBounce(t: any): number;
|
|
91
|
+
export function easeInBounce(t: any): number;
|
|
92
|
+
export function easeOutBack(t: any): number;
|
|
93
|
+
export class BezierChain {
|
|
94
|
+
segments: any[];
|
|
95
|
+
addSegment(p0: any, p1: any, p2: any, p3: any): void;
|
|
96
|
+
addSmoothSegment(p2: any, p3: any): void;
|
|
97
|
+
getPoint(globalT: any): any;
|
|
98
|
+
getTangent(globalT: any): {
|
|
99
|
+
x: number;
|
|
100
|
+
y: number;
|
|
101
|
+
magnitude: number;
|
|
102
|
+
};
|
|
103
|
+
removeFirstSegment(): void;
|
|
104
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
export function profile(name: any, fn: any): any;
|
|
2
|
+
export function profileAsync(name: any, fn: any): Promise<any>;
|
|
3
|
+
/**
|
|
4
|
+
* minimal hot-reloader - treats game module as a hot-swappable DLL
|
|
5
|
+
*
|
|
6
|
+
* @param {Object} options
|
|
7
|
+
* @param {string} options.entry - Path to game module
|
|
8
|
+
* @param {boolean} [options.watch=true] - Enable file watching
|
|
9
|
+
* @param {number} [options.debounce=100] - Debounce ms for file changes
|
|
10
|
+
* @param {string[]} [options.watchFiles=[]] - Additional files to watch for changes
|
|
11
|
+
* @returns {Promise<Object>} Game module proxy
|
|
12
|
+
*/
|
|
13
|
+
export function hotloader(state: any, options: {
|
|
14
|
+
entry: string;
|
|
15
|
+
watch?: boolean;
|
|
16
|
+
debounce?: number;
|
|
17
|
+
watchFiles?: string[];
|
|
18
|
+
}): Promise<any>;
|
|
19
|
+
/**
|
|
20
|
+
* Clamp a rectangle to canvas bounds
|
|
21
|
+
* Returns null if completely outside canvas
|
|
22
|
+
*/
|
|
23
|
+
export function clampRectToCanvas(x: any, y: any, width: any, height: any, canvasWidth: any, canvasHeight: any): {
|
|
24
|
+
x: number;
|
|
25
|
+
y: number;
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Check if a pixel should be drawn (canvas + viewport clipping)
|
|
31
|
+
* @param {Camera2D} camera
|
|
32
|
+
*/
|
|
33
|
+
export function shouldDrawPixel(x: any, y: any, canvas: any, camera: Camera2D): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* optimized drawAtlasRegionToCanvas with micro-optimized fast paths.
|
|
36
|
+
*
|
|
37
|
+
* @param {{data: Uint8Array, width: number, height: number}} atlas
|
|
38
|
+
* @param {{x: number, y: number, width: number, height: number}} srcRect
|
|
39
|
+
* @param {PixelBuffer} canvas
|
|
40
|
+
* @param {{x: number, y: number, width: number, height: number}} destRect
|
|
41
|
+
* @param {{algorithm?: "bilinear" | "nn", flipH?: boolean, flipV?: boolean, modulate?: {r:number,g:number,b:number,a:number}, assumeOpaque?: boolean, camera?: Camera2D}} options
|
|
42
|
+
*/
|
|
43
|
+
export function drawAtlasRegionToCanvas(atlas: {
|
|
44
|
+
data: Uint8Array;
|
|
45
|
+
width: number;
|
|
46
|
+
height: number;
|
|
47
|
+
}, srcRect: {
|
|
48
|
+
x: number;
|
|
49
|
+
y: number;
|
|
50
|
+
width: number;
|
|
51
|
+
height: number;
|
|
52
|
+
}, canvas: PixelBuffer, destRect: {
|
|
53
|
+
x: number;
|
|
54
|
+
y: number;
|
|
55
|
+
width: number;
|
|
56
|
+
height: number;
|
|
57
|
+
}, options?: {
|
|
58
|
+
algorithm?: "bilinear" | "nn";
|
|
59
|
+
flipH?: boolean;
|
|
60
|
+
flipV?: boolean;
|
|
61
|
+
modulate?: {
|
|
62
|
+
r: number;
|
|
63
|
+
g: number;
|
|
64
|
+
b: number;
|
|
65
|
+
a: number;
|
|
66
|
+
};
|
|
67
|
+
assumeOpaque?: boolean;
|
|
68
|
+
camera?: Camera2D;
|
|
69
|
+
}): void;
|
|
70
|
+
export const globalPerf: Profiler;
|
|
71
|
+
export function getModulePaths(): {
|
|
72
|
+
__filename: string;
|
|
73
|
+
__dirname: string;
|
|
74
|
+
require: NodeJS.Require | (() => never);
|
|
75
|
+
};
|
|
76
|
+
import { PixelBuffer } from "tessera.js";
|
|
77
|
+
declare class Profiler {
|
|
78
|
+
scopePool: ScopeData[];
|
|
79
|
+
poolIndex: number;
|
|
80
|
+
scopeStack: any[];
|
|
81
|
+
currentScope: any;
|
|
82
|
+
rootScopes: any[];
|
|
83
|
+
frameCount: number;
|
|
84
|
+
frameTimes: any[];
|
|
85
|
+
frameStart: number;
|
|
86
|
+
scopeStats: Map<any, any>;
|
|
87
|
+
enabled: boolean;
|
|
88
|
+
mismatchCount: number;
|
|
89
|
+
acquireScope(name: any): ScopeData;
|
|
90
|
+
start(name: any): void;
|
|
91
|
+
_finalizeScope(scope: any): void;
|
|
92
|
+
end(name: any): void;
|
|
93
|
+
frame(): void;
|
|
94
|
+
getStats(name: any): any;
|
|
95
|
+
getAllStats(): any[];
|
|
96
|
+
percentile(samples: any, p: any): any;
|
|
97
|
+
report(): void;
|
|
98
|
+
exportTrace(): string;
|
|
99
|
+
reset(): void;
|
|
100
|
+
enable(): void;
|
|
101
|
+
disable(): void;
|
|
102
|
+
}
|
|
103
|
+
declare class ScopeData {
|
|
104
|
+
name: string;
|
|
105
|
+
depth: number;
|
|
106
|
+
startTime: number;
|
|
107
|
+
endTime: number;
|
|
108
|
+
duration: number;
|
|
109
|
+
parent: any;
|
|
110
|
+
children: any[];
|
|
111
|
+
callCount: number;
|
|
112
|
+
totalTime: number;
|
|
113
|
+
minTime: number;
|
|
114
|
+
maxTime: number;
|
|
115
|
+
samples: any[];
|
|
116
|
+
reset(): void;
|
|
117
|
+
resetStats(): void;
|
|
118
|
+
}
|
|
119
|
+
export {};
|