bndr-js - v0.18.0 / GamepadEmitter
Class: GamepadEmitter
Hierarchy
Emitter
<GamepadData
>↳
GamepadEmitter
Constructors
constructor
• new GamepadEmitter()
Overrides
Defined in
Generators
axis
▸ axis(name?
): Emitter
<vec2
>
Parameters
Name | Type |
---|---|
name? | AxisName |
Returns
Emitter
<vec2
>
Defined in
axisDirection
▸ axisDirection(name?
, options?
): Emitter
<vec2
>
Emits the direction in which the axis is tilted. Each axis is quantized into -1, 0, or 1. If the axis is not tilted, it emits null
.
Parameters
Name | Type | Description |
---|---|---|
name? | AxisName | If omitted, it will watch all axes. |
options | Object | step: quantization step in degrees, threshold: minimum tilt value (0-1) to emit |
options.step? | 45 | 90 | - |
options.threshold? | number | - |
Returns
Emitter
<vec2
>
Example
[1, 0] // right
[0, -1] // up
[-1, 1] // down-left
Defined in
button
▸ button(name
): Emitter
<boolean
>
Parameters
Name | Type |
---|---|
name | ButtonName |
Returns
Emitter
<boolean
>
Defined in
devices
▸ devices(): Emitter
<Gamepad
[]>
Returns
Emitter
<Gamepad
[]>
Defined in
Common Filters
change
▸ change(equalFn?
): Emitter
<GamepadData
>
Emits only when the value is changed
Parameters
Name | Type | Default value | Description |
---|---|---|---|
equalFn | (a : GamepadData , b : GamepadData ) => boolean | isEqual | A comparator function. The event will be emitted when the function returns falsy value. |
Returns
Emitter
<GamepadData
>
Inherited from
Defined in
constant
▸ constant<U
>(value
): Emitter
<U
>
Creates an emitter that emits a constant value every time the current emitter is emitted.
Type parameters
Name |
---|
U |
Parameters
Name | Type |
---|---|
value | U |
Returns
Emitter
<U
>
See
https://lodash.com/docs/4.17.15#throttle
Inherited from
Defined in
debounce
▸ debounce(wait
, options
): Emitter
<unknown
>
Creates debounced version of the current emitter.
Parameters
Name | Type | Description |
---|---|---|
wait | number | Milliseconds to wait. |
options | DebounceSettings |
Returns
Emitter
<unknown
>
A new emitter
Inherited from
Defined in
delay
▸ delay(wait
): Emitter
<unknown
>
Creates delayed version of the current emitter.
Parameters
Name | Type | Description |
---|---|---|
wait | number | Milliseconds to wait. |
Returns
Emitter
<unknown
>
A new emitter
Inherited from
Defined in
delta
▸ delta<U
>(fn
): Emitter
<U
>
Creates an emitter that emits the ‘difference’ between the current value and the previous value.
Type parameters
Name |
---|
U |
Parameters
Name | Type | Description |
---|---|---|
fn | (prev : GamepadData , curt : GamepadData ) => U | A function to calculate the difference |
Returns
Emitter
<U
>
A new emitter
Inherited from
Defined in
down
▸ down(): Emitter
<true
>
Creates an emitter that emits at the moment the current value changes from falsy to truthy.
Returns
Emitter
<true
>
Inherited from
Defined in
filter
▸ filter(fn
): Emitter
<GamepadData
>
Filters events with the given predicate function
Parameters
Name | Type | Description |
---|---|---|
fn | (value : GamepadData ) => any | Return truthy value to pass events |
Returns
Emitter
<GamepadData
>
A new emitter
Inherited from
Defined in
filterMap
▸ filterMap<U
>(fn
, initialValue?
): Emitter
<U
>
Maps the current value to another type of value, and emits the mapped value only when the mapped value is not undefined
.
Type parameters
Name |
---|
U |
Parameters
Name | Type | Description |
---|---|---|
fn | (value : GamepadData ) => U | A function to map the current value. Return undefined to skip emitting. |
initialValue? | U | - |
Returns
Emitter
<U
>
Inherited from
Defined in
fold
▸ fold<U
>(fn
, initialState
): Emitter
<U
>
Initializes with an initialState
value. On each emitted event, calculates a new state based on the previous state and the current value, and emits this new state.
Type parameters
Name |
---|
U |
Parameters
Name | Type | Description |
---|---|---|
fn | (prev : U , value : GamepadData ) => U | A function to calculate a new state |
initialState | U | An initial state value |
Returns
Emitter
<U
>
A new emitter
Inherited from
Defined in
interval
▸ interval(ms?
, immediate?
): Emitter
<any
>
Creates an emitter that keeps to emit the last value of the current emitter at the specified interval.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
ms | number | 0 | The interval in milliseconds. Set 0 to use requestAnimationFrame . |
immediate | boolean | false | If set to false , the new emitter waits to emit until the current emitter emits any value. |
Returns
Emitter
<any
>
A new emitter.
Inherited from
Defined in
lerp
▸ lerp(lerp
, rate
, threshold?
): Emitter
<GamepadData
>
Smoothen the change rate of the input value.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
lerp | Lerp <GamepadData > | undefined | A function to interpolate the current value and the target value. |
rate | number | undefined | The ratio of linear interpolation from the current value to the target value with each update. |
threshold | number | 1e-4 | The threshold to determine whether the current value is close enough to the target value. If the difference between the current value and the target value is less than this value, the target value will be used as the current value and the interpolation will be stopped. |
Returns
Emitter
<GamepadData
>
A new emitter
Inherited from
Defined in
longPress
▸ longPress(wait
): Object
Parameters
Name | Type |
---|---|
wait | number |
Returns
Object
Name | Type |
---|---|
pressed | Emitter <unknown > |
Inherited from
Defined in
map
▸ map<U
>(fn
, initialValue?
): Emitter
<U
>
Transforms the payload of event with the given function.
Type parameters
Name |
---|
U |
Parameters
Name | Type | Description |
---|---|---|
fn | (value : GamepadData ) => U | A function to transform the payload |
initialValue? | U | - |
Returns
Emitter
<U
>
A new emitter
Inherited from
Defined in
not
▸ not(): Emitter
<boolean
>
Creates an emitter whose payload is negated.
Returns
Emitter
<boolean
>
Inherited from
Defined in
resetBy
▸ resetBy(emitter
, emitOnReset?
): Emitter
<GamepadData
>
Reset the state of current emitter emitter when the given event is fired.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
emitter | Emitter <any > | undefined | The emitter that triggers the current emitter to be reset. |
emitOnReset | boolean | true | If set to true , the current emitter will be triggered when it is reset. |
Returns
Emitter
<GamepadData
>
The current emitter emitter
Inherited from
Defined in
stash
▸ stash(...triggers
): Emitter
<any
>
Creates an emitter that emits the current value when one of the given events is fired.
Parameters
Name | Type | Description |
---|---|---|
...triggers | Emitter <any >[] | Emitters to trigger the current emitter to emit. |
Returns
Emitter
<any
>
A new emitter
Inherited from
Defined in
throttle
▸ throttle(wait
, options?
): Emitter
<GamepadData
>
Creates throttled version of the current emitter.
Parameters
Name | Type | Description |
---|---|---|
wait | number | Milliseconds to wait. |
options? | ThrottleSettings |
Returns
Emitter
<GamepadData
>
See
https://lodash.com/docs/4.17.15#debounced
Inherited from
Defined in
trail
▸ trail(count?
, emitAtCount?
): Emitter
<GamepadData
[]>
Emits an array caching a specified number of values that were emitted in the past.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
count | number | 2 | The number of cache frames. Set 0 to store caches infinitely. |
emitAtCount | boolean | true | When set to true , events will not be emitted until the count of cache reaches to count . |
Returns
Emitter
<GamepadData
[]>
Inherited from
Defined in
up
▸ up(): Emitter
<true
>
Creates an emitter that emits at the moment the current value changes from falsy to truthy.
Returns
Emitter
<true
>
Inherited from
Defined in
while
▸ while(emitter
, resetOnDown?
): Emitter
<GamepadData
>
Emits while the given event is truthy. The event will be also emitted when the given emitter is changed from falsy to truthy when the resetOnDown
flag is set to true.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
emitter | Emitter <boolean > | undefined | An emitter to filter the events |
resetOnDown | boolean | true | If set to true , the returned emitter will be reset when the given emitter is down. |
Returns
Emitter
<GamepadData
>
Inherited from
Defined in
Methods
connected
▸ connected(): Emitter
<boolean
>
Emits true
if there is at least one gamepad connected.
Returns
Emitter
<boolean
>
true
if there is at least one gamepad connected.
Defined in
createDerived
▸ createDerived<U
>(options
): Emitter
<U
>
Type parameters
Name |
---|
U |
Parameters
Name | Type |
---|---|
options | EmitterOptions <U > & { propagate : (e : GamepadData , emit : (v : U ) => void ) => void } |
Returns
Emitter
<U
>
Inherited from
Defined in
registerDerived
▸ registerDerived(emitter
, listener
): void
Parameters
Name | Type |
---|---|
emitter | Emitter <any > |
listener | Listener <GamepadData > |
Returns
void
Inherited from
Defined in
tween
▸ tween(lerp
, durationMs
): Emitter
<GamepadData
>
Parameters
Name | Type |
---|---|
lerp | Lerp <GamepadData > |
durationMs | number |
Returns
Emitter
<GamepadData
>
Inherited from
Defined in
Properties
_disposed
• Protected
_disposed: boolean
= false
Inherited from
Defined in
derivedEmitters
• Protected
Readonly
derivedEmitters: Map
<Emitter
<any
>, Listener
<GamepadData
>>
Stores all deviced events and their listeners. They will not be unregistered by removeAllListeners
.
Inherited from
Defined in
icon
• Optional
icon: IconSequence
Inherited from
Defined in
stateful
• get
stateful(): boolean
Returns true
if the emitter has a state and can be reset.
Returns
boolean
Inherited from
Emitter.stateful
Defined in
value
• get
value(): T
The latest value emitted from the emitter. If the emitter has never fired before, it just returns undefined
.
Returns
T
Inherited from
Emitter.value
Defined in
Accessors
disposed
• get
disposed(): boolean
Returns
boolean
Inherited from
Emitter.disposed
Defined in
Commom Filters
split
▸ split(emitter
, count
, resetOnSwitch?
): Emitter
<GamepadData
>[]
Splits the current emitter into multiple emitters. Each emitter emits only when the given emitter is changed to the corresponding index.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
emitter | Emitter <any > | undefined | An emitter to filter the current event |
count | number | undefined | The number of emitters to be created. |
resetOnSwitch | boolean | true | If set to true , the corresponding emitter will be reset when the index of current emitter is switched. |
Returns
Emitter
<GamepadData
>[]
Inherited from
Defined in
Event Handlers
dispose
▸ dispose(): void
Disposes the emitter immediately and prevent to emit any value in the future
Returns
void
Inherited from
Defined in
emit
▸ emit(value
): void
Manually emits the event.
Parameters
Name | Type |
---|---|
value | GamepadData |
Returns
void
Inherited from
Defined in
log
▸ log(message?
): GamepadEmitter
Parameters
Name | Type | Default value |
---|---|---|
message | string | 'Bndr' |
Returns
Inherited from
Defined in
off
▸ off(listener
): void
Removes the listener
function from the event.
Parameters
Name | Type |
---|---|
listener | Listener <GamepadData > |
Returns
void
Inherited from
Defined in
on
▸ on(listener
): GamepadEmitter
Adds the listener
function for the event.
Parameters
Name | Type | Description |
---|---|---|
listener | Listener <GamepadData > | The callback function |
Returns
Inherited from
Defined in
once
▸ once(listener
): void
Adds a one-time listener
function for the event
Parameters
Name | Type |
---|---|
listener | Listener <GamepadData > |
Returns
void
Inherited from
Defined in
removeAllListeners
▸ removeAllListeners(): void
Removes all listeners.
Returns
void
Inherited from
Defined in
reset
▸ reset(): void
Resets the state of the emitter.
Returns
void