From a5dc7e90b355260d265996e151f607b6ae2071f4 Mon Sep 17 00:00:00 2001 From: "andres.delikat" Date: Fri, 25 Feb 2011 19:49:29 +0000 Subject: [PATCH] Checking in some movie class progress. Basic file saving done. Progress on file loading. --- BizHawk.MultiClient/MainForm.MenuItems.cs | 7 +- BizHawk.MultiClient/MainForm.cs | 5 +- BizHawk.MultiClient/movie/Movie.cs | 96 ++++++++++++++++++- BizHawk.MultiClient/movie/MovieHeader.cs | 13 ++- BizHawk.MultiClient/movie/MovieLog.cs | 13 +++ BizHawk.MultiClient/tools/RamWatchNewWatch.cs | 1 + 6 files changed, 125 insertions(+), 10 deletions(-) diff --git a/BizHawk.MultiClient/MainForm.MenuItems.cs b/BizHawk.MultiClient/MainForm.MenuItems.cs index e469f5500e..dc73e60dd7 100644 --- a/BizHawk.MultiClient/MainForm.MenuItems.cs +++ b/BizHawk.MultiClient/MainForm.MenuItems.cs @@ -124,8 +124,11 @@ namespace BizHawk.MultiClient private void playMovieToolStripMenuItem_Click(object sender, EventArgs e) { - PlayMovie p = new PlayMovie(); - p.ShowDialog(); + //PlayMovie p = new PlayMovie(); + //p.ShowDialog(); + + //Hacky testing + InputLog.WriteMovie(); } private void stopMovieToolStripMenuItem_Click(object sender, EventArgs e) diff --git a/BizHawk.MultiClient/MainForm.cs b/BizHawk.MultiClient/MainForm.cs index 60a5ea609a..f86318daa4 100644 --- a/BizHawk.MultiClient/MainForm.cs +++ b/BizHawk.MultiClient/MainForm.cs @@ -19,7 +19,10 @@ namespace BizHawk.MultiClient private Control renderTarget; private RetainedViewportPanel retainedPanel; private string CurrentlyOpenRom; - + + //TODO: adelikat: can this be the official file extension? + Movie InputLog = new Movie("log.tas"); //This movie is always recording while user is playing + //the currently selected savestate slot private int SaveSlot = 0; diff --git a/BizHawk.MultiClient/movie/Movie.cs b/BizHawk.MultiClient/movie/Movie.cs index 77fe402b58..3a4028f77c 100644 --- a/BizHawk.MultiClient/movie/Movie.cs +++ b/BizHawk.MultiClient/movie/Movie.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.IO; namespace BizHawk.MultiClient { @@ -10,19 +11,108 @@ namespace BizHawk.MultiClient private MovieHeader Header = new MovieHeader(); private MovieLog Log = new MovieLog(); - public Movie() - { + private bool IsText = true; + private string Filename; + public Movie(string filename) + { + Filename = filename; //TODO: Validate that file is writable + Log.AddFrame("|........|0|"); } public void AddMovieRecord() { - + //TODO: validate input + //Format into string acceptable by MovieLog } public void WriteMovie() { + if (IsText) + WriteText(); + else + WriteBinary(); + } + private void WriteText() + { + var file = new FileInfo(Filename); + + int length = Log.GetMovieLength(); + string str = ""; + + using (StreamWriter sw = new StreamWriter(Filename)) + { + foreach (KeyValuePair kvp in Header.GetHeaderInfo()) + { + str += kvp.Key + " " + kvp.Value + "\n"; + } + + + for (int x = 0; x < length; x++) + { + str += Log.GetFrame(x) + "\n"; + } + sw.WriteLine(str); + } + } + + private void WriteBinary() + { + + } + + private bool LoadText() + { + var file = new FileInfo(Filename); + using (StreamReader sr = file.OpenText()) + { + string str = ""; + + while ((str = sr.ReadLine()) != null) + { + if (str.Contains(MovieHeader.EMULATIONVERSION)) + { + + } + else if (str.Contains(MovieHeader.MOVIEVERSION)) + { + + } + else if (str.Contains(MovieHeader.PLATFORM)) + { + + } + else if (str.Contains(MovieHeader.GAMENAME)) + { + + } + else if (str[0] == '|') + { + + } + else + { + //Something has gone wrong here! + } + } + } + + return true; + + } + + private bool LoadBinary() + { + return true; + } + + public bool LoadMovie() + { + var file = new FileInfo(Filename); + if (file.Exists == false) return false; //TODO: methods like writemovie will fail, some internal flag needs to prevent this + //TODO: must determine if file is text or binary + return LoadText(); } public int GetMovieLength() diff --git a/BizHawk.MultiClient/movie/MovieHeader.cs b/BizHawk.MultiClient/movie/MovieHeader.cs index cea8f5f593..2c65c37801 100644 --- a/BizHawk.MultiClient/movie/MovieHeader.cs +++ b/BizHawk.MultiClient/movie/MovieHeader.cs @@ -16,12 +16,17 @@ namespace BizHawk.MultiClient Dictionary HeaderParams = new Dictionary(); //Platform specific options go here + public const string EMULATIONVERSION = "EmulationVersion"; + public const string MOVIEVERSION = "MovieVersion"; + public const string PLATFORM = "Platform"; + public const string GAMENAME = "GameName"; + public MovieHeader() //All required fields will be set to default values { - HeaderParams.Add("EmulationVersion", "v1.0.0"); - HeaderParams.Add("MovieVersion", "v1.0.0"); - HeaderParams.Add("Platform", ""); - HeaderParams.Add("GameName", ""); + HeaderParams.Add(EMULATIONVERSION, "v1.0.0"); + HeaderParams.Add(MOVIEVERSION, "v1.0.0"); + HeaderParams.Add(PLATFORM, ""); + HeaderParams.Add(GAMENAME, ""); } public MovieHeader(string EmulatorVersion, string MovieVersion, string Platform, string GameName) diff --git a/BizHawk.MultiClient/movie/MovieLog.cs b/BizHawk.MultiClient/movie/MovieLog.cs index c343fa2add..6857805cfe 100644 --- a/BizHawk.MultiClient/movie/MovieLog.cs +++ b/BizHawk.MultiClient/movie/MovieLog.cs @@ -21,5 +21,18 @@ namespace BizHawk.MultiClient { return MovieRecords.Count; } + + public void AddFrame(string frame) + { + MovieRecords.Add(frame); //Validate the format? Or shoudl the Movie class be resonible for formatting? + } + + public string GetFrame(int frameCount) //Frame count is 0 based here, should it be? + { + if (frameCount >= 0) + return MovieRecords[frameCount]; + else + return ""; //TODO: throw an exception? + } } } diff --git a/BizHawk.MultiClient/tools/RamWatchNewWatch.cs b/BizHawk.MultiClient/tools/RamWatchNewWatch.cs index 68ec1d1673..147af653ed 100644 --- a/BizHawk.MultiClient/tools/RamWatchNewWatch.cs +++ b/BizHawk.MultiClient/tools/RamWatchNewWatch.cs @@ -12,6 +12,7 @@ namespace BizHawk.MultiClient { public partial class RamWatchNewWatch : Form { + //TODO: better input validation - Like Ram Search public Watch watch = new Watch(); public bool userSelected = false; public bool customSetup = false;