1
1
using OpenLoco . Dat . Data ;
2
2
using OpenLoco . Dat . Objects ;
3
- using OpenLoco . Dat . Types ;
4
3
using PropertyModels . Extensions ;
5
- using ReactiveUI ;
6
4
using ReactiveUI . Fody . Helpers ;
7
5
using System . ComponentModel ;
8
6
using System . ComponentModel . DataAnnotations ;
9
7
using System . Linq ;
10
8
11
9
namespace OpenLoco . Gui . ViewModels
12
10
{
13
- public class IndustryViewModel : ReactiveObject , IObjectViewModel < ILocoStruct >
11
+ public class IndustryViewModel : LocoObjectViewModel < IndustryObject >
14
12
{
15
13
[ Reactive ] public uint8_t TotalOfTypeInScenario { get ; set ; } // Total industries of this type that can be created in a scenario Note: this is not directly comparable to total industries and varies based on scenario total industries cap settings. At low industries cap this value is ~3x the amount of industries in a scenario.
16
14
[ Reactive ] public uint16_t DesignedYear { get ; set ; }
@@ -19,8 +17,8 @@ public class IndustryViewModel : ReactiveObject, IObjectViewModel<ILocoStruct>
19
17
[ Reactive ] public Colour MapColour { get ; set ; }
20
18
[ Reactive ] public uint32_t Colours { get ; set ; } // bitset
21
19
[ Reactive , Category ( "Production" ) ] public BindingList < IndustryObjectProductionRateRange > InitialProductionRate { get ; set ; }
22
- [ Reactive , Category ( "Production" ) , Length ( 0 , IndustryObject . MaxProducedCargoType ) ] public BindingList < S5Header > ProducedCargo { get ; set ; }
23
- [ Reactive , Category ( "Production" ) , Length ( 0 , IndustryObject . MaxProducedCargoType ) ] public BindingList < S5Header > RequiredCargo { get ; set ; }
20
+ [ Reactive , Category ( "Production" ) , Length ( 0 , IndustryObject . MaxProducedCargoType ) ] public BindingList < S5HeaderViewModel > ProducedCargo { get ; set ; }
21
+ [ Reactive , Category ( "Production" ) , Length ( 0 , IndustryObject . MaxProducedCargoType ) ] public BindingList < S5HeaderViewModel > RequiredCargo { get ; set ; }
24
22
[ Reactive , Category ( "Cost" ) ] public uint8_t CostIndex { get ; set ; }
25
23
[ Reactive , Category ( "Cost" ) ] public int16_t BuildCostFactor { get ; set ; }
26
24
[ Reactive , Category ( "Cost" ) ] public int16_t SellCostFactor { get ; set ; }
@@ -34,9 +32,9 @@ public class IndustryViewModel : ReactiveObject, IObjectViewModel<ILocoStruct>
34
32
[ Reactive , Category ( "Building" ) ] public uint32_t BuildingSizeFlags { get ; set ; }
35
33
[ Reactive , Category ( "Building" ) ] public uint8_t ScaffoldingSegmentType { get ; set ; }
36
34
[ Reactive , Category ( "Building" ) ] public Colour ScaffoldingColour { get ; set ; }
37
- [ Reactive , Category ( "Building" ) , Length ( 0 , IndustryObject . MaxWallTypeCount ) ] public BindingList < S5Header > WallTypes { get ; set ; }
38
- [ Reactive , Category ( "Building" ) ] public S5Header ? BuildingWall { get ; set ; }
39
- [ Reactive , Category ( "Building" ) ] public S5Header ? BuildingWallEntrance { get ; set ; }
35
+ [ Reactive , Category ( "Building" ) , Length ( 0 , IndustryObject . MaxWallTypeCount ) ] public BindingList < S5HeaderViewModel > WallTypes { get ; set ; }
36
+ [ Reactive , Category ( "Building" ) ] public S5HeaderViewModel ? BuildingWall { get ; set ; }
37
+ [ Reactive , Category ( "Building" ) ] public S5HeaderViewModel ? BuildingWallEntrance { get ; set ; }
40
38
[ Reactive , Category ( "<unknown>" ) ] public BindingList < IndustryObjectUnk38 > var_38 { get ; set ; }
41
39
[ Reactive , Category ( "<unknown>" ) ] public uint8_t var_E8 { get ; set ; }
42
40
[ Reactive , Category ( "<unknown>" ) ] public uint8_t var_E9 { get ; set ; }
@@ -54,14 +52,14 @@ public IndustryViewModel(IndustryObject io)
54
52
BuildingVariations = new ( io . BuildingVariations . Select ( x => new BindingList < uint8_t > ( x ) ) . ToBindingList ( ) ) ;
55
53
Buildings = new ( io . Buildings ) ;
56
54
BuildingSizeFlags = io . BuildingSizeFlags ;
57
- BuildingWall = io . BuildingWall ;
58
- BuildingWallEntrance = io . BuildingWallEntrance ;
55
+ BuildingWall = io . BuildingWall == null ? null : new ( io . BuildingWall ) ;
56
+ BuildingWallEntrance = io . BuildingWallEntrance == null ? null : new ( io . BuildingWallEntrance ) ;
59
57
MinNumBuildings = io . MinNumBuildings ;
60
58
MaxNumBuildings = io . MaxNumBuildings ;
61
59
InitialProductionRate = new ( io . InitialProductionRate ) ;
62
- ProducedCargo = new ( io . ProducedCargo ) ;
63
- RequiredCargo = new ( io . RequiredCargo ) ;
64
- WallTypes = new ( io . WallTypes ) ;
60
+ ProducedCargo = new ( io . ProducedCargo . ConvertAll ( x => new S5HeaderViewModel ( x ) ) ) ;
61
+ RequiredCargo = new ( io . RequiredCargo . ConvertAll ( x => new S5HeaderViewModel ( x ) ) ) ;
62
+ WallTypes = new ( io . WallTypes . ConvertAll ( x => new S5HeaderViewModel ( x ) ) ) ;
65
63
Colours = io . Colours ;
66
64
DesignedYear = io . DesignedYear ;
67
65
ObsoleteYear = io . ObsoleteYear ;
@@ -81,21 +79,21 @@ public IndustryViewModel(IndustryObject io)
81
79
var_F3 = io . var_E8 ;
82
80
}
83
81
84
- public ILocoStruct GetAsUnderlyingType ( ILocoStruct locoStruct )
85
- => GetAsStruct ( ( locoStruct as IndustryObject ) ! ) ;
86
-
87
82
// validation:
88
83
// BuildingVariationHeights.Count MUST equal BuildingVariationAnimations.Count
89
- public IndustryObject GetAsStruct ( IndustryObject io )
84
+ public override IndustryObject GetAsStruct ( IndustryObject io )
90
85
=> io with
91
86
{
92
87
BuildingSizeFlags = BuildingSizeFlags ,
93
- BuildingWall = BuildingWall ,
94
- BuildingWallEntrance = BuildingWallEntrance ,
88
+ BuildingWall = BuildingWall ? . GetAsUnderlyingType ( ) ,
89
+ BuildingWallEntrance = BuildingWallEntrance ? . GetAsUnderlyingType ( ) ,
95
90
MinNumBuildings = MinNumBuildings ,
96
91
MaxNumBuildings = MaxNumBuildings ,
97
92
NumBuildingParts = ( uint8_t ) BuildingAnimations . Count ,
98
93
NumBuildingVariations = ( uint8_t ) BuildingVariations . Count ,
94
+ ProducedCargo = ProducedCargo . ToList ( ) . ConvertAll ( x => x . GetAsUnderlyingType ( ) ) ,
95
+ RequiredCargo = RequiredCargo . ToList ( ) . ConvertAll ( x => x . GetAsUnderlyingType ( ) ) ,
96
+ WallTypes = WallTypes . ToList ( ) . ConvertAll ( x => x . GetAsUnderlyingType ( ) ) ,
99
97
Colours = Colours ,
100
98
DesignedYear = DesignedYear ,
101
99
ObsoleteYear = ObsoleteYear ,
0 commit comments