BizHawk/BizHawk.Client.Common/movie/SubtitleList.cs

56 lines
1.2 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Drawing;
using System.IO;
namespace BizHawk.Client.Common
{
public class SubtitleList : List<Subtitle>
{
public IEnumerable<Subtitle> GetSubtitles(int frame)
{
return this.Where(t => frame >= t.Frame && frame <= t.Frame + t.Duration);
}
public bool AddFromString(string subtitleStr)
{
if (!String.IsNullOrWhiteSpace(subtitleStr))
{
try
{
var subparts = subtitleStr.Split(' ');
//Unfortunately I made the file format space delminated so this hack is necessary to get the message
string message = String.Empty;
for (int i = 6; i < subparts.Length; i++)
{
message += subparts[i] + ' ';
}
Add(new Subtitle()
{
Frame = int.Parse(subparts[1]),
X = int.Parse(subparts[2]),
Y = int.Parse(subparts[3]),
Duration = int.Parse(subparts[4]),
Color = uint.Parse(subparts[5], NumberStyles.HexNumber),
Message = message
});
return true;
}
catch
{
return false;
}
}
else
{
return false;
}
}
}
}