Make Gamepad a real instance, not an abstract. Other fixes

This commit is contained in:
Joshua Granick
2015-03-18 09:45:55 -07:00
parent 128fe49f4f
commit 626c1009f1
6 changed files with 103 additions and 42 deletions

View File

@@ -14,6 +14,7 @@ import lime.ui.Window;
@:access(lime.app.Application)
@:access(lime.graphics.Renderer)
@:access(lime.ui.Gamepad)
class NativeApplication {
@@ -116,25 +117,28 @@ class NativeApplication {
case AXIS_MOVE:
parent.window.onGamepadAxisMove.dispatch (gamepadEventInfo.id, gamepadEventInfo.axis, gamepadEventInfo.value);
parent.window.onGamepadAxisMove.dispatch (Gamepad.devices.get (gamepadEventInfo.id), gamepadEventInfo.axis, gamepadEventInfo.value);
case BUTTON_DOWN:
parent.window.onGamepadButtonDown.dispatch (gamepadEventInfo.id, gamepadEventInfo.button);
parent.window.onGamepadButtonDown.dispatch (Gamepad.devices.get (gamepadEventInfo.id), gamepadEventInfo.button);
case BUTTON_UP:
parent.window.onGamepadButtonUp.dispatch (gamepadEventInfo.id, gamepadEventInfo.button);
parent.window.onGamepadButtonUp.dispatch (Gamepad.devices.get (gamepadEventInfo.id), gamepadEventInfo.button);
case CONNECT:
Gamepad.devices.push (gamepadEventInfo.id);
parent.window.onGamepadConnect.dispatch (gamepadEventInfo.id);
var gamepad = new Gamepad (gamepadEventInfo.id);
Gamepad.devices.set (gamepadEventInfo.id, gamepad);
parent.window.onGamepadConnect.dispatch (gamepad);
case DISCONNECT:
var gamepad = Gamepad.devices.get (gamepadEventInfo.id);
if (gamepad != null) gamepad.connected = false;
Gamepad.devices.remove (gamepadEventInfo.id);
parent.window.onGamepadDisconnect.dispatch (gamepadEventInfo.id);
parent.window.onGamepadDisconnect.dispatch (gamepad);
}

View File

@@ -4,13 +4,24 @@ package lime.ui;
import lime.system.System;
abstract Gamepad(Int) from Int to Int {
class Gamepad {
public static var devices = new Array<Gamepad> ();
public static var devices = new Map<Int, Gamepad> ();
public var connected (default, null):Bool;
public var guid (get, never):String;
public var id (default, null):Int;
public var name (get, never):String;
public var player:Int;
public function new (id:Int) {
this.id = id;
connected = true;
}

View File

@@ -3,11 +3,30 @@ package lime.ui;
@:enum abstract GamepadAxis(Int) from Int to Int {
var LEFT_X = 1;
var LEFT_Y = 2;
var RIGHT_X = 3;
var RIGHT_Y = 4;
var TRIGGER_LEFT = 5;
var TRIGGER_RIGHT = 6;
var LEFT_X = 0;
var LEFT_Y = 1;
var RIGHT_X = 2;
var RIGHT_Y = 3;
var TRIGGER_LEFT = 4;
var TRIGGER_RIGHT = 5;
public inline function toString ():String {
return switch (this) {
case LEFT_X: "LEFT_X";
case LEFT_Y: "LEFT_Y";
case RIGHT_X: "RIGHT_X";
case RIGHT_Y: "RIGHT_Y";
case TRIGGER_LEFT: "TRIGGER_LEFT";
case TRIGGER_RIGHT: "TRIGGER_RIGHT";
default: "UNKNOWN (" + this + ")";
}
}
}

View File

@@ -3,20 +3,48 @@ package lime.ui;
@:enum abstract GamepadButton(Int) from Int to Int {
var A = 1;
var B = 2;
var X = 3;
var Y = 4;
var BACK = 5;
var GUIDE = 6;
var START = 7;
var LEFT_STICK = 8;
var RIGHT_STICK = 9;
var LEFT_SHOULDER = 10;
var RIGHT_SHOULDER = 11;
var DPAD_UP = 12;
var DPAD_DOWN = 13;
var DPAD_LEFT = 14;
var DPAD_RIGHT = 15;
var A = 0;
var B = 1;
var X = 2;
var Y = 3;
var BACK = 4;
var GUIDE = 5;
var START = 6;
var LEFT_STICK = 7;
var RIGHT_STICK = 8;
var LEFT_SHOULDER = 9;
var RIGHT_SHOULDER = 10;
var DPAD_UP = 11;
var DPAD_DOWN = 12;
var DPAD_LEFT = 13;
var DPAD_RIGHT = 14;
public inline function toString ():String {
return switch (this) {
case A: "A";
case B: "B";
case X: "X";
case Y: "Y";
case BACK: "BACK";
case GUIDE: "GUIDE";
case START: "START";
case LEFT_STICK: "LEFT_STICK";
case RIGHT_STICK: "RIGHT_STICK";
case LEFT_SHOULDER: "LEFT_SHOULDER";
case RIGHT_SHOULDER: "RIGHT_SHOULDER";
case DPAD_UP: "DPAD_UP";
case DPAD_DOWN: "DPAD_DOWN";
case DPAD_LEFT: "DPAD_LEFT";
case DPAD_RIGHT: "DPAD_RIGHT";
default: "UNKNOWN (" + this + ")";
}
}
}

View File

@@ -210,7 +210,7 @@ namespace lime {
case SDL_CONTROLLERAXISMOTION:
gamepadEvent.type = BUTTON_UP;
gamepadEvent.type = AXIS_MOVE;
gamepadEvent.axis = event->caxis.axis;
gamepadEvent.id = event->caxis.which;
gamepadEvent.axisValue = event->caxis.value / 32768.0;

View File

@@ -2,48 +2,47 @@
<project version="2">
<!-- Output SWF options -->
<output>
<movie outputType="Application" />
<movie outputType="CustomBuild" />
<movie input="" />
<movie path="project.xml" />
<movie fps="30" />
<movie width="800" />
<movie height="600" />
<movie version="3" />
<movie version="1" />
<movie minorVersion="0" />
<movie platform="NME" />
<movie platform="Lime" />
<movie background="#FFFFFF" />
<movie preferredSDK=";3;" />
</output>
<!-- Other classes to be compiled into your SWF -->
<classpaths>
<class path="d:\Development\Haxe\lime" />
<class path="Source" />
<class path="Export\html5\haxe" />
</classpaths>
<!-- Build options -->
<build>
<option directives="" />
<option directives="lime=2.1.3&#xA;tools=2.1.3&#xA;no-compilation&#xA;lime-html5&#xA;html5&#xA;web&#xA;html5&#xA;html" />
<option flashStrict="False" />
<option mainClass="Main" />
<option noInlineOnDebug="False" />
<option mainClass="ApplicationMain" />
<option enabledebug="False" />
<option additional="" />
</build>
<!-- haxelib libraries -->
<haxelib>
<library name="openfl" />
<!-- example: <library name="..." /> -->
</haxelib>
<!-- Class files to compile (other referenced classes will automatically be included) -->
<compileTargets>
<!-- example: <compile path="..." /> -->
</compileTargets>
<!-- Assets to embed into the output SWF -->
<library>
<!-- example: <asset path="..." id="..." update="..." glyphs="..." mode="..." place="..." sharepoint="..." /> -->
</library>
<!-- Paths to exclude from the Project Explorer tree -->
<hiddenPaths>
<!-- example: <hidden path="..." /> -->
<hidden path="obj" />
</hiddenPaths>
<!-- Executed before build -->
<preBuildCommand />
<preBuildCommand>"$(CompilerPath)/haxelib" run lime build "$(OutputFile)" $(TargetBuild) -$(BuildConfig) -Dfdb</preBuildCommand>
<!-- Executed after build -->
<postBuildCommand alwaysRun="False" />
<!-- Other project options -->