/*
** FadeList
**
** $VER: FadeList 1.0.1 (21.7.94)
**
** This script requires ADPro v2.5.0 (or higher).
**
** Some code stolen from ASDG, Incorporated.   I am the great cornholio, are you threatening me?
*/

destdir='DD1:FadeAnims'
count=16

OPTIONS RESULTS

ADDRESS "ADPro"
TempDefaults = "T:TempADProDefaults"
SAVE_DEFAULTS TempDefaults

/***** set up par *****/
address ddr
 mode anim
 filter
 oldfilter=result
 filter off
 translate on
 exporter iff
address

/***** read filelist *****/
if Open(fh,'SYS:FadeList','R')=0 then do
	say 'Failed to open RAM:FileList'
	call ErrorOut 10
end
cnt=0
do while ~Eof(fh)
	files.cnt=ReadLn(fh)
	if ~Exists(files.cnt) then do
		say files.cnt 'does not exist.'
		call ErrorOut 10
	end
	cnt=cnt+1
end
call Close(fh)
cnt=cnt-2
if cnt<1 then do
	say 'Not enough files'
	call ErrorOut 10
end
/**** do the loop thing *****/

do f=0 to cnt-1

	source1=files.f
	n=f+1
	source2=files.n

	address ddr
	 file source1
	 if result='' then call ErrorOut 20
	 frames
	 frms=result
	 if frms<count then call ErrorOut 20
	 s=frms-count
	 if f=0 then do
		copy source1 destdir /* copy the first anim */
		parse var source1 d'/'filename
		maindestfile=destdir'/'filename
	 end
	 file maindestfile
	 frames
	 frms=result
	 s2=frms-count
	 delete maindestfile s2+1 frms
	 append on
	address

	fval=0	/* reset fade % value */
	do i=1 to count
		LOAD_TYPE 'REPLACE'
		LOADER 'BACKDROP' 'XXX' 752 480 COLOR
		LOAD_TYPE 'COMPOSE'
		LOADER 'UNIVERSAL' source1'.'s COMPMIX trunc(100-fval)
		if rc~=0 then do
			say 'Unable to load image'
			call ErrorOut 10
		end
		LOADER 'UNIVERSAL' source2'.'i COMPMIX trunc(fval)
		if rc~=0 then do
			say 'Unable to load image'
			call ErrorOut 10
		end
		SAVER "IFF" destdir'/temp.'i 'RAW'
		fval=fval+(100/count)
		s=s+1
	end
	address ddr
	 done
	 append off
	 copy source2 destdir count+1 1000000
	 parse var source2 d'/'filename
	 newfile=destdir'/'filename
	 join maindestfile newfile
	address
end

address ddr filter oldfilter
CALL ErrorOut 0

ErrorOut:
	PARSE ARG ExitCode

	IF (EXISTS( TempDefaults )) THEN DO
		LOAD_DEFAULTS TempDefaults
		IF (RC ~= 0) THEN DO
			ADPRO_TO_FRONT
			OKAY1 "Error restoring settings."
		END

		ADDRESS COMMAND "Delete >NIL:" TempDefaults
	END

	EXIT ExitCode
