Revert "Revert "Fix UninitializedSaveTest prototypes" (#16169)" (#16175)

* Revert "Revert "Fix UninitializedSaveTest prototypes" (#16169)"

This reverts commit de1613f7ef.

* Invert if statement
This commit is contained in:
Leon Friedrich
2023-05-07 06:30:51 +12:00
committed by GitHub
parent cebf021a12
commit e3793227b6
25 changed files with 71 additions and 103 deletions

View File

@@ -38,64 +38,6 @@ public sealed class PrototypeSaveTest
{
"Singularity", // physics collision uses "AllMask" (-1). The flag serializer currently fails to save this because this features un-named bits.
"constructionghost",
// These ones are from the serialization change to alwayswrite.
// These should NOT be added to.
// 99% of these are going to be changing the physics bodytype (where the entity is anchored)
// or some ambientsound change.
"GasVentScrubber",
"GasPassiveVent",
"CableHV",
"ParticleAcceleratorFuelChamberUnfinished",
"ComfyChair",
"PlasticFlapsOpaque",
"ParticleAcceleratorEmitterRightUnfinished",
"PlasticFlapsAirtightClear",
"SignalControlledValve",
"SignalControlledValve",
"GasPipeTJunction",
"GasFilter",
"GasOutletInjector",
"GasPressurePump",
"SurveillanceWirelessCameraAnchoredEntertainment",
"GasPort",
"Chair",
"GasMixer",
"ParticleAcceleratorPowerBoxUnfinished",
"GasValve",
"Thruster",
"BoxingBell",
"CableApcExtension",
"PlasticFlapsClear",
"ClothingBackpackChameleon",
"AMEControllerUnanchored",
"GasPipeFourway",
"NuclearBomb",
"PlasticFlapsAirtightOpaque",
"ParticleAcceleratorControlBoxUnfinished",
"GasPipeHalf",
"GasVolumePump",
"ParticleAcceleratorEmitterLeftUnfinished",
"GasMixerFlipped",
"ToiletDirtyWater",
"GasPipeBend",
"ParticleAcceleratorEndCapUnfinished",
"GasPipeStraight",
"MachineFrameDestroyed",
"ChairPilotSeat",
"VehicleJanicartDestroyed",
"Gyroscope",
"ParticleAcceleratorEmitterCenterUnfinished",
"ToiletEmpty",
"GasPassiveGate",
"CableMV",
"ClothingBackpackChameleonFill",
"GasDualPortVentPump",
"GasVentPump",
"PressureControlledValve",
"GasFilterFlipped",
"SurveillanceWirelessCameraAnchoredConstructed",
};
[Test]
@@ -127,7 +69,7 @@ public sealed class PrototypeSaveTest
grid = mapManager.CreateGrid(mapId);
var tileDefinition = tileDefinitionManager["UnderPlating"];
var tileDefinition = tileDefinitionManager["FloorSteel"]; // Wires n such disable ambiance while under the floor
var tile = new Tile(tileDefinition.TileId);
var coordinates = grid.ToCoordinates();
@@ -168,6 +110,7 @@ public sealed class PrototypeSaveTest
foreach (var prototype in prototypes)
{
uid = entityMan.SpawnEntity(prototype.ID, testLocation);
context.Prototype = prototype;
// get default prototype data
Dictionary<string, MappingDataNode> protoData = new();
@@ -177,9 +120,11 @@ public sealed class PrototypeSaveTest
foreach (var (compType, comp) in prototype.Components)
{
context.WritingComponent = compType;
protoData.Add(compType, seriMan.WriteValueAs<MappingDataNode>(comp.Component.GetType(), comp.Component, alwaysWrite: true, context: context));
}
context.WritingComponent = string.Empty;
context.WritingReadingPrototypes = false;
}
catch (Exception e)
@@ -202,6 +147,7 @@ public sealed class PrototypeSaveTest
MappingDataNode compMapping;
try
{
context.WritingComponent = compName;
compMapping = seriMan.WriteValueAs<MappingDataNode>(compType, component, alwaysWrite: true, context: context);
}
catch (Exception e)
@@ -246,6 +192,9 @@ public sealed class PrototypeSaveTest
public SerializationManager.SerializerProvider SerializerProvider { get; }
public bool WritingReadingPrototypes { get; set; }
public string WritingComponent = string.Empty;
public EntityPrototype Prototype = default!;
public TestEntityUidContext()
{
SerializerProvider = new();
@@ -262,6 +211,14 @@ public sealed class PrototypeSaveTest
IDependencyCollection dependencies, bool alwaysWrite = false,
ISerializationContext? context = null)
{
if (WritingComponent != "Transform" && !Prototype.NoSpawn)
{
// Maybe this will be necessary in the future, but at the moment it just indicates that there is some
// issue, like a non-nullable entityUid data-field. If a component MUST have an entity uid to work with,
// then the prototype very likely has to be a no-spawn entity that is never meant to be directly spawned.
Assert.Fail($"Uninitialized entities should not be saving entity Uids. Component: {WritingComponent}. Prototype: {Prototype.ID}");
}
return new ValueDataNode(value.ToString());
}