62 lines
1.6 KiB
Plaintext
62 lines
1.6 KiB
Plaintext
-- Core components
|
|
--
|
|
-- @include ./engine.txt
|
|
-- @include ./clutch.txt
|
|
-- @include ./differential.txt
|
|
--
|
|
-- Helpers & stuff
|
|
-- @include ./factories/gearbox.txt
|
|
-- @include /koptilnya/libs/table.txt
|
|
require('./engine.txt')
|
|
require('./clutch.txt')
|
|
require('./differential.txt')
|
|
require('./factories/gearbox.txt')
|
|
|
|
require('/koptilnya/libs/table.txt')
|
|
|
|
Vehicle = class('Vehicle')
|
|
|
|
function Vehicle:initialize(config)
|
|
-- should probably validate config here
|
|
if config == nil then
|
|
throw('Vehicle config not provided')
|
|
end
|
|
|
|
self.clutch = Clutch:new(config.Clutch)
|
|
self.engine = Engine:new(config.Engine, self.clutch)
|
|
|
|
local axleOrder = 0
|
|
self.axles = table.map(config.Axles, function(config)
|
|
axleOrder = axleOrder + 1
|
|
return Differential:new(config, axleOrder)
|
|
end)
|
|
|
|
self.gearbox = GearboxFactory.create(config.Gearbox, self.clutch, self.axles)
|
|
|
|
-- self.systems = table.map(config.Systems, function(config)
|
|
-- return SystemsFactory.create(config)
|
|
-- end)s
|
|
self.components = {self.clutch, self.engine, self.gearbox}
|
|
self.components = table.add(self.components, self.axles)
|
|
-- self.components = table.add(self.components, self.systems)
|
|
|
|
local inputs = {}
|
|
local outputs = {}
|
|
|
|
for _, comp in ipairs(self.components) do
|
|
inputs = table.merge(inputs, comp:getInputs())
|
|
outputs = table.merge(outputs, comp:getOutputs())
|
|
end
|
|
|
|
wire.adjustPorts(inputs, outputs)
|
|
|
|
hook.add('tick', 'vehicle_update', function()
|
|
local outputs = {}
|
|
|
|
for _, comp in pairs(self.components) do
|
|
comp:update()
|
|
comp:updateOutputs()
|
|
end
|
|
end)
|
|
end
|