diff --git a/BizHawk.Client.Common/BizHawk.Client.Common.csproj b/BizHawk.Client.Common/BizHawk.Client.Common.csproj
index c9105fcdb8..f14b21d3b0 100644
--- a/BizHawk.Client.Common/BizHawk.Client.Common.csproj
+++ b/BizHawk.Client.Common/BizHawk.Client.Common.csproj
@@ -52,6 +52,9 @@
+
+
+
diff --git a/BizHawk.MultiClient/movie/MovieHeader.cs b/BizHawk.Client.Common/movie/MovieHeader.cs
similarity index 90%
rename from BizHawk.MultiClient/movie/MovieHeader.cs
rename to BizHawk.Client.Common/movie/MovieHeader.cs
index aaf28e73ad..ef8e7b3cd5 100644
--- a/BizHawk.MultiClient/movie/MovieHeader.cs
+++ b/BizHawk.Client.Common/movie/MovieHeader.cs
@@ -1,10 +1,7 @@
using System.Collections.Generic;
using System.IO;
-using System.Linq;
-using BizHawk.Client.Common;
-
-namespace BizHawk.MultiClient
+namespace BizHawk.Client.Common
{
public class MovieHeader
{
@@ -55,16 +52,10 @@ namespace BizHawk.MultiClient
return System.Guid.NewGuid().ToString();
}
- public MovieHeader() //All required fields will be set to default values
+ public MovieHeader(string version) //All required fields will be set to default values
{
- if (GlobalWinF.MainForm != null)
- {
- HeaderParams.Add(EMULATIONVERSION, GlobalWinF.MainForm.GetEmuVersion());
- }
- else
- {
- HeaderParams.Add(EMULATIONVERSION, MainForm.EMUVERSION);
- }
+
+ HeaderParams.Add(EMULATIONVERSION, version);
HeaderParams.Add(MOVIEVERSION, MovieVersion);
HeaderParams.Add(PLATFORM, "");
HeaderParams.Add(GAMENAME, "");
@@ -285,15 +276,12 @@ namespace BizHawk.MultiClient
public void ReadHeader(StreamReader reader)
{
- using (reader)
+ string str;
+ while ((str = reader.ReadLine()) != null)
{
- string str;
- while ((str = reader.ReadLine()) != null)
- {
- AddHeaderFromLine(str);
- }
- reader.Close();
+ AddHeaderFromLine(str);
}
+ reader.Close();
}
}
}
diff --git a/BizHawk.Client.Common/movie/Subtitle.cs b/BizHawk.Client.Common/movie/Subtitle.cs
new file mode 100644
index 0000000000..e897d36255
--- /dev/null
+++ b/BizHawk.Client.Common/movie/Subtitle.cs
@@ -0,0 +1,49 @@
+using System;
+using System.Text;
+
+namespace BizHawk.Client.Common
+{
+ public class Subtitle
+ {
+ public string Message { get; set; }
+ public int Frame { get; set; }
+ public int X { get; set; }
+ public int Y { get; set; }
+ public int Duration { get; set; }
+ public uint Color { get; set; }
+
+ public Subtitle()
+ {
+ Message = String.Empty;
+ X = 0;
+ Y = 0;
+ Duration = 120;
+ Frame = 0;
+ Color = 0xFFFFFFFF;
+ }
+
+ public Subtitle(Subtitle s)
+ {
+ Message = s.Message;
+ Frame = s.Frame;
+ X = s.X;
+ Y = s.Y;
+ Duration = s.Duration;
+ Color = s.Color;
+ }
+
+ public override string ToString()
+ {
+ StringBuilder sb = new StringBuilder("subtitle ");
+ sb
+ .Append(Frame.ToString()).Append(" ")
+ .Append(X.ToString()).Append(" ")
+ .Append(Y.ToString()).Append(" ")
+ .Append(Duration.ToString()).Append(" ")
+ .Append(String.Format("{0:X8}", Color)).Append(" ")
+ .Append(Message);
+
+ return sb.ToString();
+ }
+ }
+}
diff --git a/BizHawk.MultiClient/movie/SubtitleList.cs b/BizHawk.Client.Common/movie/SubtitleList.cs
similarity index 56%
rename from BizHawk.MultiClient/movie/SubtitleList.cs
rename to BizHawk.Client.Common/movie/SubtitleList.cs
index 45e00ab02e..3fc424806a 100644
--- a/BizHawk.MultiClient/movie/SubtitleList.cs
+++ b/BizHawk.Client.Common/movie/SubtitleList.cs
@@ -1,62 +1,46 @@
-using System.Collections.Generic;
+using System;
+using System.Collections;
+using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Drawing;
using System.IO;
+using BizHawk.Client.Common;
+
namespace BizHawk.MultiClient
{
- public class SubtitleList
+ public class SubtitleList : IEnumerable
{
- private readonly List subs = new List();
+ private readonly List _subtitles = new List();
- public SubtitleList()
+ public SubtitleList() { }
+
+ public SubtitleList(SubtitleList subtitles)
{
-
- }
-
- public SubtitleList(Movie m)
- {
- if (m != null && m.Subtitles.Count == 0)
+ foreach (var subtitle in subtitles)
{
- return;
- }
-
- for (int x = 0; x < m.Subtitles.Count; x++)
- {
- Subtitle s = new Subtitle(m.Subtitles.GetSubtitleByIndex(x));
- subs.Add(s);
+ _subtitles.Add(new Subtitle(subtitle)); //TODO: Multiclient.EditSubtitlesForm needs a deep copy here, refactor it so that it doesn't
}
}
- public Subtitle GetSubtitleByIndex(int index)
+ public IEnumerator GetEnumerator()
{
- if (index >= subs.Count || index < 0) return new Subtitle();
-
- return subs[index];
+ return _subtitles.GetEnumerator();
}
- public string GetSubtitleText(int index)
+ IEnumerator IEnumerable.GetEnumerator()
{
- if (index >= subs.Count || index < 0)
- {
- return "";
- }
+ return GetEnumerator();
+ }
- StringBuilder sb = new StringBuilder("subtitle ");
- sb.Append(subs[index].Frame.ToString());
- sb.Append(" ");
- sb.Append(subs[index].X.ToString());
- sb.Append(" ");
- sb.Append(subs[index].Y.ToString());
- sb.Append(" ");
- sb.Append(subs[index].Duration.ToString());
- sb.Append(" ");
- sb.Append(string.Format("{0:X8}", subs[index].Color));
- sb.Append(" ");
- sb.Append(subs[index].Message);
- return sb.ToString();
+ public Subtitle this[int index]
+ {
+ get
+ {
+ return _subtitles[index];
+ }
}
///
@@ -66,45 +50,42 @@ namespace BizHawk.MultiClient
///
public string GetSubtitleMessage(int frame)
{
- if (subs.Count == 0) return "";
+ if (_subtitles.Count == 0) return "";
- foreach (Subtitle t in subs)
+ foreach (Subtitle t in _subtitles)
{
if (frame >= t.Frame && frame <= t.Frame + t.Duration)
{
return t.Message;
}
}
- return "";
+ return String.Empty;
}
public Subtitle GetSubtitle(int frame)
{
- if (subs.Count == 0) return new Subtitle();
-
- foreach (Subtitle t in subs)
+ if (_subtitles.Any())
{
- if (frame >= t.Frame && frame <= t.Frame + t.Duration)
+ foreach (Subtitle t in _subtitles)
{
- return t;
+ if (frame >= t.Frame && frame <= t.Frame + t.Duration)
+ {
+ return t;
+ }
}
}
+
return new Subtitle();
}
public List GetSubtitles(int frame)
{
- if (subs.Count == 0)
- {
- return null;
- }
-
- return subs.Where(t => frame >= t.Frame && frame <= t.Frame + t.Duration).ToList();
+ return _subtitles.Where(t => frame >= t.Frame && frame <= t.Frame + t.Duration).ToList();
}
public int Count
{
- get { return subs.Count; }
+ get { return _subtitles.Count; }
}
//TODO
@@ -119,9 +100,12 @@ namespace BizHawk.MultiClient
///
///
///
- public bool AddSubtitle(string subtitleStr)
+ public bool AddSubtitle(string subtitleStr) //TODO: refactor with String.Split
{
- if (subtitleStr.Length == 0) return false;
+ if (!String.IsNullOrWhiteSpace(subtitleStr))
+ {
+ return false;
+ }
Subtitle s = new Subtitle();
@@ -199,34 +183,33 @@ namespace BizHawk.MultiClient
}
s.Message = str;
- subs.Add(s);
+ _subtitles.Add(s);
return true;
}
public void AddSubtitle(Subtitle s)
{
- subs.Add(s);
+ _subtitles.Add(s);
}
- public void ClearSubtitles()
+ public void Clear()
{
- subs.Clear();
+ _subtitles.Clear();
}
- public void Remove(int index)
+ public void RemoveAt(int index)
{
- if (index >= subs.Count) return;
+ if (index >= _subtitles.Count) return;
- subs.RemoveAt(index);
+ _subtitles.RemoveAt(index);
}
public void WriteText(StreamWriter sw)
{
- int length = subs.Count;
- for (int x = 0; x < length; x++)
+ foreach(var subtitle in _subtitles)
{
- sw.WriteLine(GetSubtitleText(x));
+ sw.WriteLine(subtitle.ToString());
}
}
}
diff --git a/BizHawk.MultiClient/BizHawk.MultiClient.csproj b/BizHawk.MultiClient/BizHawk.MultiClient.csproj
index 0c76fa2cf4..10ba7df166 100644
--- a/BizHawk.MultiClient/BizHawk.MultiClient.csproj
+++ b/BizHawk.MultiClient/BizHawk.MultiClient.csproj
@@ -358,7 +358,6 @@
EditSubtitlesForm.cs
-
@@ -376,8 +375,6 @@
RecordMovie.cs
-
-
Form
diff --git a/BizHawk.MultiClient/MainForm.MenuItems.cs b/BizHawk.MultiClient/MainForm.MenuItems.cs
index c2313894d0..d40334a195 100644
--- a/BizHawk.MultiClient/MainForm.MenuItems.cs
+++ b/BizHawk.MultiClient/MainForm.MenuItems.cs
@@ -860,7 +860,7 @@ namespace BizHawk.MultiClient
Subtitle sub = new Subtitle();
for (int x = 0; x < GlobalWinF.MovieSession.Movie.Subtitles.Count; x++)
{
- sub = GlobalWinF.MovieSession.Movie.Subtitles.GetSubtitleByIndex(x);
+ sub = GlobalWinF.MovieSession.Movie.Subtitles[x];
if (Global.Emulator.Frame == sub.Frame)
{
index = x;
@@ -876,7 +876,7 @@ namespace BizHawk.MultiClient
if (s.ShowDialog() == DialogResult.OK)
{
if (index >= 0)
- GlobalWinF.MovieSession.Movie.Subtitles.Remove(index);
+ GlobalWinF.MovieSession.Movie.Subtitles.RemoveAt(index);
GlobalWinF.MovieSession.Movie.Subtitles.AddSubtitle(s.sub);
}
}
diff --git a/BizHawk.MultiClient/movie/EditSubtitlesForm.cs b/BizHawk.MultiClient/movie/EditSubtitlesForm.cs
index c1648748b9..3cc761ece3 100644
--- a/BizHawk.MultiClient/movie/EditSubtitlesForm.cs
+++ b/BizHawk.MultiClient/movie/EditSubtitlesForm.cs
@@ -3,6 +3,8 @@ using System.Drawing;
using System.Windows.Forms;
using System.Globalization;
+using BizHawk.Client.Common;
+
namespace BizHawk.MultiClient
{
public partial class EditSubtitlesForm : Form
@@ -53,7 +55,7 @@ namespace BizHawk.MultiClient
{
if (!ReadOnly)
{
- selectedMovie.Subtitles.ClearSubtitles();
+ selectedMovie.Subtitles.Clear();
for (int x = 0; x < SubGrid.Rows.Count - 1; x++)
{
Subtitle s = new Subtitle();
@@ -86,12 +88,12 @@ namespace BizHawk.MultiClient
public void GetMovie(Movie m)
{
selectedMovie = m;
- SubtitleList subs = new SubtitleList(m);
+ SubtitleList subs = new SubtitleList(m.Subtitles);
if (subs.Count == 0) return;
for (int x = 0; x < subs.Count; x++)
{
- Subtitle s = subs.GetSubtitleByIndex(x);
+ Subtitle s = subs[x];
SubGrid.Rows.Add();
DataGridViewCell c = SubGrid.Rows[x].Cells[0];
c.Value = s.Frame;
diff --git a/BizHawk.MultiClient/movie/Movie.cs b/BizHawk.MultiClient/movie/Movie.cs
index 4194afa62d..4ca8c8980a 100644
--- a/BizHawk.MultiClient/movie/Movie.cs
+++ b/BizHawk.MultiClient/movie/Movie.cs
@@ -12,33 +12,30 @@ namespace BizHawk.MultiClient
#region Constructors
public Movie(string filename)
+ : this()
{
- Mode = MOVIEMODE.INACTIVE;
Rerecords = 0;
Filename = filename;
- IsText = true;
- preload_framecount = 0;
- IsCountingRerecords = true;
- StartsFromSavestate = false;
- if (filename.Length > 0)
- Loaded = true;
+ Loaded = filename.Length > 0;
}
public Movie()
{
- Filename = "";
- Mode = MOVIEMODE.INACTIVE;
- IsText = true;
+ Filename = String.Empty;
preload_framecount = 0;
StartsFromSavestate = false;
- Loaded = false;
IsCountingRerecords = true;
+ Mode = MOVIEMODE.INACTIVE;
+ IsText = true;
+
+ string version = GlobalWinF.MainForm != null ? GlobalWinF.MainForm.GetEmuVersion() : MainForm.EMUVERSION;
+ Header = new MovieHeader(version);
}
#endregion
#region Properties
- public MovieHeader Header = new MovieHeader();
+ public MovieHeader Header;
public SubtitleList Subtitles = new SubtitleList();
public bool MakeBackup = true; //make backup before altering movie
diff --git a/BizHawk.MultiClient/movie/Subtitle.cs b/BizHawk.MultiClient/movie/Subtitle.cs
deleted file mode 100644
index f9dc8e5501..0000000000
--- a/BizHawk.MultiClient/movie/Subtitle.cs
+++ /dev/null
@@ -1,44 +0,0 @@
-using System;
-
-namespace BizHawk.MultiClient
-{
- public class Subtitle
- {
- public string Message;
- public int Frame;
- public int X;
- public int Y;
- public int Duration;
- public uint Color;
-
- public Subtitle()
- {
- Message = "";
- X = 0;
- Y = 0;
- Duration = 120;
- Frame = 0;
- Color = 0xFFFFFFFF;
- }
-
- public Subtitle(string message, int x, int y, int dur, int frame, UInt32 color)
- {
- Message = message;
- Frame = frame;
- X = x;
- Y = y;
- Duration = dur;
- Color = color;
- }
-
- public Subtitle(Subtitle s)
- {
- Message = s.Message;
- Frame = s.Frame;
- X = s.X;
- Y = s.Y;
- Duration = s.Duration;
- Color = s.Color;
- }
- }
-}
diff --git a/BizHawk.MultiClient/movie/SubtitleMaker.cs b/BizHawk.MultiClient/movie/SubtitleMaker.cs
index 538512381b..0c6fa50f96 100644
--- a/BizHawk.MultiClient/movie/SubtitleMaker.cs
+++ b/BizHawk.MultiClient/movie/SubtitleMaker.cs
@@ -2,6 +2,8 @@
using System.Drawing;
using System.Windows.Forms;
+using BizHawk.Client.Common;
+
namespace BizHawk.MultiClient
{
public partial class SubtitleMaker : Form