Refactor map loading & saving (#34020)

This commit is contained in:
Leon Friedrich
2025-02-16 21:36:35 +11:00
committed by GitHub
39 changed files with 718 additions and 419 deletions

View File

@@ -1,3 +1,4 @@
using System.Linq;
using System.Numerics;
using Content.Shared.Administration.Managers;
using Content.Shared.Database;
@@ -44,8 +45,8 @@ public sealed class FollowerSystem : EntitySystem
SubscribeLocalEvent<FollowedComponent, ComponentGetStateAttemptEvent>(OnFollowedAttempt);
SubscribeLocalEvent<FollowerComponent, GotEquippedHandEvent>(OnGotEquippedHand);
SubscribeLocalEvent<FollowedComponent, EntityTerminatingEvent>(OnFollowedTerminating);
SubscribeLocalEvent<BeforeSerializationEvent>(OnBeforeSave);
SubscribeLocalEvent<FollowedComponent, PolymorphedEvent>(OnFollowedPolymorphed);
SubscribeLocalEvent<BeforeSaveEvent>(OnBeforeSave);
}
private void OnFollowedAttempt(Entity<FollowedComponent> ent, ref ComponentGetStateAttemptEvent args)
@@ -63,10 +64,16 @@ public sealed class FollowerSystem : EntitySystem
}
}
private void OnBeforeSave(BeforeSaveEvent ev)
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<FollowerComponent, TransformComponent, MetaDataComponent>();
while (query.MoveNext(out var uid, out var follower, out var xform, out var meta))
@@ -74,7 +81,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);

View File

@@ -8,6 +8,7 @@ using Content.Shared.Movement.Events;
using Robust.Shared.GameStates;
using Robust.Shared.Input;
using Robust.Shared.Input.Binding;
using Robust.Shared.Map.Components;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
@@ -207,7 +208,7 @@ namespace Content.Shared.Movement.Systems
}
// If we went from grid -> map we'll preserve our worldrotation
if (relative != null && _mapManager.IsMap(relative.Value))
if (relative != null && HasComp<MapComponent>(relative.Value))
{
targetRotation = currentRotation.FlipPositive().Reduced();
}