VPet/VPet.Solution/Models/SettingEditor/SettingModel.cs

90 lines
2.2 KiB
C#
Raw Normal View History

2023-12-30 14:54:49 +00:00
using FastMember;
using HKW.HKWUtils.Observable;
2024-01-09 15:22:25 +00:00
using LinePutScript;
2023-12-30 14:54:49 +00:00
using System.ComponentModel;
2024-01-10 13:37:17 +00:00
using System.Reflection;
2023-12-30 14:54:49 +00:00
using System.Runtime.CompilerServices;
using System.Windows;
using VPet.Solution.Properties;
using VPet_Simulator.Windows.Interface;
2024-01-07 14:57:27 +00:00
namespace VPet.Solution.Models.SettingEditor;
2023-12-30 14:54:49 +00:00
public class SettingModel : ObservableClass<SettingModel>
{
private string _name;
/// <summary>
/// 名称
/// </summary>
public string Name
{
get => _name;
set => SetProperty(ref _name, value);
}
private string _filePath;
/// <summary>
2024-01-09 15:22:25 +00:00
/// 文件路径
2023-12-30 14:54:49 +00:00
/// </summary>
public string FilePath
{
get => _filePath;
set => SetProperty(ref _filePath, value);
}
private GraphicsSettingModel _graphicsSetting;
public GraphicsSettingModel GraphicsSetting
{
get => _graphicsSetting;
set => SetProperty(ref _graphicsSetting, value);
}
private SystemSettingModel _systemSetting;
public SystemSettingModel SystemSetting
{
get => _systemSetting;
set => SetProperty(ref _systemSetting, value);
}
private InteractiveSettingModel _interactiveSetting;
public InteractiveSettingModel InteractiveSetting
{
get => _interactiveSetting;
set => SetProperty(ref _interactiveSetting, value);
}
2024-01-09 15:22:25 +00:00
private static HashSet<string> _settingProperties =
new(typeof(Setting).GetProperties().Select(p => p.Name));
private Setting _setting;
2024-01-10 13:37:17 +00:00
private ReflectionOptions _saveReflectionOptions = new() { CheckValueEquals = true };
2023-12-30 14:54:49 +00:00
public SettingModel(Setting setting)
{
2024-01-09 15:22:25 +00:00
_setting = setting;
GraphicsSetting = LoadGraphicsSettings();
2023-12-30 14:54:49 +00:00
}
2024-01-09 15:22:25 +00:00
private GraphicsSettingModel LoadGraphicsSettings()
2023-12-30 14:54:49 +00:00
{
2024-01-10 13:37:17 +00:00
var graphicsSetting = new GraphicsSettingModel();
ReflectionUtils.SetValue(_setting, graphicsSetting);
return graphicsSetting;
2023-12-30 14:54:49 +00:00
}
2024-01-09 15:22:25 +00:00
public void Save()
{
SaveGraphicsSettings();
File.WriteAllText(FilePath, _setting.ToString());
}
private void SaveGraphicsSettings()
{
2024-01-10 13:37:17 +00:00
ReflectionUtils.SetValue(GraphicsSetting, _setting, _saveReflectionOptions);
2024-01-09 15:22:25 +00:00
}
2023-12-30 14:54:49 +00:00
}