55 lines
1.1 KiB
Plaintext
55 lines
1.1 KiB
Plaintext
-- @include /koptilnya/libs/watcher.txt
|
|
-- @include ./base.txt
|
|
require('/koptilnya/libs/watcher.txt')
|
|
require('./base.txt')
|
|
|
|
ManualGearbox = class('ManualGearbox', Gearbox)
|
|
|
|
function ManualGearbox:initialize(...)
|
|
Gearbox.initialize(self, ...)
|
|
|
|
function shiftFunc()
|
|
local upshift = wire.ports.Upshift or 0
|
|
local downshift = wire.ports.Downshift or 0
|
|
|
|
return upshift - downshift
|
|
end
|
|
|
|
self.shiftWatcher = watcher(shiftFunc, function(val)
|
|
if val ~= 0 then
|
|
self:shift(val)
|
|
end
|
|
end)
|
|
end
|
|
|
|
function ManualGearbox:recalcRatio()
|
|
if self.gear == -1 then
|
|
self.ratio = -self.reverse
|
|
elseif self.gear == 0 then
|
|
self.ratio = 0
|
|
else
|
|
self.ratio = self.ratios[self.gear]
|
|
end
|
|
end
|
|
|
|
function ManualGearbox:shift(dir)
|
|
self:setGear(self.gear + dir)
|
|
end
|
|
|
|
-- function ManualGearbox:getOutputs()
|
|
-- return {
|
|
-- Gearbox_RPM = 'number',
|
|
-- Gearbox_Torque = 'number'
|
|
-- }
|
|
-- end
|
|
|
|
-- function ManualGearbox:updateOutputs()
|
|
|
|
-- end
|
|
|
|
function ManualGearbox:update()
|
|
Gearbox.update(self)
|
|
|
|
self.shiftWatcher()
|
|
end
|