Implemented new input system
This commit is contained in:
68
koptilnya/input_system/cl_input.txt
Normal file
68
koptilnya/input_system/cl_input.txt
Normal file
@@ -0,0 +1,68 @@
|
||||
-- @include ../libs/constants.txt
|
||||
require('../libs/constants.txt')
|
||||
|
||||
Input = class('Input')
|
||||
-- Private here
|
||||
|
||||
function Input:_setupHooks()
|
||||
hook.add('inputPressed', 'KeyPress', function(key)
|
||||
if self.driver == CURRENT_PLAYER then
|
||||
self:_trySetTargetValue(key, 'press')
|
||||
end
|
||||
end)
|
||||
|
||||
hook.add('inputReleased', 'KeyRelease', function(key)
|
||||
if self.driver == CURRENT_PLAYER then
|
||||
self:_trySetTargetValue(key, 'release')
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function Input:_trySetTargetValue(key, evt)
|
||||
local triggeredKey = self.keys[key]
|
||||
|
||||
if triggeredKey ~= nil then
|
||||
local targetValue = evt == 'press' and triggeredKey.Value or 0
|
||||
|
||||
net.start('SetTargetAxle')
|
||||
net.writeString(triggeredKey.Axle)
|
||||
net.writeInt(targetValue, 4)
|
||||
net.send()
|
||||
end
|
||||
end
|
||||
|
||||
function Input:_setupNetListeners()
|
||||
net.receive('SyncDriver', function()
|
||||
self.driver = net.readEntity()
|
||||
end)
|
||||
end
|
||||
|
||||
function Input:_mapKeys(axles)
|
||||
for k, v in pairs(axles) do
|
||||
self.keys[v.Negative] = {
|
||||
Axle = k,
|
||||
Value = -1
|
||||
}
|
||||
|
||||
self.keys[v.Positive] = {
|
||||
Axle = k,
|
||||
Value = 1
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
-- Public here
|
||||
|
||||
function Input:initialize(options)
|
||||
options = options or {}
|
||||
self.keys = {}
|
||||
self.driver = NULL_ENTITY
|
||||
|
||||
self:_setupHooks();
|
||||
self:_setupNetListeners();
|
||||
self:_mapKeys(options.Axles)
|
||||
end
|
||||
|
||||
function Input:update()
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user