Remove all dependencies from LocalizationManager.

Remove IoCManager calls from EntityPrototype.
Add missing using statements preventing EXCEPTION_TOLERANCE from building.
This commit is contained in:
Acruid
2020-07-10 03:24:39 -07:00
parent 2183cd7ca1
commit 0ba2272cab
7 changed files with 37 additions and 30 deletions

View File

@@ -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;

View File

@@ -269,7 +269,7 @@ namespace Robust.Server
// TODO: solve this properly.
_serializer.Initialize();
_loc.AddLoadedToStringSerializer();
_loc.AddLoadedToStringSerializer(_stringSerializer);
//IoCManager.Resolve<IMapLoader>().LoadedMapData +=
// IoCManager.Resolve<IRobustMappedStringSerializer>().AddStrings;

View File

@@ -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;

View File

@@ -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
/// <summary>
/// Load data for a culture.
/// </summary>
/// <param name="resourceManager"></param>
/// <param name="textMacroFactory"></param>
/// <param name="culture"></param>
void LoadCulture(CultureInfo culture);
void LoadCulture(IResourceManager resourceManager, ITextMacroFactory textMacroFactory, CultureInfo culture);
}
internal interface ILocalizationManagerInternal : ILocalizationManager
{
void AddLoadedToStringSerializer();
void AddLoadedToStringSerializer(IRobustMappedStringSerializer serializer);
}
}

View File

@@ -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
/// <summary>
/// Load data for a culture.
/// </summary>
/// <param name="resourceManager"></param>
/// <param name="macroFactory"></param>
/// <param name="culture"></param>
public static void LoadCulture(CultureInfo culture)
public static void LoadCulture(IResourceManager resourceManager, ITextMacroFactory macroFactory, CultureInfo culture)
{
LocalizationManager.LoadCulture(culture);
LocalizationManager.LoadCulture(resourceManager, macroFactory, culture);
}
}
}

View File

@@ -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<CultureInfo, Catalog> _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<string> 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/<language-code>/*
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);
}
}

View File

@@ -20,6 +20,8 @@ namespace Robust.Shared.Prototypes
[Prototype("entity")]
public class EntityPrototype : IPrototype, IIndexedPrototype, ISyncingPrototype
{
[Dependency] private readonly IComponentFactory _componentFactory = default!;
/// <summary>
/// The "in code name" of the object. Must be unique.
/// </summary>
@@ -171,16 +173,15 @@ namespace Robust.Shared.Prototypes
// COMPONENTS
if (mapping.TryGetNode<YamlSequenceNode>("components", out var componentsequence))
{
var factory = IoCManager.Resolve<IComponentFactory>();
foreach (var componentMapping in componentsequence.Cast<YamlMappingNode>())
{
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<string, YamlMappingNode> 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<IComponentFactory>();
foreach (var refType in factory.GetRegistration(component.Key).References)
{
if (target.ReferenceTypes.Contains(refType))