/*
*		Retarget gerarchia e User Data
*		by Tommaso Sanguigni (Tommix)
*		www.tommasosanguigni.it
*		www.youtube.com/tommix83
*/

copyRecourse(from, to);
copyUserData(from, to);
copyCoords(from, to);
copyDataAndCoords(from, to);

main()
{
	println("Avvio script per la copia ricorsiva dei dati utente");
	println("Oggetto sorgente:" + source#ID_BASELIST_NAME);
	println("Oggetto target:" + target#ID_BASELIST_NAME);
	copyRecourse(source, target);
}

copyUserData(from, to){
	//Copia dati utente
	println("USER_DATA da " + from#ID_BASELIST_NAME + " a " + to#ID_BASELIST_NAME);
	try{
		to#ID_USERDATA = from#ID_USERDATA;
	}catch(ExLastException){}
}

copyCoords(from, to){
		//Copia coordinate
		println("COORDINATE da "+ from#ID_BASELIST_NAME + " a " + to#ID_BASELIST_NAME);
		to->SetMg(from->GetMg());
}

copyDataAndCoords(from, to){
		copyUserData(from, to);
		copyCoords(from, to);
}

copyRecourse(from, to){
	
	//Copia dati
	copyDataAndCoords(from, to);

	//Lancia ricorsione sui figli
	var from_Child = from->GetDown();
	var to_Child = to->GetDown();
	 
	while(from_Child!=nil && to_Child!=nil){
		
		println(from#ID_BASELIST_NAME + "." + from_Child#ID_BASELIST_NAME + " -> " + to#ID_BASELIST_NAME + "." + to_Child#ID_BASELIST_NAME );
		
		//Copia ricorsiva
		copyRecourse(from_Child, to_Child);		

		from_Child = from_Child->GetNext();
		to_Child = to_Child->GetNext();
	}
		
}
