local HudNameFadeSystem = inherited("HudNameFadeSystem", SystemMap)

function HudNameFadeSystem:new()
	local ms = instance(self)
	return ms
end

function HudNameFadeSystem:dynamic_wants(ent)
	return ent.aspects.hud_name and ent.hud_name and ent.hud_name_display and ent.hud_name_display_fade and not ent.hud_info_display
end

function HudNameFadeSystem:ent_added(ent)
	ent.rx = ent.x
	ent.ry = ent.y
	ent.rz = ent.z
end

function HudNameFadeSystem:ent_removed(ent)
	ent.hud_name_display = false
end


function HudNameFadeSystem:step(dt)
	for ent, _ in pairs(self.ents) do
		if ent.hud_name_display_fade then
			if ent.hud_name_display_increase then
				ent.hud_name_display_fade = math.min(1,ent.hud_name_display_fade + dt*4)
				if ent.hud_name_display_fade >= 1 then
					ent.hud_name_display_increase = nil
				end
			else
				ent.hud_name_display_fade = ent.hud_name_display_fade - dt
				if ent.hud_name_display_fade <= 0 then
					ent.hud_name_display_fade = nil
					ent:set_hud_name_display(false)
				end
			end
		end
	end
end

return HudNameFadeSystem