Prevent mapping the same key to two controls (fixes #20)

This commit is contained in:
Ishaan Bhardwaj 2021-07-11 13:53:27 -04:00
parent 2cb0416548
commit 61d5410f22
2 changed files with 8 additions and 1 deletions

View File

@ -88,7 +88,7 @@ function KeyConfigScene:onInputPress(e)
elseif e.scancode == "tab" then elseif e.scancode == "tab" then
self.set_inputs[configurable_inputs[self.input_state]] = "skipped" self.set_inputs[configurable_inputs[self.input_state]] = "skipped"
self.input_state = self.input_state + 1 self.input_state = self.input_state + 1
elseif e.scancode ~= "escape" then elseif e.scancode ~= "escape" and not self.new_input[e.scancode] then
-- all other keys can be configured -- all other keys can be configured
self.set_inputs[configurable_inputs[self.input_state]] = "key " .. love.keyboard.getKeyFromScancode(e.scancode) .. " (" .. e.scancode .. ")" self.set_inputs[configurable_inputs[self.input_state]] = "key " .. love.keyboard.getKeyFromScancode(e.scancode) .. " (" .. e.scancode .. ")"
self.new_input[e.scancode] = configurable_inputs[self.input_state] self.new_input[e.scancode] = configurable_inputs[self.input_state]

View File

@ -104,6 +104,7 @@ function StickConfigScene:onInputPress(e)
if not self.new_input[e.name].buttons then if not self.new_input[e.name].buttons then
self.new_input[e.name].buttons = {} self.new_input[e.name].buttons = {}
end end
if self.new_input[e.name].buttons[e.button] then return end
self.set_inputs[configurable_inputs[self.input_state]] = self.set_inputs[configurable_inputs[self.input_state]] =
"jbtn " .. "jbtn " ..
e.button .. e.button ..
@ -119,6 +120,9 @@ function StickConfigScene:onInputPress(e)
if not self.new_input[e.name].axes[e.axis] then if not self.new_input[e.name].axes[e.axis] then
self.new_input[e.name].axes[e.axis] = {} self.new_input[e.name].axes[e.axis] = {}
end end
if (
self.new_input[e.name].axes[e.axis][e.value >= 1 and "positive" or "negative"]
) then return end
self.set_inputs[configurable_inputs[self.input_state]] = self.set_inputs[configurable_inputs[self.input_state]] =
"jaxis " .. "jaxis " ..
(e.value >= 1 and "+" or "-") .. e.axis .. (e.value >= 1 and "+" or "-") .. e.axis ..
@ -137,6 +141,9 @@ function StickConfigScene:onInputPress(e)
if not self.new_input[e.name].hats[e.hat] then if not self.new_input[e.name].hats[e.hat] then
self.new_input[e.name].hats[e.hat] = {} self.new_input[e.name].hats[e.hat] = {}
end end
if self.new_input[e.name].hats[e.hat][e.direction] then
return
end
self.set_inputs[configurable_inputs[self.input_state]] = self.set_inputs[configurable_inputs[self.input_state]] =
"jhat " .. "jhat " ..
e.hat .. " " .. e.direction .. e.hat .. " " .. e.direction ..