From 68d0ff94ebd75703db3eecdf0a7eeabb72cb0a2a Mon Sep 17 00:00:00 2001 From: "andres.delikat" Date: Tue, 5 Jul 2011 23:16:54 +0000 Subject: [PATCH] Refactor movie writing code. MovieHeader, MovieLog, and SubtitleList all have their own write methods now instead of the Movie object doing all of the work. Conceptually these 3 objects should be autonomous and the Movie object is simply an object that manages a collection of these objects. --- BizHawk.MultiClient/movie/Movie.cs | 22 +--- BizHawk.MultiClient/movie/MovieHeader.cs | 14 +++ BizHawk.MultiClient/movie/MovieLog.cs | 124 ++++++++++++---------- BizHawk.MultiClient/movie/SubtitleList.cs | 10 ++ 4 files changed, 94 insertions(+), 76 deletions(-) diff --git a/BizHawk.MultiClient/movie/Movie.cs b/BizHawk.MultiClient/movie/Movie.cs index 0a01663cea..963a566b21 100644 --- a/BizHawk.MultiClient/movie/Movie.cs +++ b/BizHawk.MultiClient/movie/Movie.cs @@ -186,25 +186,9 @@ namespace BizHawk.MultiClient using (StreamWriter sw = new StreamWriter(file)) { - foreach (KeyValuePair kvp in Header.HeaderParams) - { - sw.WriteLine(kvp.Key + " " + kvp.Value); - } - - for (int x = 0; x < Header.Comments.Count; x++) - { - sw.WriteLine(Header.Comments[x]); - } - - for (int x = 0; x < Subtitles.Count(); x++) - { - sw.WriteLine(Subtitles.GetSubtitleText(x)); - } - - for (int x = 0; x < length; x++) - { - sw.WriteLine(Log.GetFrame(x)); - } + Header.WriteText(sw); + Subtitles.WriteText(sw); + Log.WriteText(sw); } } diff --git a/BizHawk.MultiClient/movie/MovieHeader.cs b/BizHawk.MultiClient/movie/MovieHeader.cs index 3808a9c448..487f05fc5b 100644 --- a/BizHawk.MultiClient/movie/MovieHeader.cs +++ b/BizHawk.MultiClient/movie/MovieHeader.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.IO; namespace BizHawk.MultiClient { @@ -93,5 +94,18 @@ namespace BizHawk.MultiClient { HeaderParams[key] = value; } + + public void WriteText(StreamWriter sw) + { + foreach (KeyValuePair kvp in HeaderParams) + { + sw.WriteLine(kvp.Key + " " + kvp.Value); + } + + for (int x = 0; x < Comments.Count; x++) + { + sw.WriteLine(Comments[x]); + } + } } } diff --git a/BizHawk.MultiClient/movie/MovieLog.cs b/BizHawk.MultiClient/movie/MovieLog.cs index bf401d3017..50424308bb 100644 --- a/BizHawk.MultiClient/movie/MovieLog.cs +++ b/BizHawk.MultiClient/movie/MovieLog.cs @@ -2,72 +2,82 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.IO; namespace BizHawk.MultiClient { - /// - /// Represents the controller key presses of a movie - /// - public class MovieLog - { - //TODO: Insert(int frame) not useful for convenctional tasing but TAStudio will want it + /// + /// Represents the controller key presses of a movie + /// + public class MovieLog + { + //TODO: Insert(int frame) not useful for convenctional tasing but TAStudio will want it - List MovieRecords = new List(); - - public MovieLog() - { - //Should this class initialize with an empty string to MovieRecords so that first frame is index 1? - //MovieRecords.Add(""); - } + List MovieRecords = new List(); - public int Length() - { - return MovieRecords.Count; - } + public MovieLog() + { + //Should this class initialize with an empty string to MovieRecords so that first frame is index 1? + //MovieRecords.Add(""); + } - public void Clear() - { - MovieRecords.Clear(); - } + public int Length() + { + return MovieRecords.Count; + } - public int GetMovieLength() - { - return MovieRecords.Count; - } + public void Clear() + { + MovieRecords.Clear(); + } - public void AddFrame(string frame) - { - MovieRecords.Add(frame); - } + public int GetMovieLength() + { + return MovieRecords.Count; + } + + public void AddFrame(string frame) + { + MovieRecords.Add(frame); + } public void SetFrameAt(int frameNum, string frame) - { - if (MovieRecords.Count > frameNum) - MovieRecords[frameNum] = frame; - else - MovieRecords.Insert(frameNum, frame); - } - public void AddFrameAt(string frame, int frameNum) - { - MovieRecords.Insert(frameNum, frame); - } + { + if (MovieRecords.Count > frameNum) + MovieRecords[frameNum] = frame; + else + MovieRecords.Insert(frameNum, frame); + } + public void AddFrameAt(string frame, int frameNum) + { + MovieRecords.Insert(frameNum, frame); + } - public void Truncate(int frame) - { - if (frame >= 0 && frame < Length()) - { MovieRecords.RemoveRange(frame,Length() - frame); } - } + public void Truncate(int frame) + { + if (frame >= 0 && frame < Length()) + { MovieRecords.RemoveRange(frame, Length() - frame); } + } - public string GetFrame(int frameCount) //Frame count is 0 based here, should it be? - { - if (frameCount >= 0) - { - if (frameCount < MovieRecords.Count) - return MovieRecords[frameCount]; - else - return ""; - } - else - return ""; //TODO: throw an exception? - } - } + public string GetFrame(int frameCount) //Frame count is 0 based here, should it be? + { + if (frameCount >= 0) + { + if (frameCount < MovieRecords.Count) + return MovieRecords[frameCount]; + else + return ""; + } + else + return ""; //TODO: throw an exception? + } + + public void WriteText(StreamWriter sw) + { + int length = GetMovieLength(); + for (int x = 0; x < length; x++) + { + sw.WriteLine(GetFrame(x)); + } + } + } } diff --git a/BizHawk.MultiClient/movie/SubtitleList.cs b/BizHawk.MultiClient/movie/SubtitleList.cs index 5e2a513e3f..52e72d0152 100644 --- a/BizHawk.MultiClient/movie/SubtitleList.cs +++ b/BizHawk.MultiClient/movie/SubtitleList.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing; +using System.IO; namespace BizHawk.MultiClient { @@ -202,5 +203,14 @@ namespace BizHawk.MultiClient subs.RemoveAt(index); } + + public void WriteText(StreamWriter sw) + { + int length = subs.Count; + for (int x = 0; x < length; x++) + { + sw.WriteLine(GetSubtitleText(x)); + } + } } }