add .dsm importer, doesn't import commands yet, need some examples, doesn't parse the TimeAtBoot value

This commit is contained in:
adelikat 2020-03-28 17:08:09 -05:00
parent d1032f38f8
commit 6511632f15
2 changed files with 136 additions and 0 deletions

View File

@ -0,0 +1,135 @@
using System;
using System.Linq;
using BizHawk.Common;
using BizHawk.Common.BufferExtensions;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Consoles.Nintendo.NDS;
namespace BizHawk.Client.Common
{
[ImporterFor("DeSmuME", ".dsm")]
internal class DsmImport : MovieImporter
{
protected override void RunImport()
{
Result.Movie.HeaderEntries[HeaderKeys.Platform] = "NDS";
var syncSettings = new MelonDS.MelonSyncSettings();
using var sr = SourceFile.OpenText();
string line;
while ((line = sr.ReadLine()) != null)
{
if (string.IsNullOrWhiteSpace(line))
{
continue;
}
if (line[0] == '|')
{
ImportInputFrame(line);
}
else if (line.StartsWith("rerecordCount"))
{
int.TryParse(ParseHeader(line, "rerecordCount"), out var rerecordCount);
Result.Movie.Rerecords = (ulong)rerecordCount;
}
else if (line.StartsWith("firmNickname"))
{
syncSettings.Nickname = ParseHeader(line, "firmNickname");
}
else if (line.StartsWith("firmFavColour"))
{
syncSettings.FavoriteColor = byte.Parse(ParseHeader(line, "firmFavColour"));
}
else if (line.StartsWith("firmBirthDay"))
{
syncSettings.BirthdayDay = byte.Parse(ParseHeader(line, "firmBirthDay"));
}
else if (line.StartsWith("firmBirthMonth"))
{
syncSettings.BirthdayMonth = byte.Parse(ParseHeader(line, "firmBirthMonth"));
}
else if (line.StartsWith("rtcStartNew"))
{
//TODO: what is this format?? 2010-JAN-01 00:00:00:000
//var time = DateTime.Parse(ParseHeader(line, "rtcStartNew"));
//syncSettings.TimeAtBoot = (uint)new DateTimeOffset(time.ToLocalTime()).ToUnixTimeSeconds();
}
else if (line.StartsWith("comment author"))
{
Result.Movie.HeaderEntries[HeaderKeys.Author] = ParseHeader(line, "comment author");
}
else if (line.StartsWith("comment"))
{
Result.Movie.Comments.Add(ParseHeader(line, "comment"));
}
else if (line.ToLower().StartsWith("guid"))
{
// We no longer care to keep this info
}
else
{
Result.Movie.Comments.Add(line); // Everything not explicitly defined is treated as a comment.
}
Result.Movie.SyncSettingsJson = ConfigService.SaveWithType(syncSettings);
}
}
private readonly string[] _buttons = { "Right", "Left", "Down", "Up", "Start", "Select", "B", "A", "Y", "X", "L", "R" };
private void ImportInputFrame(string line)
{
var controller = new SimpleController
{
Definition = new ControllerDefinition
{
BoolButtons =
{
"Right", "Left", "Down", "Up", "Start", "Select",
"B", "A", "X", "Y", "L", "R", "Touch", "LidOpen", "LidClose"
}
}
};
controller.Definition.FloatControls.Add("TouchX");
controller.Definition.FloatRanges.Add(new ControllerDefinition.AxisRange(0, 128, 255));
controller.Definition.FloatControls.Add("TouchY");
controller.Definition.FloatRanges.Add(new ControllerDefinition.AxisRange(0, 96, 191));
string[] sections = line.Split(new[] {'|'}, StringSplitOptions.RemoveEmptyEntries);
if (sections.Length > 0)
{
ProcessCmd(sections[0], controller);
}
if (sections.Length > 1)
{
var mnemonics = sections[1].Take(_buttons.Length).ToList();
for (var i = 0; i < mnemonics.Count; i++)
{
controller[_buttons[i]] = mnemonics[i] != '.';
}
controller["Touch"] = sections[1].Substring(21, 1) != "0";
var touchX = int.Parse(sections[1].Substring(13, 3));
var touchY = int.Parse(sections[1].Substring(17, 3));
controller.AcceptNewFloats(new[]
{
new Tuple<string, float>("TouchX", touchX),
new Tuple<string, float>("TouchY", touchY)
});
}
Result.Movie.AppendFrame(controller);
}
private void ProcessCmd(string cmd, SimpleController controller)
{
// TODO
}
}
}

View File

@ -258,6 +258,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Coleco/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Colecovision/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=colesced/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Colour/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Commavid/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Compositing/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Compumate/@EntryIndexedValue">True</s:Boolean>