Sync get value changes from DatItem

This commit is contained in:
Matt Nadareski
2024-03-12 22:12:51 -04:00
parent c42e939595
commit 36e3a8d246
2 changed files with 34 additions and 8 deletions

View File

@@ -7,6 +7,7 @@ using SabreTools.Core;
using SabreTools.Core.Tools;
using SabreTools.DatFiles.Formats;
using SabreTools.Filter;
using SabreTools.Serialization;
namespace SabreTools.DatFiles
{
@@ -207,8 +208,14 @@ namespace SabreTools.DatFiles
if (string.IsNullOrEmpty(fieldName) || !_header.ContainsKey(fieldName!))
return default;
// Get the value based on the type
return _header.ReadDouble(fieldName!);
// Try to parse directly
double? doubleValue = _header.ReadDouble(fieldName!);
if (doubleValue != null)
return doubleValue;
// Try to parse from the string
string? stringValue = _header.ReadString(fieldName!);
return NumberHelper.ConvertToDouble(stringValue);
}
/// <summary>
@@ -222,8 +229,14 @@ namespace SabreTools.DatFiles
if (string.IsNullOrEmpty(fieldName) || !_header.ContainsKey(fieldName!))
return default;
// Get the value based on the type
return _header.ReadLong(fieldName!);
// Try to parse directly
long? longValue = _header.ReadLong(fieldName!);
if (longValue != null)
return longValue;
// Try to parse from the string
string? stringValue = _header.ReadString(fieldName!);
return NumberHelper.ConvertToInt64(stringValue);
}
/// <summary>

View File

@@ -2,6 +2,7 @@
using System.Xml.Serialization;
using Newtonsoft.Json;
using SabreTools.Core;
using SabreTools.Core.Tools;
using SabreTools.Filter;
namespace SabreTools.DatItems
@@ -107,8 +108,14 @@ namespace SabreTools.DatItems
if (string.IsNullOrEmpty(fieldName) || !_machine.ContainsKey(fieldName!))
return default;
// Get the value based on the type
return _machine.ReadDouble(fieldName!);
// Try to parse directly
double? doubleValue = _machine.ReadDouble(fieldName!);
if (doubleValue != null)
return doubleValue;
// Try to parse from the string
string? stringValue = _machine.ReadString(fieldName!);
return NumberHelper.ConvertToDouble(stringValue);
}
/// <summary>
@@ -122,8 +129,14 @@ namespace SabreTools.DatItems
if (string.IsNullOrEmpty(fieldName) || !_machine.ContainsKey(fieldName!))
return default;
// Get the value based on the type
return _machine.ReadLong(fieldName!);
// Try to parse directly
long? longValue = _machine.ReadLong(fieldName!);
if (longValue != null)
return longValue;
// Try to parse from the string
string? stringValue = _machine.ReadString(fieldName!);
return NumberHelper.ConvertToInt64(stringValue);
}
/// <summary>