Call reload protoypes on admin changes (#13160)
* Call reload protoypes on admin changes Fixes NPCs not working after engine change. * Also chems * other fixes
This commit is contained in:
@@ -1,8 +1,4 @@
|
|||||||
using System;
|
|
||||||
using Content.Shared.Administration;
|
using Content.Shared.Administration;
|
||||||
using Robust.Shared.IoC;
|
|
||||||
using Robust.Shared.Localization;
|
|
||||||
using Robust.Shared.Log;
|
|
||||||
using Robust.Shared.Network;
|
using Robust.Shared.Network;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
|
|
||||||
@@ -21,19 +17,20 @@ public sealed class GamePrototypeLoadManager : IGamePrototypeLoadManager
|
|||||||
|
|
||||||
private void LoadGamePrototype(GamePrototypeLoadMessage message)
|
private void LoadGamePrototype(GamePrototypeLoadMessage message)
|
||||||
{
|
{
|
||||||
_prototypeManager.LoadString(message.PrototypeData, true);
|
var changed = new Dictionary<Type, HashSet<string>>();
|
||||||
|
_prototypeManager.LoadString(message.PrototypeData, true, changed);
|
||||||
_prototypeManager.ResolveResults();
|
_prototypeManager.ResolveResults();
|
||||||
|
_prototypeManager.ReloadPrototypes(changed);
|
||||||
_localizationManager.ReloadLocalizations();
|
_localizationManager.ReloadLocalizations();
|
||||||
GamePrototypeLoaded?.Invoke();
|
|
||||||
Logger.InfoS("adminbus", "Loaded adminbus prototype data.");
|
Logger.InfoS("adminbus", "Loaded adminbus prototype data.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendGamePrototype(string prototype)
|
public void SendGamePrototype(string prototype)
|
||||||
{
|
{
|
||||||
var msg = _netManager.CreateNetMessage<GamePrototypeLoadMessage>();
|
var msg = new GamePrototypeLoadMessage
|
||||||
msg.PrototypeData = prototype;
|
{
|
||||||
|
PrototypeData = prototype
|
||||||
|
};
|
||||||
_netManager.ClientSendMessage(msg);
|
_netManager.ClientSendMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public event Action? GamePrototypeLoaded;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public sealed class GamePrototypeLoadManager : IGamePrototypeLoadManager
|
|||||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||||
[Dependency] private readonly ILocalizationManager _localizationManager = default!;
|
[Dependency] private readonly ILocalizationManager _localizationManager = default!;
|
||||||
|
|
||||||
private readonly List<string> LoadedPrototypes = new();
|
private readonly List<string> _loadedPrototypes = new();
|
||||||
|
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
{
|
{
|
||||||
@@ -30,8 +30,6 @@ public sealed class GamePrototypeLoadManager : IGamePrototypeLoadManager
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public event Action? GamePrototypeLoaded;
|
|
||||||
|
|
||||||
private void ClientLoadsPrototype(GamePrototypeLoadMessage message)
|
private void ClientLoadsPrototype(GamePrototypeLoadMessage message)
|
||||||
{
|
{
|
||||||
var player = _playerManager.GetSessionByChannel(message.MsgChannel);
|
var player = _playerManager.GetSessionByChannel(message.MsgChannel);
|
||||||
@@ -48,23 +46,28 @@ public sealed class GamePrototypeLoadManager : IGamePrototypeLoadManager
|
|||||||
|
|
||||||
private void LoadPrototypeData(string prototypeData)
|
private void LoadPrototypeData(string prototypeData)
|
||||||
{
|
{
|
||||||
LoadedPrototypes.Add(prototypeData);
|
_loadedPrototypes.Add(prototypeData);
|
||||||
var msg = new GamePrototypeLoadMessage();
|
var msg = new GamePrototypeLoadMessage
|
||||||
msg.PrototypeData = prototypeData;
|
{
|
||||||
|
PrototypeData = prototypeData
|
||||||
|
};
|
||||||
_netManager.ServerSendToAll(msg); // everyone load it up!
|
_netManager.ServerSendToAll(msg); // everyone load it up!
|
||||||
_prototypeManager.LoadString(prototypeData, true); // server needs it too.
|
var changed = new Dictionary<Type, HashSet<string>>();
|
||||||
|
_prototypeManager.LoadString(prototypeData, true, changed); // server needs it too.
|
||||||
_prototypeManager.ResolveResults();
|
_prototypeManager.ResolveResults();
|
||||||
|
_prototypeManager.ReloadPrototypes(changed);
|
||||||
_localizationManager.ReloadLocalizations();
|
_localizationManager.ReloadLocalizations();
|
||||||
GamePrototypeLoaded?.Invoke();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void NetManagerOnConnected(object? sender, NetChannelArgs e)
|
private void NetManagerOnConnected(object? sender, NetChannelArgs e)
|
||||||
{
|
{
|
||||||
// Just dump all the prototypes on connect, before them missing could be an issue.
|
// Just dump all the prototypes on connect, before them missing could be an issue.
|
||||||
foreach (var prototype in LoadedPrototypes)
|
foreach (var prototype in _loadedPrototypes)
|
||||||
{
|
{
|
||||||
var msg = new GamePrototypeLoadMessage();
|
var msg = new GamePrototypeLoadMessage
|
||||||
msg.PrototypeData = prototype;
|
{
|
||||||
|
PrototypeData = prototype
|
||||||
|
};
|
||||||
e.Channel.SendMessage(msg);
|
e.Channel.SendMessage(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace Content.Server.Chemistry.EntitySystems
|
|||||||
|
|
||||||
var coordinates = Transform(owner).Coordinates;
|
var coordinates = Transform(owner).Coordinates;
|
||||||
|
|
||||||
_adminLogger.Add(LogType.ChemicalReaction, reaction.Impact,
|
AdminLogger.Add(LogType.ChemicalReaction, reaction.Impact,
|
||||||
$"Chemical reaction {reaction.ID:reaction} occurred with strength {unitReactions:strength} on entity {ToPrettyString(owner):metabolizer} at {coordinates}");
|
$"Chemical reaction {reaction.ID:reaction} occurred with strength {unitReactions:strength} on entity {ToPrettyString(owner):metabolizer} at {coordinates}");
|
||||||
|
|
||||||
SoundSystem.Play(reaction.Sound.GetSound(), Filter.Pvs(owner, entityManager:EntityManager), owner);
|
SoundSystem.Play(reaction.Sound.GetSound(), Filter.Pvs(owner, entityManager:EntityManager), owner);
|
||||||
|
|||||||
@@ -4,6 +4,4 @@ public interface IGamePrototypeLoadManager
|
|||||||
{
|
{
|
||||||
public void Initialize();
|
public void Initialize();
|
||||||
public void SendGamePrototype(string prototype);
|
public void SendGamePrototype(string prototype);
|
||||||
|
|
||||||
event Action GamePrototypeLoaded;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,7 @@ namespace Content.Shared.Chemistry.Reaction
|
|||||||
|
|
||||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||||
[Dependency] private readonly IRobustRandom _random = default!;
|
[Dependency] private readonly IRobustRandom _random = default!;
|
||||||
[Dependency] protected readonly ISharedAdminLogManager _adminLogger = default!;
|
[Dependency] protected readonly ISharedAdminLogManager AdminLogger = default!;
|
||||||
[Dependency] private readonly IGamePrototypeLoadManager _gamePrototypeLoadManager = default!;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A cache of all existant chemical reactions indexed by one of their
|
/// A cache of all existant chemical reactions indexed by one of their
|
||||||
@@ -36,7 +35,12 @@ namespace Content.Shared.Chemistry.Reaction
|
|||||||
|
|
||||||
InitializeReactionCache();
|
InitializeReactionCache();
|
||||||
_prototypeManager.PrototypesReloaded += OnPrototypesReloaded;
|
_prototypeManager.PrototypesReloaded += OnPrototypesReloaded;
|
||||||
_gamePrototypeLoadManager.GamePrototypeLoaded += InitializeReactionCache;
|
}
|
||||||
|
|
||||||
|
public override void Shutdown()
|
||||||
|
{
|
||||||
|
base.Shutdown();
|
||||||
|
_prototypeManager.PrototypesReloaded -= OnPrototypesReloaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -210,7 +214,7 @@ namespace Content.Shared.Chemistry.Reaction
|
|||||||
if (effect.ShouldLog)
|
if (effect.ShouldLog)
|
||||||
{
|
{
|
||||||
var entity = args.SolutionEntity;
|
var entity = args.SolutionEntity;
|
||||||
_adminLogger.Add(LogType.ReagentEffect, effect.LogImpact,
|
AdminLogger.Add(LogType.ReagentEffect, effect.LogImpact,
|
||||||
$"Reaction effect {effect.GetType().Name:effect} of reaction ${reaction.ID:reaction} applied on entity {ToPrettyString(entity):entity} at {Transform(entity).Coordinates:coordinates}");
|
$"Reaction effect {effect.GetType().Name:effect} of reaction ${reaction.ID:reaction} applied on entity {ToPrettyString(entity):entity} at {Transform(entity).Coordinates:coordinates}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user