Added Godot settings
This commit is contained in:
3 files changed
+239
No files matched your search
@@ -685,5 +685,153 @@ public static class AppSettings
|
||||
|
||||
#endregion
|
||||
|
||||
#region Godot Generator Enabled/Disabled
|
||||
|
||||
private static bool CACHE_GENERATOR_GODOT_ENABLED = true;
|
||||
private static bool CACHE_GENERATOR_GODOT_ENABLED_IS_LOADED = false;
|
||||
|
||||
public static async Task<bool> GetGeneratorGodotEnabled()
|
||||
{
|
||||
// When possible, use the cache:
|
||||
if (CACHE_GENERATOR_GODOT_ENABLED_IS_LOADED)
|
||||
return CACHE_GENERATOR_GODOT_ENABLED;
|
||||
|
||||
var generatorGodotEnabled = false;
|
||||
try
|
||||
{
|
||||
// Get the database:
|
||||
await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
|
||||
|
||||
// Check, if the setting is already set:
|
||||
if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.GENERATOR_GODOT_ENABLED) is { } existingSetting)
|
||||
{
|
||||
generatorGodotEnabled = existingSetting.BoolValue;
|
||||
return generatorGodotEnabled;
|
||||
}
|
||||
|
||||
// Does not exist, so create it:
|
||||
var setting = new Setting
|
||||
{
|
||||
Code = SettingNames.GENERATOR_GODOT_ENABLED,
|
||||
BoolValue = generatorGodotEnabled,
|
||||
};
|
||||
|
||||
await db.Settings.AddAsync(setting);
|
||||
await db.SaveChangesAsync();
|
||||
return generatorGodotEnabled;
|
||||
}
|
||||
finally
|
||||
{
|
||||
CACHE_GENERATOR_GODOT_ENABLED_IS_LOADED = true;
|
||||
CACHE_GENERATOR_GODOT_ENABLED = generatorGodotEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task SetGeneratorGodotEnabled(bool enabled)
|
||||
{
|
||||
// Update the cache:
|
||||
CACHE_GENERATOR_GODOT_ENABLED = enabled;
|
||||
CACHE_GENERATOR_GODOT_ENABLED_IS_LOADED = true;
|
||||
|
||||
// Get the database:
|
||||
await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
|
||||
|
||||
// Check, if the setting is already set:
|
||||
if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.GENERATOR_GODOT_ENABLED) is { } existingSetting)
|
||||
{
|
||||
existingSetting.BoolValue = enabled;
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
// Does not exist, so create it:
|
||||
else
|
||||
{
|
||||
var setting = new Setting
|
||||
{
|
||||
Code = SettingNames.GENERATOR_GODOT_ENABLED,
|
||||
BoolValue = enabled,
|
||||
};
|
||||
|
||||
await db.Settings.AddAsync(setting);
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Godot Generator Destination Path
|
||||
|
||||
private static string CACHE_GENERATOR_GODOT_DESTINATION_PATH = string.Empty;
|
||||
private static bool CACHE_GENERATOR_GODOT_DESTINATION_PATH_IS_LOADED = false;
|
||||
|
||||
public static async Task<string> GetGeneratorGodotDestinationPath()
|
||||
{
|
||||
// When possible, use the cache:
|
||||
if (CACHE_GENERATOR_GODOT_DESTINATION_PATH_IS_LOADED)
|
||||
return CACHE_GENERATOR_GODOT_DESTINATION_PATH;
|
||||
|
||||
var generatorGodotDestinationPath = string.Empty;
|
||||
try
|
||||
{
|
||||
// Get the database:
|
||||
await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
|
||||
|
||||
// Check, if the setting is already set:
|
||||
if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.GENERATOR_GODOT_DESTINATION_PATH) is { } existingSetting)
|
||||
{
|
||||
generatorGodotDestinationPath = existingSetting.TextValue;
|
||||
return generatorGodotDestinationPath;
|
||||
}
|
||||
|
||||
// Does not exist, so create it:
|
||||
var setting = new Setting
|
||||
{
|
||||
Code = SettingNames.GENERATOR_GODOT_DESTINATION_PATH,
|
||||
TextValue = generatorGodotDestinationPath,
|
||||
};
|
||||
|
||||
await db.Settings.AddAsync(setting);
|
||||
await db.SaveChangesAsync();
|
||||
return generatorGodotDestinationPath;
|
||||
}
|
||||
finally
|
||||
{
|
||||
CACHE_GENERATOR_GODOT_DESTINATION_PATH_IS_LOADED = true;
|
||||
CACHE_GENERATOR_GODOT_DESTINATION_PATH = generatorGodotDestinationPath;
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task SetGeneratorGodotDestinationPath(string path)
|
||||
{
|
||||
// Update the cache:
|
||||
CACHE_GENERATOR_GODOT_DESTINATION_PATH = path;
|
||||
CACHE_GENERATOR_GODOT_DESTINATION_PATH_IS_LOADED = true;
|
||||
|
||||
// Get the database:
|
||||
await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
|
||||
|
||||
// Check, if the setting is already set:
|
||||
if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.GENERATOR_GODOT_DESTINATION_PATH) is { } existingSetting)
|
||||
{
|
||||
existingSetting.TextValue = path;
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
// Does not exist, so create it:
|
||||
else
|
||||
{
|
||||
var setting = new Setting
|
||||
{
|
||||
Code = SettingNames.GENERATOR_GODOT_DESTINATION_PATH,
|
||||
TextValue = path,
|
||||
};
|
||||
|
||||
await db.Settings.AddAsync(setting);
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in new issue
Block a user