Add mapping editor (#23427)
* Add mapping editor (#757) * Remove mapping actions, never again * Cleanup actions system * Jarvis, remove all references to CM14 * Fix InventoryUIController crashing when an InventoryGui is not found * Rename mapping1 to mapping * Clean up context calls * Add doc comments * Add delegate for hiding decals in the mapping screen * Jarvis mission failed * a * Add test * Fix not flushing save stream in mapping manager * change * Fix verbs * fixes * localise --------- Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com> Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
76
Content.Server/Mapping/MappingManager.cs
Normal file
76
Content.Server/Mapping/MappingManager.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System.IO;
|
||||
using Content.Server.Administration.Managers;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Mapping;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Utility;
|
||||
using YamlDotNet.Core;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
|
||||
namespace Content.Server.Mapping;
|
||||
|
||||
public sealed class MappingManager : IPostInjectInit
|
||||
{
|
||||
[Dependency] private readonly IAdminManager _admin = default!;
|
||||
[Dependency] private readonly ILogManager _log = default!;
|
||||
[Dependency] private readonly IMapManager _map = default!;
|
||||
[Dependency] private readonly IServerNetManager _net = default!;
|
||||
[Dependency] private readonly IPlayerManager _players = default!;
|
||||
[Dependency] private readonly IEntitySystemManager _systems = default!;
|
||||
|
||||
private ISawmill _sawmill = default!;
|
||||
private ZStdCompressionContext _zstd = default!;
|
||||
|
||||
public void PostInject()
|
||||
{
|
||||
#if !FULL_RELEASE
|
||||
_net.RegisterNetMessage<MappingSaveMapMessage>(OnMappingSaveMap);
|
||||
_net.RegisterNetMessage<MappingSaveMapErrorMessage>();
|
||||
_net.RegisterNetMessage<MappingMapDataMessage>();
|
||||
|
||||
_sawmill = _log.GetSawmill("mapping");
|
||||
_zstd = new ZStdCompressionContext();
|
||||
#endif
|
||||
}
|
||||
|
||||
private void OnMappingSaveMap(MappingSaveMapMessage message)
|
||||
{
|
||||
#if !FULL_RELEASE
|
||||
try
|
||||
{
|
||||
if (!_players.TryGetSessionByChannel(message.MsgChannel, out var session) ||
|
||||
!_admin.IsAdmin(session, true) ||
|
||||
!_admin.HasAdminFlag(session, AdminFlags.Host) ||
|
||||
session.AttachedEntity is not { } player)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var mapId = _systems.GetEntitySystem<TransformSystem>().GetMapCoordinates(player).MapId;
|
||||
var mapEntity = _map.GetMapEntityIdOrThrow(mapId);
|
||||
var data = _systems.GetEntitySystem<MapLoaderSystem>().GetSaveData(mapEntity);
|
||||
var document = new YamlDocument(data.ToYaml());
|
||||
var stream = new YamlStream { document };
|
||||
var writer = new StringWriter();
|
||||
stream.Save(new YamlMappingFix(new Emitter(writer)), false);
|
||||
|
||||
var msg = new MappingMapDataMessage()
|
||||
{
|
||||
Context = _zstd,
|
||||
Yml = writer.ToString()
|
||||
};
|
||||
_net.ServerSendMessage(msg, message.MsgChannel);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_sawmill.Error($"Error saving map in mapping mode:\n{e}");
|
||||
var msg = new MappingSaveMapErrorMessage();
|
||||
_net.ServerSendMessage(msg, message.MsgChannel);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user