-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNPCInputManager.gd
267 lines (222 loc) · 12.8 KB
/
NPCInputManager.gd
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
extends "res://input_manager.gd"
signal initiated
var cmd = null
const BTN_PRESSED_MAP_IX=0
const BTN_HOLD_MAP_IX=1
const BTN_RELEASED_MAP_IX=2
enum Behavior{
SPAM, # a command is spammed every frame
CONTROL_2ND_CONTROLLER, # another player controls npc with a 2nd controller
CONTROL_MAIN_CONTROLLER, #give up control on your character and control np
MIRROR_INPUT, #the main player controls both characeters asynchronously (facing will affect heros differently)
MIRROR_COMMAND #the main player controls both characeters Synchronously (facing DOESN'T affect heros differently),
}
var behavior = Behavior.SPAM
var btnCmdReverseMap ={}
var controller1InputDevice = null #the controller controlling opponent player
var controller2InputDevice = null #the controller controlling training bot that controls this kinmeatic body
#used by training mode recording inputs
var recInputJustPressedBitMap=0
var recInputHoldingBitMap=0
var recInputReleasedBitMap=0
var playingInputRecording = false #true means recInputJustPressedBitMap,recInputHoldingBitMap, recInputReleasedBitMap used a button bot input
func init(flag=true):
.init(flag)
playingInputRecording = false
#[PRESS,HOLD,RELEASE]
btnCmdReverseMap[null]=[0,0,0]
btnCmdReverseMap[Command.CMD_JUMP]=[BTN_A,0,0]
btnCmdReverseMap[Command.CMD_JUMP_FORWARD]=[BTN_A,BTN_RIGHT,0]
btnCmdReverseMap[Command.CMD_JUMP_BACKWARD]=[BTN_A,BTN_LEFT,0]
btnCmdReverseMap[Command.CMD_NEUTRAL_MELEE]=[BTN_X,0,0]
btnCmdReverseMap[Command.CMD_BACKWARD_MELEE]=[BTN_X,BTN_LEFT,0]
btnCmdReverseMap[Command.CMD_FORWARD_MELEE]=[BTN_X ,BTN_RIGHT,0]
btnCmdReverseMap[Command.CMD_DOWNWARD_MELEE]=[BTN_X ,BTN_DOWN,0]
btnCmdReverseMap[Command.CMD_UPWARD_MELEE]=[BTN_X ,BTN_UP,0]
btnCmdReverseMap[Command.CMD_NEUTRAL_SPECIAL]=[BTN_Y ,0,0]
btnCmdReverseMap[Command.CMD_BACKWARD_SPECIAL]=[BTN_Y,BTN_LEFT,0]
btnCmdReverseMap[Command.CMD_FORWARD_SPECIAL]=[BTN_Y ,BTN_RIGHT,0]
btnCmdReverseMap[Command.CMD_DOWNWARD_SPECIAL]=[BTN_Y ,BTN_DOWN,0]
btnCmdReverseMap[Command.CMD_UPWARD_SPECIAL]=[BTN_Y ,BTN_UP,0]
btnCmdReverseMap[Command.CMD_NEUTRAL_TOOL]=[BTN_B,0,0]
btnCmdReverseMap[Command.CMD_BACKWARD_TOOL]=[BTN_B ,BTN_LEFT,0]
btnCmdReverseMap[Command.CMD_FORWARD_TOOL]=[BTN_B ,BTN_RIGHT,0]
btnCmdReverseMap[Command.CMD_DOWNWARD_TOOL]=[BTN_B ,BTN_DOWN,0]
btnCmdReverseMap[Command.CMD_UPWARD_TOOL]=[BTN_B ,BTN_UP,0]
btnCmdReverseMap[Command.CMD_MOVE_FORWARD]=[BTN_RIGHT,0,0]
btnCmdReverseMap[Command.CMD_MOVE_BACKWARD]=[BTN_LEFT,0,0]
btnCmdReverseMap[Command.CMD_STOP_MOVE_FORWARD]=[0,0,BTN_RIGHT]
btnCmdReverseMap[Command.CMD_STOP_MOVE_BACKWARD]=[0,0,BTN_LEFT]
btnCmdReverseMap[Command.CMD_DASH_FORWARD]=[BTN_RIGHT_TRIGGER,BTN_RIGHT,0]
btnCmdReverseMap[Command.CMD_DASH_BACKWARD]=[BTN_RIGHT_TRIGGER,BTN_LEFT,0]
btnCmdReverseMap[Command.CMD_CROUCH]=[BTN_DOWN,0,0]
btnCmdReverseMap[Command.CMD_STOP_CROUCH]=[0,0,BTN_DOWN]
btnCmdReverseMap[Command.CMD_AIR_DASH_DOWNWARD]=[BTN_RIGHT_TRIGGER,BTN_DOWN,0]
btnCmdReverseMap[Command.CMD_START]=[BTN_START,0,0]
btnCmdReverseMap[Command.CMD_AUTO_RIPOST]=[BTN_LEFT_TRIGGER|BTN_RIGHT_BUMPER,0,0]
btnCmdReverseMap[Command.CMD_GRAB]=[BTN_LEFT_BUMPER,0,0]
btnCmdReverseMap[Command.CMD_RIPOST_NEUTRAL_MELEE]=[BTN_RIGHT_BUMPER|BTN_X,0,0]
btnCmdReverseMap[Command.CMD_RIPOST_NEUTRAL_SPECIAL]=[BTN_RIGHT_BUMPER|BTN_Y,0,0]
btnCmdReverseMap[Command.CMD_RIPOST_NEUTRAL_TOOL]=[BTN_RIGHT_BUMPER|BTN_B,0,0]
btnCmdReverseMap[Command.CMD_RIPOST_BACKWARD_SPECIAL]=[BTN_RIGHT_BUMPER|BTN_Y,BTN_LEFT,0]
btnCmdReverseMap[Command.CMD_RIPOST_FORWARD_SPECIAL]=[BTN_RIGHT_BUMPER|BTN_Y,BTN_RIGHT,0]
btnCmdReverseMap[Command.CMD_RIPOST_DOWNWARD_SPECIAL]=[BTN_RIGHT_BUMPER|BTN_Y,BTN_DOWN,0]
btnCmdReverseMap[Command.CMD_RIPOST_UPWARD_SPECIAL]=[BTN_RIGHT_BUMPER|BTN_Y,BTN_UP,0]
btnCmdReverseMap[Command.CMD_RIPOST_BACKWARD_MELEE]=[BTN_RIGHT_BUMPER|BTN_X,BTN_LEFT,0]
btnCmdReverseMap[Command.CMD_RIPOST_FORWARD_MELEE]=[BTN_RIGHT_BUMPER|BTN_X,BTN_RIGHT,0]
btnCmdReverseMap[Command.CMD_RIPOST_DOWNWARD_MELEE]=[BTN_RIGHT_BUMPER|BTN_X,BTN_DOWN,0]
btnCmdReverseMap[Command.CMD_RIPOST_UPWARD_MELEE]=[BTN_RIGHT_BUMPER|BTN_X,BTN_UP,0]
btnCmdReverseMap[Command.CMD_RIPOST_BACKWARD_TOOL]=[BTN_RIGHT_BUMPER|BTN_B,BTN_LEFT,0]
btnCmdReverseMap[Command.CMD_RIPOST_FORWARD_TOOL]=[BTN_RIGHT_BUMPER|BTN_B,BTN_RIGHT,0]
btnCmdReverseMap[Command.CMD_RIPOST_DOWNWARD_TOOL]=[BTN_RIGHT_BUMPER|BTN_B,BTN_DOWN,0]
btnCmdReverseMap[Command.CMD_RIPOST_UPWARD_TOOL]=[BTN_RIGHT_BUMPER|BTN_B,BTN_UP,0]
btnCmdReverseMap[Command.CMD_ABILITY_BAR_CANCEL_NEXT_MOVE]=[BTN_LEFT_TRIGGER,0,0]
btnCmdReverseMap[Command.CMD_COUNTER_RIPOST_NEUTRAL_MELEE]=[BTN_LEFT_BUMPER|BTN_RIGHT_BUMPER|BTN_X,0,0]
btnCmdReverseMap[Command.CMD_COUNTER_RIPOST_NEUTRAL_SPECIAL]=[BTN_LEFT_BUMPER|BTN_RIGHT_BUMPER|BTN_Y,0,0]
btnCmdReverseMap[Command.CMD_COUNTER_RIPOST_NEUTRAL_TOOL]=[BTN_LEFT_BUMPER|BTN_RIGHT_BUMPER|BTN_B,0,0]
btnCmdReverseMap[Command.CMD_COUNTER_RIPOST_BACKWARD_SPECIAL]=[BTN_LEFT_BUMPER|BTN_RIGHT_BUMPER|BTN_Y,BTN_LEFT,0]
btnCmdReverseMap[Command.CMD_COUNTER_RIPOST_FORWARD_SPECIAL]=[BTN_LEFT_BUMPER|BTN_RIGHT_BUMPER|BTN_Y,BTN_RIGHT,0]
btnCmdReverseMap[Command.CMD_COUNTER_RIPOST_DOWNWARD_SPECIAL]=[BTN_LEFT_BUMPER|BTN_RIGHT_BUMPER|BTN_Y,BTN_DOWN,0]
btnCmdReverseMap[Command.CMD_COUNTER_RIPOST_UPWARD_SPECIAL]=[BTN_LEFT_BUMPER|BTN_RIGHT_BUMPER|BTN_Y,BTN_UP,0]
btnCmdReverseMap[Command.CMD_COUNTER_RIPOST_BACKWARD_MELEE]=[BTN_LEFT_BUMPER|BTN_RIGHT_BUMPER|BTN_X,BTN_LEFT,0]
btnCmdReverseMap[Command.CMD_COUNTER_RIPOST_FORWARD_MELEE]=[BTN_LEFT_BUMPER|BTN_RIGHT_BUMPER|BTN_X,BTN_RIGHT,0]
btnCmdReverseMap[Command.CMD_COUNTER_RIPOST_DOWNWARD_MELEE]=[BTN_LEFT_BUMPER|BTN_RIGHT_BUMPER|BTN_X,BTN_DOWN,0]
btnCmdReverseMap[Command.CMD_COUNTER_RIPOST_UPWARD_MELEE]=[BTN_LEFT_BUMPER|BTN_RIGHT_BUMPER|BTN_X,BTN_UP,0]
btnCmdReverseMap[Command.CMD_COUNTER_RIPOST_BACKWARD_TOOL]=[BTN_LEFT_BUMPER|BTN_RIGHT_BUMPER|BTN_B,BTN_LEFT,0]
btnCmdReverseMap[Command.CMD_COUNTER_RIPOST_FORWARD_TOOL]=[BTN_LEFT_BUMPER|BTN_RIGHT_BUMPER|BTN_B,BTN_RIGHT,0]
btnCmdReverseMap[Command.CMD_COUNTER_RIPOST_DOWNWARD_TOOL]=[BTN_LEFT_BUMPER|BTN_RIGHT_BUMPER|BTN_B,BTN_DOWN,0]
btnCmdReverseMap[Command.CMD_COUNTER_RIPOST_UPWARD_TOOL]=[BTN_LEFT_BUMPER|BTN_RIGHT_BUMPER|BTN_B,BTN_UP,0]
btnCmdReverseMap[Command.CMD_FORWARD_CROUCH]=[0,BTN_RIGHT|BTN_DOWN,0]
btnCmdReverseMap[Command.CMD_BACKWARD_CROUCH]=[0,BTN_LEFT|BTN_DOWN,0]
btnCmdReverseMap[Command.CMD_DASH_FORWARD_NO_DIRECTIONAL_INPUT]=[BTN_RIGHT_TRIGGER,0,0]
btnCmdReverseMap[Command.CMD_FORWARD_UP]=[0,BTN_RIGHT|BTN_UP,0]
btnCmdReverseMap[Command.CMD_BACKWARD_UP]=[0,BTN_LEFT|BTN_UP,0]
btnCmdReverseMap[Command.CMD_UP]=[0,BTN_UP,0]
btnCmdReverseMap[Command.CMD_BACKWARD_CROUCH_PUSH_BLOCK]=[BTN_LEFT_TRIGGER,BTN_LEFT|BTN_DOWN,0]
btnCmdReverseMap[Command.CMD_BACKWARD_UP_PUSH_BLOCK]=[BTN_LEFT_TRIGGER,BTN_LEFT|BTN_UP,0]
btnCmdReverseMap[Command.CMD_BACKWARD_PUSH_BLOCK]=[BTN_LEFT_TRIGGER,BTN_LEFT,0]
btnCmdReverseMap[Command.CMD_FORWARD_CROUCH_PUSH_BLOCK]=[BTN_LEFT_TRIGGER,BTN_RIGHT|BTN_DOWN,0]
btnCmdReverseMap[Command.CMD_FORWARD_UP_PUSH_BLOCK]=[BTN_LEFT_TRIGGER,BTN_UP|BTN_RIGHT,0]
btnCmdReverseMap[Command.CMD_FORWARD_PUSH_BLOCK]=[BTN_LEFT_TRIGGER,BTN_RIGHT,0]
btnCmdReverseMap[Command.CMD_BUFFERED_PUSH_BLOCK]=[BTN_LEFT_TRIGGER,0,0]
#testButtonMapping()
emit_signal("initiated")
func testButtonMapping():
var success = true
for _cmdKey in btnCmdReverseMap.keys():
#don't allow CMD_BUFFERED_PUSH_BLOCK as a command. We leave it to the playercontroller to buffer it in
#when they see ability cancel
if _cmdKey ==Command.CMD_BUFFERED_PUSH_BLOCK:
_cmdKey =Command.CMD_ABILITY_BAR_CANCEL_NEXT_MOVE
cmd =_cmdKey
#var remappedInputs = btnCmdReverseMap[_cmdKey]
#var inputJustPressedBitMap=remappedInputs[BTN_PRESSED_MAP_IX]
#var inputHoldingBitMap=remappedInputs[BTN_HOLD_MAP_IX]
#var inputReleasedBitMap=remappedInputs[BTN_RELEASED_MAP_IX]
var actualCmd = processInput(0,0,0)
if actualCmd !=_cmdKey:
success=false
var valsMap = Command.keys()
print("failed for command. Expected "+str(valsMap[_cmdKey])+" but was "+str(valsMap[actualCmd]))
reset()
print("testing the npc input bunttons reverse mapping. Success?: "+str(success))
#func handleInputSignaling(inputJustPressedBitMap,inputHoldingBitMap,inputReleasedBitMap):
# if behavior != Behavior.SPAM:
#
# #we process input as usual when not controlling command via scrip
# handleInputSignaling(inputJustPressedBitMap,inputHoldingBitMap,inputReleasedBitMap)
# else:
#gotta convert command to button
# var remappedInputs = btnCmdReverseMap[cmd]
# emit_signal("input_update",remappedInputs[BTN_PRESSED_MAP_IX],remappedInputs[BTN_HOLD_MAP_IX],remappedInputs[BTN_RELEASED_MAP_IX])
func processInput(inputJustPressedBitMap,inputHoldingBitMap,inputReleasedBitMap):
var spamBehaviorFlag =false
match(behavior):
Behavior.SPAM:
spamBehaviorFlag=true
Behavior.CONTROL_2ND_CONTROLLER:
if controller2InputDevice != null:
self.inputDeviceId = controller2InputDevice#this will make next call to processInput have correct buttons
else:
spamBehaviorFlag=true #spam behavior, since controller input device not specified
Behavior.CONTROL_MAIN_CONTROLLER:
if controller1InputDevice != null:
self.inputDeviceId = controller1InputDevice #this will make next call to processInput have correct buttons
else:
spamBehaviorFlag=true #spam behavior, since controller input device not specified
Behavior.MIRROR_INPUT:
if controller1InputDevice != null:
self.inputDeviceId = controller1InputDevice #this will make next call to processInput have correct buttons
else:
spamBehaviorFlag=true #spam behavior, since controller input device not specified
Behavior.MIRROR_COMMAND:
if controller1InputDevice != null:
self.inputDeviceId = controller1InputDevice #this will make next call to processInput have correct buttons
else:
spamBehaviorFlag=true #spam behavior, since controller input device not specified
#were not playing a training mode recording
if not playingInputRecording:
#we need to convert the given command to button presses
if spamBehaviorFlag:
#don't allow CMD_BUFFERED_PUSH_BLOCK as a command. We leave it to the playercontroller to buffer it in
#when they see ability cancel
if cmd ==Command.CMD_BUFFERED_PUSH_BLOCK:
cmd =Command.CMD_ABILITY_BAR_CANCEL_NEXT_MOVE
if btnCmdReverseMap.has(cmd):
var remappedInputs = btnCmdReverseMap[cmd]
inputJustPressedBitMap=remappedInputs[BTN_PRESSED_MAP_IX]
inputHoldingBitMap=remappedInputs[BTN_HOLD_MAP_IX]
inputReleasedBitMap=remappedInputs[BTN_RELEASED_MAP_IX]
else:
inputJustPressedBitMap=0
inputHoldingBitMap=0
inputReleasedBitMap=0
else:
pass
else:
inputJustPressedBitMap = recInputJustPressedBitMap
inputHoldingBitMap = recInputHoldingBitMap
inputReleasedBitMap = recInputReleasedBitMap
return .processInput(inputJustPressedBitMap,inputHoldingBitMap,inputReleasedBitMap)
#func parseCommand(inputJustPressedBitMap,inputHoldingBitMap, inputReleasedBitMap):
#lastDI = parseDirectionalInput(inputJustPressedBitMap,inputHoldingBitMap)
# match(behavior):
# Behavior.SPAM:
# return cmd
# Behavior.CONTROL_2ND_CONTROLLER:
# if controller2InputDevice != null:
# self.inputDeviceId = controller2InputDevice
# return .parseCommand(inputJustPressedBitMap,inputHoldingBitMap, inputReleasedBitMap)
# else:
# return cmd #spam behavior, since controller input device not specified
# Behavior.CONTROL_MAIN_CONTROLLER:
# if controller1InputDevice != null:
# self.inputDeviceId = controller1InputDevice
# return .parseCommand(inputJustPressedBitMap,inputHoldingBitMap, inputReleasedBitMap)
# else:
# return cmd #spam behavior, since controller input device not specified
# Behavior.MIRROR_INPUT:
# if controller1InputDevice != null:
# self.inputDeviceId = controller1InputDevice
# return .parseCommand(inputJustPressedBitMap,inputHoldingBitMap, inputReleasedBitMap)
# else:
# return cmd #spam behavior, since controller input device not specified
# Behavior.MIRROR_COMMAND:
# if controller1InputDevice != null:
# self.inputDeviceId = controller1InputDevice
# return .parseCommand(inputJustPressedBitMap,inputHoldingBitMap, inputReleasedBitMap)
# else:
# return cmd #spam behavior, since controller input device not specified
#returns the command appropriate depending on given facing and command
#paras: cmd: command used to find appropriate mirrored command
#params: facingRight: fflag that is true when facing right, and false otherwise
func getFacingDependantCommand(cmd, facingRight):
#when mirroring a command, make sure the facing of both characters will be intepreted same
if behavior == Behavior.MIRROR_COMMAND:
return .getFacingDependantCommand(cmd, not facingRight)
else:
return .getFacingDependantCommand(cmd, facingRight)
func reset():
.reset()
#just to make sure no input
cmd = null