mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-01 17:47:24 +02:00
* [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>
69 lines
2.1 KiB
C#
69 lines
2.1 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Log;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Robust.Client.UserInterface.Controllers;
|
|
|
|
/// <summary>
|
|
/// Each <see cref="UIController"/> is instantiated as a singleton by <see cref="UserInterfaceManager"/>
|
|
/// <see cref="UIController"/> can use <see cref="DependencyAttribute"/> for regular IoC dependencies
|
|
/// and <see cref="UISystemDependencyAttribute"/> to depend on <see cref="EntitySystem"/>s, which will be automatically
|
|
/// injected once they are created.
|
|
/// </summary>
|
|
public abstract partial class UIController : IPostInjectInit
|
|
{
|
|
[Dependency] protected IUserInterfaceManager UIManager = default!;
|
|
[Dependency] protected IEntitySystemManager EntitySystemManager = default!;
|
|
[Dependency] protected IEntityManager EntityManager = default!;
|
|
[Dependency] protected ILogManager LogManager = default!;
|
|
|
|
public ISawmill Log { get; protected set; } = default!;
|
|
|
|
public virtual void Initialize()
|
|
{
|
|
}
|
|
|
|
public virtual void FrameUpdate(FrameEventArgs args)
|
|
{
|
|
}
|
|
|
|
protected virtual string SawmillName
|
|
{
|
|
get
|
|
{
|
|
var name = GetType().Name;
|
|
|
|
// Strip trailing "UIController"
|
|
if (name.EndsWith("UIController"))
|
|
name = name.Substring(0, name.Length - "UIController".Length);
|
|
|
|
// Convert CamelCase to snake_case
|
|
// Ignore if all uppercase, assume acronym (e.g. NPC or HTN)
|
|
if (name.All(char.IsUpper))
|
|
{
|
|
name = name.ToLower(CultureInfo.InvariantCulture);
|
|
}
|
|
else
|
|
{
|
|
name = string.Concat(name.Select(x => char.IsUpper(x) ? $"_{char.ToLower(x)}" : x.ToString()));
|
|
name = name.Trim('_');
|
|
}
|
|
|
|
return $"ui.{name}";
|
|
}
|
|
}
|
|
|
|
public void PostInject()
|
|
{
|
|
Log = LogManager.GetSawmill(SawmillName);
|
|
|
|
#if !DEBUG
|
|
Log.Level = LogLevel.Info;
|
|
#endif
|
|
}
|
|
}
|