-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start of fixing all SpaceWarp warnings, removes all unused imports an…
…d adds doc comments to SpaceWarp.Core.API.Assets, SpaceWarp.Core.API.Configuration, SpaceWarp.Core.API.Loading and SpaceWarp.Core.API.Lua namespaces
- Loading branch information
Showing
91 changed files
with
441 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,69 @@ | ||
using System.Collections.Generic; | ||
using BepInEx.Configuration; | ||
using BepInEx.Configuration; | ||
using JetBrains.Annotations; | ||
|
||
namespace SpaceWarp.API.Configuration; | ||
|
||
/// <summary> | ||
/// A wrapper around BepInEx's <see cref="ConfigFile" /> to make it implement <see cref="IConfigFile" />. | ||
/// </summary> | ||
[PublicAPI] | ||
public class BepInExConfigFile : IConfigFile | ||
{ | ||
|
||
/// <summary> | ||
/// The underlying <see cref="ConfigFile" /> instance. | ||
/// </summary> | ||
public readonly ConfigFile AdaptedConfigFile; | ||
|
||
/// <summary> | ||
/// Creates a new <see cref="BepInExConfigFile" /> instance. | ||
/// </summary> | ||
/// <param name="adaptedConfigFile">The <see cref="ConfigFile" /> instance to wrap.</param> | ||
public BepInExConfigFile(ConfigFile adaptedConfigFile) | ||
{ | ||
AdaptedConfigFile = adaptedConfigFile; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void Save() | ||
{ | ||
AdaptedConfigFile.Save(); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public IConfigEntry this[string section, string key] => new BepInExConfigEntry(AdaptedConfigFile[section, key]); | ||
|
||
/// <inheritdoc /> | ||
public IConfigEntry Bind<T>(string section, string key, T defaultValue = default, string description = "") | ||
{ | ||
return new BepInExConfigEntry(AdaptedConfigFile.Bind(section, key, defaultValue, description)); | ||
} | ||
|
||
public IConfigEntry Bind<T>(string section, string key, T defaultValue, string description, IValueConstraint valueConstraint) | ||
/// <summary> | ||
/// Binds a new config entry to the given section and key with the given default value and description. | ||
/// </summary> | ||
/// <param name="section">Section to bind the entry to.</param> | ||
/// <param name="key">Key to bind the entry to.</param> | ||
/// <param name="defaultValue">Default value of the entry.</param> | ||
/// <param name="description">Description of the entry.</param> | ||
/// <param name="valueConstraint">Value constraint of the entry.</param> | ||
/// <typeparam name="T">Type of the entry.</typeparam> | ||
/// <returns>The newly bound config entry.</returns> | ||
public IConfigEntry Bind<T>( | ||
string section, | ||
string key, | ||
T defaultValue, | ||
string description, | ||
IValueConstraint valueConstraint | ||
) | ||
{ | ||
return new BepInExConfigEntry(AdaptedConfigFile.Bind(new ConfigDefinition(section, key), defaultValue, | ||
new ConfigDescription(description, valueConstraint.ToAcceptableValueBase()))); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public IReadOnlyList<string> Sections => AdaptedConfigFile.Keys.Select(x => x.Section).Distinct().ToList(); | ||
|
||
/// <inheritdoc /> | ||
public IReadOnlyList<string> this[string section] => AdaptedConfigFile.Keys.Where(x => x.Section == section) | ||
.Select(x => x.Key).ToList(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,52 @@ | ||
using System.Collections.Generic; | ||
using JetBrains.Annotations; | ||
using JetBrains.Annotations; | ||
|
||
namespace SpaceWarp.API.Configuration; | ||
|
||
/// <summary> | ||
/// An empty config file that does not save anything. | ||
/// </summary> | ||
[PublicAPI] | ||
public class EmptyConfigFile : IConfigFile | ||
{ | ||
/// <inheritdoc /> | ||
public void Save() | ||
{ | ||
} | ||
|
||
/// <inheritdoc /> | ||
public IConfigEntry this[string section, string key] => throw new KeyNotFoundException($"{section}/{key}"); | ||
|
||
/// <inheritdoc /> | ||
public IConfigEntry Bind<T>(string section, string key, T defaultValue = default, string description = "") | ||
{ | ||
throw new System.NotImplementedException(); | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public IConfigEntry Bind<T>(string section, string key, T defaultValue, string description, IValueConstraint valueConstraint) | ||
/// <summary> | ||
/// Binds a config entry to a section and key. | ||
/// </summary> | ||
/// <param name="section">Section to bind to.</param> | ||
/// <param name="key">Key to bind to.</param> | ||
/// <param name="defaultValue">Default value to use if no value is found.</param> | ||
/// <param name="description">Description of the config entry.</param> | ||
/// <param name="valueConstraint">Constraint to use for the value.</param> | ||
/// <typeparam name="T">Type of the value.</typeparam> | ||
/// <returns>The config entry.</returns> | ||
/// <exception cref="NotImplementedException">Always thrown.</exception> | ||
public IConfigEntry Bind<T>( | ||
string section, | ||
string key, | ||
T defaultValue, | ||
string description, | ||
IValueConstraint valueConstraint | ||
) | ||
{ | ||
throw new System.NotImplementedException(); | ||
throw new NotImplementedException(); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public IReadOnlyList<string> Sections => new List<string>(); | ||
|
||
/// <inheritdoc /> | ||
public IReadOnlyList<string> this[string section] => throw new KeyNotFoundException($"{section}"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,52 @@ | ||
using System; | ||
using JetBrains.Annotations; | ||
using JetBrains.Annotations; | ||
|
||
namespace SpaceWarp.API.Configuration; | ||
|
||
/// <summary> | ||
/// Represents a config entry | ||
/// </summary> | ||
[PublicAPI] | ||
public interface IConfigEntry | ||
{ | ||
/// <summary> | ||
/// The value of the config entry | ||
/// </summary> | ||
public object Value { get; set; } | ||
|
||
/// <summary> | ||
/// The type of the value of the config entry | ||
/// </summary> | ||
public Type ValueType { get; } | ||
|
||
/// <summary> | ||
/// Gets the value of the config entry as a specific type | ||
/// </summary> | ||
/// <typeparam name="T">The type to cast to</typeparam> | ||
/// <returns>The value as the specified type</returns> | ||
public T Get<T>() where T : class; | ||
|
||
/// <summary> | ||
/// Sets the value of the config entry | ||
/// </summary> | ||
/// <param name="value">The value to set</param> | ||
/// <typeparam name="T">The type of the value</typeparam> | ||
public void Set<T>(T value); | ||
|
||
/// <summary> | ||
/// The description of the config entry | ||
/// </summary> | ||
public string Description { get; } | ||
|
||
/// <summary> | ||
/// The value constraint of the config entry | ||
/// </summary> | ||
public IValueConstraint Constraint { get; } | ||
|
||
/// <summary> | ||
/// Called when setting the value on a config file | ||
/// Registers a callback to be called when setting the value on a config file | ||
/// </summary> | ||
/// <param name="valueChangedCallback">An action that takes te old value and the new value and calls a callback</param> | ||
/// <param name="valueChangedCallback"> | ||
/// An action that takes the old value and the new value and calls a callback | ||
/// </param> | ||
public void RegisterCallback(Action<object, object> valueChangedCallback); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,44 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using JetBrains.Annotations; | ||
using JetBrains.Annotations; | ||
|
||
namespace SpaceWarp.API.Configuration; | ||
|
||
/// <summary> | ||
/// Represents a configuration file. | ||
/// </summary> | ||
[PublicAPI] | ||
public interface IConfigFile | ||
{ | ||
/// <summary> | ||
/// Saves the configuration file. | ||
/// </summary> | ||
public void Save(); | ||
|
||
/// <summary> | ||
/// Gets the <see cref="IConfigEntry" /> with the specified section and key. | ||
/// </summary> | ||
/// <param name="section">Section of the entry.</param> | ||
/// <param name="key">Key of the entry.</param> | ||
public IConfigEntry this[string section, string key] { get; } | ||
|
||
/// <summary> | ||
/// Binds a new <see cref="IConfigEntry" /> to the specified section and key. | ||
/// </summary> | ||
/// <param name="section">Section of the entry.</param> | ||
/// <param name="key">Key of the entry.</param> | ||
/// <param name="defaultValue">Default value of the entry.</param> | ||
/// <param name="description">Description of the entry.</param> | ||
/// <typeparam name="T">Type of the entry.</typeparam> | ||
/// <returns>The bound <see cref="IConfigEntry" />.</returns> | ||
public IConfigEntry Bind<T>(string section, string key, T defaultValue = default, string description = ""); | ||
|
||
|
||
/// <summary> | ||
/// A list of all sections in the configuration file. | ||
/// </summary> | ||
public IReadOnlyList<string> Sections { get; } | ||
|
||
/// <summary> | ||
/// A list of all keys in the specified section. | ||
/// </summary> | ||
/// <param name="section"></param> | ||
public IReadOnlyList<string> this[string section] { get; } | ||
} |
Oops, something went wrong.