local AreaGeneratorSystem = inherited("AreaGeneratorSystem", SystemMap)

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

function AreaGeneratorSystem:wants(ent)
	return false and ent.aspects.area_generator
end

function AreaGeneratorSystem:ent_added(ent)
end

function AreaGeneratorSystem:ent_removed(ent)
end

function AreaGeneratorSystem:step()	
	local watching_camera = self.world.watching_camera
	if watching_camera then
		local universe = self.world.universe
		local cx,cy = watching_camera.x, watching_camera.y
		local w,h = watching_camera.width, watching_camera.height
		local extra = math.distance(0,0,w,h)
		for ent, _ in pairs(self.ents) do
			if not ent.area_generated then

				local dist2 = math.distance2(ent.x, ent.y, cx, cy) 

				if dist2 < (ent.area_generator_range*2+extra)^2 then
					universe:prio_location(ent)
					ent.prioritized = true
					break
				end
			end
		end
	end
end

return AreaGeneratorSystem