|
| 1 | +using OpenLoco.Dat.Objects; |
| 2 | +using ReactiveUI.Fody.Helpers; |
| 3 | +using System.ComponentModel; |
| 4 | +using System.ComponentModel.DataAnnotations; |
| 5 | +using System.Linq; |
| 6 | + |
| 7 | +namespace OpenLoco.Gui.ViewModels |
| 8 | +{ |
| 9 | + public class TrainSignalViewModel : LocoObjectViewModel<TrainSignalObject> |
| 10 | + { |
| 11 | + [Reactive] public TrainSignalObjectFlags Flags { get; set; } |
| 12 | + [Reactive] public uint8_t AnimationSpeed { get; set; } |
| 13 | + [Reactive] public uint8_t NumFrames { get; set; } |
| 14 | + [Reactive, Category("Cost")] public uint8_t CostIndex { get; set; } |
| 15 | + [Reactive, Category("Cost")] public int16_t BuildCostFactor { get; set; } |
| 16 | + [Reactive, Category("Cost")] public int16_t SellCostFactor { get; set; } |
| 17 | + [Reactive, Category("Stats")] public uint16_t DesignedYear { get; set; } |
| 18 | + [Reactive, Category("Stats")] public uint16_t ObsoleteYear { get; set; } |
| 19 | + [Reactive, Length(0, TrainSignalObject.ModsLength)] public BindingList<S5HeaderViewModel> Mods { get; set; } |
| 20 | + |
| 21 | + public TrainSignalViewModel(TrainSignalObject ro) |
| 22 | + { |
| 23 | + Flags = ro.Flags; |
| 24 | + AnimationSpeed = ro.AnimationSpeed; |
| 25 | + NumFrames = ro.NumFrames; |
| 26 | + CostIndex = ro.CostIndex; |
| 27 | + BuildCostFactor = ro.BuildCostFactor; |
| 28 | + SellCostFactor = ro.SellCostFactor; |
| 29 | + DesignedYear = ro.DesignedYear; |
| 30 | + ObsoleteYear = ro.ObsoleteYear; |
| 31 | + Mods = new(ro.Mods.ConvertAll(x => new S5HeaderViewModel(x))); |
| 32 | + } |
| 33 | + |
| 34 | + public override TrainSignalObject GetAsStruct(TrainSignalObject input) |
| 35 | + => input with |
| 36 | + { |
| 37 | + Flags = Flags, |
| 38 | + AnimationSpeed = AnimationSpeed, |
| 39 | + NumFrames = NumFrames, |
| 40 | + CostIndex = CostIndex, |
| 41 | + BuildCostFactor = BuildCostFactor, |
| 42 | + SellCostFactor = SellCostFactor, |
| 43 | + DesignedYear = DesignedYear, |
| 44 | + ObsoleteYear = ObsoleteYear, |
| 45 | + Mods = Mods.ToList().ConvertAll(x => x.GetAsUnderlyingType()), |
| 46 | + NumCompatible = (uint8_t)Mods.Count, |
| 47 | + }; |
| 48 | + } |
| 49 | +} |
0 commit comments