Skip to content

Commit

Permalink
fix(calibration): Fixed an issue where calibration settings were not …
Browse files Browse the repository at this point in the history
…saved

feat(settings): Added a default parameter to settings load
  • Loading branch information
benaclejames committed Jul 26, 2023
1 parent 7d9cd4c commit f95570f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public interface ILocalSettingsService
{
Task<T> ReadSettingAsync<T>(string key);
Task<T> ReadSettingAsync<T>(string key, T? defaultValue = default);

Task SaveSettingAsync<T>(string key, T value);
}
18 changes: 9 additions & 9 deletions VRCFaceTracking.Core/Params/Data/UnifiedTrackingMutator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public UnifiedTrackingMutator(ILogger<UnifiedTrackingMutator> logger, IDispatche
_dispatcherService = dispatcherService;
_localSettingsService = localSettingsService;

Enabled = true;
Enabled = false;
ContinuousCalibration = true;
CalibrationWeight = 0.2f;
}
Expand Down Expand Up @@ -177,20 +177,20 @@ public void SetSmoothness(float setValue = 0.0f)
public async Task SaveCalibration()
{
_logger.LogDebug("Saving configuration...");
await _localSettingsService.SaveSettingAsync("Mutation", mutationData);
await _localSettingsService.SaveSettingAsync("CalibrationEnabled", Enabled);
await _localSettingsService.SaveSettingAsync("CalibrationWeight", CalibrationWeight);
await _localSettingsService.SaveSettingAsync("ContinuousCalibrationEnabled", ContinuousCalibration);
await _localSettingsService.SaveSettingAsync("Mutations", mutationData);
}

public async void LoadCalibration()
{
// Try to load config and propogate data into Unified if they exist.
_logger.LogDebug("Reading configuration...");
mutationData = await _localSettingsService.ReadSettingAsync<UnifiedMutationConfig>("Mutation");
// If the config is null, create a new one.
if (mutationData.ShapeMutations == null)
{
_logger.LogDebug("Configuration not found. Creating new configuration...");
mutationData = new();
}
Enabled = await _localSettingsService.ReadSettingAsync<bool>("CalibrationEnabled");
CalibrationWeight = await _localSettingsService.ReadSettingAsync<float>("CalibrationWeight", 0.2f);
ContinuousCalibration = await _localSettingsService.ReadSettingAsync<bool>("ContinuousCalibrationEnabled", true);
mutationData = await _localSettingsService.ReadSettingAsync<UnifiedMutationConfig>("Mutation", new());
_logger.LogDebug("Configuration loaded.");
}

Expand Down
4 changes: 2 additions & 2 deletions VRCFaceTracking/Services/LocalSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private async Task InitializeAsync()
}
}

public async Task<T?> ReadSettingAsync<T>(string key)
public async Task<T?> ReadSettingAsync<T>(string key, T? defaultValue = default)
{
if (RuntimeHelper.IsMSIX)
{
Expand All @@ -67,7 +67,7 @@ private async Task InitializeAsync()
}
}

return default;
return defaultValue;
}

public async Task SaveSettingAsync<T>(string key, T value)
Expand Down

0 comments on commit f95570f

Please sign in to comment.