-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathBuildingComponents.cs
More file actions
66 lines (56 loc) · 2.61 KB
/
BuildingComponents.cs
File metadata and controls
66 lines (56 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using Definitions.ObjectModels.Objects.Building;
using Definitions.ObjectModels.Validation;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
namespace Definitions.ObjectModels.Objects.Common;
[TypeConverter(typeof(ExpandableObjectConverter))]
public class BuildingComponents : ILocoStruct
{
#pragma warning disable IL2026 // LengthAttribute constructor uses reflection to get 'Count' on non-ICollection types; our properties use List<T> which implements ICollection so Count is preserved.
[Length(1, BuildingObject.Constants.MaxAnimationsCount)]
[CountEqualTo(nameof(BuildingAnimations))]
public List<uint8_t> BuildingHeights { get; set; } = [];
[Length(1, BuildingObject.Constants.MaxHeightsCount)]
[CountEqualTo(nameof(BuildingHeights))]
public List<BuildingPartAnimation> BuildingAnimations { get; set; } = [];
[Length(1, BuildingObject.Constants.MaxVariationsCount)]
public List<List<uint8_t>> BuildingVariations { get; set; } = [];
#pragma warning restore IL2026
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
// heights and animations
{
if (BuildingHeights.Count is < 1 or > BuildingObject.Constants.MaxHeightsCount)
{
yield return new ValidationResult($"{nameof(BuildingHeights)} must contain between 1 and {BuildingObject.Constants.MaxHeightsCount} entries.", [nameof(BuildingHeights)]);
}
if (BuildingAnimations.Count is < 1 or > BuildingObject.Constants.MaxAnimationsCount)
{
yield return new ValidationResult($"{nameof(BuildingAnimations)} must contain between 1 and {BuildingObject.Constants.MaxAnimationsCount} entries.", [nameof(BuildingAnimations)]);
}
if (BuildingHeights.Count != BuildingAnimations.Count)
{
yield return new ValidationResult($"{nameof(BuildingHeights)} and {nameof(BuildingAnimations)} must contain the same number of entries.", [nameof(BuildingHeights), nameof(BuildingAnimations)]);
}
}
// variations
{
if (BuildingVariations.Count is < 1 or > BuildingObject.Constants.MaxVariationsCount)
{
yield return new ValidationResult($"{nameof(BuildingVariations)} must contain between 1 and {BuildingObject.Constants.MaxVariationsCount} entries.", [nameof(BuildingVariations)]);
}
foreach (var bv in BuildingVariations)
{
foreach (var bvl in bv)
{
if (bvl >= BuildingHeights.Count)
{
yield return new ValidationResult($"A building variation layer index ({bvl}) is out of range. It must be less than the number of building heights ({BuildingHeights.Count}).", [nameof(BuildingVariations)]);
}
}
}
}
yield break;
}
}