Skip to content

Commit

Permalink
cleanup new s5 viewmodel
Browse files Browse the repository at this point in the history
  • Loading branch information
LeftofZen committed Nov 30, 2024
1 parent 6ae1a96 commit 6509618
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 67 deletions.
37 changes: 2 additions & 35 deletions Gui/ViewModels/DatTypes/Objects/VehicleViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using OpenLoco.Dat.Data;
using OpenLoco.Dat.Objects;
using OpenLoco.Dat.Types;
using ReactiveUI;
Expand All @@ -9,38 +8,6 @@

namespace OpenLoco.Gui.ViewModels
{
[TypeConverter(typeof(ExpandableObjectConverter))]
public class S5ViewModel : ReactiveObject //, IObjectViewModel<S5Header>
{
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<ILocoStruct>
{
[Reactive, Category("Stats")] public TransportMode Mode { get; set; }
Expand Down Expand Up @@ -81,7 +48,7 @@ public class VehicleViewModel : ReactiveObject, IObjectViewModel<ILocoStruct>
[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<S5ViewModel> StartSounds { get; set; }
[Reactive, Category("Sound")] public BindingList<S5HeaderViewModel> StartSounds { get; set; }

public VehicleViewModel(VehicleObject veh)
{
Expand Down Expand Up @@ -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;
Expand Down
55 changes: 23 additions & 32 deletions Gui/ViewModels/DatTypes/S5HeaderViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}
}

0 comments on commit 6509618

Please sign in to comment.