Skip to content

Commit dcadd34

Browse files
Serv5 fixes (space-wizards#6761)
1 parent c2d0490 commit dcadd34

4 files changed

Lines changed: 34 additions & 16 deletions

File tree

Robust.Serialization.Generator/Generator.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,21 +1140,7 @@ private static StringBuilder GetCopyBody(DataDefinition definition, string targe
11401140
var nullableValue = isNullableValueType ? ".Value" : string.Empty;
11411141
var nullNotAllowed = isClass && !isNullable;
11421142

1143-
if (CanBeCopiedByValue(field.Symbol, field.Type))
1144-
{
1145-
if (nullNotAllowed)
1146-
{
1147-
builder.AppendLine($$"""
1148-
if (source.{{name}} == null)
1149-
{
1150-
throw new NullNotAllowedException();
1151-
}
1152-
""");
1153-
}
1154-
1155-
builder.AppendLine($"{targetName} = source.{name};");
1156-
}
1157-
else if (field.CustomSerializer is { Serializer: var serializer, Type: var serializerType } &&
1143+
if (field.CustomSerializer is { Serializer: var serializer, Type: var serializerType } &&
11581144
((serializerType & Copier) != 0 || (serializerType & CopyCreator) != 0))
11591145
{
11601146
if (nullNotAllowed)
@@ -1201,6 +1187,20 @@ private static StringBuilder GetCopyBody(DataDefinition definition, string targe
12011187
if (isNullable || isNullableValueType)
12021188
builder.AppendLine("}");
12031189
}
1190+
else if (CanBeCopiedByValue(field.Symbol, field.Type))
1191+
{
1192+
if (nullNotAllowed)
1193+
{
1194+
builder.AppendLine($$"""
1195+
if (source.{{name}} == null)
1196+
{
1197+
throw new NullNotAllowedException();
1198+
}
1199+
""");
1200+
}
1201+
1202+
builder.AppendLine($"{targetName} = source.{name};");
1203+
}
12041204
else
12051205
{
12061206
if (nullNotAllowed)

Robust.Serialization.Generator/Types.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ private static bool CanTypeBeCopiedByValue(ITypeSymbol type, HashSet<string> vis
7878
if (HasAttribute(type, CopyByRefNamespace))
7979
return true;
8080

81+
if (type is INamedTypeSymbol named &&
82+
HasAttribute(named.OriginalDefinition, CopyByRefNamespace))
83+
{
84+
return true;
85+
}
86+
8187
if (type.TypeKind == TypeKind.Enum)
8288
return true;
8389

Robust.Shared/Prototypes/ProtoId.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using Robust.Shared.Serialization.Manager.Attributes;
23
using Robust.Shared.Serialization.TypeSerializers.Implementations.Generic;
34
using Robust.Shared.Toolshed.TypeParsers;
45

@@ -14,6 +15,7 @@ namespace Robust.Shared.Prototypes;
1415
/// </remarks>
1516
/// <remarks><seealso cref="EntProtoId"/> for an <see cref="EntityPrototype"/> alias.</remarks>
1617
[Serializable]
18+
[CopyByRef]
1719
[PreferOtherType(typeof(EntityPrototype), typeof(EntProtoId))]
1820
public readonly record struct ProtoId<T>(string Id) :
1921
IEquatable<string>,

Robust.Shared/Serialization/TypeSerializers/Implementations/Custom/TimeOffsetSerializer.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
2121
/// to prevent time-offsets from being unintentionally saved to maps while mapping. If an entity must have an initial
2222
/// non-zero time, then that time should just be configured during map-init.
2323
/// </remarks>
24-
public sealed class TimeOffsetSerializer : ITypeSerializer<TimeSpan, ValueDataNode>
24+
public sealed class TimeOffsetSerializer : ITypeSerializer<TimeSpan, ValueDataNode>, ITypeCopyCreator<TimeSpan>
2525
{
2626
public TimeSpan Read(ISerializationManager serializationManager, ValueDataNode node,
2727
IDependencyCollection dependencies,
@@ -81,4 +81,14 @@ public DataNode Write(
8181

8282
return new ValueDataNode(value.TotalSeconds.ToString(CultureInfo.InvariantCulture));
8383
}
84+
85+
public TimeSpan CreateCopy(
86+
ISerializationManager serializationManager,
87+
TimeSpan source,
88+
IDependencyCollection dependencies,
89+
SerializationHookContext hookCtx,
90+
ISerializationContext? context = null)
91+
{
92+
return source;
93+
}
8494
}

0 commit comments

Comments
 (0)