mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Sound.Channels as a number
This commit is contained in:
@@ -571,16 +571,23 @@ namespace SabreTools.Library.DatFiles
|
||||
break;
|
||||
|
||||
case "sound":
|
||||
datItems.Add(new Sound
|
||||
var sound = new Sound
|
||||
{
|
||||
Channels = reader.GetAttribute("channels"),
|
||||
|
||||
Source = new Source
|
||||
{
|
||||
Index = indexId,
|
||||
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();
|
||||
break;
|
||||
@@ -1666,7 +1673,7 @@ namespace SabreTools.Library.DatFiles
|
||||
case ItemType.Sound:
|
||||
var sound = datItem as Sound;
|
||||
xtw.WriteStartElement("sound");
|
||||
xtw.WriteOptionalAttributeString("channels", sound.Channels);
|
||||
xtw.WriteOptionalAttributeString("channels", sound.Channels?.ToString());
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1644,7 +1644,7 @@ namespace SabreTools.Library.DatFiles
|
||||
var sound = datItem as Sound;
|
||||
xtw.WriteStartElement("file");
|
||||
xtw.WriteAttributeString("type", "sound");
|
||||
xtw.WriteOptionalAttributeString("channels", sound.Channels);
|
||||
xtw.WriteOptionalAttributeString("channels", sound.Channels?.ToString());
|
||||
xtw.WriteEndElement();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using SabreTools.Library.Filtering;
|
||||
@@ -18,7 +19,7 @@ namespace SabreTools.Library.DatItems
|
||||
/// Number of channels
|
||||
/// </summary>
|
||||
[JsonProperty("channels", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public string Channels { get; set; } // TODO: Int32?
|
||||
public long? Channels { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -35,7 +36,10 @@ namespace SabreTools.Library.DatItems
|
||||
|
||||
// Handle Sound-specific fields
|
||||
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
|
||||
@@ -102,9 +106,11 @@ namespace SabreTools.Library.DatItems
|
||||
return false;
|
||||
|
||||
// Filter on channels
|
||||
if (filter.DatItem_Channels.MatchesPositiveSet(Channels) == false)
|
||||
if (filter.DatItem_Channels.MatchesNeutral(null, Channels) == 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 true;
|
||||
|
||||
@@ -260,7 +260,7 @@ namespace SabreTools.Library.Filtering
|
||||
public FilterItem<string> DatItem_Filter { get; private set; } = new FilterItem<string>();
|
||||
|
||||
// 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
|
||||
|
||||
@@ -1574,17 +1574,62 @@ namespace SabreTools.Library.Filtering
|
||||
|
||||
// Sound
|
||||
case Field.DatItem_Channels:
|
||||
if (negate)
|
||||
DatItem_Channels.NegativeSet.Add(value);
|
||||
else
|
||||
DatItem_Channels.PositiveSet.Add(value);
|
||||
bool? channelsOperation = null;
|
||||
if (value.StartsWith(">"))
|
||||
channelsOperation = true;
|
||||
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;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#endregion // Item-Specific
|
||||
#endregion // Item-Specific
|
||||
|
||||
#endregion // DatItem Filters
|
||||
#endregion // DatItem Filters
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user