From caad34eecbc8d69e03ff927a2346ac909ef49db0 Mon Sep 17 00:00:00 2001 From: Moony Date: Sat, 11 Dec 2021 17:28:16 -0600 Subject: [PATCH] Mid-game prototype loading for game admins (#5675) --- .../Managers/GamePrototypeLoadManager.cs | 39 ++++++++++ .../UI/Tabs/AdminbusTab/AdminbusTab.xaml | 1 + .../UI/Tabs/AdminbusTab/AdminbusTab.xaml.cs | 21 ++++- Content.Client/Entry/EntryPoint.cs | 2 + Content.Client/IoC/ClientContentIoC.cs | 5 +- .../GamePrototypeLoadManager.cs | 76 +++++++++++++++++++ Content.Server/Entry/EntryPoint.cs | 4 +- Content.Server/IoC/ServerContentIoC.cs | 2 + .../GamePrototypeLoadMessage.cs | 25 ++++++ .../IGamePrototypeLoadManager.cs | 11 +++ .../Reaction/SharedChemicalReactionSystem.cs | 3 + .../ui/tabs/adminbus-tab/adminbus-tab.ftl | 1 + 12 files changed, 186 insertions(+), 4 deletions(-) create mode 100644 Content.Client/Administration/Managers/GamePrototypeLoadManager.cs create mode 100644 Content.Server/Administration/GamePrototypeLoadManager.cs create mode 100644 Content.Shared/Administration/GamePrototypeLoadMessage.cs create mode 100644 Content.Shared/Administration/IGamePrototypeLoadManager.cs diff --git a/Content.Client/Administration/Managers/GamePrototypeLoadManager.cs b/Content.Client/Administration/Managers/GamePrototypeLoadManager.cs new file mode 100644 index 0000000000..15944516a2 --- /dev/null +++ b/Content.Client/Administration/Managers/GamePrototypeLoadManager.cs @@ -0,0 +1,39 @@ +using System; +using Content.Shared.Administration; +using Robust.Shared.IoC; +using Robust.Shared.Localization; +using Robust.Shared.Log; +using Robust.Shared.Network; +using Robust.Shared.Prototypes; + +namespace Content.Client.Administration.Managers; + +public class GamePrototypeLoadManager : IGamePrototypeLoadManager +{ + [Dependency] private readonly IClientNetManager _netManager = default!; + [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + [Dependency] private readonly ILocalizationManager _localizationManager = default!; + + public void Initialize() + { + _netManager.RegisterNetMessage(LoadGamePrototype); + } + + private void LoadGamePrototype(GamePrototypeLoadMessage message) + { + _prototypeManager.LoadString(message.PrototypeData); + _prototypeManager.Resync(); + _localizationManager.ReloadLocalizations(); + GamePrototypeLoaded?.Invoke(); + Logger.InfoS("adminbus", "Loaded adminbus prototype data."); + } + + public void SendGamePrototype(string prototype) + { + var msg = _netManager.CreateNetMessage(); + msg.PrototypeData = prototype; + _netManager.ClientSendMessage(msg); + } + + public event Action? GamePrototypeLoaded; +} diff --git a/Content.Client/Administration/UI/Tabs/AdminbusTab/AdminbusTab.xaml b/Content.Client/Administration/UI/Tabs/AdminbusTab/AdminbusTab.xaml index 898a4404a9..3fc51089d7 100644 --- a/Content.Client/Administration/UI/Tabs/AdminbusTab/AdminbusTab.xaml +++ b/Content.Client/Administration/UI/Tabs/AdminbusTab/AdminbusTab.xaml @@ -8,6 +8,7 @@