Make Gamepad a real instance, not an abstract. Other fixes
This commit is contained in:
@@ -14,6 +14,7 @@ import lime.ui.Window;
|
|||||||
|
|
||||||
@:access(lime.app.Application)
|
@:access(lime.app.Application)
|
||||||
@:access(lime.graphics.Renderer)
|
@:access(lime.graphics.Renderer)
|
||||||
|
@:access(lime.ui.Gamepad)
|
||||||
|
|
||||||
|
|
||||||
class NativeApplication {
|
class NativeApplication {
|
||||||
@@ -116,25 +117,28 @@ class NativeApplication {
|
|||||||
|
|
||||||
case AXIS_MOVE:
|
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:
|
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:
|
case BUTTON_UP:
|
||||||
|
|
||||||
parent.window.onGamepadButtonUp.dispatch (gamepadEventInfo.id, gamepadEventInfo.button);
|
parent.window.onGamepadButtonUp.dispatch (Gamepad.devices.get (gamepadEventInfo.id), gamepadEventInfo.button);
|
||||||
|
|
||||||
case CONNECT:
|
case CONNECT:
|
||||||
|
|
||||||
Gamepad.devices.push (gamepadEventInfo.id);
|
var gamepad = new Gamepad (gamepadEventInfo.id);
|
||||||
parent.window.onGamepadConnect.dispatch (gamepadEventInfo.id);
|
Gamepad.devices.set (gamepadEventInfo.id, gamepad);
|
||||||
|
parent.window.onGamepadConnect.dispatch (gamepad);
|
||||||
|
|
||||||
case DISCONNECT:
|
case DISCONNECT:
|
||||||
|
|
||||||
|
var gamepad = Gamepad.devices.get (gamepadEventInfo.id);
|
||||||
|
if (gamepad != null) gamepad.connected = false;
|
||||||
Gamepad.devices.remove (gamepadEventInfo.id);
|
Gamepad.devices.remove (gamepadEventInfo.id);
|
||||||
parent.window.onGamepadDisconnect.dispatch (gamepadEventInfo.id);
|
parent.window.onGamepadDisconnect.dispatch (gamepad);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,13 +4,24 @@ package lime.ui;
|
|||||||
import lime.system.System;
|
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 guid (get, never):String;
|
||||||
|
public var id (default, null):Int;
|
||||||
public var name (get, never):String;
|
public var name (get, never):String;
|
||||||
|
public var player:Int;
|
||||||
|
|
||||||
|
|
||||||
|
public function new (id:Int) {
|
||||||
|
|
||||||
|
this.id = id;
|
||||||
|
connected = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,30 @@ package lime.ui;
|
|||||||
|
|
||||||
@:enum abstract GamepadAxis(Int) from Int to Int {
|
@:enum abstract GamepadAxis(Int) from Int to Int {
|
||||||
|
|
||||||
var LEFT_X = 1;
|
|
||||||
var LEFT_Y = 2;
|
var LEFT_X = 0;
|
||||||
var RIGHT_X = 3;
|
var LEFT_Y = 1;
|
||||||
var RIGHT_Y = 4;
|
var RIGHT_X = 2;
|
||||||
var TRIGGER_LEFT = 5;
|
var RIGHT_Y = 3;
|
||||||
var TRIGGER_RIGHT = 6;
|
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 + ")";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,20 +3,48 @@ package lime.ui;
|
|||||||
|
|
||||||
@:enum abstract GamepadButton(Int) from Int to Int {
|
@:enum abstract GamepadButton(Int) from Int to Int {
|
||||||
|
|
||||||
var A = 1;
|
|
||||||
var B = 2;
|
var A = 0;
|
||||||
var X = 3;
|
var B = 1;
|
||||||
var Y = 4;
|
var X = 2;
|
||||||
var BACK = 5;
|
var Y = 3;
|
||||||
var GUIDE = 6;
|
var BACK = 4;
|
||||||
var START = 7;
|
var GUIDE = 5;
|
||||||
var LEFT_STICK = 8;
|
var START = 6;
|
||||||
var RIGHT_STICK = 9;
|
var LEFT_STICK = 7;
|
||||||
var LEFT_SHOULDER = 10;
|
var RIGHT_STICK = 8;
|
||||||
var RIGHT_SHOULDER = 11;
|
var LEFT_SHOULDER = 9;
|
||||||
var DPAD_UP = 12;
|
var RIGHT_SHOULDER = 10;
|
||||||
var DPAD_DOWN = 13;
|
var DPAD_UP = 11;
|
||||||
var DPAD_LEFT = 14;
|
var DPAD_DOWN = 12;
|
||||||
var DPAD_RIGHT = 15;
|
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 + ")";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -210,7 +210,7 @@ namespace lime {
|
|||||||
|
|
||||||
case SDL_CONTROLLERAXISMOTION:
|
case SDL_CONTROLLERAXISMOTION:
|
||||||
|
|
||||||
gamepadEvent.type = BUTTON_UP;
|
gamepadEvent.type = AXIS_MOVE;
|
||||||
gamepadEvent.axis = event->caxis.axis;
|
gamepadEvent.axis = event->caxis.axis;
|
||||||
gamepadEvent.id = event->caxis.which;
|
gamepadEvent.id = event->caxis.which;
|
||||||
gamepadEvent.axisValue = event->caxis.value / 32768.0;
|
gamepadEvent.axisValue = event->caxis.value / 32768.0;
|
||||||
|
|||||||
@@ -2,48 +2,47 @@
|
|||||||
<project version="2">
|
<project version="2">
|
||||||
<!-- Output SWF options -->
|
<!-- Output SWF options -->
|
||||||
<output>
|
<output>
|
||||||
<movie outputType="Application" />
|
<movie outputType="CustomBuild" />
|
||||||
<movie input="" />
|
<movie input="" />
|
||||||
<movie path="project.xml" />
|
<movie path="project.xml" />
|
||||||
<movie fps="30" />
|
<movie fps="30" />
|
||||||
<movie width="800" />
|
<movie width="800" />
|
||||||
<movie height="600" />
|
<movie height="600" />
|
||||||
<movie version="3" />
|
<movie version="1" />
|
||||||
<movie minorVersion="0" />
|
<movie minorVersion="0" />
|
||||||
<movie platform="NME" />
|
<movie platform="Lime" />
|
||||||
<movie background="#FFFFFF" />
|
<movie background="#FFFFFF" />
|
||||||
<movie preferredSDK=";3;" />
|
<movie preferredSDK=";3;" />
|
||||||
</output>
|
</output>
|
||||||
<!-- Other classes to be compiled into your SWF -->
|
<!-- Other classes to be compiled into your SWF -->
|
||||||
<classpaths>
|
<classpaths>
|
||||||
|
<class path="d:\Development\Haxe\lime" />
|
||||||
<class path="Source" />
|
<class path="Source" />
|
||||||
|
<class path="Export\html5\haxe" />
|
||||||
</classpaths>
|
</classpaths>
|
||||||
<!-- Build options -->
|
<!-- Build options -->
|
||||||
<build>
|
<build>
|
||||||
<option directives="" />
|
<option directives="lime=2.1.3
tools=2.1.3
no-compilation
lime-html5
html5
web
html5
html" />
|
||||||
<option flashStrict="False" />
|
<option flashStrict="False" />
|
||||||
<option mainClass="Main" />
|
<option noInlineOnDebug="False" />
|
||||||
|
<option mainClass="ApplicationMain" />
|
||||||
<option enabledebug="False" />
|
<option enabledebug="False" />
|
||||||
<option additional="" />
|
<option additional="" />
|
||||||
</build>
|
</build>
|
||||||
<!-- haxelib libraries -->
|
<!-- haxelib libraries -->
|
||||||
<haxelib>
|
<haxelib>
|
||||||
<library name="openfl" />
|
<!-- example: <library name="..." /> -->
|
||||||
</haxelib>
|
</haxelib>
|
||||||
<!-- Class files to compile (other referenced classes will automatically be included) -->
|
<!-- Class files to compile (other referenced classes will automatically be included) -->
|
||||||
<compileTargets>
|
<compileTargets>
|
||||||
<!-- example: <compile path="..." /> -->
|
<!-- example: <compile path="..." /> -->
|
||||||
</compileTargets>
|
</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 -->
|
<!-- Paths to exclude from the Project Explorer tree -->
|
||||||
<hiddenPaths>
|
<hiddenPaths>
|
||||||
<!-- example: <hidden path="..." /> -->
|
<hidden path="obj" />
|
||||||
</hiddenPaths>
|
</hiddenPaths>
|
||||||
<!-- Executed before build -->
|
<!-- Executed before build -->
|
||||||
<preBuildCommand />
|
<preBuildCommand>"$(CompilerPath)/haxelib" run lime build "$(OutputFile)" $(TargetBuild) -$(BuildConfig) -Dfdb</preBuildCommand>
|
||||||
<!-- Executed after build -->
|
<!-- Executed after build -->
|
||||||
<postBuildCommand alwaysRun="False" />
|
<postBuildCommand alwaysRun="False" />
|
||||||
<!-- Other project options -->
|
<!-- Other project options -->
|
||||||
|
|||||||
Reference in New Issue
Block a user