2021-11-12 00:07:30 +05:00

51 lines
1.4 KiB
Plaintext

-- @include ./engine.txt
-- @include /koptilnya/libs/table.txt
require('./engine.txt')
require('/koptilnya/libs/table.txt')
Vehicle = class('Vehicle')
function Vehicle:initialize(config)
if config == nil then
throw('Vehicle config not provided')
end
-- self.clutch = Clutch:new(config.Clutch)
self.engine = Engine:new(config.Engine, self.clutch)
-- self.gearbox = GearboxBuilder:create(config.Gearbox, self.clutch)
-- self.axles = table.map(config.Axles, function(config)
-- return Differential:new(config)
-- end)
-- self.systems = table.map(config.Systems, function(config)
-- return SystemsBuilder:create(config)
-- end)
self.components = {self.engine} -- , self.gearbox, self.clutch}
-- 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)
-- for _, ent in self.entities do
-- ent:createInputs()
-- ent:createOutputs()
-- end
hook.add('tick', 'vehicle_update', function()
local outputs = {}
for _, comp in pairs(self.components) do
comp:update()
comp:updateOutputs()
end
end)
end