Skip to content

Commit

Permalink
Lutro compat
Browse files Browse the repository at this point in the history
  • Loading branch information
kivutar committed Oct 7, 2022
1 parent 0827c97 commit 0fa704c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions input/binds_keyboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var keyBinds = map[glfw.Key]uint32{
glfw.KeyRight: libretro.DeviceIDJoypadRight,
glfw.KeyEnter: libretro.DeviceIDJoypadStart,
glfw.KeyRightShift: libretro.DeviceIDJoypadSelect,
glfw.KeyTab: ActionSwitchPads,
glfw.KeySpace: ActionFastForwardToggle,
glfw.KeyP: ActionMenuToggle,
glfw.KeyF: ActionFullscreenToggle,
Expand Down
10 changes: 8 additions & 2 deletions input/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ const (
ActionShouldClose uint32 = lr.DeviceIDJoypadR3 + 3
// ActionFastForwardToggle will run the core as fast as possible
ActionFastForwardToggle uint32 = lr.DeviceIDJoypadR3 + 4
// ActionSwitchPads
ActionSwitchPads uint32 = lr.DeviceIDJoypadR3 + 5
// ActionLast is used for iterating
ActionLast uint32 = lr.DeviceIDJoypadR3 + 5
ActionLast uint32 = lr.DeviceIDJoypadR3 + 6
)

// joystickCallback is triggered when a joypad is plugged.
Expand All @@ -72,6 +74,8 @@ func Init(v *video.Video) {
vid = v
if !glfw.UpdateGamepadMappings(mappings) {
log.Println("Failed to update mappings")
} else {
log.Println("Updated mappings")
}
glfw.SetJoystickCallback(joystickCallback)
}
Expand Down Expand Up @@ -132,11 +136,13 @@ func pollJoypads(state States, analogState AnalogStates) (States, AnalogStates)
return state, analogState
}

var KbdPort int = 0

// pollKeyboard processes keyboard keys
func pollKeyboard(state States) States {
for k, v := range keyBinds {
if vid.Window.GetKey(k) == glfw.Press {
state[0][v] = 1
state[KbdPort][v] = 1
}
}
return state
Expand Down
5 changes: 5 additions & 0 deletions menu/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ func (m *Menu) ProcessHotkeys() {
}
}

if input.Released[input.KbdPort][input.ActionSwitchPads] == 1 {
input.KbdPort = (input.KbdPort + 1) % 2
ntf.DisplayAndLog(ntf.Info, "Menu", "Switched pads")
}

// Close if ActionShouldClose is pressed, but display a confirmation dialog
// in case a game is running
if input.Pressed[0][input.ActionShouldClose] == 1 {
Expand Down

0 comments on commit 0fa704c

Please sign in to comment.