mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Pass WithFormat<T> through IsValueDefault to fix map saving.
This commit is contained in:
@@ -17,6 +17,7 @@ using Robust.Shared.Interfaces.GameObjects;
|
||||
using System.Linq;
|
||||
using Robust.Server.Interfaces.Timing;
|
||||
using Robust.Shared.GameObjects.Components.Map;
|
||||
using Robust.Shared.Interfaces.Serialization;
|
||||
using Robust.Shared.Prototypes;
|
||||
using YamlDotNet.Core;
|
||||
|
||||
@@ -781,7 +782,7 @@ namespace Robust.Server.Maps
|
||||
return CurrentReadingEntityComponents.Keys;
|
||||
}
|
||||
|
||||
public override bool IsValueDefault<T>(string field, T value)
|
||||
public override bool IsValueDefault<T>(string field, T value, WithFormat<T> format)
|
||||
{
|
||||
if (CurrentWritingEntity.Prototype == null)
|
||||
{
|
||||
@@ -796,7 +797,7 @@ namespace Robust.Server.Maps
|
||||
}
|
||||
|
||||
var testSer = YamlObjectSerializer.NewReader(compData);
|
||||
if (testSer.TryReadDataFieldCached(field, out T prototypeVal))
|
||||
if (testSer.TryReadDataFieldCached(field, format, out var prototypeVal))
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
|
||||
@@ -226,16 +226,25 @@ namespace Robust.Shared.Serialization
|
||||
/// <summary>
|
||||
/// Try- pattern version of <see cref="ReadDataField" />.
|
||||
/// </summary>
|
||||
public abstract bool TryReadDataField<T>(string name, out T value);
|
||||
public virtual bool TryReadDataField<T>(string name, out T value)
|
||||
{
|
||||
return TryReadDataField(name, WithFormat<T>.NoFormat, out value);
|
||||
}
|
||||
|
||||
public abstract bool TryReadDataField<T>(string name, WithFormat<T> format, out T value);
|
||||
|
||||
/// <summary>
|
||||
/// Try- pattern version of <see cref="ReadDataFieldCached" />.
|
||||
/// </summary>
|
||||
public virtual bool TryReadDataFieldCached<T>(string name, out T value)
|
||||
{
|
||||
return TryReadDataField(name, out value);
|
||||
return TryReadDataFieldCached(name, WithFormat<T>.NoFormat, out value);
|
||||
}
|
||||
|
||||
public virtual bool TryReadDataFieldCached<T>(string name, WithFormat<T> format, out T value)
|
||||
{
|
||||
return TryReadDataField(name, format, out value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a cached field for this serialization context.
|
||||
|
||||
@@ -131,7 +131,7 @@ namespace Robust.Shared.Serialization
|
||||
else // write
|
||||
{
|
||||
// don't write if value is null or default
|
||||
if (!alwaysWrite && IsValueDefault(name, value, defaultValue))
|
||||
if (!alwaysWrite && IsValueDefault(name, value, defaultValue, format))
|
||||
return;
|
||||
|
||||
var customFormatter = format.GetYamlSerializer();
|
||||
@@ -249,7 +249,7 @@ namespace Robust.Shared.Serialization
|
||||
}
|
||||
|
||||
// don't write if value is null or default
|
||||
if (!alwaysWrite && IsValueDefault(name, value, defaultValue))
|
||||
if (!alwaysWrite && IsValueDefault(name, value, defaultValue, WithFormat<TTarget>.NoFormat))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -349,7 +349,7 @@ namespace Robust.Shared.Serialization
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool TryReadDataField<T>(string name, out T value)
|
||||
public override bool TryReadDataField<T>(string name, WithFormat<T> format, out T value)
|
||||
{
|
||||
if (!Reading)
|
||||
{
|
||||
@@ -360,7 +360,8 @@ namespace Robust.Shared.Serialization
|
||||
{
|
||||
if (map.TryGetNode(name, out var node))
|
||||
{
|
||||
value = (T)NodeToType(typeof(T), node);
|
||||
var customFormatter = format.GetYamlSerializer();
|
||||
value = (T)customFormatter.NodeToType(typeof(T), node, this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -368,8 +369,7 @@ namespace Robust.Shared.Serialization
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool TryReadDataFieldCached<T>(string name, out T value)
|
||||
public override bool TryReadDataFieldCached<T>(string name, WithFormat<T> format, out T value)
|
||||
{
|
||||
if (!Reading)
|
||||
{
|
||||
@@ -385,7 +385,8 @@ namespace Robust.Shared.Serialization
|
||||
{
|
||||
if (map.TryGetNode(name, out var node))
|
||||
{
|
||||
value = (T)NodeToType(typeof(T), node);
|
||||
var customFormatter = format.GetYamlSerializer();
|
||||
value = (T)customFormatter.NodeToType(typeof(T), node, this);
|
||||
_context?.SetCachedField(name, value);
|
||||
return true;
|
||||
}
|
||||
@@ -394,6 +395,7 @@ namespace Robust.Shared.Serialization
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void DataReadFunction<T>(string name, T defaultValue, ReadFunctionDelegate<T> func)
|
||||
{
|
||||
@@ -419,7 +421,7 @@ namespace Robust.Shared.Serialization
|
||||
var value = func.Invoke();
|
||||
|
||||
// don't write if value is null or default
|
||||
if (!alwaysWrite && IsValueDefault(name, value, defaultValue))
|
||||
if (!alwaysWrite && IsValueDefault(name, value, defaultValue, WithFormat<T>.NoFormat))
|
||||
return;
|
||||
|
||||
var key = name;
|
||||
@@ -698,7 +700,7 @@ namespace Robust.Shared.Serialization
|
||||
throw new ArgumentException($"Type {type.FullName} is not supported.", nameof(obj));
|
||||
}
|
||||
|
||||
bool IsValueDefault<T>(string field, T value, T providedDefault)
|
||||
bool IsValueDefault<T>(string field, T value, T providedDefault, WithFormat<T> format)
|
||||
{
|
||||
if ((value != null || providedDefault == null) && (value == null || IsSerializedEqual(value, providedDefault)))
|
||||
{
|
||||
@@ -707,7 +709,7 @@ namespace Robust.Shared.Serialization
|
||||
|
||||
if (_context != null)
|
||||
{
|
||||
return _context.IsValueDefault(field, value);
|
||||
return _context.IsValueDefault(field, value, format);
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -848,7 +850,7 @@ namespace Robust.Shared.Serialization
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual bool IsValueDefault<T>(string field, T value)
|
||||
public virtual bool IsValueDefault<T>(string field, T value, WithFormat<T> format)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user