Mid-game prototype loading for game admins (#5675)
This commit is contained in:
@@ -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<GamePrototypeLoadMessage>(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<GamePrototypeLoadMessage>();
|
||||
msg.PrototypeData = prototype;
|
||||
_netManager.ClientSendMessage(msg);
|
||||
}
|
||||
|
||||
public event Action? GamePrototypeLoaded;
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
<GridContainer Columns="3">
|
||||
<Button Name="SpawnEntitiesButton" Text="{Loc 'sandbox-window-spawn-entities-button'}" />
|
||||
<Button Name="SpawnTilesButton" Text="{Loc 'sandbox-window-spawn-tiles-button'} " />
|
||||
<Button Name="LoadGamePrototypeButton" Text="{Loc 'load-game-prototype'}"/>
|
||||
<cc:CommandButton Command="deleteewc Singularity" Name="DeleteSingulos" Text="{Loc 'delete-singularities'}"/>
|
||||
<cc:UICommandButton Command="events" Text="{Loc 'open-station-events'}" WindowType="{x:Type abt:StationEventsWindow}" />
|
||||
</GridContainer>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Content.Client.Administration.Managers;
|
||||
using System.IO;
|
||||
using Content.Client.Administration.Managers;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.Placement;
|
||||
using Robust.Client.ResourceManagement;
|
||||
@@ -24,6 +26,23 @@ namespace Content.Client.Administration.UI.Tabs.AdminbusTab
|
||||
// TODO: This will probably need some command check at some point
|
||||
SpawnEntitiesButton.OnPressed += SpawnEntitiesButtonOnOnPressed;
|
||||
SpawnTilesButton.OnPressed += SpawnTilesButtonOnOnPressed;
|
||||
LoadGamePrototypeButton.OnPressed += LoadGamePrototypeButtonOnOnPressed;
|
||||
LoadGamePrototypeButton.Visible = IoCManager.Resolve<IClientAdminManager>().HasFlag(AdminFlags.Query);
|
||||
}
|
||||
|
||||
private async void LoadGamePrototypeButtonOnOnPressed(BaseButton.ButtonEventArgs obj)
|
||||
{
|
||||
var dialogManager = IoCManager.Resolve<IFileDialogManager>();
|
||||
var loadManager = IoCManager.Resolve<IGamePrototypeLoadManager>();
|
||||
|
||||
var stream = await dialogManager.OpenFile();
|
||||
if (stream is null)
|
||||
return;
|
||||
|
||||
// ew oop
|
||||
var reader = new StreamReader(stream);
|
||||
var proto = await reader.ReadToEndAsync();
|
||||
loadManager.SendGamePrototype(proto);
|
||||
}
|
||||
|
||||
private void SpawnEntitiesButtonOnOnPressed(BaseButton.ButtonEventArgs obj)
|
||||
|
||||
Reference in New Issue
Block a user