diff --git a/Robust.Client/GameObjects/ClientEntityManager.cs b/Robust.Client/GameObjects/ClientEntityManager.cs index 1cbe34d10..e2e466b14 100644 --- a/Robust.Client/GameObjects/ClientEntityManager.cs +++ b/Robust.Client/GameObjects/ClientEntityManager.cs @@ -1,8 +1,10 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; +using Robust.Shared.Exceptions; using Robust.Shared.GameObjects; using Robust.Shared.IoC; +using Robust.Shared.Log; using Robust.Shared.Map; using Robust.Shared.Utility; diff --git a/Robust.Server/BaseServer.cs b/Robust.Server/BaseServer.cs index 0ee553a6c..4a88ab64e 100644 --- a/Robust.Server/BaseServer.cs +++ b/Robust.Server/BaseServer.cs @@ -269,7 +269,7 @@ namespace Robust.Server // TODO: solve this properly. _serializer.Initialize(); - _loc.AddLoadedToStringSerializer(); + _loc.AddLoadedToStringSerializer(_stringSerializer); //IoCManager.Resolve().LoadedMapData += // IoCManager.Resolve().AddStrings; diff --git a/Robust.Shared/GameObjects/ComponentManager.cs b/Robust.Shared/GameObjects/ComponentManager.cs index e2995ef68..bb0600e14 100644 --- a/Robust.Shared/GameObjects/ComponentManager.cs +++ b/Robust.Shared/GameObjects/ComponentManager.cs @@ -1,8 +1,9 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Runtime.CompilerServices; +using Robust.Shared.Exceptions; using Robust.Shared.Serialization; using Robust.Shared.Utility; using DependencyAttribute = Robust.Shared.IoC.DependencyAttribute; diff --git a/Robust.Shared/Localization/ILocalizationManager.cs b/Robust.Shared/Localization/ILocalizationManager.cs index 46749925d..c077e32ec 100644 --- a/Robust.Shared/Localization/ILocalizationManager.cs +++ b/Robust.Shared/Localization/ILocalizationManager.cs @@ -1,5 +1,8 @@ using System.Globalization; using JetBrains.Annotations; +using Robust.Shared.ContentPack; +using Robust.Shared.Localization.Macros; +using Robust.Shared.Serialization; namespace Robust.Shared.Localization { @@ -63,12 +66,14 @@ namespace Robust.Shared.Localization /// /// Load data for a culture. /// + /// + /// /// - void LoadCulture(CultureInfo culture); + void LoadCulture(IResourceManager resourceManager, ITextMacroFactory textMacroFactory, CultureInfo culture); } internal interface ILocalizationManagerInternal : ILocalizationManager { - void AddLoadedToStringSerializer(); + void AddLoadedToStringSerializer(IRobustMappedStringSerializer serializer); } } diff --git a/Robust.Shared/Localization/Loc.cs b/Robust.Shared/Localization/Loc.cs index 993135654..7cfba0e72 100644 --- a/Robust.Shared/Localization/Loc.cs +++ b/Robust.Shared/Localization/Loc.cs @@ -1,6 +1,8 @@ using System.Globalization; using JetBrains.Annotations; +using Robust.Shared.ContentPack; using Robust.Shared.IoC; +using Robust.Shared.Localization.Macros; namespace Robust.Shared.Localization { @@ -87,10 +89,12 @@ namespace Robust.Shared.Localization /// /// Load data for a culture. /// + /// + /// /// - public static void LoadCulture(CultureInfo culture) + public static void LoadCulture(IResourceManager resourceManager, ITextMacroFactory macroFactory, CultureInfo culture) { - LocalizationManager.LoadCulture(culture); + LocalizationManager.LoadCulture(resourceManager, macroFactory, culture); } } } diff --git a/Robust.Shared/Localization/LocalizationManager.cs b/Robust.Shared/Localization/LocalizationManager.cs index 26d8dcdc2..3b127db33 100644 --- a/Robust.Shared/Localization/LocalizationManager.cs +++ b/Robust.Shared/Localization/LocalizationManager.cs @@ -5,7 +5,6 @@ using System.IO; using System.Linq; using NGettext; using Robust.Shared.ContentPack; -using Robust.Shared.IoC; using Robust.Shared.Localization.Macros; using Robust.Shared.Serialization; using Robust.Shared.Utility; @@ -15,10 +14,6 @@ namespace Robust.Shared.Localization { internal sealed class LocalizationManager : ILocalizationManagerInternal { - [Dependency] private readonly IResourceManager _resourceManager = default!; - [Dependency] private readonly ITextMacroFactory _textMacroFactory = default!; - [Dependency] private readonly IRobustMappedStringSerializer _stringSerializer = default!; - private readonly Dictionary _catalogs = new(); private CultureInfo? _defaultCulture; @@ -123,22 +118,22 @@ namespace Robust.Shared.Localization } } - public void LoadCulture(CultureInfo culture) + public void LoadCulture(IResourceManager resourceManager, ITextMacroFactory textMacroFactory, CultureInfo culture) { var catalog = new CustomFormatCatalog(culture); _catalogs.Add(culture, catalog); - _loadData(culture, catalog); - _loadMacros(culture, catalog); + _loadData(resourceManager, culture, catalog); + _loadMacros(textMacroFactory, culture, catalog); if (DefaultCulture == null) { DefaultCulture = culture; } } - public void AddLoadedToStringSerializer() + public void AddLoadedToStringSerializer(IRobustMappedStringSerializer serializer) { - _stringSerializer.AddStrings(StringIterator()); + serializer.AddStrings(StringIterator()); IEnumerable StringIterator() { @@ -157,24 +152,24 @@ namespace Robust.Shared.Localization } } - private void _loadData(CultureInfo culture, Catalog catalog) + private static void _loadData(IResourceManager resourceManager, CultureInfo culture, Catalog catalog) { // Load data from .yml files. // Data is loaded from /Locale//* var root = new ResourcePath($"/Locale/{culture.IetfLanguageTag}/"); - foreach (var file in _resourceManager.ContentFindFiles(root)) + foreach (var file in resourceManager.ContentFindFiles(root)) { var yamlFile = root / file; - _loadFromFile(yamlFile, catalog); + _loadFromFile(resourceManager, yamlFile, catalog); } } - private void _loadFromFile(ResourcePath filePath, Catalog catalog) + private static void _loadFromFile(IResourceManager resourceManager, ResourcePath filePath, Catalog catalog) { var yamlStream = new YamlStream(); - using (var fileStream = _resourceManager.ContentFileRead(filePath)) + using (var fileStream = resourceManager.ContentFileRead(filePath)) using (var reader = new StreamReader(fileStream, EncodingHelpers.UTF8)) { yamlStream.Load(reader); @@ -210,9 +205,9 @@ namespace Robust.Shared.Localization catalog.Translations.Add(id, strings); } - private void _loadMacros(CultureInfo culture, CustomFormatCatalog catalog) + private static void _loadMacros(ITextMacroFactory textMacroFactory, CultureInfo culture, CustomFormatCatalog catalog) { - var macros = _textMacroFactory.GetMacrosForLanguage(culture.IetfLanguageTag); + var macros = textMacroFactory.GetMacrosForLanguage(culture.IetfLanguageTag); catalog.CustomFormatProvider = new MacroFormatProvider(new MacroFormatter(macros), culture); } } diff --git a/Robust.Shared/Prototypes/EntityPrototype.cs b/Robust.Shared/Prototypes/EntityPrototype.cs index d92819bdf..781afa1c8 100644 --- a/Robust.Shared/Prototypes/EntityPrototype.cs +++ b/Robust.Shared/Prototypes/EntityPrototype.cs @@ -20,6 +20,8 @@ namespace Robust.Shared.Prototypes [Prototype("entity")] public class EntityPrototype : IPrototype, IIndexedPrototype, ISyncingPrototype { + [Dependency] private readonly IComponentFactory _componentFactory = default!; + /// /// The "in code name" of the object. Must be unique. /// @@ -171,16 +173,15 @@ namespace Robust.Shared.Prototypes // COMPONENTS if (mapping.TryGetNode("components", out var componentsequence)) { - var factory = IoCManager.Resolve(); foreach (var componentMapping in componentsequence.Cast()) { - ReadComponent(componentMapping, factory); + ReadComponent(componentMapping, _componentFactory); } // Assert that there are no conflicting component references. foreach (var componentName in Components.Keys) { - var registration = factory.GetRegistration(componentName); + var registration = _componentFactory.GetRegistration(componentName); foreach (var type in registration.References) { if (ReferenceTypes.Contains(type)) @@ -317,7 +318,7 @@ namespace Robust.Shared.Prototypes foreach (var target in targetList) { - PushInheritance(source, target); + PushInheritance(_componentFactory, source, target); } newSources.AddRange(targetList); @@ -338,7 +339,7 @@ namespace Robust.Shared.Prototypes } } - private static void PushInheritance(EntityPrototype source, EntityPrototype target) + private static void PushInheritance(IComponentFactory factory, EntityPrototype source, EntityPrototype target) { // Copy component data over. foreach (KeyValuePair component in source.Components) @@ -358,7 +359,6 @@ namespace Robust.Shared.Prototypes { // Copy component into the target, since it doesn't have it yet. // Unless it'd cause a conflict. - var factory = IoCManager.Resolve(); foreach (var refType in factory.GetRegistration(component.Key).References) { if (target.ReferenceTypes.Contains(refType))