Skip to content

Commit 1effec1

Browse files
committed
add climate viewmodel
1 parent 65e2798 commit 1effec1

File tree

6 files changed

+59
-13
lines changed

6 files changed

+59
-13
lines changed

Dat/Objects/Sound/SoundObject.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using OpenLoco.Dat.FileParsing;
33
using OpenLoco.Dat.Types;
44
using System.ComponentModel;
5+
using System.ComponentModel.DataAnnotations;
56

67
namespace OpenLoco.Dat.Objects.Sound
78
{
@@ -17,9 +18,9 @@ public record SoundObject(
1718
[property: LocoStructOffset(0x08)] uint32_t Volume
1819
) : ILocoStruct, ILocoStructVariableData
1920
{
20-
public SoundObjectData SoundObjectData { get; set; }
21+
[Editable(false)] public SoundObjectData SoundObjectData { get; set; }
2122

22-
public byte[] PcmData { get; set; } = [];
23+
[Browsable(false)] public byte[] PcmData { get; set; } = [];
2324

2425
uint numUnkStructs;
2526
uint pcmDataLength;

Gui/ViewModels/DatTypes/DatObjectEditorViewModel.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ public override void Load()
120120
{
121121
CurrentObjectViewModel = new StreetLightViewModel(sl);
122122
}
123+
else if (CurrentObject.LocoObject.Object is ClimateObject cl)
124+
{
125+
CurrentObjectViewModel = new ClimateViewModel(cl);
126+
}
123127
else
124128
{
125129
CurrentObjectViewModel = new GenericObjectViewModel() { Object = CurrentObject.LocoObject.Object };
Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
1-
using OpenLoco.Dat.Types;
2-
using ReactiveUI;
3-
41
namespace OpenLoco.Gui.ViewModels
52
{
63
public interface IObjectViewModel<T>
74
{
85
T GetAsUnderlyingType(T underlyingType);
96
}
10-
11-
public abstract class LocoObjectViewModel<T> : ReactiveObject, IObjectViewModel<ILocoStruct> where T : class, ILocoStruct
12-
{
13-
public ILocoStruct GetAsUnderlyingType(ILocoStruct locoStruct)
14-
=> GetAsStruct((locoStruct as T)!);
15-
16-
public abstract T GetAsStruct(T input);
17-
}
187
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using OpenLoco.Dat.Types;
2+
using ReactiveUI;
3+
4+
namespace OpenLoco.Gui.ViewModels
5+
{
6+
public abstract class LocoObjectViewModel<T> : ReactiveObject, IObjectViewModel<ILocoStruct> where T : class, ILocoStruct
7+
{
8+
public ILocoStruct GetAsUnderlyingType(ILocoStruct locoStruct)
9+
=> GetAsStruct((locoStruct as T)!);
10+
11+
public abstract T GetAsStruct(T input);
12+
}
13+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 ClimateViewModel : LocoObjectViewModel<ClimateObject>
9+
{
10+
[Reactive] public uint8_t FirstSeason { get; set; }
11+
[Reactive] public uint8_t WinterSnowLine { get; set; }
12+
[Reactive] public uint8_t SummerSnowLine { get; set; }
13+
[Reactive] public uint8_t var_09 { get; set; }
14+
[Reactive] public BindingList<uint8_t> SeasonLengths { get; set; }
15+
16+
public ClimateViewModel(ClimateObject ro)
17+
{
18+
FirstSeason = ro.FirstSeason;
19+
WinterSnowLine = ro.WinterSnowLine;
20+
SummerSnowLine = ro.SummerSnowLine;
21+
var_09 = ro.var_09;
22+
SeasonLengths = ro.SeasonLengths.ToBindingList();
23+
}
24+
25+
public override ClimateObject GetAsStruct(ClimateObject input)
26+
=> input with
27+
{
28+
FirstSeason = FirstSeason,
29+
WinterSnowLine = WinterSnowLine,
30+
SummerSnowLine = SummerSnowLine,
31+
var_09 = var_09,
32+
SeasonLengths = [.. SeasonLengths]
33+
};
34+
}
35+
}

Gui/Views/MainWindow.axaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@
176176
<pgc:PropertyGrid DataContext="{Binding}" Margin="2" ShowTitle="False" AllowFilter="False" AllowQuickFilter="False" Background="{DynamicResource ExpanderContentBackground}"></pgc:PropertyGrid>
177177
</DataTemplate>
178178

179+
<DataTemplate DataType="vm:ClimateViewModel">
180+
<pgc:PropertyGrid DataContext="{Binding}" Margin="2" ShowTitle="False" AllowFilter="False" AllowQuickFilter="False" Background="{DynamicResource ExpanderContentBackground}"></pgc:PropertyGrid>
181+
</DataTemplate>
182+
179183
<DataTemplate DataType="vm:DatObjectEditorViewModel">
180184
<DockPanel DataContext="{Binding}" Margin="10">
181185
<Grid ColumnDefinitions="*, Auto, 384">

0 commit comments

Comments
 (0)