From 2d71eec6f9b7eca098c0f119f07a3a9bf3392ed5 Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Sun, 10 Sep 2023 12:35:05 +1200 Subject: [PATCH] Remove AllComponentsOneEntityDeleteTest (#19965) * Remove AllComponentsOneEntityDeleteTest * AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA --- Content.IntegrationTests/Tests/EntityTest.cs | 132 +----------------- .../RandomFillSolutionComponent.cs | 2 +- .../EntitySystems/SolutionRandomFillSystem.cs | 3 + .../RandomHumanoidSpawnerComponent.cs | 2 +- .../Humanoid/Systems/RandomHumanoidSystem.cs | 3 +- .../Light/EntitySystems/PoweredLightSystem.cs | 2 +- .../Power/EntitySystems/ApcSystem.cs | 2 +- Content.Server/Power/SMES/SmesSystem.cs | 4 +- .../Solar/EntitySystems/PowerSolarSystem.cs | 4 +- .../Containers/ContainerFillSystem.cs | 3 - 10 files changed, 13 insertions(+), 144 deletions(-) diff --git a/Content.IntegrationTests/Tests/EntityTest.cs b/Content.IntegrationTests/Tests/EntityTest.cs index 0966e984bb..d1430cbe29 100644 --- a/Content.IntegrationTests/Tests/EntityTest.cs +++ b/Content.IntegrationTests/Tests/EntityTest.cs @@ -208,6 +208,7 @@ namespace Content.IntegrationTests.Tests "GridFillComponent", "Map", // We aren't testing a map entity in this test "MapGrid", + "Broadphase", "StationData", // errors when removed mid-round "Actor", // We aren't testing actor components, those need their player session set. "BlobFloorPlanBuilder", // Implodes if unconfigured. @@ -292,136 +293,5 @@ namespace Content.IntegrationTests.Tests await pair.CleanReturnAsync(); } - - [Test] - public async Task AllComponentsOneEntityDeleteTest() - { - var skipComponents = new[] - { - "DebugExceptionOnAdd", // Debug components that explicitly throw exceptions - "DebugExceptionExposeData", - "DebugExceptionInitialize", - "DebugExceptionStartup", - "GridFillComponent", - "Map", // We aren't testing a map entity in this test - "MapGrid", - "StationData", // errors when deleted mid-round - "Actor", // We aren't testing actor components, those need their player session set. - "BlobFloorPlanBuilder", // Implodes if unconfigured. - "DebrisFeaturePlacerController", // Above. - "LoadedChunk", // Worldgen chunk loading malding. - "BiomeSelection", // Whaddya know, requires config. - "DeployableBarrier", - }; - - await using var pair = await PoolManager.GetServerClient(); - var server = pair.Server; - - var mapManager = server.ResolveDependency(); - var entityManager = server.ResolveDependency(); - var componentFactory = server.ResolveDependency(); - var tileDefinitionManager = server.ResolveDependency(); - var logmill = server.ResolveDependency().GetSawmill("EntityTest"); - - MapGridComponent grid = default; - - await server.WaitPost(() => - { - // Create a one tile grid to stave off the grid 0 monsters - var mapId = mapManager.CreateMap(); - - mapManager.AddUninitializedMap(mapId); - - grid = mapManager.CreateGrid(mapId); - - var tileDefinition = tileDefinitionManager["Plating"]; - var tile = new Tile(tileDefinition.TileId); - - grid.SetTile(Vector2i.Zero, tile); - mapManager.DoMapInitialize(mapId); - }); - await server.WaitRunTicks(5); - - var distinctComponents = new List<(List components, List references)> - { - (new List(), new List()) - }; - - // Split components into groups, ensuring that their references don't conflict - foreach (var type in componentFactory.AllRegisteredTypes) - { - var registration = componentFactory.GetRegistration(type); - - for (var i = 0; i < distinctComponents.Count; i++) - { - var (components, references) = distinctComponents[i]; - - if (references.Intersect(registration.References).Any()) - { - // Ensure the next list if this one has conflicting references - if (i + 1 >= distinctComponents.Count) - { - distinctComponents.Add((new List(), new List())); - } - - continue; - } - - // Add the component and its references if no conflicting references were found - components.Add(registration.Idx); - references.AddRange(registration.References); - } - } - - // Sanity check - Assert.That(distinctComponents, Is.Not.Empty); - - await server.WaitAssertion(() => - { - Assert.Multiple(() => - { - foreach (var (components, _) in distinctComponents) - { - var testLocation = grid.ToCoordinates(); - var entity = entityManager.SpawnEntity(null, testLocation); - - Assert.That(entityManager.GetComponent(entity).EntityInitialized); - - foreach (var type in components) - { - var component = (Component) componentFactory.GetComponent(type); - - // If the entity already has this component, if it was ensured or added by another - if (entityManager.HasComponent(entity, component.GetType())) - { - continue; - } - - var name = componentFactory.GetComponentName(component.GetType()); - - // If this component is ignored - if (skipComponents.Contains(name)) - continue; - - component.Owner = entity; - logmill.Debug($"Adding component: {name}"); - - // Note for the future coder: if an exception occurs where a component reference - // was already occupied it might be because some component is ensuring another // initialize. - // If so, search for cases of EnsureComponent, EnsureComponentWarn - // and all others variations (out parameter) - Assert.DoesNotThrow(() => - { - entityManager.AddComponent(entity, component); - }, "Component '{0}' threw an exception.", - name); - } - entityManager.DeleteEntity(entity); - } - }); - }); - - await pair.CleanReturnAsync(); - } } } diff --git a/Content.Server/Chemistry/Components/SolutionManager/RandomFillSolutionComponent.cs b/Content.Server/Chemistry/Components/SolutionManager/RandomFillSolutionComponent.cs index bbc06a056e..e4ee6bfc0b 100644 --- a/Content.Server/Chemistry/Components/SolutionManager/RandomFillSolutionComponent.cs +++ b/Content.Server/Chemistry/Components/SolutionManager/RandomFillSolutionComponent.cs @@ -20,5 +20,5 @@ public sealed partial class RandomFillSolutionComponent : Component /// Weighted random fill prototype Id. Used to pick reagent and quantity. /// [DataField("weightedRandomId", required: true, customTypeSerializer: typeof(PrototypeIdSerializer))] - public string WeightedRandomId { get; set; } = "default"; + public string? WeightedRandomId; } diff --git a/Content.Server/Chemistry/EntitySystems/SolutionRandomFillSystem.cs b/Content.Server/Chemistry/EntitySystems/SolutionRandomFillSystem.cs index 78afda9910..efd7857147 100644 --- a/Content.Server/Chemistry/EntitySystems/SolutionRandomFillSystem.cs +++ b/Content.Server/Chemistry/EntitySystems/SolutionRandomFillSystem.cs @@ -22,6 +22,9 @@ public sealed class SolutionRandomFillSystem : EntitySystem private void OnRandomSolutionFillMapInit(EntityUid uid, RandomFillSolutionComponent component, MapInitEvent args) { + if (component.WeightedRandomId == null) + return; + var target = _solutionsSystem.EnsureSolution(uid, component.Solution); var pick = _proto.Index(component.WeightedRandomId).Pick(_random); diff --git a/Content.Server/Humanoid/Components/RandomHumanoidSpawnerComponent.cs b/Content.Server/Humanoid/Components/RandomHumanoidSpawnerComponent.cs index f3b064c132..b56664fe19 100644 --- a/Content.Server/Humanoid/Components/RandomHumanoidSpawnerComponent.cs +++ b/Content.Server/Humanoid/Components/RandomHumanoidSpawnerComponent.cs @@ -12,5 +12,5 @@ namespace Content.Server.Humanoid.Components; public sealed partial class RandomHumanoidSpawnerComponent : Component { [DataField("settings", customTypeSerializer: typeof(PrototypeIdSerializer))] - public string SettingsPrototypeId = default!; + public string? SettingsPrototypeId; } diff --git a/Content.Server/Humanoid/Systems/RandomHumanoidSystem.cs b/Content.Server/Humanoid/Systems/RandomHumanoidSystem.cs index 6ec1770ccd..6a17a52c3d 100644 --- a/Content.Server/Humanoid/Systems/RandomHumanoidSystem.cs +++ b/Content.Server/Humanoid/Systems/RandomHumanoidSystem.cs @@ -29,7 +29,8 @@ public sealed class RandomHumanoidSystem : EntitySystem private void OnMapInit(EntityUid uid, RandomHumanoidSpawnerComponent component, MapInitEvent args) { QueueDel(uid); - SpawnRandomHumanoid(component.SettingsPrototypeId, Transform(uid).Coordinates, MetaData(uid).EntityName); + if (component.SettingsPrototypeId != null) + SpawnRandomHumanoid(component.SettingsPrototypeId, Transform(uid).Coordinates, MetaData(uid).EntityName); } public EntityUid SpawnRandomHumanoid(string prototypeId, EntityCoordinates coordinates, string name) diff --git a/Content.Server/Light/EntitySystems/PoweredLightSystem.cs b/Content.Server/Light/EntitySystems/PoweredLightSystem.cs index acb354082a..144190cf8e 100644 --- a/Content.Server/Light/EntitySystems/PoweredLightSystem.cs +++ b/Content.Server/Light/EntitySystems/PoweredLightSystem.cs @@ -246,7 +246,7 @@ namespace Content.Server.Light.EntitySystems ApcPowerReceiverComponent? powerReceiver = null, AppearanceComponent? appearance = null) { - if (!Resolve(uid, ref light, ref powerReceiver)) + if (!Resolve(uid, ref light, ref powerReceiver, false)) return; // Optional component. diff --git a/Content.Server/Power/EntitySystems/ApcSystem.cs b/Content.Server/Power/EntitySystems/ApcSystem.cs index d477fa4360..5356318aaa 100644 --- a/Content.Server/Power/EntitySystems/ApcSystem.cs +++ b/Content.Server/Power/EntitySystems/ApcSystem.cs @@ -120,7 +120,7 @@ public sealed class ApcSystem : EntitySystem ApcComponent? apc=null, PowerNetworkBatteryComponent? battery = null) { - if (!Resolve(uid, ref apc, ref battery)) + if (!Resolve(uid, ref apc, ref battery, false)) return; var newState = CalcChargeState(uid, battery.NetworkBattery); diff --git a/Content.Server/Power/SMES/SmesSystem.cs b/Content.Server/Power/SMES/SmesSystem.cs index 7da8eb0688..ebd56ee3e1 100644 --- a/Content.Server/Power/SMES/SmesSystem.cs +++ b/Content.Server/Power/SMES/SmesSystem.cs @@ -57,7 +57,7 @@ internal sealed class SmesSystem : EntitySystem private int CalcChargeLevel(EntityUid uid, BatteryComponent? battery = null) { - if (!Resolve(uid, ref battery)) + if (!Resolve(uid, ref battery, false)) return 0; return ContentHelpers.RoundToLevels(battery.CurrentCharge, battery.MaxCharge, 6); @@ -65,7 +65,7 @@ internal sealed class SmesSystem : EntitySystem private ChargeState CalcChargeState(EntityUid uid, PowerNetworkBatteryComponent? netBattery = null) { - if (!Resolve(uid, ref netBattery)) + if (!Resolve(uid, ref netBattery, false)) return ChargeState.Still; return (netBattery.CurrentSupply - netBattery.CurrentReceiving) switch diff --git a/Content.Server/Solar/EntitySystems/PowerSolarSystem.cs b/Content.Server/Solar/EntitySystems/PowerSolarSystem.cs index 74f88bc0d1..cead16b76d 100644 --- a/Content.Server/Solar/EntitySystems/PowerSolarSystem.cs +++ b/Content.Server/Solar/EntitySystems/PowerSolarSystem.cs @@ -172,10 +172,8 @@ namespace Content.Server.Solar.EntitySystems SolarPanelComponent? solar = null, PowerSupplierComponent? supplier = null) { - if (!Resolve(uid, ref solar, ref supplier)) - { + if (!Resolve(uid, ref solar, ref supplier, false)) return; - } supplier.MaxSupply = (int) (solar.MaxSupply * solar.Coverage); } diff --git a/Content.Shared/Containers/ContainerFillSystem.cs b/Content.Shared/Containers/ContainerFillSystem.cs index 81b9782dcd..88aa1def35 100644 --- a/Content.Shared/Containers/ContainerFillSystem.cs +++ b/Content.Shared/Containers/ContainerFillSystem.cs @@ -17,10 +17,7 @@ public sealed class ContainerFillSystem : EntitySystem private void OnMapInit(EntityUid uid, ContainerFillComponent component, MapInitEvent args) { if (!TryComp(uid, out ContainerManagerComponent? containerComp)) - { - Log.Error($"Entity {ToPrettyString(uid)} with a {nameof(ContainerFillComponent)} has no {nameof(ContainerManagerComponent)}."); return; - } var xform = Transform(uid); var coords = new EntityCoordinates(uid, Vector2.Zero);