-
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.
Merge pull request #263 from SpaceWarpDev/dev
Dev --> Main for 1.5 release
- Loading branch information
Showing
152 changed files
with
7,084 additions
and
3,418 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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using BepInEx.Configuration; | ||
using JetBrains.Annotations; | ||
|
||
namespace SpaceWarp.API.Configuration; | ||
|
||
[PublicAPI] | ||
public class BepInExConfigEntry : IConfigEntry | ||
{ | ||
public readonly ConfigEntryBase EntryBase; | ||
|
||
public BepInExConfigEntry(ConfigEntryBase entryBase) | ||
{ | ||
EntryBase = entryBase; | ||
} | ||
|
||
public object Value | ||
{ | ||
get => EntryBase.BoxedValue; | ||
set => EntryBase.BoxedValue = value; | ||
} | ||
public Type ValueType => EntryBase.SettingType; | ||
|
||
public T Get<T>() where T : class | ||
{ | ||
if (!typeof(T).IsAssignableFrom(ValueType)) | ||
{ | ||
throw new InvalidCastException($"Cannot cast {ValueType} to {typeof(T)}"); | ||
} | ||
|
||
return Value as T; | ||
} | ||
|
||
public void Set<T>(T value) | ||
{ | ||
if (!ValueType.IsAssignableFrom(typeof(T))) | ||
{ | ||
throw new InvalidCastException($"Cannot cast {ValueType} to {typeof(T)}"); | ||
} | ||
|
||
EntryBase.BoxedValue = Convert.ChangeType(value, ValueType); | ||
} | ||
|
||
public string Description => EntryBase.Description.Description; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Collections.Generic; | ||
using BepInEx.Configuration; | ||
using JetBrains.Annotations; | ||
|
||
namespace SpaceWarp.API.Configuration; | ||
|
||
[PublicAPI] | ||
public class BepInExConfigFile : IConfigFile | ||
{ | ||
|
||
public readonly ConfigFile AdaptedConfigFile; | ||
|
||
public BepInExConfigFile(ConfigFile adaptedConfigFile) | ||
{ | ||
AdaptedConfigFile = adaptedConfigFile; | ||
} | ||
|
||
public void Save() | ||
{ | ||
AdaptedConfigFile.Save(); | ||
} | ||
|
||
public IConfigEntry this[string section, string key] => new BepInExConfigEntry(AdaptedConfigFile[section, key]); | ||
|
||
public IConfigEntry Bind<T>(string section, string key, T defaultValue = default, string description = "") | ||
{ | ||
return new BepInExConfigEntry(AdaptedConfigFile.Bind(section, key, defaultValue, description)); | ||
} | ||
|
||
public IReadOnlyList<string> Sections => AdaptedConfigFile.Keys.Select(x => x.Section).Distinct().ToList(); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using JetBrains.Annotations; | ||
|
||
namespace SpaceWarp.API.Configuration; | ||
|
||
[PublicAPI] | ||
public class ConfigValue<T> | ||
{ | ||
public IConfigEntry Entry; | ||
|
||
public ConfigValue(IConfigEntry entry) | ||
{ | ||
Entry = entry; | ||
if (typeof(T) != entry.ValueType) | ||
{ | ||
throw new ArgumentException(nameof(entry)); | ||
} | ||
} | ||
|
||
public T Value | ||
{ | ||
get => (T)Entry.Value; | ||
set => Entry.Value = value; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Collections.Generic; | ||
using JetBrains.Annotations; | ||
|
||
namespace SpaceWarp.API.Configuration; | ||
|
||
[PublicAPI] | ||
public class EmptyConfigFile : IConfigFile | ||
{ | ||
public void Save() | ||
{ | ||
} | ||
|
||
public IConfigEntry this[string section, string key] => throw new KeyNotFoundException($"{section}/{key}"); | ||
|
||
public IConfigEntry Bind<T>(string section, string key, T defaultValue = default, string description = "") | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public IReadOnlyList<string> Sections => new List<string>(); | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using JetBrains.Annotations; | ||
|
||
namespace SpaceWarp.API.Configuration; | ||
|
||
[PublicAPI] | ||
public interface IConfigEntry | ||
{ | ||
public object Value { get; set; } | ||
public Type ValueType { get; } | ||
public T Get<T>() where T : class; | ||
public void Set<T>(T value); | ||
|
||
public string Description { get; } | ||
} |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Collections.Generic; | ||
using JetBrains.Annotations; | ||
|
||
namespace SpaceWarp.API.Configuration; | ||
|
||
[PublicAPI] | ||
public interface IConfigFile | ||
{ | ||
public void Save(); | ||
|
||
public IConfigEntry this[string section, string key] { get; } | ||
|
||
public IConfigEntry Bind<T>(string section, string key, T defaultValue = default, string description = ""); | ||
|
||
public IReadOnlyList<string> Sections { get; } | ||
public IReadOnlyList<string> this[string section] { get; } | ||
} |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using JetBrains.Annotations; | ||
|
||
namespace SpaceWarp.API.Configuration; | ||
|
||
[PublicAPI] | ||
public class JsonConfigEntry : IConfigEntry | ||
{ | ||
private readonly JsonConfigFile _configFile; | ||
private object _value; | ||
|
||
public JsonConfigEntry(JsonConfigFile configFile, Type type, string description, object value) | ||
{ | ||
_configFile = configFile; | ||
_value = value; | ||
Description = description; | ||
ValueType = type; | ||
} | ||
|
||
|
||
public object Value | ||
{ | ||
get => _value; | ||
set | ||
{ | ||
_value = value; | ||
_configFile.Save(); | ||
} | ||
} | ||
|
||
public Type ValueType { get; } | ||
public T Get<T>() where T : class | ||
{ | ||
if (!typeof(T).IsAssignableFrom(ValueType)) | ||
{ | ||
throw new InvalidCastException($"Cannot cast {ValueType} to {typeof(T)}"); | ||
} | ||
|
||
return Value as T; | ||
} | ||
|
||
public void Set<T>(T value) | ||
{ | ||
if (!ValueType.IsAssignableFrom(typeof(T))) | ||
{ | ||
throw new InvalidCastException($"Cannot cast {ValueType} to {typeof(T)}"); | ||
} | ||
|
||
Value = Convert.ChangeType(value, ValueType); | ||
} | ||
|
||
public string Description { get; } | ||
} |
Oops, something went wrong.