Fixed target values bug

This commit is contained in:
Иван Грачёв
2021-09-19 19:51:10 +05:00
parent 8dc9689601
commit d5bbad6f1d
3 changed files with 136 additions and 8 deletions

View File

@@ -7,22 +7,35 @@ Input = class('Input')
function Input:_setupHooks()
hook.add('inputPressed', 'KeyPress', function(key)
if self.driver == CURRENT_PLAYER then
self:_trySetTargetValue(key, 'press')
self:_trySetTargetValue(key)
end
end)
hook.add('inputReleased', 'KeyRelease', function(key)
if self.driver == CURRENT_PLAYER then
self:_trySetTargetValue(key, 'release')
self:_trySetTargetValue(key)
end
end)
end
function Input:_trySetTargetValue(key, evt)
function Input:bothKeysHolding(axle)
return (input.isKeyDown(axle.Positive) == true) and (input.isKeyDown(axle.Negative) == true)
end
function Input:noKeysHolding(axle)
return (input.isKeyDown(axle.Positive) == false) and (input.isKeyDown(axle.Negative) == false)
end
function Input:getAxleValue(axle)
return (input.isKeyDown(axle.Positive) and 1 or 0) - (input.isKeyDown(axle.Negative) and 1 or 0)
end
function Input:_trySetTargetValue(key)
local triggeredKey = self.keys[key]
if triggeredKey ~= nil then
local targetValue = evt == 'press' and triggeredKey.Value or 0
local triggeredAxle = self.axles[triggeredKey.Axle]
local targetValue = self:getAxleValue(triggeredAxle)
net.start('SetTargetAxle')
net.writeString(triggeredKey.Axle)
@@ -40,13 +53,11 @@ end
function Input:_mapKeys(axles)
for k, v in pairs(axles) do
self.keys[v.Negative] = {
Axle = k,
Value = -1
Axle = k
}
self.keys[v.Positive] = {
Axle = k,
Value = 1
Axle = k
}
end
end
@@ -55,6 +66,7 @@ end
function Input:initialize(options)
options = options or {}
self.axles = options.Axles
self.keys = {}
self.driver = NULL_ENTITY