From b555a6049ee6faa15ca03759f16ab32b7eaff6a3 Mon Sep 17 00:00:00 2001 From: ElectroJr Date: Tue, 24 Dec 2024 21:00:53 +1300 Subject: [PATCH] Even more engine changes --- Content.IntegrationTests/Tests/PostMapInitTest.cs | 2 +- .../DeviceNetwork/Systems/DeviceListSystem.cs | 7 +++++-- .../Systems/NetworkConfiguratorSystem.cs | 8 ++++++-- Content.Server/Mapping/MappingManager.cs | 3 ++- Content.Server/Maps/ResaveCommand.cs | 2 +- Content.Server/Procedural/DungeonSystem.cs | 2 +- Content.Shared/Follower/FollowerSystem.cs | 13 ++++++++++--- 7 files changed, 26 insertions(+), 11 deletions(-) diff --git a/Content.IntegrationTests/Tests/PostMapInitTest.cs b/Content.IntegrationTests/Tests/PostMapInitTest.cs index 9e908371df..f07d1e4996 100644 --- a/Content.IntegrationTests/Tests/PostMapInitTest.cs +++ b/Content.IntegrationTests/Tests/PostMapInitTest.cs @@ -426,7 +426,7 @@ namespace Content.IntegrationTests.Tests { try { - Assert.That(mapLoader.TryLoadEntities(path, out maps, out _, opts)); + Assert.That(mapLoader.TryLoadGeneric(path, out maps, out _, opts)); } catch (Exception ex) { diff --git a/Content.Server/DeviceNetwork/Systems/DeviceListSystem.cs b/Content.Server/DeviceNetwork/Systems/DeviceListSystem.cs index 4defec0aab..1988a07cea 100644 --- a/Content.Server/DeviceNetwork/Systems/DeviceListSystem.cs +++ b/Content.Server/DeviceNetwork/Systems/DeviceListSystem.cs @@ -131,7 +131,7 @@ public sealed class DeviceListSystem : SharedDeviceListSystem var enumerator = AllEntityQuery(); while (enumerator.MoveNext(out var uid, out var device, out var xform)) { - if (xform.MapUid != ev.Map) + if (!ev.MapIds.Contains(xform.MapID)) continue; foreach (var ent in device.Devices) @@ -144,7 +144,10 @@ public sealed class DeviceListSystem : SharedDeviceListSystem continue; } - if (linkedXform.MapUid == ev.Map) + // This is assuming that **all** of the map is getting saved. + // Which is not necessarily true. + // AAAAAAAAAAAAAA + if (ev.MapIds.Contains(linkedXform.MapID)) continue; toRemove.Add(ent); diff --git a/Content.Server/DeviceNetwork/Systems/NetworkConfiguratorSystem.cs b/Content.Server/DeviceNetwork/Systems/NetworkConfiguratorSystem.cs index 7e6452d955..645d28f6d2 100644 --- a/Content.Server/DeviceNetwork/Systems/NetworkConfiguratorSystem.cs +++ b/Content.Server/DeviceNetwork/Systems/NetworkConfiguratorSystem.cs @@ -75,7 +75,10 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem var enumerator = AllEntityQuery(); while (enumerator.MoveNext(out var uid, out var conf)) { - if (CompOrNull(conf.ActiveDeviceList)?.MapUid != ev.Map) + if (!TryComp(conf.ActiveDeviceList, out TransformComponent? listXform)) + continue; + + if (!ev.MapIds.Contains(listXform.MapID)) continue; // The linked device list is (probably) being saved. Make sure that the configurator is also being saved @@ -83,9 +86,10 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem // containing a set of all entities that are about to be saved, which would make checking this much easier. // This is a shitty bandaid, and will force close the UI during auto-saves. // TODO Map serialization refactor + // I'm refactoring it now and I still dont know what to do var xform = Transform(uid); - if (xform.MapUid == ev.Map && IsSaveable(uid)) + if (ev.MapIds.Contains(xform.MapID) && IsSaveable(uid)) continue; _uiSystem.CloseUi(uid, NetworkConfiguratorUiKey.Configure); diff --git a/Content.Server/Mapping/MappingManager.cs b/Content.Server/Mapping/MappingManager.cs index be6f503bf0..0097df2e55 100644 --- a/Content.Server/Mapping/MappingManager.cs +++ b/Content.Server/Mapping/MappingManager.cs @@ -54,7 +54,8 @@ public sealed class MappingManager : IPostInjectInit return; } - var data = _systems.GetEntitySystem().SerializeEntityRecursive(mapUid).Node; + var sys = _systems.GetEntitySystem(); + var data = sys.SerializeEntitiesRecursive([mapUid]).Node; var document = new YamlDocument(data.ToYaml()); var stream = new YamlStream { document }; var writer = new StringWriter(); diff --git a/Content.Server/Maps/ResaveCommand.cs b/Content.Server/Maps/ResaveCommand.cs index 39507c850f..c48c02c1f7 100644 --- a/Content.Server/Maps/ResaveCommand.cs +++ b/Content.Server/Maps/ResaveCommand.cs @@ -44,7 +44,7 @@ public sealed class ResaveCommand : LocalizedCommands var fn = files[i]; log.Info($"Re-saving file {i}/{files.Count} : {fn}"); - if (!loader.TryLoadEntities(fn, out var result, opts)) + if (!loader.TryLoadGeneric(fn, out var result, opts)) continue; if (result.Maps.Count != 1) diff --git a/Content.Server/Procedural/DungeonSystem.cs b/Content.Server/Procedural/DungeonSystem.cs index 75cdb69130..521ebed7ec 100644 --- a/Content.Server/Procedural/DungeonSystem.cs +++ b/Content.Server/Procedural/DungeonSystem.cs @@ -182,7 +182,7 @@ public sealed partial class DungeonSystem : SharedDungeonSystem ExpectedCategory = FileCategory.Map }; - if (!_loader.TryLoadEntities(proto.AtlasPath, out var res, opts) || !res.Maps.TryFirstOrNull(out var map)) + if (!_loader.TryLoadGeneric(proto.AtlasPath, out var res, opts) || !res.Maps.TryFirstOrNull(out var map)) throw new Exception($"Failed to load dungeon template."); comp = AddComp(map.Value.Owner); diff --git a/Content.Shared/Follower/FollowerSystem.cs b/Content.Shared/Follower/FollowerSystem.cs index ec13a4f7c2..feea40fb2f 100644 --- a/Content.Shared/Follower/FollowerSystem.cs +++ b/Content.Shared/Follower/FollowerSystem.cs @@ -1,3 +1,4 @@ +using System.Linq; using System.Numerics; using Content.Shared.Administration.Managers; using Content.Shared.Database; @@ -62,8 +63,14 @@ public sealed class FollowerSystem : EntitySystem private void OnBeforeSave(BeforeSerializationEvent ev) { - // Some followers will not be map savable. This ensures that maps don't get saved with empty/invalid - // followers, but just stopping any following on the map being saved. + // Some followers will not be map savable. This ensures that maps don't get saved with some entities that have + // empty/invalid followers, by just stopping any following happening on the map being saved. + // I hate this so much. + // TODO WeakEntityReference + // We need some way to store entity references in a way that doesn't imply that the entity still exists. + // Then we wouldn't have to deal with this shit. + + var maps = ev.Entities.Select(x => Transform(x).MapUid).ToHashSet(); var query = AllEntityQuery(); while (query.MoveNext(out var uid, out var follower, out var xform, out var meta)) @@ -71,7 +78,7 @@ public sealed class FollowerSystem : EntitySystem if (meta.EntityPrototype == null || meta.EntityPrototype.MapSavable) continue; - if (xform.MapUid != ev.Map) + if (!maps.Contains(xform.MapUid)) continue; StopFollowingEntity(uid, follower.Following);