local M = {}

local function onInit()
	for s,n in pairs(v.data.nodes) do
		if n.name == "LQ7" then engine1Node = n.cid elseif
		   n.name == "LQ8" then engine3Node = n.cid elseif
		   n.name == "LQ5" then engine2Node = n.cid
		end
	end
	
	electrics.values['steering_rear'] = 0
	
end

local function onReset()
	onInit()
end

local function updateGFX(dt)
	if electrics.values['rpm'] > 10000 then 
	   drivetrain.engineDisabled = true
	   sounds.playSoundOnceAtNode("engine_damage2a", engine1Node, 0.6)
	   sounds.playSoundOnceAtNode("engine_damage4a", engine2Node, 0.65)
	   sounds.playSoundOnceAtNode("engine_damage3a", engine3Node, 0.85)
	end
	
	if input.keys.H then 
		electrics.values['steering_rear'] = 1
	end

    if input.keys.G then 
		electrics.values['steering_rear'] = -1
	end

    if not input.keys.H and not input.keys.G then 
		electrics.values['steering_rear'] = 0
	end
	
end

-- public interface
M.onInit = onInit
M.onReset = onReset
M.updateGFX = updateGFX

return M