42 lines
1.0 KiB
Haxe
42 lines
1.0 KiB
Haxe
package ca.wegetsignal.nativeextensions;
|
|
|
|
class MacJoystick
|
|
{
|
|
public var id:Int=-1;
|
|
|
|
public var axes:Array<Float>;
|
|
public var buttons:Array<Bool>;
|
|
|
|
public function new(id:Int,numAxes:Int,numButtons:Int)
|
|
{
|
|
this.id=id;
|
|
this.axes=new Array<Float>(numAxes);
|
|
this.buttons=new Array<Bool>(numButtons);
|
|
}
|
|
|
|
/** Returns the value for axis at index between -1 and 1
|
|
* Returns 0 for invalid axis index queries */
|
|
public function getAxis(index:Int=0):Float {
|
|
if(index<0 || index>=axes.length)
|
|
return 0;
|
|
return axes[index];
|
|
}
|
|
|
|
/** Returns true if the button is on, false if released.
|
|
* Returns false if button index is out of valid range */
|
|
public function getButton(index:Int=0):Bool {
|
|
if(index<0 || index>=buttons.length)
|
|
return false;
|
|
return buttons[index];
|
|
}
|
|
|
|
private function updateAxes(params:Array):Void {
|
|
// first param is this joystick id.. or should be..
|
|
if(params[0] !=id)
|
|
throw new Dynamic("Invalid joystick ID for Axes update");
|
|
|
|
for(i in 1...params.lengthi){
|
|
axes[i-1]=Std.parseFloat(params[i]);
|
|
}
|
|
}
|
|
} |