Skip to content

Commit c781c41

Browse files
committed
fix rackrail in vehicle viewmodel
1 parent e35881f commit c781c41

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

Gui/ViewModels/LocoTypes/Objects/VehicleViewModel.cs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,13 @@ public VehicleViewModel(VehicleObject model) : base(model)
3535
RoadOrTrackType = model.RoadOrTrackType;
3636
RackRail = model.RackRail;
3737

38-
HasRackRail = model.Flags.HasFlag(VehicleObjectFlags.RackRail);
39-
4038
SimpleMotorSound = model.SimpleMotorSound ?? new SimpleMotorSound();
4139
FrictionSound = model.FrictionSound ?? new FrictionSound();
4240
GearboxMotorSound = model.GearboxMotorSound ?? new GearboxMotorSound();
4341
Sound = model.Sound;
4442

45-
_ = this.WhenAnyValue(x => x.RackRail)
46-
.Subscribe((_) => model.RackRail = RackRail);
43+
//_ = this.WhenAnyValue(x => x.RackRail)
44+
// .Subscribe((_) => model.RackRail = RackRail);
4745

4846
#region Road/Track Type Binding
4947

@@ -53,8 +51,8 @@ public VehicleViewModel(VehicleObject model) : base(model)
5351
_ = this.WhenAnyValue(x => x.IsTrackTypeSettable)
5452
.Subscribe((_) => this.RaisePropertyChanged(nameof(RoadOrTrackType)));
5553

56-
_ = this.WhenAnyValue(x => x.RoadOrTrackType)
57-
.Subscribe((_) => model.RoadOrTrackType = RoadOrTrackType);
54+
//_ = this.WhenAnyValue(x => x.RoadOrTrackType)
55+
// .Subscribe((_) => model.RoadOrTrackType = RoadOrTrackType);
5856

5957
#endregion
6058

@@ -165,10 +163,13 @@ public VehicleObjectFlags Flags
165163
bool IsTrackTypeSettable
166164
=> !model.Flags.HasFlag(VehicleObjectFlags.AnyRoadType) && (model.Mode == TransportMode.Rail || model.Mode == TransportMode.Road);
167165

168-
[Reactive]
169166
[ConditionTarget]
170167
[PropertyVisibilityCondition(nameof(IsTrackTypeSettable), true)]
171-
public ObjectModelHeader? RoadOrTrackType { get; set; }
168+
public ObjectModelHeader? RoadOrTrackType
169+
{
170+
get => model.RoadOrTrackType;
171+
set => model.RoadOrTrackType = value;
172+
}
172173

173174
[ConditionTarget]
174175
public bool HasRackRail
@@ -177,16 +178,23 @@ public bool HasRackRail
177178
set
178179
{
179180
model.Flags = model.Flags.ToggleFlag(VehicleObjectFlags.RackRail, value);
180-
RackRail = value && RackRail == null
181-
? new ObjectModelHeader("<obj>", ObjectType.TrackExtra, ObjectSource.OpenLoco, 0)
182-
: null;
181+
182+
if (RackRail == null && model.Flags.HasFlag(VehicleObjectFlags.RackRail))
183+
{
184+
RackRail = new ObjectModelHeader() { Name = "<obj>", ObjectSource = ObjectSource.Custom, ObjectType = ObjectType.TrackExtra };
185+
}
186+
187+
this.RaisePropertyChanged(nameof(RackRail));
183188
}
184189
}
185190

186-
[Reactive]
187191
[ConditionTarget]
188192
[PropertyVisibilityCondition(nameof(HasRackRail), true)]
189-
public ObjectModelHeader? RackRail { get; set; }
193+
public ObjectModelHeader? RackRail
194+
{
195+
get => model.RackRail;
196+
set => model.RackRail = value;
197+
}
190198

191199
[Range(0, 4)]
192200
public uint8_t NumCarComponents

0 commit comments

Comments
 (0)