Skip to content

Commit

Permalink
Adjust code style to better match official c# guidelines
Browse files Browse the repository at this point in the history
  • Loading branch information
Olaren15 committed May 26, 2024
1 parent e6e8557 commit e94f5b3
Show file tree
Hide file tree
Showing 87 changed files with 1,373 additions and 1,291 deletions.
351 changes: 228 additions & 123 deletions .editorconfig

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions EasyTranslate.DalamudPlugin/Attributes/EntryPointAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace EasyTranslate.DalamudPlugin.Attributes;

using System;

namespace EasyTranslate.DalamudPlugin.Attributes;

[AttributeUsage(AttributeTargets.Class)]
public class EntryPointAttribute : Attribute;
76 changes: 38 additions & 38 deletions EasyTranslate.DalamudPlugin/Configuration/DalamudPluginModule.cs
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
namespace EasyTranslate.DalamudPlugin.Configuration;

using Dalamud.Interface.Windowing;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin;
using Dalamud.Plugin.Services;
using Infrastructure.Configuration;
using Localisation;
using EasyTranslate.DalamudPlugin.Localisation;
using EasyTranslate.DalamudPlugin.Search;
using EasyTranslate.DalamudPlugin.Settings;
using EasyTranslate.Infrastructure.Configuration;
using EasyTranslate.UseCase.Configuration;
using Lumina.Excel;
using Microsoft.Extensions.DependencyInjection;
using Search;
using Settings;
using UseCase.Configuration;

namespace EasyTranslate.DalamudPlugin.Configuration;

