GARbro-mirror/GameRes/ScriptText.cs

110 lines
3.2 KiB
C#
Raw Normal View History

2014-07-22 03:26:28 +08:00
//! \file ScriptText.cs
//! \date Thu Jul 10 11:09:32 2014
//! \brief Script text resource interface.
//
using System.IO;
using System.Collections.Generic;
using System.ComponentModel.Composition;
2014-07-22 03:26:28 +08:00
namespace GameRes
{
public struct ScriptLine
{
public uint Id;
public string Text;
}
public class ScriptData
{
public ICollection<ScriptLine> TextLines { get { return m_text; } }
protected List<ScriptLine> m_text = new List<ScriptLine>();
/*
public abstract void Serialize (Stream output);
public abstract void Deserialize (Stream input);
*/
}
public abstract class ScriptFormat : IResource
{
public override string Type { get { return "script"; } }
2023-08-24 05:33:50 +08:00
public abstract bool IsScript (IBinaryStream file);
public abstract Stream ConvertFrom (IBinaryStream file);
public abstract Stream ConvertBack (IBinaryStream file);
2014-07-22 03:26:28 +08:00
public abstract ScriptData Read (string name, Stream file);
public abstract void Write (Stream file, ScriptData script);
2023-08-24 05:33:50 +08:00
public static ScriptFormat FindFormat (IBinaryStream file)
{
foreach (var impl in FormatCatalog.Instance.FindFormats<ScriptFormat> (file.Name, file.Signature))
{
try
{
file.Position = 0;
if (impl.IsScript (file))
return impl;
}
catch (System.OperationCanceledException)
{
throw;
}
catch { }
}
return null;
}
2014-07-22 03:26:28 +08:00
}
public abstract class GenericScriptFormat : ScriptFormat
{
2023-08-24 05:33:50 +08:00
public override bool IsScript (IBinaryStream file)
{
return false;
}
public override Stream ConvertFrom (IBinaryStream file)
{
return file.AsStream;
}
public override Stream ConvertBack (IBinaryStream file)
{
return file.AsStream;
}
public override ScriptData Read (string name, Stream file)
{
throw new System.NotImplementedException();
}
public override void Write (Stream file, ScriptData script)
{
throw new System.NotImplementedException();
}
}
[Export(typeof(ScriptFormat))]
public class TextScriptFormat : GenericScriptFormat
{
public override string Tag { get { return "TXT"; } }
public override string Description { get { return "Text file"; } }
public override uint Signature { get { return 0; } }
}
[Export(typeof(ScriptFormat))]
public class BinScriptFormat : GenericScriptFormat
{
public override string Tag { get { return "SCR"; } }
public override string Description { get { return "Binary script format"; } }
public override uint Signature { get { return 0; } }
public BinScriptFormat ()
{
Extensions = new[] { "scr", "bin" };
}
}
2014-07-22 03:26:28 +08:00
}