Skip to content

Commit

Permalink
Starting on cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
softwareantics committed Dec 5, 2023
1 parent c2bb7ba commit f1b9f0e
Show file tree
Hide file tree
Showing 262 changed files with 681 additions and 10,792 deletions.
21 changes: 1 addition & 20 deletions FinalEngine.Audio.OpenAL/Factories/CASLSoundFactory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// <copyright file="CASLSoundFactory.cs" company="Software Antics">
// Copyright (c) Software Antics. All rights reserved.
// Copyright (c) Software Antics. All rights reserved.
// </copyright>

namespace FinalEngine.Audio.OpenAL.Factories;
Expand All @@ -9,28 +9,9 @@ namespace FinalEngine.Audio.OpenAL.Factories;
using CASLSound = CASL.Sound;
using ICASLSound = CASL.ISound;

/// <summary>
/// Provides a standard implementation of an <see cref="ICASLSoundFactory"/>.
/// </summary>
/// <seealso cref="ICASLSoundFactory" />
[ExcludeFromCodeCoverage]
internal sealed class CASLSoundFactory : ICASLSoundFactory
{
/// <summary>
/// Creates an <see cref="ICASLSound" /> by loading it from the specified <paramref name="filePath" />.
/// </summary>
///
/// <param name="filePath">
/// Specifies a <see cref="string"/> that represents the file path of the sound to load.
/// </param>
///
/// <exception cref="ArgumentNullException">
/// The specified <paramref name="filePath"/> parameter cannot be null or whitespace.
/// </exception>
///
/// <returns>
/// Returns <see cref="ICASLSound"/> that represents the CASL sound implementation.
/// </returns>
public ICASLSound CreateSound(string filePath)
{
if (string.IsNullOrWhiteSpace(filePath))
Expand Down
16 changes: 1 addition & 15 deletions FinalEngine.Audio.OpenAL/Factories/ICASLSoundFactory.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
// <copyright file="ICASLSoundFactory.cs" company="Software Antics">
// Copyright (c) Software Antics. All rights reserved.
// Copyright (c) Software Antics. All rights reserved.
// </copyright>

namespace FinalEngine.Audio.OpenAL.Factories;

using ICASLSound = CASL.ISound;

/// <summary>
/// Represents an interface that defines a method to load an <see cref="ICASLSound"/>.
/// </summary>
internal interface ICASLSoundFactory
{
/// <summary>
/// Creates an <see cref="ICASLSound"/> by loading it from the specified <paramref name="filePath"/>.
/// </summary>
///
/// <param name="filePath">
/// The file path of the sound to load.
/// </param>
///
/// <returns>
/// Returns the newly created <see cref="ICASLSound"/>.
/// </returns>
ICASLSound CreateSound(string filePath);
}
9 changes: 4 additions & 5 deletions FinalEngine.Audio.OpenAL/FinalEngine.Audio.OpenAL.csproj
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>11.0</LangVersion>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<NoWarn>SA0001</NoWarn>
<AnalysisMode>All</AnalysisMode>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Platforms>x64</Platforms>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
<AdditionalFiles Include="..\Styling\StyleCop\Other\stylecop.json" Link="stylecop.json" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\GlobalSuppressions.cs" Link="GlobalSuppressions.cs" />
<Compile Include="..\SharedAssemblyInfo.cs" Link="Properties\SharedAssemblyInfo.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="KinsonDigital.CASL" Version="1.0.0-preview.15" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.3">
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
123 changes: 2 additions & 121 deletions FinalEngine.Audio.OpenAL/Loaders/SoundResourceLoader.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// <copyright file="SoundResourceLoader.cs" company="Software Antics">
// Copyright (c) Software Antics. All rights reserved.
// Copyright (c) Software Antics. All rights reserved.
// </copyright>

namespace FinalEngine.Audio.OpenAL.Loaders;
Expand All @@ -11,146 +11,27 @@ namespace FinalEngine.Audio.OpenAL.Loaders;
using FinalEngine.Audio.OpenAL.Factories;
using FinalEngine.Resources;

/// <summary>
/// Provides an implementation of a <see cref="ResourceLoaderBase{TResource}"/> that can load <see cref="ISound"/> resources.
/// </summary>
///
/// <remarks>
/// This implementation loads an <see cref="ISound"/> by creating an <see cref="OpenALSound"/> instance.
/// </remarks>
///
/// <example>
/// Below you'll find an example showing how to register an instance of <see cref="SoundResourceLoader" /> to an <see cref="IResourceManager"/> instance. This example assumes that the following criteria has been met:
///
/// <list type="bullet">
/// <item>
/// The user intends to use the singleton implementation of <see cref="IResourceManager" /> (see <see cref="ResourceManager.Instance" />).
/// </item>
/// </list>
///
/// <code>
/// // First, register the resource loader with the resource manager.
/// // You can choose to load resources directory using the resource loader but then they will not be managed by the manager.
/// ResourceManager.Instance.RegisterLoader(new SoundResourceLoader());
///
/// // Load the resource via the resource manager.
/// ISound sound = ResourceManager.Instance.LoadResource&lt;ISound&gt;("sound.mp3");
///
/// // Let's play the sound.
/// sound.Play();
/// </code>
/// </example>
public class SoundResourceLoader : ResourceLoaderBase<ISound>
{
/// <summary>
/// The factory used to create the underlying CASL sound instance.
/// </summary>
private readonly ICASLSoundFactory factory;

/// <summary>
/// The file system used to load sound resources.
/// </summary>
private readonly IFileSystem fileSystem;

/// <summary>
/// Initializes a new instance of the <see cref="SoundResourceLoader"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public SoundResourceLoader()
: this(new FileSystem())
{
}

/// <summary>
/// Initializes a new instance of the <see cref="SoundResourceLoader" /> class.
/// </summary>
///
/// <param name="fileSystem">
/// Specifies an <see cref="IFileSystem"/> that represents the file system used to load sound resources.
/// </param>
///
/// <exception cref="ArgumentNullException">
/// The specified <paramref name="fileSystem"/> parameter cannot be null.
/// </exception>
[ExcludeFromCodeCoverage]
public SoundResourceLoader(IFileSystem fileSystem)
: this(fileSystem, new CASLSoundFactory())
{
}

/// <summary>
/// Initializes a new instance of the <see cref="SoundResourceLoader" /> class.
/// </summary>
///
/// <param name="fileSystem">
/// Specifies an <see cref="IFileSystem"/> that represents the file system used to load sound resources.
/// </param>
///
/// <param name="factory">
/// Specifies an <see cref="ICASLSoundFactory"/> that represents the factory used to create the underlying CASL sound instance.
/// </param>
///
/// <exception cref="ArgumentNullException">
/// Thrown when the one of the following parameters are null:
/// <list type="bullet">
/// <item>
/// <paramref name="fileSystem"/>
/// </item>
/// <item>
/// <paramref name="factory"/>
/// </item>
/// </list>
/// </exception>
internal SoundResourceLoader(IFileSystem fileSystem, ICASLSoundFactory factory)
{
this.fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
this.factory = factory ?? throw new ArgumentNullException(nameof(factory));
}

/// <summary>
/// Loads an <see cref="ISound"/> resource from the specified <paramref name="filePath" />.
/// </summary>
///
/// <param name="filePath">
/// Specifies a <see cref="string"/> that represents the file path of the sound resource to load.
/// </param>
///
/// <remarks>
/// Please note that you should use an instance of an <see cref="IResourceManager"/> (such as <see cref="ResourceManager.Instance"/> and not load resources directly; unless you wish to take control of the life-cycle of the resource.
/// </remarks>
///
/// <example>
/// Below you'll find an example showing how to load a sound resource using the <see cref="SoundResourceLoader"/>.
///
/// <code>
/// var loader = new SoundResourceLoader();
///
/// // You should typically use an instance of an IResourceManager to load resources
/// // However, there may be instances where you'd like to take control of the life-cycle of the resource.
/// ISound sound = loader.LoadResource&lt;ISound&gt;("sound.mp3");
///
/// // Finally, let's play the sound.
/// sound.Play();
/// </code>
/// </example>
///
/// <exception cref="ArgumentException">
/// The specified <paramref name="filePath"/> parameter cannot be null or whitespace.
/// </exception>
///
/// <exception cref="FileNotFoundException">
/// The specified <paramref name="filePath"/> parameter cannot be located.
/// </exception>
///
/// <returns>
/// Returns an <see cref="ISound"/> instance that represents the newly loaded resource.
/// </returns>
public override ISound LoadResource(string filePath)
{
if (string.IsNullOrWhiteSpace(filePath))
{
throw new ArgumentException($"'{nameof(filePath)}' cannot be null or whitespace.", nameof(filePath));
}
ArgumentException.ThrowIfNullOrWhiteSpace(filePath, nameof(filePath));

if (!this.fileSystem.File.Exists(filePath))
{
Expand Down
Loading

0 comments on commit f1b9f0e

Please sign in to comment.