-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: AtomicLiquid <[email protected]>
- Loading branch information
1 parent
72072e6
commit e072604
Showing
176 changed files
with
3,881 additions
and
1,124 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
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,47 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using Config.Net; | ||
using EvoSC.Common.Themes; | ||
using Tomlet; | ||
using Tomlet.Models; | ||
|
||
namespace EvoSC.Common.Config.Mapping; | ||
|
||
public class ThemeOptionsParser : ITypeParser | ||
{ | ||
public bool TryParse(string? value, Type t, [UnscopedRef] out object? result) | ||
{ | ||
var parser = new TomlParser(); | ||
var doc = parser.Parse(value); | ||
var options = new Dictionary<string, object>(); | ||
|
||
foreach (var entry in doc.Entries) | ||
{ | ||
GetEntriesRecursive(entry.Key, entry.Value, options); | ||
} | ||
|
||
result = new DynamicThemeOptions(options); | ||
return true; | ||
} | ||
|
||
public string? ToRawString(object? value) | ||
{ | ||
return ""; | ||
} | ||
|
||
public IEnumerable<Type> SupportedTypes => new[] { typeof(DynamicThemeOptions) }; | ||
|
||
private void GetEntriesRecursive(string name, TomlValue tomlValue, Dictionary<string, object> options) | ||
{ | ||
if (tomlValue is TomlTable table) | ||
{ | ||
foreach (var entry in table.Entries) | ||
{ | ||
GetEntriesRecursive($"{name}.{entry.Key}", entry.Value, options); | ||
} | ||
} | ||
else | ||
{ | ||
options[name] = tomlValue.StringValue; | ||
} | ||
} | ||
} |
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
82 changes: 82 additions & 0 deletions
82
src/EvoSC.Common/Config/Mapping/Toml/ThemeConfigOptionsMapper.cs
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,82 @@ | ||
using EvoSC.Common.Interfaces.Config.Mapping; | ||
using EvoSC.Common.Themes; | ||
using Tomlet; | ||
using Tomlet.Models; | ||
|
||
namespace EvoSC.Common.Config.Mapping.Toml; | ||
|
||
public class ThemeConfigOptionsMapper : ITomlTypeMapper<DynamicThemeOptions> | ||
{ | ||
public TomlValue Serialize(DynamicThemeOptions? typeValue) | ||
{ | ||
var doc = TomlDocument.CreateEmpty(); | ||
|
||
foreach (var option in typeValue) | ||
{ | ||
BuildTomlDocument(doc, option.Key.Split('.'), option.Value); | ||
} | ||
|
||
return doc; | ||
} | ||
|
||
public DynamicThemeOptions Deserialize(TomlValue tomlValue) | ||
{ | ||
var doc = tomlValue as TomlDocument; | ||
|
||
if (doc == null) | ||
{ | ||
throw new InvalidOperationException("Value is not a document"); | ||
} | ||
|
||
var options = new DynamicThemeOptions(); | ||
|
||
foreach (var entry in doc.Entries) | ||
{ | ||
BuildOptionsObject(options, entry.Key, entry.Value); | ||
} | ||
|
||
return options; | ||
} | ||
|
||
private void BuildTomlDocument(TomlDocument doc, IEnumerable<string> optionParts, object value) | ||
{ | ||
var parts = optionParts as string[] ?? optionParts.ToArray(); | ||
|
||
if (parts.Length == 1) | ||
{ | ||
var tomlValue = TomletMain.ValueFrom(value); | ||
doc.Entries[parts.First()] = tomlValue; | ||
return; | ||
} | ||
|
||
foreach (var part in parts) | ||
{ | ||
if (doc.ContainsKey(part)) | ||
{ | ||
BuildTomlDocument((TomlDocument)doc.Entries[part], parts.Skip(1), value); | ||
} | ||
else | ||
{ | ||
var newDoc = TomlDocument.CreateEmpty(); | ||
doc.Entries[part] = newDoc; | ||
BuildTomlDocument(newDoc, parts.Skip(1), value); | ||
} | ||
} | ||
} | ||
|
||
private void BuildOptionsObject(DynamicThemeOptions options, string key, TomlValue tomlValue) | ||
{ | ||
var doc = tomlValue as TomlDocument; | ||
|
||
if (doc == null) | ||
{ | ||
options[key] = tomlValue.StringValue; | ||
return; | ||
} | ||
|
||
foreach (var entry in doc.Entries) | ||
{ | ||
BuildOptionsObject(options, $"{key}.{entry.Key}", entry.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 |
---|---|---|
@@ -1,12 +1,16 @@ | ||
namespace EvoSC.Common.Config.Models; | ||
using EvoSC.Common.Themes; | ||
|
||
namespace EvoSC.Common.Config.Models; | ||
|
||
public interface IEvoScBaseConfig | ||
{ | ||
public IDatabaseConfig Database { get; set; } | ||
public ILoggingConfig Logging { get; set; } | ||
public IServerConfig Server { get; set; } | ||
public IPathConfig Path { get; set; } | ||
public IThemeConfig Theme { get; set; } | ||
|
||
public IModuleConfig Modules { get; set; } | ||
public ILocaleConfig Locale { get; set; } | ||
|
||
public DynamicThemeOptions Theme { get; set; } | ||
} |
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
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,5 +1,4 @@ | ||
using LinqToDB; | ||
using LinqToDB.Data; | ||
|
||
namespace EvoSC.Common.Interfaces.Database; | ||
|
||
|
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
14 changes: 14 additions & 0 deletions
14
src/EvoSC.Common/Interfaces/Themes/Builders/IReplaceComponentBuilder.cs
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,14 @@ | ||
using EvoSC.Common.Themes; | ||
|
||
namespace EvoSC.Common.Interfaces.Themes.Builders; | ||
|
||
public interface IReplaceComponentBuilder<out TTheme> | ||
where TTheme : Theme<TTheme> | ||
{ | ||
/// <summary> | ||
/// Replace a component with the provided component. | ||
/// </summary> | ||
/// <param name="newComponent">Name of the new component that will replace the old component.</param> | ||
/// <returns></returns> | ||
public TTheme With(string newComponent); | ||
} |
13 changes: 13 additions & 0 deletions
13
src/EvoSC.Common/Interfaces/Themes/Builders/ISetThemeOptionBuilder.cs
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,13 @@ | ||
using EvoSC.Common.Themes; | ||
|
||
namespace EvoSC.Common.Interfaces.Themes.Builders; | ||
|
||
public interface ISetThemeOptionBuilder<TTheme> where TTheme : Theme<TTheme> | ||
{ | ||
/// <summary> | ||
/// Set a theme option value. | ||
/// </summary> | ||
/// <param name="value">Value of the theme option.</param> | ||
/// <returns></returns> | ||
public TTheme To(object value); | ||
} |
Oops, something went wrong.