Skip to content

Commit 65e2798

Browse files
committed
add streetlight, trainsignal viewmodels
1 parent 758a43e commit 65e2798

File tree

8 files changed

+96
-8
lines changed

8 files changed

+96
-8
lines changed

Dat/Objects/StreetLightObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace OpenLoco.Dat.Objects
1111
[LocoStringTable("Name")]
1212
public record StreetLightObject(
1313
[property: LocoStructOffset(0x00), LocoString, Browsable(false)] string_id Name,
14-
[property: LocoStructOffset(0x02), LocoArrayLength(StreetLightObject.DesignedYearLength)] uint16_t[] DesignedYear
14+
[property: LocoStructOffset(0x02), LocoArrayLength(StreetLightObject.DesignedYearLength)] uint16_t[] DesignedYears
1515
) : ILocoStruct, IImageTableNameProvider
1616
{
1717
public const int DesignedYearLength = 3;

Dat/Objects/TrainSignalObject.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public record TrainSignalObject(
2323
[property: LocoStructOffset(0x02)] TrainSignalObjectFlags Flags,
2424
[property: LocoStructOffset(0x04)] uint8_t AnimationSpeed,
2525
[property: LocoStructOffset(0x05)] uint8_t NumFrames,
26-
[property: LocoStructOffset(0x06)] int16_t CostFactor,
26+
[property: LocoStructOffset(0x06)] int16_t BuildCostFactor,
2727
[property: LocoStructOffset(0x08)] int16_t SellCostFactor,
2828
[property: LocoStructOffset(0x0A)] uint8_t CostIndex,
2929
[property: LocoStructOffset(0x0B)] uint8_t var_0B,
@@ -91,7 +91,7 @@ public bool Validate()
9191
return false;
9292
}
9393

94-
if (-SellCostFactor > CostFactor)
94+
if (-SellCostFactor > BuildCostFactor)
9595
{
9696
return false;
9797
}

Gui/ViewModels/DatTypes/DatObjectEditorViewModel.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ public override void Load()
112112
{
113113
CurrentObjectViewModel = new RegionViewModel(ro);
114114
}
115+
else if (CurrentObject.LocoObject.Object is TrainSignalObject tso)
116+
{
117+
CurrentObjectViewModel = new TrainSignalViewModel(tso);
118+
}
119+
else if (CurrentObject.LocoObject.Object is StreetLightObject sl)
120+
{
121+
CurrentObjectViewModel = new StreetLightViewModel(sl);
122+
}
115123
else
116124
{
117125
CurrentObjectViewModel = new GenericObjectViewModel() { Object = CurrentObject.LocoObject.Object };

Gui/ViewModels/DatTypes/Objects/RegionViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using OpenLoco.Dat.Objects;
1+
using OpenLoco.Dat.Objects;
22
using ReactiveUI.Fody.Helpers;
33
using System.ComponentModel;
44
using System.Linq;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using OpenLoco.Dat.Objects;
2+
using PropertyModels.Extensions;
3+
using ReactiveUI.Fody.Helpers;
4+
using System.ComponentModel;
5+
6+
namespace OpenLoco.Gui.ViewModels
7+
{
8+
public class StreetLightViewModel : LocoObjectViewModel<StreetLightObject>
9+
{
10+
[Reactive] public BindingList<uint16_t> DesignedYears { get; set; }
11+
12+
public StreetLightViewModel(StreetLightObject ro)
13+
{
14+
DesignedYears = ro.DesignedYears.ToBindingList();
15+
}
16+
17+
public override StreetLightObject GetAsStruct(StreetLightObject input)
18+
=> input with
19+
{
20+
DesignedYears = [.. DesignedYears]
21+
};
22+
}
23+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
}

Gui/Views/MainWindow.axaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,14 @@
168168
<pgc:PropertyGrid DataContext="{Binding}" Margin="2" ShowTitle="False" AllowFilter="False" AllowQuickFilter="False" Background="{DynamicResource ExpanderContentBackground}"></pgc:PropertyGrid>
169169
</DataTemplate>
170170

171+
<DataTemplate DataType="vm:TrainSignalViewModel">
172+
<pgc:PropertyGrid DataContext="{Binding}" Margin="2" ShowTitle="False" AllowFilter="False" AllowQuickFilter="False" Background="{DynamicResource ExpanderContentBackground}"></pgc:PropertyGrid>
173+
</DataTemplate>
174+
175+
<DataTemplate DataType="vm:StreetLightViewModel">
176+
<pgc:PropertyGrid DataContext="{Binding}" Margin="2" ShowTitle="False" AllowFilter="False" AllowQuickFilter="False" Background="{DynamicResource ExpanderContentBackground}"></pgc:PropertyGrid>
177+
</DataTemplate>
178+
171179
<DataTemplate DataType="vm:DatObjectEditorViewModel">
172180
<DockPanel DataContext="{Binding}" Margin="10">
173181
<Grid ColumnDefinitions="*, Auto, 384">

Tests/LoadSaveTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -762,9 +762,9 @@ void assertFunc(ILocoObject obj, StreetLightObject struc) => Assert.Multiple(()
762762
{
763763
Assert.That(struc.Name, Is.EqualTo(0));
764764

765-
Assert.That(struc.DesignedYear[0], Is.EqualTo(1900), nameof(struc.DesignedYear) + "[0]");
766-
Assert.That(struc.DesignedYear[1], Is.EqualTo(1950), nameof(struc.DesignedYear) + "[1]");
767-
Assert.That(struc.DesignedYear[2], Is.EqualTo(1985), nameof(struc.DesignedYear) + "[2]");
765+
Assert.That(struc.DesignedYears[0], Is.EqualTo(1900), nameof(struc.DesignedYears) + "[0]");
766+
Assert.That(struc.DesignedYears[1], Is.EqualTo(1950), nameof(struc.DesignedYears) + "[1]");
767+
Assert.That(struc.DesignedYears[2], Is.EqualTo(1985), nameof(struc.DesignedYears) + "[2]");
768768

769769
Assert.That(obj.StringTable["Name"][LanguageId.English_UK], Is.EqualTo("Street Lights"));
770770
Assert.That(obj.StringTable["Name"][LanguageId.English_US], Is.EqualTo("Street Lights"));
@@ -866,7 +866,7 @@ void assertFunc(ILocoObject obj, TrainSignalObject struc) => Assert.Multiple(()
866866
Assert.That(struc.Image, Is.EqualTo(0));
867867

868868
Assert.That(struc.AnimationSpeed, Is.EqualTo(1), nameof(struc.AnimationSpeed));
869-
Assert.That(struc.CostFactor, Is.EqualTo(4), nameof(struc.CostFactor));
869+
Assert.That(struc.BuildCostFactor, Is.EqualTo(4), nameof(struc.BuildCostFactor));
870870
Assert.That(struc.CostIndex, Is.EqualTo(1), nameof(struc.CostIndex));
871871
Assert.That(struc.DesignedYear, Is.EqualTo(0), nameof(struc.DesignedYear));
872872
Assert.That(struc.Flags, Is.EqualTo(TrainSignalObjectFlags.IsLeft), nameof(struc.Flags));

0 commit comments

Comments
 (0)