@edv4h/usketch-plugin-character 0.3.0 → 0.4.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/README.md +72 -11
- package/dist/character-input.d.ts +15 -4
- package/dist/character-input.d.ts.map +1 -1
- package/dist/character-input.js +174 -26
- package/dist/character-input.js.map +1 -1
- package/dist/character-key-choices.d.ts +14 -0
- package/dist/character-key-choices.d.ts.map +1 -0
- package/dist/character-key-choices.js +23 -0
- package/dist/character-key-choices.js.map +1 -0
- package/dist/character-layer.d.ts +1 -1
- package/dist/character-layer.d.ts.map +1 -1
- package/dist/character-layer.js +45 -14
- package/dist/character-layer.js.map +1 -1
- package/dist/character-physics.d.ts +156 -2
- package/dist/character-physics.d.ts.map +1 -1
- package/dist/character-physics.js +270 -22
- package/dist/character-physics.js.map +1 -1
- package/dist/character-runtime.d.ts +8 -1
- package/dist/character-runtime.d.ts.map +1 -1
- package/dist/character-runtime.js +74 -8
- package/dist/character-runtime.js.map +1 -1
- package/dist/character-service.d.ts +23 -3
- package/dist/character-service.d.ts.map +1 -1
- package/dist/character-service.js +7 -0
- package/dist/character-service.js.map +1 -1
- package/dist/character-store.d.ts +34 -1
- package/dist/character-store.d.ts.map +1 -1
- package/dist/character-store.js +86 -4
- package/dist/character-store.js.map +1 -1
- package/dist/character-sync.d.ts +11 -1
- package/dist/character-sync.d.ts.map +1 -1
- package/dist/character-sync.js +23 -1
- package/dist/character-sync.js.map +1 -1
- package/dist/character-types.d.ts +31 -2
- package/dist/character-types.d.ts.map +1 -1
- package/dist/character-types.js +2 -1
- package/dist/character-types.js.map +1 -1
- package/dist/character-virtual-input.d.ts +20 -0
- package/dist/character-virtual-input.d.ts.map +1 -0
- package/dist/character-virtual-input.js +34 -0
- package/dist/character-virtual-input.js.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/plugin.d.ts +13 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +2 -0
- package/dist/plugin.js.map +1 -1
- package/dist/register-character-hud.d.ts.map +1 -1
- package/dist/register-character-hud.js +88 -1
- package/dist/register-character-hud.js.map +1 -1
- package/package.json +2 -2
package/dist/character-layer.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
// The one fixed (screen-space) layer that places every character — self and remote
|
|
3
3
|
// — at `worldToScreen(position)`. It draws NOTHING itself: each spot is a zero-size,
|
|
4
4
|
// pointer-transparent wrapper whose content is the host's `renderCharacter`. One
|
|
5
5
|
// screen-space layer keeps self/remote consistent (same size under zoom, same
|
|
6
|
-
// `screenHeading` math under camera rotation).
|
|
6
|
+
// `screenHeading` math under camera rotation). The optional `renderShadow` gets a spot
|
|
7
|
+
// of its own on the GROUND under each character, while the body stands at its feet
|
|
8
|
+
// height — under a 3D view (Mode 7) a jump lifts the body off its shadow.
|
|
7
9
|
import { viewportRotation, worldToScreen, wrapDeg } from "@edv4h/usketch-shared";
|
|
8
10
|
import { useSyncExternalStore } from "react";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
import { hoverGaugeOf } from "./character-store.js";
|
|
12
|
+
/** Screen px a shadow floats above its ground, so it doesn't z-fight a raised terrain top. */
|
|
13
|
+
const SHADOW_LIFT_PX = 0.5;
|
|
14
|
+
function Spot({ shadow = false, x, y, lift, renderer, props, }) {
|
|
15
|
+
return (_jsx("div", { "data-character-id": shadow ? undefined : props.id, "data-character-shadow": shadow ? props.id : undefined, style: {
|
|
11
16
|
position: "absolute",
|
|
12
17
|
left: x,
|
|
13
18
|
top: y,
|
|
@@ -22,12 +27,15 @@ export function CharacterLayer({ store, viewport, heightAt, }) {
|
|
|
22
27
|
const renderer = store.getRenderer();
|
|
23
28
|
if (!renderer)
|
|
24
29
|
return null; // headless: no look supplied → draw nothing
|
|
30
|
+
const shadowRenderer = store.getShadowRenderer();
|
|
25
31
|
const rot = viewportRotation(viewport);
|
|
26
|
-
const
|
|
32
|
+
const bodies = [];
|
|
27
33
|
for (const r of state.remotes.values()) {
|
|
28
|
-
const p = worldToScreen(r.x, r.y, viewport);
|
|
29
34
|
const elevation = heightAt?.(r.x, r.y) ?? 0;
|
|
30
|
-
|
|
35
|
+
const z = Math.max(elevation, r.z ?? elevation);
|
|
36
|
+
bodies.push({
|
|
37
|
+
at: worldToScreen(r.x, r.y, viewport),
|
|
38
|
+
props: {
|
|
31
39
|
id: r.id,
|
|
32
40
|
isSelf: false,
|
|
33
41
|
heading: r.heading,
|
|
@@ -41,14 +49,24 @@ export function CharacterLayer({ store, viewport, heightAt, }) {
|
|
|
41
49
|
appearance: r.appearance,
|
|
42
50
|
name: r.name,
|
|
43
51
|
elevation,
|
|
44
|
-
|
|
52
|
+
z,
|
|
53
|
+
altitude: z - elevation,
|
|
54
|
+
airborne: r.airborne,
|
|
55
|
+
verticalSpeed: r.vz,
|
|
56
|
+
hovering: r.hovering,
|
|
57
|
+
hoverGauge: r.hoverGauge,
|
|
58
|
+
},
|
|
59
|
+
});
|
|
45
60
|
}
|
|
46
61
|
if (state.enabled && state.spawned) {
|
|
47
62
|
const { pose } = state;
|
|
48
|
-
const p = worldToScreen(pose.x, pose.y, viewport);
|
|
49
63
|
const elevation = heightAt?.(pose.x, pose.y) ?? 0;
|
|
64
|
+
// Before the first vertical step a fresh spawn's `z` may still be below the ground.
|
|
65
|
+
const z = Math.max(elevation, pose.z);
|
|
50
66
|
// Self last → drawn on top of the others.
|
|
51
|
-
|
|
67
|
+
bodies.push({
|
|
68
|
+
at: worldToScreen(pose.x, pose.y, viewport),
|
|
69
|
+
props: {
|
|
52
70
|
id: "self",
|
|
53
71
|
isSelf: true,
|
|
54
72
|
heading: pose.heading,
|
|
@@ -62,15 +80,28 @@ export function CharacterLayer({ store, viewport, heightAt, }) {
|
|
|
62
80
|
appearance: state.appearance,
|
|
63
81
|
name: state.name,
|
|
64
82
|
elevation,
|
|
65
|
-
|
|
83
|
+
z,
|
|
84
|
+
altitude: z - elevation,
|
|
85
|
+
airborne: pose.airborne,
|
|
86
|
+
verticalSpeed: pose.vz,
|
|
87
|
+
hovering: pose.hovering,
|
|
88
|
+
hoverGauge: hoverGaugeOf(state),
|
|
89
|
+
},
|
|
90
|
+
});
|
|
66
91
|
}
|
|
67
|
-
if (
|
|
92
|
+
if (bodies.length === 0)
|
|
68
93
|
return null;
|
|
69
|
-
|
|
94
|
+
const key = (props) => (props.isSelf ? "self" : `remote-${props.id}`);
|
|
95
|
+
// Shadows first, so every body draws over every shadow.
|
|
96
|
+
const shadowSpots = shadowRenderer
|
|
97
|
+
? bodies.map(({ at, props }) => (_jsx(Spot, { shadow: true, x: at.x, y: at.y, lift: props.elevation * viewport.zoom + SHADOW_LIFT_PX, renderer: shadowRenderer, props: props }, `shadow-${key(props)}`)))
|
|
98
|
+
: [];
|
|
99
|
+
const bodySpots = bodies.map(({ at, props }) => (_jsx(Spot, { x: at.x, y: at.y, lift: props.z * viewport.zoom, renderer: renderer, props: props }, key(props))));
|
|
100
|
+
return (_jsxs("div", { style: {
|
|
70
101
|
position: "absolute",
|
|
71
102
|
inset: 0,
|
|
72
103
|
pointerEvents: "none",
|
|
73
104
|
transformStyle: "preserve-3d",
|
|
74
|
-
}, children:
|
|
105
|
+
}, children: [shadowSpots, bodySpots] }));
|
|
75
106
|
}
|
|
76
107
|
//# sourceMappingURL=character-layer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"character-layer.js","sourceRoot":"","sources":["../src/character-layer.tsx"],"names":[],"mappings":";AAAA,mFAAmF;AACnF,qFAAqF;AACrF,iFAAiF;AACjF,8EAA8E;AAC9E
|
|
1
|
+
{"version":3,"file":"character-layer.js","sourceRoot":"","sources":["../src/character-layer.tsx"],"names":[],"mappings":";AAAA,mFAAmF;AACnF,qFAAqF;AACr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QAAQ,EAAE,UAAU;YACpB,KAAK,EAAE,CAAC;YACR,aAAa,EAAE,MAAM;YACrB,cAAc,EAAE,aAAa;SAC7B,aAEA,WAAW,EACX,SAAS,IACL,CACN,CAAC;AACH,CAAC"}
|
|
@@ -7,6 +7,19 @@ export interface MoveInput {
|
|
|
7
7
|
right: boolean;
|
|
8
8
|
/** Vehicle: the drift key (only acts when drift is enabled). */
|
|
9
9
|
drift?: boolean;
|
|
10
|
+
/** The drift key was pressed since the previous step (an edge: starts a drift hop). */
|
|
11
|
+
driftPressed?: boolean;
|
|
12
|
+
/** The jump key is held (a release while rising cuts the jump short). */
|
|
13
|
+
jump?: boolean;
|
|
14
|
+
/** The jump key was pressed since the previous step (an edge, so a quick tap counts). */
|
|
15
|
+
jumpPressed?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Analog forward / back, -1 (full reverse / screen down) … 1 (full throttle / screen
|
|
18
|
+
* up), e.g. from a touch stick. When set it replaces `up` / `down`.
|
|
19
|
+
*/
|
|
20
|
+
throttle?: number;
|
|
21
|
+
/** Analog steering, -1 (left) … 1 (right). When set it replaces `left` / `right`. */
|
|
22
|
+
steer?: number;
|
|
10
23
|
}
|
|
11
24
|
export declare const NO_INPUT: MoveInput;
|
|
12
25
|
export interface CharacterPose {
|
|
@@ -28,6 +41,23 @@ export interface CharacterPose {
|
|
|
28
41
|
slip: number;
|
|
29
42
|
/** Vehicle: the running drift's direction, -1 (left) / 1 (right), 0 = not drifting. */
|
|
30
43
|
drift: -1 | 0 | 1;
|
|
44
|
+
/**
|
|
45
|
+
* Height of the character's feet, world units — absolute, like the ground height
|
|
46
|
+
* (0 = the flat board). On the ground it equals the ground height; it rises above it
|
|
47
|
+
* while jumping or falling, so it stays smooth across cliff edges.
|
|
48
|
+
*/
|
|
49
|
+
z: number;
|
|
50
|
+
/** Vertical speed, world units / s (positive = rising). */
|
|
51
|
+
vz: number;
|
|
52
|
+
/** Whether the character is in the air (jumping or falling). */
|
|
53
|
+
airborne: boolean;
|
|
54
|
+
/** Hovering: the jump key held while falling slows the descent (see `HoverParams`). */
|
|
55
|
+
hovering: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Hover gauge, 0 (empty) … 1 (full): drains while hovering, refills on the ground.
|
|
58
|
+
* Stays 1 while hovering is off.
|
|
59
|
+
*/
|
|
60
|
+
hoverGauge: number;
|
|
31
61
|
}
|
|
32
62
|
/** A pose at rest at the origin, facing up. */
|
|
33
63
|
export declare const ORIGIN_POSE: CharacterPose;
|
|
@@ -71,6 +101,13 @@ export interface DriftParams {
|
|
|
71
101
|
steerSlipAngle: number;
|
|
72
102
|
/** How fast the slip follows its target (1/s, exponential). */
|
|
73
103
|
recoveryRate: number;
|
|
104
|
+
/**
|
|
105
|
+
* Pressing the drift key on the ground hops first (a small jump; the drift starts on
|
|
106
|
+
* landing if still held and steering, since a car can't steer in the air).
|
|
107
|
+
*/
|
|
108
|
+
hop: boolean;
|
|
109
|
+
/** Height of that hop, world units. */
|
|
110
|
+
hopHeight: number;
|
|
74
111
|
}
|
|
75
112
|
export declare const DEFAULT_DRIFT: DriftParams;
|
|
76
113
|
/** Unit vector of a heading in world space (0° → (0, -1), 90° → (1, 0)). */
|
|
@@ -82,17 +119,25 @@ export declare function headingVector(deg: number): {
|
|
|
82
119
|
export declare function vectorHeading(x: number, y: number): number;
|
|
83
120
|
/** Move `from` toward `to` by at most `maxStep` degrees, the short way round. */
|
|
84
121
|
export declare function turnToward(from: number, to: number, maxStep: number): number;
|
|
122
|
+
/** Clamp to -1 … 1; a missing or non-finite value counts as 0 (released). */
|
|
123
|
+
export declare const clampUnit: (v: number | undefined) => number;
|
|
124
|
+
/** Forward / back of an input, -1 … 1: the analog `throttle` when set, else up − down. */
|
|
125
|
+
export declare function inputThrottle(input: MoveInput): number;
|
|
126
|
+
/** Left / right of an input, -1 … 1: the analog `steer` when set, else right − left. */
|
|
127
|
+
export declare function inputSteer(input: MoveInput): number;
|
|
85
128
|
/**
|
|
86
129
|
* Advance `pose` by `dt` seconds.
|
|
87
130
|
*
|
|
88
131
|
* - `directional`: the held keys give a SCREEN-space direction (up = screen up),
|
|
89
132
|
* turned into world space through the camera rotation; the character moves that
|
|
90
133
|
* way at `moveSpeed` and its heading turns toward it at `turnRate`. (Turning
|
|
91
|
-
* rather than snapping keeps a heading-following camera from spinning.)
|
|
134
|
+
* rather than snapping keeps a heading-following camera from spinning.) An analog
|
|
135
|
+
* input (`steer` / `throttle`) moves at `moveSpeed` × its length (capped at 1).
|
|
92
136
|
* - `vehicle`: up/down are throttle/reverse along the heading, left/right steer.
|
|
93
137
|
* Steering authority scales with speed (a stopped car can't turn) and inverts
|
|
94
138
|
* when reversing, like a car. With `driftParams`, holding the drift key while
|
|
95
|
-
* steering at speed drifts (see `DriftParams`).
|
|
139
|
+
* steering at speed drifts (see `DriftParams`). An analog `throttle` aims for that
|
|
140
|
+
* fraction of the top speed, and an analog `steer` turns by that fraction.
|
|
96
141
|
*/
|
|
97
142
|
export declare function stepCharacter(pose: CharacterPose, input: MoveInput, dt: number, scheme: ControlScheme, params: MotionParams, cameraRotation?: number, driftParams?: DriftParams | null): CharacterPose;
|
|
98
143
|
/** Ground height at a world point (world units; see `groundHeightService`). */
|
|
@@ -105,4 +150,113 @@ export type HeightAt = (x: number, y: number) => number;
|
|
|
105
150
|
* vehicle also loses its speed, as if it bumped the wall). The heading still turns.
|
|
106
151
|
*/
|
|
107
152
|
export declare function constrainToGround(prev: CharacterPose, next: CharacterPose, heightAt: HeightAt, maxStep: number): CharacterPose;
|
|
153
|
+
/**
|
|
154
|
+
* Jump tuning. The arc is set by its apex `height` and `timeToApex`; gravity and the
|
|
155
|
+
* take-off speed follow from them (see `jumpArc`).
|
|
156
|
+
*/
|
|
157
|
+
export interface JumpParams {
|
|
158
|
+
/** Apex of a jump from the ground, world units above the take-off point. */
|
|
159
|
+
height: number;
|
|
160
|
+
/** Seconds from take-off to the apex. */
|
|
161
|
+
timeToApex: number;
|
|
162
|
+
/** Gravity multiplier while falling (> 1 = floaty rise, snappy fall). */
|
|
163
|
+
fallGravity: number;
|
|
164
|
+
/** Releasing the key while rising scales the vertical speed by this (0 … 1): a short hop. */
|
|
165
|
+
releaseCut: number;
|
|
166
|
+
/** Seconds after walking off a ledge during which a jump still counts as from the ground. */
|
|
167
|
+
coyoteTime: number;
|
|
168
|
+
/** Seconds a press just before landing is remembered and jumps on touchdown. */
|
|
169
|
+
bufferTime: number;
|
|
170
|
+
/** Extra jumps in the air (0 = a single jump, 1 = a double jump …), reset on landing. */
|
|
171
|
+
airJumps: number;
|
|
172
|
+
/** An air jump's height as a fraction of `height` (its take-off speed is × √ratio). */
|
|
173
|
+
airJumpRatio: number;
|
|
174
|
+
/** Hovering while the key is held in a fall, or `null` = off. */
|
|
175
|
+
hover: HoverParams | null;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Hover tuning. Once the air jumps are used up (or there are none), holding the jump key
|
|
179
|
+
* while falling fires a thrust and drains a gauge; an empty gauge falls normally. The
|
|
180
|
+
* gauge refills on the ground over `rechargeTime` (not instantly on landing).
|
|
181
|
+
*
|
|
182
|
+
* The thrust is a multiple of gravity (a thrust-to-weight ratio, so no mass is needed):
|
|
183
|
+
* below 1 the character still sinks, at 1 it keeps its vertical speed, above 1 it climbs
|
|
184
|
+
* for as long as the key is held. Sinking is capped at `fallSpeed`, climbing at
|
|
185
|
+
* `riseSpeed`.
|
|
186
|
+
*/
|
|
187
|
+
export interface HoverParams {
|
|
188
|
+
/** Seconds of hover a full gauge lasts. */
|
|
189
|
+
duration: number;
|
|
190
|
+
/** Fastest descent while hovering, world units / s (0 = never sink). */
|
|
191
|
+
fallSpeed: number;
|
|
192
|
+
/** Seconds on the ground to refill an empty gauge. */
|
|
193
|
+
rechargeTime: number;
|
|
194
|
+
/** Thrust as a multiple of gravity: < 1 sinks, 1 balances, > 1 climbs. */
|
|
195
|
+
thrust: number;
|
|
196
|
+
/** Fastest climb while hovering, world units / s. */
|
|
197
|
+
riseSpeed: number;
|
|
198
|
+
}
|
|
199
|
+
export declare const DEFAULT_HOVER: HoverParams;
|
|
200
|
+
export declare const DEFAULT_JUMP: JumpParams;
|
|
201
|
+
/** Gravity (world units / s²) and take-off speed (world units / s) of a jump. */
|
|
202
|
+
export declare function jumpArc(params: JumpParams): {
|
|
203
|
+
gravity: number;
|
|
204
|
+
speed: number;
|
|
205
|
+
};
|
|
206
|
+
/** Per-character jump bookkeeping that is not part of the visible pose. */
|
|
207
|
+
export interface JumpTimers {
|
|
208
|
+
/** Seconds since the character last stood on the ground. */
|
|
209
|
+
sinceGround: number;
|
|
210
|
+
/** Seconds since the jump key was last pressed (`Infinity` = no pending press). */
|
|
211
|
+
sincePress: number;
|
|
212
|
+
/** The current airtime started with a jump (not a fall), so coyote time is spent. */
|
|
213
|
+
jumped: boolean;
|
|
214
|
+
/** The rise has been cut short already (the key was released). */
|
|
215
|
+
cut: boolean;
|
|
216
|
+
/** Air jumps used since the character last stood on the ground. */
|
|
217
|
+
airJumpsUsed: number;
|
|
218
|
+
}
|
|
219
|
+
export declare const IDLE_JUMP: JumpTimers;
|
|
220
|
+
/**
|
|
221
|
+
* Advance the vertical motion by `dt` seconds, after the horizontal step put the
|
|
222
|
+
* character over ground of height `ground`.
|
|
223
|
+
*
|
|
224
|
+
* - On the ground, a step up (already limited to `maxStep` by `constrainToGround`) or a
|
|
225
|
+
* step down of at most `maxStep` keeps the feet on the ground; a bigger drop starts a
|
|
226
|
+
* fall instead of snapping down.
|
|
227
|
+
* - With `jump` tuning, a press (or one buffered for `bufferTime`) jumps from the ground
|
|
228
|
+
* or within `coyoteTime` of leaving it; releasing the key while rising cuts the jump.
|
|
229
|
+
* - A fresh press in the air uses one of the `airJumps` while any remain (`airJumpRatio`
|
|
230
|
+
* of the height); they come back on landing.
|
|
231
|
+
* - With `hover` tuning, once the air jumps are used up, holding the key while falling
|
|
232
|
+
* hovers: the thrust pushes against gravity (see `hoverSpeed`) while the gauge drains,
|
|
233
|
+
* and it keeps firing while the key stays held, also once it climbs; an empty gauge
|
|
234
|
+
* falls normally. On the ground the gauge refills over `rechargeTime`.
|
|
235
|
+
* - A `hopHeight` above 0 (a vehicle's drift hop) makes a drift-key press on the ground
|
|
236
|
+
* hop that high, under the same gravity.
|
|
237
|
+
* - In the air, gravity pulls the feet down (`fallGravity` × while falling) until they
|
|
238
|
+
* meet the ground. Without `jump` the default arc's gravity still drives falls.
|
|
239
|
+
*/
|
|
240
|
+
export declare function stepVertical(pose: CharacterPose, timers: JumpTimers, input: MoveInput, dt: number, ground: number, maxStep: number, jump: JumpParams | null, hopHeight?: number): {
|
|
241
|
+
pose: CharacterPose;
|
|
242
|
+
timers: JumpTimers;
|
|
243
|
+
};
|
|
244
|
+
/**
|
|
245
|
+
* The input for the horizontal step on a frame that may start a drift hop: the press
|
|
246
|
+
* that hops doesn't also start the drift (it would carry through the air), so the drift
|
|
247
|
+
* begins on landing if the key is still held and steering.
|
|
248
|
+
*/
|
|
249
|
+
export declare function holdDriftForHop(input: MoveInput, pose: CharacterPose, hopHeight: number): MoveInput;
|
|
250
|
+
/** An air jump's take-off speed: the same gravity reaches `ratio` × the height. */
|
|
251
|
+
export declare function airJumpSpeed(takeoffSpeed: number, ratio: number): number;
|
|
252
|
+
/**
|
|
253
|
+
* The vertical speed after `dt` seconds of hovering from `vz`: the thrust (× `gravity`)
|
|
254
|
+
* against gravity, so the speed changes by (thrust − 1) × gravity per second, kept
|
|
255
|
+
* between −`fallSpeed` (a faster fall is caught at once) and `riseSpeed`.
|
|
256
|
+
*/
|
|
257
|
+
export declare function hoverSpeed(vz: number, dt: number, gravity: number, hover: HoverParams): number;
|
|
258
|
+
/** The hover gauge after `dt` seconds of hovering (a full gauge lasts `duration`). */
|
|
259
|
+
export declare function drainHoverGauge(gauge: number, dt: number, hover: HoverParams): number;
|
|
260
|
+
/** The hover gauge after `dt` seconds on the ground (empty → full in `rechargeTime`). */
|
|
261
|
+
export declare function rechargeHoverGauge(gauge: number, dt: number, hover: HoverParams): number;
|
|
108
262
|
//# sourceMappingURL=character-physics.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"character-physics.d.ts","sourceRoot":"","sources":["../src/character-physics.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,aAAa,GAAG,aAAa,GAAG,SAAS,CAAC;AAEtD,oDAAoD;AACpD,MAAM,WAAW,SAAS;IACzB,EAAE,EAAE,OAAO,CAAC;IACZ,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,OAAO,CAAC;IACf,gEAAgE;IAChE,KAAK,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"character-physics.d.ts","sourceRoot":"","sources":["../src/character-physics.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,aAAa,GAAG,aAAa,GAAG,SAAS,CAAC;AAEtD,oDAAoD;AACpD,MAAM,WAAW,SAAS;IACzB,EAAE,EAAE,OAAO,CAAC;IACZ,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,OAAO,CAAC;IACf,gEAAgE;IAChE,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,uFAAuF;IACvF,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,yEAAyE;IACzE,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,yFAAyF;IACzF,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qFAAqF;IACrF,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED,eAAO,MAAM,QAAQ,EAAE,SAQtB,CAAC;AAEF,MAAM,WAAW,aAAa;IAC7B,sBAAsB;IACtB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,gDAAgD;IAChD,OAAO,EAAE,MAAM,CAAC;IAChB,8EAA8E;IAC9E,KAAK,EAAE,MAAM,CAA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