--[[
SetVisibility

Script to show the objects between the given 'eveningTime' and 'morningTime' in the xmlFile

@Author:	Ifko[nator]
@Date:		07.01.2017

@Version:	1.0 - intial release in FS 17

@Usage:

	<setVisibilitys>
		<setVisibility index="0>2|3|2" eveningTime="19" morningTime="8"/>
		<setVisibility index="0>2|2" eveningTime="17" morningTime="3"/>
		
		...
	</setVisibilitys>

]]

SetVisibility = {};

function SetVisibility.prerequisitesPresent(specializations)
    return true; 
end;

function SetVisibility:load(savegame)
	local count = 0;

	self.objects = {};
	
	while true do
		xmlString = "vehicle.setVisibilitys.setVisibility(" .. tostring(count) .. ")";
		
		if not hasXMLProperty(self.xmlFile, xmlString) then
            break;
        end;
		
		local object = {};
		
		object.node = Utils.indexToObject(self.components, getXMLString(self.xmlFile, xmlString .. "#index"));
		
		if object.node ~= nil then
			object.eveningTime = tonumber(Utils.getNoNil(getXMLString(self.xmlFile, xmlString .. "#eveningTime"), 20));
			object.morningTime = tonumber(Utils.getNoNil(getXMLString(self.xmlFile, xmlString .. "#morningTime"), 7) - 1);
			
			table.insert(self.objects, object);
		end;
	
		count = count + 1;
	end;
end;

function SetVisibility:update(dt)
	for _, object in pairs(self.objects) do
		setVisibility(object.node, g_currentMission.environment.currentHour >= object.eveningTime or g_currentMission.environment.currentHour <= object.morningTime);
	end;
end;

function SetVisibility:delete()end;
function SetVisibility:mouseEvent(posX, posY, isDown, isUp, button)end;
function SetVisibility:keyEvent(unicode, sym, modifier, isDown)end;
function SetVisibility:draw()end;