-
Notifications
You must be signed in to change notification settings - Fork 1
/
PlayerSettings.hx
89 lines (73 loc) · 1.88 KB
/
PlayerSettings.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package;
import Controls;
import flixel.FlxCamera;
import flixel.FlxG;
import flixel.util.FlxSignal;
// import ui.DeviceManager;
// import props.Player;
class PlayerSettings
{
static public var numPlayers(default, null) = 0;
static public var numAvatars(default, null) = 0;
static public var player1(default, null):PlayerSettings;
static public var player2(default, null):PlayerSettings;
#if (haxe >= "4.0.0")
static public final onAvatarAdd = new FlxTypedSignal<PlayerSettings->Void>();
static public final onAvatarRemove = new FlxTypedSignal<PlayerSettings->Void>();
#else
static public var onAvatarAdd = new FlxTypedSignal<PlayerSettings->Void>();
static public var onAvatarRemove = new FlxTypedSignal<PlayerSettings->Void>();
#end
public var id(default, null):Int;
#if (haxe >= "4.0.0")
public final controls:Controls;
#else
public var controls:Controls;
#end
// public var avatar:Player;
// public var camera(get, never):PlayCamera;
function new(id, scheme)
{
this.id = id;
this.controls = new Controls('player$id', scheme);
}
public function setKeyboardScheme(scheme)
{
controls.setKeyboardScheme(scheme);
}
static public function init():Void
{
if (player1 == null)
{
player1 = new PlayerSettings(0, Solo);
++numPlayers;
}
var numGamepads = FlxG.gamepads.numActiveGamepads;
if (numGamepads > 0)
{
var gamepad = FlxG.gamepads.getByID(0);
if (gamepad == null)
throw 'Unexpected null gamepad. id:0';
player1.controls.addDefaultGamepad(0);
}
if (numGamepads > 1)
{
if (player2 == null)
{
player2 = new PlayerSettings(1, None);
++numPlayers;
}
var gamepad = FlxG.gamepads.getByID(1);
if (gamepad == null)
throw 'Unexpected null gamepad. id:0';
player2.controls.addDefaultGamepad(1);
}
// DeviceManager.init();
}
static public function reset()
{
player1 = null;
player2 = null;
numPlayers = 0;
}
}