moon add Milky2018/gamepadmoon test --target native
moon run --target native///|
test "quick start" {
let gil = Gil::new()
while true {
match gil.next_event() {
None => break
Some(ev) => ...
}
}
}///|
test "mock button press" {
let gil = GilBuilder::new()
.with_mock_gamepad_count(1)
.with_default_filters(false)
.build()
let id = @gamepad.GamepadId(0)
gil.insert_event(Event::at(id, ButtonPressed(South, BTN_SOUTH), 0L))
assert_true(gil.next_event() is Some(_))
}type GilErrortype MappingErrortype ParserErrorpub(all) enum Axis {
LeftStickX
LeftStickY
LeftZ
RightStickX
RightStickY
RightZ
DPadX
DPadY
Unknown
}pub struct AxisData {
last_event_ts : Int64
last_event_c : Int64
value : Double
}pub struct AxisInfo {
min : Int
max : Int
deadzone : Int?
}pub(all) enum Button {
South
East
C
North
West
Z
LeftTrigger
RightTrigger
LeftTrigger2
RightTrigger2
Select
Start
Mode
LeftThumb
RightThumb
DPadUp
DPadDown
DPadLeft
DPadRight
Unknown
}pub struct ButtonData {
last_event_ts : Int64
counter : Int64
value : Double
is_pressed : Bool
is_repeating : Bool
}pub enum DistanceModel {
None
Linear(ref_distance~ : Double, rolloff_factor~ : Double, max_distance~ : Double)
LinearClamped(ref_distance~ : Double, rolloff_factor~ : Double, max_distance~ : Double)
Inverse(ref_distance~ : Double, rolloff_factor~ : Double)
InverseClamped(ref_distance~ : Double, rolloff_factor~ : Double, max_distance~ : Double)
Exponential(ref_distance~ : Double, rolloff_factor~ : Double)
ExponentialClamped(ref_distance~ : Double, rolloff_factor~ : Double, max_distance~ : Double)
}pub struct Effect {
gil : Gil
effect_token : Int
gamepads : Array[GamepadId]
strong : Double
weak : Double
duration_ms : Int64
base_effects : Array[BaseEffect]
repeat_mode : FfRepeat
distance_model : DistanceModel
position : (Double, Double, Double)
gain : Double
playing_since_ms : Int64?
}pub struct EffectBuilder {
gamepads : Array[GamepadId]
base_effects : Array[BaseEffect]
repeat_mode : FfRepeat
distance_model : DistanceModel
position : (Double, Double, Double)
gain : Double
strong : Double
weak : Double
duration_ms : Int64
}fn EffectBuilder::position(self : EffectBuilder, position : (Double, Double, Double)) -> EffectBuilderpub struct Envelope {
attack_length : Int
attack_level : Double
fade_length : Int
fade_level : Double
}pub struct GamepadData {
state : GamepadState
connected : Bool
mapping : Mapping
name : String
uuid : Uuid
vendor_id : Int?
product_id : Int?
ff_supported : Bool
listener_position : (Double, Double, Double)
power_info : PowerInfo
axes : Array[Int]
buttons : Array[Int]
axis_info : Array[(Int, AxisInfo)]
deadzones : Array[(Int, Double)]
have_sent_nonzero_for_axis : Array[Bool]
}pub struct GamepadId {
value : Int
}pub struct Gil {
counter : Int64
update_state : Bool
default_filters : Bool
axis_to_btn_pressed : Double
axis_to_btn_released : Double
events : Array[Event]
events_head : Int
gamepads_data : Array[GamepadData]
mappings : MappingDb
now_ms : Int64
next_effect_token : Int
ff_tick_base_ms : Int64
ff_tick : Int
ff_dirty : Bool
ff_effects : Array[FfEffectSource]
ff_events : Array[Event]
ff_events_head : Int
backend : NativeBackend?
}fn Gil::set_mapping_data(self : Gil, id : GamepadId, mapping_data : MappingData, name? : String?) -> String raise MappingErrorfn Gil::set_mapping_data_strict(self : Gil, id : GamepadId, mapping_data : MappingData, name? : String?) -> String raise MappingErrorpub struct GilBuilder {
update_state : Bool
default_filters : Bool
axis_to_btn_pressed : Double
axis_to_btn_released : Double
env_mappings : Bool
included_mappings : Bool
mock_gamepad_count : Int
use_native_backend : Bool
mapping_inputs : Array[String]
}fn GilBuilder::set_axis_to_btn(self : GilBuilder, pressed : Double, released : Double) -> GilBuilderpub struct Jitter {
threshold : Double
}fn Mapping::from_data(data : MappingData, buttons : Array[Int], axes : Array[Int], name : String, uuid : Uuid) -> (Mapping, String) raise MappingErrorfn Mapping::parse_sdl_mapping(line : String, buttons : Array[Int], axes : Array[Int]) -> Mapping raise ParseSdlMappingErrorfn NativeBackend::set_rumble(self : NativeBackend, id : Int, strong : Double, weak : Double, duration_ms : Int) -> Boolpub(all) enum NativeEventTag {
Connected
Disconnected
ButtonPressed
ButtonReleased
AxisChanged
ButtonChanged
}pub(all) enum ParserErrorKind {
InvalidGuid
InvalidKeyValPair
InvalidValue
EmptyValue
UnknownAxis
UnknownButton
InvalidParserState
UnexpectedEnd
}pub struct Repeat {
after_ms : Int64
every_ms : Int64
}pub struct Replay {
after : Int
play_for : Int
with_delay : Int
}pub struct Ticks {
ms : Int64
}pub struct Uuid {
simple : String
}