-- This Source Code Form is subject to the terms of the bCDDL, v. 1.1.
-- If a copy of the bCDDL was not distributed with this
-- file, You can obtain one at http://beamng.com/bCDDL-1.1.txt

local M = {}
M.type = "auxilliary"
M.relevantDevice = nil

local fans = {}

local function init(jbeamData)
  fans = {}
  for _, fan in pairs(jbeamData.fans) do
    fan.speed = fan.speed or 30
    electrics.values[fan.out_electric] = 0
    table.insert(fans, fan)
  end
end

local function updateGFX(dt)
  for _, fan in ipairs(fans) do
    local onVal = electrics.values[fan.on_electric]
    if onVal ~= nil and onVal > 0 then
      electrics.values[fan.out_electric] = (electrics.values[fan.out_electric] + (dt * fan.speed)) % 360
    end
  end
  
end

M.init = init
M.updateGFX = updateGFX

return M