Change display rotation to long?

This commit is contained in:
Matt Nadareski
2020-09-04 10:28:25 -07:00
parent b7dbe728a3
commit 7f8766b0a4
7 changed files with 46 additions and 30 deletions

View File

@@ -357,11 +357,10 @@ namespace SabreTools.Library.DatFiles
break;
case "display":
datItems.Add(new Display
var display = new Display
{
Tag = reader.GetAttribute("tag"),
DisplayType = reader.GetAttribute("type").AsDisplayType(),
Rotate = reader.GetAttribute("rotate"),
FlipX = reader.GetAttribute("flipx").AsYesNo(),
Width = reader.GetAttribute("width"),
Height = reader.GetAttribute("height"),
@@ -379,7 +378,16 @@ namespace SabreTools.Library.DatFiles
Index = indexId,
Name = filename,
},
});
};
// Set the rotation
if (reader.GetAttribute("rotate") != null)
{
if (Int64.TryParse(reader.GetAttribute("rotate"), out long rotate))
display.Rotate = rotate;
}
datItems.Add(display);
reader.Read();
break;
@@ -1531,7 +1539,7 @@ namespace SabreTools.Library.DatFiles
xtw.WriteStartElement("display");
xtw.WriteOptionalAttributeString("tag", display.Tag);
xtw.WriteOptionalAttributeString("type", display.DisplayType.FromDisplayType());
xtw.WriteOptionalAttributeString("rotate", display.Rotate);
xtw.WriteOptionalAttributeString("rotate", display.Rotate?.ToString());
xtw.WriteOptionalAttributeString("flipx", display.FlipX.FromYesNo());
xtw.WriteOptionalAttributeString("width", display.Width);
xtw.WriteOptionalAttributeString("height", display.Height);

View File

@@ -1437,7 +1437,7 @@ namespace SabreTools.Library.DatFiles
xtw.WriteAttributeString("type", "display");
xtw.WriteOptionalAttributeString("tag", display.Tag);
xtw.WriteOptionalAttributeString("type", display.DisplayType.FromDisplayType());
xtw.WriteOptionalAttributeString("rotate", display.Rotate);
xtw.WriteOptionalAttributeString("rotate", display.Rotate?.ToString());
xtw.WriteOptionalAttributeString("flipx", display.FlipX.FromYesNo());
xtw.WriteOptionalAttributeString("width", display.Width);
xtw.WriteOptionalAttributeString("height", display.Height);

View File

@@ -359,23 +359,7 @@ namespace SabreTools.Library.DatFiles
switch (reader.Name)
{
case "rom":
// If the rom is continue or ignore, add the size to the previous rom
if (reader.GetAttribute("loadflag") == "continue" || reader.GetAttribute("loadflag") == "ignore")
{
int index = Items[key].Count - 1;
DatItem lastrom = Items[key][index];
if (lastrom.ItemType == ItemType.Rom)
{
((Rom)lastrom).Size += Sanitizer.CleanSize(reader.GetAttribute("size"));
}
Items[key].RemoveAt(index);
Items[key].Add(lastrom);
reader.Read();
continue;
}
DatItem rom = new Rom
var rom = new Rom
{
Name = reader.GetAttribute("name"),
Size = Sanitizer.CleanSize(reader.GetAttribute("size")),
@@ -389,6 +373,24 @@ namespace SabreTools.Library.DatFiles
DataArea = dataArea,
};
// If the rom is continue or ignore, add the size to the previous rom
// TODO: Can this be done on write? We technically lose information this way.
// Order is not guaranteed, and since these don't tend to have any way
// of determining what the "previous" item was after this, that info would
// have to be stored *with* the item somehow
if (rom.LoadFlag == LoadFlag.Continue || rom.LoadFlag == LoadFlag.Ignore)
{
int index = Items[key].Count - 1;
DatItem lastrom = Items[key][index];
if (lastrom.ItemType == ItemType.Rom)
(lastrom as Rom).Size += rom.Size;
Items[key].RemoveAt(index);
Items[key].Add(lastrom);
reader.Read();
continue;
}
items.Add(rom);
reader.Read();
break;