From fd2023598b722b96149d98f45a15bf326a3af11e Mon Sep 17 00:00:00 2001 From: Ben Wallis Date: Wed, 28 Nov 2018 21:50:42 +0000 Subject: [PATCH] #83 - Fixed theme serialization --- .../ThemeEditor/ColorThemeComponent.cs | 6 +++++- .../ThemeEditor/EffectColorThemeComponent.cs | 15 +++++++------- .../ThemeEditor/IconThemeComponent.cs | 10 +++++++--- .../ThemeEditor/IntegerThemeComponent.cs | 6 +++++- .../ThemeEditor/StrIntThemeComponent.cs | 8 ++++++-- .../ThemeEditor/StringThemeComponent.cs | 15 +++++++++----- Filtration.ObjectModel/ThemeEditor/Theme.cs | 20 +++++++++++-------- Filtration/App.xaml.cs | 2 +- 8 files changed, 53 insertions(+), 29 deletions(-) diff --git a/Filtration.ObjectModel/ThemeEditor/ColorThemeComponent.cs b/Filtration.ObjectModel/ThemeEditor/ColorThemeComponent.cs index 044f468..f4b8311 100644 --- a/Filtration.ObjectModel/ThemeEditor/ColorThemeComponent.cs +++ b/Filtration.ObjectModel/ThemeEditor/ColorThemeComponent.cs @@ -9,6 +9,10 @@ namespace Filtration.ObjectModel.ThemeEditor { private Color _color; + private ColorThemeComponent() + { + } + public ColorThemeComponent(ThemeComponentType componentType, string componentName, Color componentColor) { if (componentName == null || componentColor == null) @@ -23,7 +27,7 @@ namespace Filtration.ObjectModel.ThemeEditor public Color Color { - get { return _color; } + get => _color; set { _color = value; diff --git a/Filtration.ObjectModel/ThemeEditor/EffectColorThemeComponent.cs b/Filtration.ObjectModel/ThemeEditor/EffectColorThemeComponent.cs index ec99fc6..08faae6 100644 --- a/Filtration.ObjectModel/ThemeEditor/EffectColorThemeComponent.cs +++ b/Filtration.ObjectModel/ThemeEditor/EffectColorThemeComponent.cs @@ -9,22 +9,21 @@ namespace Filtration.ObjectModel.ThemeEditor private EffectColor _effectColor; private bool _temporary; + private EffectColorThemeComponent() + { + } + public EffectColorThemeComponent(ThemeComponentType componentType, string componentName, EffectColor componentEffectColor, bool componentTemporary) { - if (componentName == null) - { - throw new ArgumentException("Null parameters not allowed in EffectColorThemeComponent constructor"); - } - ComponentType = componentType; - ComponentName = componentName; + ComponentName = componentName ?? throw new ArgumentException("Null parameters not allowed in EffectColorThemeComponent constructor"); EffectColor = componentEffectColor; Temporary = componentTemporary; } public EffectColor EffectColor { - get { return _effectColor; } + get => _effectColor; set { _effectColor = value; @@ -35,7 +34,7 @@ namespace Filtration.ObjectModel.ThemeEditor public bool Temporary { - get { return _temporary; } + get => _temporary; set { _temporary = value; diff --git a/Filtration.ObjectModel/ThemeEditor/IconThemeComponent.cs b/Filtration.ObjectModel/ThemeEditor/IconThemeComponent.cs index fd7f082..2c6bed9 100644 --- a/Filtration.ObjectModel/ThemeEditor/IconThemeComponent.cs +++ b/Filtration.ObjectModel/ThemeEditor/IconThemeComponent.cs @@ -10,6 +10,10 @@ namespace Filtration.ObjectModel.ThemeEditor private IconColor _iconColor; private IconShape _iconShape; + private IconThemeComponent() + { + } + public IconThemeComponent(ThemeComponentType componentType, string componentName, IconSize componentIconSize, IconColor componentIconColor, IconShape componentIconShape) { if (componentName == null) @@ -26,7 +30,7 @@ namespace Filtration.ObjectModel.ThemeEditor public IconSize IconSize { - get { return _iconSize; } + get => _iconSize; set { _iconSize = value; @@ -37,7 +41,7 @@ namespace Filtration.ObjectModel.ThemeEditor public IconColor IconColor { - get { return _iconColor; } + get => _iconColor; set { _iconColor = value; @@ -48,7 +52,7 @@ namespace Filtration.ObjectModel.ThemeEditor public IconShape IconShape { - get { return _iconShape; } + get => _iconShape; set { _iconShape = value; diff --git a/Filtration.ObjectModel/ThemeEditor/IntegerThemeComponent.cs b/Filtration.ObjectModel/ThemeEditor/IntegerThemeComponent.cs index a72d822..73148ed 100644 --- a/Filtration.ObjectModel/ThemeEditor/IntegerThemeComponent.cs +++ b/Filtration.ObjectModel/ThemeEditor/IntegerThemeComponent.cs @@ -9,6 +9,10 @@ namespace Filtration.ObjectModel.ThemeEditor { private int _value; + private IntegerThemeComponent() + { + } + public IntegerThemeComponent(ThemeComponentType componentType, string componentName, int componentValue) { if (componentName == null) @@ -23,7 +27,7 @@ namespace Filtration.ObjectModel.ThemeEditor public int Value { - get { return _value; } + get => _value; set { _value = value; diff --git a/Filtration.ObjectModel/ThemeEditor/StrIntThemeComponent.cs b/Filtration.ObjectModel/ThemeEditor/StrIntThemeComponent.cs index 945eac8..2277123 100644 --- a/Filtration.ObjectModel/ThemeEditor/StrIntThemeComponent.cs +++ b/Filtration.ObjectModel/ThemeEditor/StrIntThemeComponent.cs @@ -9,6 +9,10 @@ namespace Filtration.ObjectModel.ThemeEditor private string _value; private int _secondValue; + private StrIntThemeComponent() + { + } + public StrIntThemeComponent(ThemeComponentType componentType, string componentName, string componentValue, int componentSecondValue) { if (componentName == null || componentValue == null) @@ -24,7 +28,7 @@ namespace Filtration.ObjectModel.ThemeEditor public string Value { - get { return _value; } + get => _value; set { _value = value; @@ -35,7 +39,7 @@ namespace Filtration.ObjectModel.ThemeEditor public int SecondValue { - get { return _secondValue; } + get => _secondValue; set { _secondValue = value; diff --git a/Filtration.ObjectModel/ThemeEditor/StringThemeComponent.cs b/Filtration.ObjectModel/ThemeEditor/StringThemeComponent.cs index 1975dc5..ca2c064 100644 --- a/Filtration.ObjectModel/ThemeEditor/StringThemeComponent.cs +++ b/Filtration.ObjectModel/ThemeEditor/StringThemeComponent.cs @@ -1,6 +1,7 @@ using System; using System.Collections.ObjectModel; using System.Linq; +using System.Xml.Serialization; using Filtration.ObjectModel.Enums; using GalaSoft.MvvmLight.Command; using Microsoft.Win32; @@ -13,6 +14,10 @@ namespace Filtration.ObjectModel.ThemeEditor private string _value; public static ObservableCollection _customSoundsAvailable; + private StringThemeComponent() + { + } + public StringThemeComponent(ThemeComponentType componentType, string componentName, string componentValue) { if (componentName == null || componentValue == null) @@ -61,13 +66,14 @@ namespace Filtration.ObjectModel.ThemeEditor CustomSoundFileDialogCommand = new RelayCommand(OnCustomSoundFileDialog); } + [XmlIgnore] public RelayCommand CustomSoundFileDialogCommand { get; set; } public ObservableCollection CustomSoundsAvailable => _customSoundsAvailable; public string Value { - get { return _value; } + get => _value; set { _value = value; @@ -78,12 +84,11 @@ namespace Filtration.ObjectModel.ThemeEditor private void OnCustomSoundFileDialog() { - OpenFileDialog fileDialog = new OpenFileDialog(); - fileDialog.DefaultExt = ".mp3"; - var poePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments).ToString() + @"\My Games\Path of Exile\"; + OpenFileDialog fileDialog = new OpenFileDialog {DefaultExt = ".mp3"}; + var poePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\My Games\Path of Exile\"; fileDialog.InitialDirectory = poePath; - Nullable result = fileDialog.ShowDialog(); + bool? result = fileDialog.ShowDialog(); if (result == true) { var fileName = fileDialog.FileName; diff --git a/Filtration.ObjectModel/ThemeEditor/Theme.cs b/Filtration.ObjectModel/ThemeEditor/Theme.cs index 7d9d3fc..47a2644 100644 --- a/Filtration.ObjectModel/ThemeEditor/Theme.cs +++ b/Filtration.ObjectModel/ThemeEditor/Theme.cs @@ -7,13 +7,17 @@ using Filtration.ObjectModel.Enums; namespace Filtration.ObjectModel.ThemeEditor { [Serializable] + [XmlInclude(typeof(ColorThemeComponent))] + [XmlInclude(typeof(EffectColorThemeComponent))] + [XmlInclude(typeof(IconThemeComponent))] + [XmlInclude(typeof(IntegerThemeComponent))] + [XmlInclude(typeof(StringThemeComponent))] + [XmlInclude(typeof(StrIntThemeComponent))] public class Theme { - private readonly ThemeComponentCollection _components; - public Theme() { - _components = new ThemeComponentCollection { IsMasterCollection = false}; + Components = new ThemeComponentCollection { IsMasterCollection = false}; } public string Name { get; set; } @@ -21,28 +25,28 @@ namespace Filtration.ObjectModel.ThemeEditor [XmlIgnore] public string FilePath { get; set; } - public ThemeComponentCollection Components => _components; + public ThemeComponentCollection Components { get; set; } public bool ComponentExists(ThemeComponentType componentType, string componentName) { var componentCount = - _components.Count(c => c.ComponentName == componentName && c.ComponentType == componentType); + Components.Count(c => c.ComponentName == componentName && c.ComponentType == componentType); return componentCount > 0; } public void AddComponent(ThemeComponentType componentType, string componentName, Color componentColor) { - _components.Add(new ColorThemeComponent(componentType, componentName, componentColor)); + Components.Add(new ColorThemeComponent(componentType, componentName, componentColor)); } public void AddComponent(ThemeComponentType componentType, string componentName, int componentValue) { - _components.Add(new IntegerThemeComponent(componentType, componentName, componentValue)); + Components.Add(new IntegerThemeComponent(componentType, componentName, componentValue)); } public void AddComponent(ThemeComponentType componentType, string componentName, string componentValue, int componentSecondValue) { - _components.Add(new StrIntThemeComponent(componentType, componentName, componentValue, componentSecondValue)); + Components.Add(new StrIntThemeComponent(componentType, componentName, componentValue, componentSecondValue)); } } } diff --git a/Filtration/App.xaml.cs b/Filtration/App.xaml.cs index 692aa95..7158adc 100644 --- a/Filtration/App.xaml.cs +++ b/Filtration/App.xaml.cs @@ -43,7 +43,7 @@ namespace Filtration cfg.CreateMap().ReverseMap(); cfg.CreateMap().ReverseMap(); cfg.CreateMap().ReverseMap(); - cfg.CreateMap(); + cfg.CreateMap(); }); Mapper.AssertConfigurationIsValid();