Files
RobustToolbox/Robust.Shared/Upload/SharedPrototypeLoadManager.cs
T
83c2a1be11 [Dependency] source generator part 2 (#6550)
* [Dependency] source generator

No more reflection, no more codegen at runtime

Also various changes to Roslyn helpers to make this easier to write.

Requires all types with dependencies to be partial and not have readonly dependency fields. An analyzer enforces this at warning level, the previous injection strategies have remained in the code *for now* as a fallback.

No fallback is available for [field: Dependency] properties, due to a Roslyn bug.

Code Fixes exist. We love Roslyn

* Apply dependencies generator changes to all code

* Release notes

* Preprocessor got hands

* Handle nullable dependencies

These are bad but gotta deal with it.

* Apply suggestions from code review

Co-authored-by: Moony <moony@hellomouse.net>

* Fine, let's not use collection expressions

---------

Co-authored-by: Moony <moony@hellomouse.net>
2026-05-08 12:38:33 +02:00

62 lines
2.2 KiB
C#

using System;
using System.Collections.Generic;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Network;
using Robust.Shared.Prototypes;
using Robust.Shared.Replays;
using Robust.Shared.Serialization.Markdown.Mapping;
namespace Robust.Shared.Upload;
/// <summary>
/// Manages sending runtime-loaded prototypes from game staff to clients.
/// </summary>
public abstract partial class SharedPrototypeLoadManager : IGamePrototypeLoadManager
{
[Dependency] private IReplayRecordingManager _replay = default!;
[Dependency] private IPrototypeManager _prototypeManager = default!;
[Dependency] private ILocalizationManager _localizationManager = default!;
[Dependency] protected INetManager NetManager = default!;
[Access(typeof(SharedPrototypeLoadManager))]
public readonly List<string> LoadedPrototypes = new();
private ISawmill _sawmill = default!;
public virtual void Initialize()
{
_replay.RecordingStarted += OnStartReplayRecording;
_sawmill = Logger.GetSawmill("adminbus");
NetManager.RegisterNetMessage<GamePrototypeLoadMessage>(LoadPrototypeData);
}
public abstract void SendGamePrototype(string prototype);
protected virtual void LoadPrototypeData(GamePrototypeLoadMessage message)
{
var data = message.PrototypeData;
// TODO validate yaml before loading?
var changed = new Dictionary<Type, HashSet<string>>();
_prototypeManager.LoadString(data, true, changed);
_prototypeManager.ReloadPrototypes(changed);
_localizationManager.ReloadLocalizations();
// Add to replay recording after we have loaded the file, in case it contains bad yaml that throws exceptions.
LoadedPrototypes.Add(data);
_replay.RecordReplayMessage(new ReplayPrototypeUploadMsg { PrototypeData = data });
_sawmill.Info("Loaded adminbus prototype data.");
}
private void OnStartReplayRecording(MappingDataNode metadata, List<object> events)
{
foreach (var prototype in LoadedPrototypes)
{
events.Add(new ReplayPrototypeUploadMsg { PrototypeData = prototype });
}
}
}