public static class DalamudPluginModule
{
public static ServiceProvider CreateServiceProvider(DalamudPluginInterface pluginInterface)
{
return new ServiceCollection()
.AddDalamudServices(pluginInterface)
.AddPluginServices()
.AddUseCaseServices()
.AddInfrastructureServices()
.BuildServiceProvider();
.AddDalamudServices(pluginInterface)
.AddPluginServices()
.AddUseCaseServices()
.AddInfrastructureServices()
.BuildServiceProvider();
}

public static IServiceCollection AddDalamudServices(
private static IServiceCollection AddDalamudServices(
this IServiceCollection serviceCollection,
DalamudPluginInterface pluginInterface
)
{
return serviceCollection
.AddExisting(pluginInterface)
.AddExisting(pluginInterface.UiBuilder)
.AddDalamudService<ICommandManager>()
.AddDalamudService<ITextureProvider>()
.AddDalamudService<IDataManager>()
.AddDalamudService<IGameConfig>()
.AddDalamudService<IContextMenu>()
.AddDalamudService<IDataManager>()
.AddSingleton<ExcelModule>(serviceProvider => serviceProvider.GetService<IDataManager>()!.Excel);
.AddExisting(pluginInterface)
.AddExisting(pluginInterface.UiBuilder)
.AddDalamudService<ICommandManager>()
.AddDalamudService<ITextureProvider>()
.AddDalamudService<IDataManager>()
.AddDalamudService<IGameConfig>()
.AddDalamudService<IContextMenu>()
.AddDalamudService<IDataManager>()
.AddSingleton<ExcelModule>(serviceProvider => serviceProvider.GetService<IDataManager>()!.Excel);
}

public static IServiceCollection AddPluginServices(this IServiceCollection serviceCollection)
private static IServiceCollection AddPluginServices(this IServiceCollection serviceCollection)
{
return serviceCollection
.AddSingleton<LanguageSwitcher>()
.AddSingleton<WindowSystem>(_ => new WindowSystem("EasyTranslate"))
.AddSingleton<SearchView>()
.AddTransient<SearchViewModel>()
.AddSingleton<ContentMapper>()
.AddSingleton<OpenSearchCommand>()
.AddSingleton<UserSettingsRepository>()
.AddSingleton<OpenSettingsCommand>()
.AddSingleton<SettingsView>()
.AddTransient<SettingsViewModel>()
.AddSingleton<SearchContextMenuItem>();
.AddSingleton<LanguageSwitcher>()
.AddSingleton<WindowSystem>(_ => new WindowSystem("EasyTranslate"))
.AddSingleton<SearchView>()
.AddTransient<SearchViewModel>()
.AddSingleton<ContentMapper>()
.AddSingleton<OpenSearchCommand>()
.AddSingleton<UserSettingsRepository>()
.AddSingleton<OpenSettingsCommand>()
.AddSingleton<SettingsView>()
.AddTransient<SettingsViewModel>()
.AddSingleton<SearchContextMenuItem>();
}

public static IServiceCollection AddExisting<T>(this IServiceCollection serviceCollection, T service)
private static IServiceCollection AddExisting<T>(this IServiceCollection serviceCollection, T service)
where T : class
{
return serviceCollection.AddSingleton(service);
Expand All @@ -67,8 +67,8 @@ public static IServiceCollection AddExisting<T>(this IServiceCollection serviceC
serviceCollection.AddSingleton(
serviceProvider =>
{
var pluginInterface = serviceProvider.GetService<DalamudPluginInterface>();
var wrapper = new DalamudServiceWrapper<T>(pluginInterface!);
DalamudPluginInterface? pluginInterface = serviceProvider.GetService<DalamudPluginInterface>();
DalamudServiceWrapper<T> wrapper = new(pluginInterface!);
return wrapper.Service;
}
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace EasyTranslate.DalamudPlugin.Configuration;

using Dalamud.IoC;
using Dalamud.IoC;
using Dalamud.Plugin;

namespace EasyTranslate.DalamudPlugin.Configuration;

#pragma warning disable CS8618

public class DalamudServiceWrapper<T>
Expand Down
76 changes: 38 additions & 38 deletions EasyTranslate.DalamudPlugin/EasyTranslate.DalamudPlugin.csproj
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../Dalamud.Libs.targets"/>
<Import Project="$(DalamudLibPath)/targets/Dalamud.Plugin.targets"/>
<Import Project="../Dalamud.Libs.targets"/>
<Import Project="$(DalamudLibPath)/targets/Dalamud.Plugin.targets"/>

<PropertyGroup>
<Authors>Olaren</Authors>
<Company></Company>
<Version>2.1.0.0</Version>
<Description>Search for FFXIV translations right from the game!</Description>
<Copyright></Copyright>
<PackageProjectUrl>https://github.com/Olaren15/ffxiv-easy-translate</PackageProjectUrl>
<PackageLicenseExpression>AGPL-3.0-or-later</PackageLicenseExpression>
<IsPackable>false</IsPackable>
<RootNamespace>EasyTranslate.DalamudPlugin</RootNamespace>
<TargetFramework>net8.0-windows</TargetFramework>
<NeutralLanguage>en</NeutralLanguage>
<LangVersion>12</LangVersion>
</PropertyGroup>
<PropertyGroup>
<Authors>Olaren</Authors>
<Company></Company>
<Version>2.1.0.0</Version>
<Description>Search for FFXIV translations right from the game!</Description>
<Copyright></Copyright>
<PackageProjectUrl>https://github.com/Olaren15/ffxiv-easy-translate</PackageProjectUrl>
<PackageLicenseExpression>AGPL-3.0-or-later</PackageLicenseExpression>
<IsPackable>false</IsPackable>
<RootNamespace>EasyTranslate.DalamudPlugin</RootNamespace>
<TargetFramework>net8.0-windows</TargetFramework>
<NeutralLanguage>en</NeutralLanguage>
<LangVersion>12</LangVersion>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\EasyTranslate.Domain\EasyTranslate.Domain.csproj"/>
<ProjectReference Include="..\EasyTranslate.Infrastructure\EasyTranslate.Infrastructure.csproj"/>
<ProjectReference Include="..\EasyTranslate.UseCase\EasyTranslate.UseCase.csproj"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EasyTranslate.Domain\EasyTranslate.Domain.csproj"/>
<ProjectReference Include="..\EasyTranslate.Infrastructure\EasyTranslate.Infrastructure.csproj"/>
<ProjectReference Include="..\EasyTranslate.UseCase\EasyTranslate.UseCase.csproj"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0"/>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Resources\Strings.fr.resx"/>
<EmbeddedResource Update="Resources\Strings.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Strings.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Resources\Strings.fr.resx"/>
<EmbeddedResource Update="Resources\Strings.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Strings.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
<Compile Update="Resources\Strings.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Strings.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Update="Resources\Strings.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Strings.resx</DependentUpon>
</Compile>
</ItemGroup>
</Project>
36 changes: 18 additions & 18 deletions EasyTranslate.DalamudPlugin/EasyTranslatePlugin.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
namespace EasyTranslate.DalamudPlugin;

using System;
using System;
using System.Linq;
using System.Reflection;
using Attributes;
using Configuration;
using Dalamud.Interface;
using Dalamud.Interface.Windowing;
using Dalamud.IoC;
using Dalamud.Plugin;
using EasyTranslate.DalamudPlugin.Attributes;
using EasyTranslate.DalamudPlugin.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace EasyTranslate.DalamudPlugin;

// ReSharper disable once UnusedType.Global
public sealed class EasyTranslatePlugin : IDalamudPlugin
{
private readonly ServiceProvider serviceProvider;
private readonly UiBuilder uiBuilder;
private readonly WindowSystem windowSystem;
private readonly ServiceProvider _serviceProvider;
private readonly UiBuilder _uiBuilder;
private readonly WindowSystem _windowSystem;

public EasyTranslatePlugin([RequiredVersion("1.0")] DalamudPluginInterface pluginInterface)
{
serviceProvider = DalamudPluginModule.CreateServiceProvider(pluginInterface);
windowSystem = serviceProvider.GetService<WindowSystem>()!;
uiBuilder = serviceProvider.GetService<UiBuilder>()!;
_serviceProvider = DalamudPluginModule.CreateServiceProvider(pluginInterface);
_windowSystem = _serviceProvider.GetService<WindowSystem>()!;
_uiBuilder = _serviceProvider.GetService<UiBuilder>()!;

uiBuilder.Draw += windowSystem.Draw;
_uiBuilder.Draw += _windowSystem.Draw;

// Instantiate classes with [EntryPoint] attribute.
Assembly.GetAssembly(typeof(EasyTranslatePlugin))!
.GetTypes()
.Where(type => type.GetCustomAttribute(typeof(EntryPointAttribute), false) is not null)
.ToList()
.ForEach(entryPoint => ActivatorUtilities.CreateInstance(serviceProvider, entryPoint));
.GetTypes()
.Where(type => type.GetCustomAttribute(typeof(EntryPointAttribute), false) is not null)
.ToList()
.ForEach(entryPoint => ActivatorUtilities.CreateInstance(_serviceProvider, entryPoint));
}

public void Dispose()
{
uiBuilder.Draw -= windowSystem.Draw;
serviceProvider.Dispose();
_uiBuilder.Draw -= _windowSystem.Draw;
_serviceProvider.Dispose();
GC.SuppressFinalize(this);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace EasyTranslate.DalamudPlugin.Localisation;
using System.ComponentModel;
using EasyTranslate.DalamudPlugin.Resources;
using EasyTranslate.Domain.Entities;

using System.ComponentModel;
using Domain.Entities;
using Resources;
namespace EasyTranslate.DalamudPlugin.Localisation;

public static class ContentTypeTranslations
{
Expand All @@ -27,7 +27,7 @@ public static string LocalisedName(this ContentType contentType)
ContentType.Title => Strings.Title,
ContentType.Trait => Strings.Trait,
ContentType.Weather => Strings.Weather,
_ => throw new InvalidEnumArgumentException(nameof(contentType), (int)contentType, typeof(ContentType)),
_ => throw new InvalidEnumArgumentException(nameof(contentType), (int)contentType, typeof(ContentType))
};
}
}
12 changes: 6 additions & 6 deletions EasyTranslate.DalamudPlugin/Localisation/LanguageSwitcher.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
namespace EasyTranslate.DalamudPlugin.Localisation;

using System;
using System.Globalization;
using Dalamud.Plugin;
using Resources;
using EasyTranslate.DalamudPlugin.Resources;

namespace EasyTranslate.DalamudPlugin.Localisation;

public sealed class LanguageSwitcher : IDisposable
{
private readonly DalamudPluginInterface pluginInterface;
private readonly DalamudPluginInterface _pluginInterface;

public LanguageSwitcher(DalamudPluginInterface pluginInterface)
{
this.pluginInterface = pluginInterface;
_pluginInterface = pluginInterface;

LanguageChangedHandler(pluginInterface.UiLanguage);
pluginInterface.LanguageChanged += LanguageChangedHandler;
}

public void Dispose()
{
pluginInterface.LanguageChanged -= LanguageChangedHandler;
_pluginInterface.LanguageChanged -= LanguageChangedHandler;
GC.SuppressFinalize(this);
}

Expand Down
Loading

0 comments on commit e94f5b3

Please sign in to comment.