Files
wwdpublic/Content.Client/Mapping/MappingManager.cs
sleepyyapril a4ab8448b9 Mapping Mini-Wizmerge & New Central Command (#1610)
# Description

<!--
Explain this PR in as much detail as applicable

Some example prompts to consider:
How might this affect the game? The codebase?
What might be some alternatives to this?
How/Who does this benefit/hurt [the game/codebase]?
-->

Ports https://github.com/space-wizards/space-station-14/pull/32294
Ports https://github.com/ss14-harmony/ss14-harmony/pull/310 (and
everything needed for it to function)
Early-merges
https://github.com/space-wizards/space-station-14/pull/34302

Adds the ability for multiple central command maps that get randomly
selected.
Tested and works.

---

# Changelog

<!--
You can add an author after the `🆑` to change the name that appears
in the changelog (ex: `🆑 Death`)
Leaving it blank will default to your GitHub display name
This includes all available types for the changelog
-->

🆑 Several contributors
- add: Added a new central command map that is randomly picked alongside
the old one (thank you to Spanky from Harmony)
- add: Added Advanced SMES for mappers.
- add: Added the atmospheric network monitor for seeing what the
temperature, moles, and pressure is on every pipe everywhere through a
computer.
- add: Nukie med bundle now contains a compact defibrillator.
- add: Ported a better mapping editor.
- add: Added the throngler plushie.
- remove: Removed the Throngler as a possible loot spawn for gamble
crates.

---------

Signed-off-by: sleepyyapril <123355664+sleepyyapril@users.noreply.github.com>

(cherry picked from commit 9272f65b64392f66a7cd4fd7c84bb152dc93b65a)
2025-01-20 21:34:45 +03:00

116 lines
3.5 KiB
C#

using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Content.Shared.Decals;
using Content.Shared.Mapping;
using Content.Shared.Maps;
using Robust.Client.UserInterface;
using Robust.Shared.Network;
using Robust.Shared.Prototypes;
namespace Content.Client.Mapping;
public sealed class MappingManager : IPostInjectInit
{
[Dependency] private readonly IFileDialogManager _file = default!;
[Dependency] private readonly IClientNetManager _net = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
private Stream? _saveStream;
private MappingMapDataMessage? _mapData;
private List<IPrototype>? _favoritePrototypes;
public event Action<List<IPrototype>>? OnFavoritePrototypesLoaded;
public void PostInject()
{
_net.RegisterNetMessage<MappingSaveMapMessage>();
_net.RegisterNetMessage<MappingSaveMapErrorMessage>(OnSaveError);
_net.RegisterNetMessage<MappingMapDataMessage>(OnMapData);
_net.RegisterNetMessage<MappingFavoritesDataMessage>(OnFavoritesData);
_net.RegisterNetMessage<MappingFavoritesSaveMessage>();
}
private void OnSaveError(MappingSaveMapErrorMessage message)
{
_saveStream?.DisposeAsync();
_saveStream = null;
}
private async void OnMapData(MappingMapDataMessage message)
{
if (_saveStream == null)
{
_mapData = message;
return;
}
await _saveStream.WriteAsync(Encoding.ASCII.GetBytes(message.Yml));
await _saveStream.DisposeAsync();
_saveStream = null;
_mapData = null;
}
private void OnFavoritesData(MappingFavoritesDataMessage message)
{
_favoritePrototypes = new List<IPrototype>();
foreach (var prototype in message.PrototypeIDs)
{
if (_prototypeManager.TryIndex<EntityPrototype>(prototype, out var entity))
_favoritePrototypes.Add(entity);
else if (_prototypeManager.TryIndex<ContentTileDefinition>(prototype, out var tile))
_favoritePrototypes.Add(tile);
else if (_prototypeManager.TryIndex<DecalPrototype>(prototype, out var decal))
_favoritePrototypes.Add(decal);
}
OnFavoritePrototypesLoaded?.Invoke(_favoritePrototypes);
}
public async Task SaveMap()
{
if (_saveStream != null)
await _saveStream.DisposeAsync();
var request = new MappingSaveMapMessage();
_net.ClientSendMessage(request);
var path = await _file.SaveFile();
if (path is not { fileStream: var stream })
return;
if (_mapData != null)
{
await stream.WriteAsync(Encoding.ASCII.GetBytes(_mapData.Yml));
_mapData = null;
await stream.FlushAsync();
await stream.DisposeAsync();
return;
}
_saveStream = stream;
}
public void SaveFavorites(List<MappingPrototype> prototypes)
{
// TODO: that doesnt save null prototypes (mapping templates and abstract parents)
var msg = new MappingFavoritesSaveMessage()
{
PrototypeIDs = prototypes
.FindAll(p => p.Prototype != null)
.Select(p => p.Prototype!.ID)
.ToList(),
};
_net.ClientSendMessage(msg);
}
public void LoadFavorites()
{
var request = new MappingFavoritesLoadMessage();
_net.ClientSendMessage(request);
}
}