Even more engine changes

This commit is contained in:
ElectroJr
2024-12-24 21:00:53 +13:00
parent a8cc0397c2
commit b555a6049e
7 changed files with 26 additions and 11 deletions

View File

@@ -426,7 +426,7 @@ namespace Content.IntegrationTests.Tests
{ {
try try
{ {
Assert.That(mapLoader.TryLoadEntities(path, out maps, out _, opts)); Assert.That(mapLoader.TryLoadGeneric(path, out maps, out _, opts));
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@@ -131,7 +131,7 @@ public sealed class DeviceListSystem : SharedDeviceListSystem
var enumerator = AllEntityQuery<DeviceListComponent, TransformComponent>(); var enumerator = AllEntityQuery<DeviceListComponent, TransformComponent>();
while (enumerator.MoveNext(out var uid, out var device, out var xform)) while (enumerator.MoveNext(out var uid, out var device, out var xform))
{ {
if (xform.MapUid != ev.Map) if (!ev.MapIds.Contains(xform.MapID))
continue; continue;
foreach (var ent in device.Devices) foreach (var ent in device.Devices)
@@ -144,7 +144,10 @@ public sealed class DeviceListSystem : SharedDeviceListSystem
continue; 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; continue;
toRemove.Add(ent); toRemove.Add(ent);

View File

@@ -75,7 +75,10 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem
var enumerator = AllEntityQuery<NetworkConfiguratorComponent>(); var enumerator = AllEntityQuery<NetworkConfiguratorComponent>();
while (enumerator.MoveNext(out var uid, out var conf)) while (enumerator.MoveNext(out var uid, out var conf))
{ {
if (CompOrNull<TransformComponent>(conf.ActiveDeviceList)?.MapUid != ev.Map) if (!TryComp(conf.ActiveDeviceList, out TransformComponent? listXform))
continue;
if (!ev.MapIds.Contains(listXform.MapID))
continue; continue;
// The linked device list is (probably) being saved. Make sure that the configurator is also being saved // 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. // 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. // This is a shitty bandaid, and will force close the UI during auto-saves.
// TODO Map serialization refactor // TODO Map serialization refactor
// I'm refactoring it now and I still dont know what to do
var xform = Transform(uid); var xform = Transform(uid);
if (xform.MapUid == ev.Map && IsSaveable(uid)) if (ev.MapIds.Contains(xform.MapID) && IsSaveable(uid))
continue; continue;
_uiSystem.CloseUi(uid, NetworkConfiguratorUiKey.Configure); _uiSystem.CloseUi(uid, NetworkConfiguratorUiKey.Configure);

View File

@@ -54,7 +54,8 @@ public sealed class MappingManager : IPostInjectInit
return; return;
} }
var data = _systems.GetEntitySystem<MapLoaderSystem>().SerializeEntityRecursive(mapUid).Node; var sys = _systems.GetEntitySystem<MapLoaderSystem>();
var data = sys.SerializeEntitiesRecursive([mapUid]).Node;
var document = new YamlDocument(data.ToYaml()); var document = new YamlDocument(data.ToYaml());
var stream = new YamlStream { document }; var stream = new YamlStream { document };
var writer = new StringWriter(); var writer = new StringWriter();

View File

@@ -44,7 +44,7 @@ public sealed class ResaveCommand : LocalizedCommands
var fn = files[i]; var fn = files[i];
log.Info($"Re-saving file {i}/{files.Count} : {fn}"); 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; continue;
if (result.Maps.Count != 1) if (result.Maps.Count != 1)

View File

@@ -182,7 +182,7 @@ public sealed partial class DungeonSystem : SharedDungeonSystem
ExpectedCategory = FileCategory.Map 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."); throw new Exception($"Failed to load dungeon template.");
comp = AddComp<DungeonAtlasTemplateComponent>(map.Value.Owner); comp = AddComp<DungeonAtlasTemplateComponent>(map.Value.Owner);

View File

@@ -1,3 +1,4 @@
using System.Linq;
using System.Numerics; using System.Numerics;
using Content.Shared.Administration.Managers; using Content.Shared.Administration.Managers;
using Content.Shared.Database; using Content.Shared.Database;
@@ -62,8 +63,14 @@ public sealed class FollowerSystem : EntitySystem
private void OnBeforeSave(BeforeSerializationEvent ev) private void OnBeforeSave(BeforeSerializationEvent ev)
{ {
// Some followers will not be map savable. This ensures that maps don't get saved with empty/invalid // Some followers will not be map savable. This ensures that maps don't get saved with some entities that have
// followers, but just stopping any following on the map being saved. // 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<FollowerComponent, TransformComponent, MetaDataComponent>(); var query = AllEntityQuery<FollowerComponent, TransformComponent, MetaDataComponent>();
while (query.MoveNext(out var uid, out var follower, out var xform, out var meta)) 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) if (meta.EntityPrototype == null || meta.EntityPrototype.MapSavable)
continue; continue;
if (xform.MapUid != ev.Map) if (!maps.Contains(xform.MapUid))
continue; continue;
StopFollowingEntity(uid, follower.Following); StopFollowingEntity(uid, follower.Following);