From 6509618ebcb769d3e065891214002bf8d7e1ab0d Mon Sep 17 00:00:00 2001 From: Benjamin Sutas Date: Sat, 30 Nov 2024 15:24:04 +1100 Subject: [PATCH] cleanup new s5 viewmodel --- .../DatTypes/Objects/VehicleViewModel.cs | 37 +------------ Gui/ViewModels/DatTypes/S5HeaderViewModel.cs | 55 ++++++++----------- 2 files changed, 25 insertions(+), 67 deletions(-) diff --git a/Gui/ViewModels/DatTypes/Objects/VehicleViewModel.cs b/Gui/ViewModels/DatTypes/Objects/VehicleViewModel.cs index c00ad155..de630cc9 100644 --- a/Gui/ViewModels/DatTypes/Objects/VehicleViewModel.cs +++ b/Gui/ViewModels/DatTypes/Objects/VehicleViewModel.cs @@ -1,4 +1,3 @@ -using OpenLoco.Dat.Data; using OpenLoco.Dat.Objects; using OpenLoco.Dat.Types; using ReactiveUI; @@ -9,38 +8,6 @@ namespace OpenLoco.Gui.ViewModels { - [TypeConverter(typeof(ExpandableObjectConverter))] - public class S5ViewModel : ReactiveObject //, IObjectViewModel - { - public S5ViewModel(string name, uint checksum, SourceGame sourceGame, ObjectType objectType) - { - Name = name; - Checksum = checksum; - SourceGame = sourceGame; - ObjectType = objectType; - } - public S5ViewModel(S5Header s5Header) - { - Name = s5Header.Name; - Checksum = s5Header.Checksum; - SourceGame = s5Header.SourceGame; - ObjectType = s5Header.ObjectType; - } - - public string Name { get; set; } - public uint32_t Checksum { get; set; } - public SourceGame SourceGame { get; set; } - - public ObjectType ObjectType { get; set; } - - public S5Header GetAsUnderlyingType() - => new(Name, Checksum) - { - ObjectType = ObjectType, - SourceGame = SourceGame - }; - } - public class VehicleViewModel : ReactiveObject, IObjectViewModel { [Reactive, Category("Stats")] public TransportMode Mode { get; set; } @@ -81,7 +48,7 @@ public class VehicleViewModel : ReactiveObject, IObjectViewModel [Reactive, Category("Sound")] public FrictionSound? FrictionSound { get; set; } [Reactive, Category("Sound")] public Engine1Sound? Engine1Sound { get; set; } [Reactive, Category("Sound")] public Engine2Sound? Engine2Sound { get; set; } - [Reactive, Category("Sound")] public BindingList StartSounds { get; set; } + [Reactive, Category("Sound")] public BindingList StartSounds { get; set; } public VehicleViewModel(VehicleObject veh) { @@ -117,7 +84,7 @@ public VehicleViewModel(VehicleObject veh) RackRail = veh.RackRail; Sound = veh.Sound; SoundType = veh.DrivingSoundType; - StartSounds = new(veh.StartSounds.ConvertAll(x => new S5ViewModel(x))); + StartSounds = new(veh.StartSounds.ConvertAll(x => new S5HeaderViewModel(x))); FrictionSound = veh.SoundPropertyFriction; Engine1Sound = veh.SoundPropertyEngine1; Engine2Sound = veh.SoundPropertyEngine2; diff --git a/Gui/ViewModels/DatTypes/S5HeaderViewModel.cs b/Gui/ViewModels/DatTypes/S5HeaderViewModel.cs index ea9d4edc..d81ef2f9 100644 --- a/Gui/ViewModels/DatTypes/S5HeaderViewModel.cs +++ b/Gui/ViewModels/DatTypes/S5HeaderViewModel.cs @@ -2,55 +2,46 @@ using OpenLoco.Dat.Types; using ReactiveUI; using ReactiveUI.Fody.Helpers; -using System; +using System.ComponentModel; using System.ComponentModel.DataAnnotations; namespace OpenLoco.Gui.ViewModels { + [TypeConverter(typeof(ExpandableObjectConverter))] public class S5HeaderViewModel : ReactiveObject { - S5Header s5Header { get; init; } - - public S5HeaderViewModel(S5Header s5) + public S5HeaderViewModel(string name, uint checksum, SourceGame sourceGame, ObjectType objectType) { - s5Header = s5; - Name = s5.Name; - SourceGame = s5.SourceGame; - ObjectType = s5.ObjectType; - //Checksum = s5.Checksum; - //Flags = s5.Flags; - - _ = this.WhenAnyValue(o => o.Name) - .Subscribe(_ => s5Header.Name = Name); - - _ = this.WhenAnyValue(o => o.SourceGame) - .Subscribe(_ => - { - s5Header.SourceGame = SourceGame; - this.RaisePropertyChanged(nameof(Flags)); - }); - - _ = this.WhenAnyValue(o => o.ObjectType) - .Subscribe(_ => - { - s5Header.ObjectType = ObjectType; - this.RaisePropertyChanged(nameof(Flags)); - }); + Name = name; + Checksum = checksum; + SourceGame = sourceGame; + ObjectType = objectType; + } + public S5HeaderViewModel(S5Header s5Header) + { + Name = s5Header.Name; + Checksum = s5Header.Checksum; + SourceGame = s5Header.SourceGame; + ObjectType = s5Header.ObjectType; } [Reactive, MaxLength(8)] public string Name { get; set; } + [Reactive] + public uint32_t Checksum { get; set; } + [Reactive] public SourceGame SourceGame { get; set; } [Reactive] public ObjectType ObjectType { get; set; } - [Editable(false)] - public uint32_t Checksum => s5Header.Checksum; - - [Editable(false)] - public uint32_t Flags => s5Header.Flags; + public S5Header GetAsUnderlyingType() + => new(Name, Checksum) + { + ObjectType = ObjectType, + SourceGame = SourceGame + }; } }