indexing description: "[ An EM_ANIMATION is an array of EM_DRAWABLE. To create an EM_ANIMATION you have to give an animation script file to the creation feature make. The format of the animation script file: File ::= [file_name_of_picture [duration]nl]* eof If no `duration' is given every frame takes 125ms, which equals 8 frames per second. The unit of `duration' is millisecons. ]" date: "$Date$" revision: "$Revision$" class EM_ANIMATION inherit ARRAY [EM_PAIR [EM_DRAWABLE, INTEGER]] rename count as nr_of_frames, entry as frame end EM_SHARED_BITMAP_FACTORY export {NONE} all undefine is_equal, copy end EM_SHARED_ERROR_HANDLER export {NONE} all undefine is_equal, copy end create make_from_file, make_from_array, make feature {NONE} -- Initialisation make_from_file (a_file_name: STRING) is -- Builds an EM_ANIMATION from the information provided by the script file `a_file_name'. -- The script file has the following format: -- File ::= [file_name_of_picture [duration]nl]* eof require a_file_name_exist: a_file_name /= void a_file_name_not_empty: not a_file_name.is_empty file_must_exist: file_exists (a_file_name) file_in_correct_format: file_in_correct_format (a_file_name) local file: KL_TEXT_INPUT_FILE duration: INTEGER cur_frame_nr: INTEGER cur_bitmap: EM_BITMAP list: LIST [STRING] do create file.make (a_file_name) file.open_read make (1, 1) -- [file_name_of_picture nl pause_for_picture nl]* from cur_frame_nr := 1 until file.end_of_file loop file.read_line if not file.end_of_file then list := file.last_string.split (' ') if not list.first.is_empty then Bitmap_factory.create_bitmap_from_image (list.first) cur_bitmap := bitmap_factory.last_bitmap if list.last.is_integer then duration := list.last.to_integer else duration := default_duration end force (create {EM_PAIR [EM_DRAWABLE, INTEGER]}.make (cur_bitmap, duration), cur_frame_nr) cur_frame_nr := cur_frame_nr+1 end end end file.close end feature -- Status report file_in_correct_format (a_file_name: STRING): BOOLEAN is -- if file with `a_file_name' in correct format? -- The correct format is: -- File ::= [file_name_of_picture [duration]nl]* eof require a_file_name_exist: a_file_name /= void a_file_name_not_empty: not a_file_name.is_empty file_exist: file_exists (a_file_name) local file: KL_TEXT_INPUT_FILE list: LIST [STRING] duration: INTEGER do result := true create file.make (a_file_name) file.open_read if not file.end_of_file then -- check frame data from until file.end_of_file or result = false loop file.read_line if not file.end_of_file then list := file.last_string.split (' ') duration := default_duration if not file_exists (list.first) and not list.first.is_empty then result := False end end end else result := false end file.close end is_file_name_valid (fn: STRING): BOOLEAN is -- Is `fn' a valid file name? require file_name_exists: fn /= Void file_name_not_empty: not fn.is_empty local n: FILE_NAME do create n.make_from_string (fn) Result := n.is_valid end file_exists (fn: STRING): BOOLEAN is -- Does file with name `fn' exist? require file_name_exists: fn /= Void file_name_not_empty: not fn.is_empty file_name_valid: is_file_name_valid (fn) local f: PLAIN_TEXT_FILE do create f.make (fn) Result := f.exists end feature {NONE} -- Implementation to_integer (str: STRING): INTEGER is -- returns the number in `str' or -1 if `str' is not a number do if str.is_integer then result := str.to_integer else result := -1 end end default_duration: INTEGER is 125 -- the default duration of a frame end