Sound.Channels as a number

This commit is contained in:
Matt Nadareski
2020-09-03 22:35:09 -07:00
parent d204f8eb1f
commit 9c38fd82aa
4 changed files with 77 additions and 19 deletions

View File

@@ -571,16 +571,23 @@ namespace SabreTools.Library.DatFiles
break; break;
case "sound": case "sound":
datItems.Add(new Sound var sound = new Sound
{ {
Channels = reader.GetAttribute("channels"),
Source = new Source Source = new Source
{ {
Index = indexId, Index = indexId,
Name = filename, Name = filename,
}, },
}); };
// Set the channels
if (reader.GetAttribute("channels") != null)
{
if (Int64.TryParse(reader.GetAttribute("channels"), out long channels))
sound.Channels = channels;
}
datItems.Add(sound);
reader.Read(); reader.Read();
break; break;
@@ -1666,7 +1673,7 @@ namespace SabreTools.Library.DatFiles
case ItemType.Sound: case ItemType.Sound:
var sound = datItem as Sound; var sound = datItem as Sound;
xtw.WriteStartElement("sound"); xtw.WriteStartElement("sound");
xtw.WriteOptionalAttributeString("channels", sound.Channels); xtw.WriteOptionalAttributeString("channels", sound.Channels?.ToString());
xtw.WriteEndElement(); xtw.WriteEndElement();
break; break;
} }

View File

@@ -1644,7 +1644,7 @@ namespace SabreTools.Library.DatFiles
var sound = datItem as Sound; var sound = datItem as Sound;
xtw.WriteStartElement("file"); xtw.WriteStartElement("file");
xtw.WriteAttributeString("type", "sound"); xtw.WriteAttributeString("type", "sound");
xtw.WriteOptionalAttributeString("channels", sound.Channels); xtw.WriteOptionalAttributeString("channels", sound.Channels?.ToString());
xtw.WriteEndElement(); xtw.WriteEndElement();
break; break;
} }

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using SabreTools.Library.Filtering; using SabreTools.Library.Filtering;
@@ -18,7 +19,7 @@ namespace SabreTools.Library.DatItems
/// Number of channels /// Number of channels
/// </summary> /// </summary>
[JsonProperty("channels", DefaultValueHandling = DefaultValueHandling.Ignore)] [JsonProperty("channels", DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Channels { get; set; } // TODO: Int32? public long? Channels { get; set; }
#endregion #endregion
@@ -35,7 +36,10 @@ namespace SabreTools.Library.DatItems
// Handle Sound-specific fields // Handle Sound-specific fields
if (mappings.Keys.Contains(Field.DatItem_Channels)) if (mappings.Keys.Contains(Field.DatItem_Channels))
Channels = mappings[Field.DatItem_Channels]; {
if (Int64.TryParse(mappings[Field.DatItem_Channels], out long channels))
Channels = channels;
}
} }
#endregion #endregion
@@ -102,9 +106,11 @@ namespace SabreTools.Library.DatItems
return false; return false;
// Filter on channels // Filter on channels
if (filter.DatItem_Channels.MatchesPositiveSet(Channels) == false) if (filter.DatItem_Channels.MatchesNeutral(null, Channels) == false)
return false; return false;
if (filter.DatItem_Channels.MatchesNegativeSet(Channels) == true) else if (filter.DatItem_Channels.MatchesPositive(null, Channels) == false)
return false;
else if (filter.DatItem_Channels.MatchesNegative(null, Channels) == false)
return false; return false;
return true; return true;

View File

@@ -260,7 +260,7 @@ namespace SabreTools.Library.Filtering
public FilterItem<string> DatItem_Filter { get; private set; } = new FilterItem<string>(); public FilterItem<string> DatItem_Filter { get; private set; } = new FilterItem<string>();
// Sound // Sound
public FilterItem<string> DatItem_Channels { get; private set; } = new FilterItem<string>(); public FilterItem<long?> DatItem_Channels { get; private set; } = new FilterItem<long?>() { Positive = null, Negative = null, Neutral = null };
#endregion #endregion
@@ -1574,17 +1574,62 @@ namespace SabreTools.Library.Filtering
// Sound // Sound
case Field.DatItem_Channels: case Field.DatItem_Channels:
if (negate) bool? channelsOperation = null;
DatItem_Channels.NegativeSet.Add(value); if (value.StartsWith(">"))
else channelsOperation = true;
DatItem_Channels.PositiveSet.Add(value); else if (value.StartsWith("<"))
channelsOperation = false;
else if (value.StartsWith("="))
channelsOperation = null;
string channelsString = value.TrimStart('>', '<', '=');
if (!Int64.TryParse(channelsString, out long channels))
return;
// Equal
if (channelsOperation == null && !negate)
{
DatItem_Channels.Neutral = channels;
}
// Not Equal
else if (channelsOperation == null && negate)
{
DatItem_Channels.Negative = channels - 1;
DatItem_Channels.Positive = channels + 1;
}
// Greater Than or Equal
else if (channelsOperation == true && !negate)
{
DatItem_Channels.Positive = channels;
}
// Strictly Less Than
else if (channelsOperation == true && negate)
{
DatItem_Channels.Negative = channels - 1;
}
// Less Than or Equal
else if (channelsOperation == false && !negate)
{
DatItem_Channels.Negative = channels;
}
// Strictly Greater Than
else if (channelsOperation == false && negate)
{
DatItem_Channels.Positive = channels + 1;
}
break; break;
#endregion #endregion
#endregion // Item-Specific #endregion // Item-Specific
#endregion // DatItem Filters #endregion // DatItem Filters
} }
} }