Skip to content

Commit 51eb0c3

Browse files
committed
feat: update IAttributeValues interface to enforce value validation and modify AttributeType constructor for consistency
1 parent d7adbc9 commit 51eb0c3

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed
+14-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System;
2+
13
namespace DiceRolling.Interfaces.Attribute;
24

35
/// <summary>
@@ -7,10 +9,20 @@ public interface IAttributeValues {
79
/// <summary>
810
/// Valor mínimo do atributo.
911
/// </summary>
10-
int MinValue { get; set; }
12+
int MinValue { get; }
1113

1214
/// <summary>
1315
/// Valor máximo do atributo.
1416
/// </summary>
15-
int MaxValue { get; set; }
17+
int MaxValue { get; }
18+
19+
/// <summary>
20+
/// Valida se os valores mínimo e máximo são consistentes.
21+
/// </summary>
22+
/// <returns>true se MinValue é menor que MaxValue</returns>
23+
void ValidateValues() {
24+
if (MinValue >= MaxValue) {
25+
throw new ArgumentException("MinValue must be less than MaxValue");
26+
}
27+
}
1628
}

src/models/Attribute/AttributeType.cs

+15-3
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,27 @@ public Texture2D? Icon {
2323
}
2424
}
2525
public string? IconPath { get; private set; }
26-
[Export] public int MinValue { get; set; }
27-
[Export] public int MaxValue { get; set; }
26+
[Export] public int MinValue { get; private set; }
27+
[Export] public int MaxValue { get; private set; }
2828

2929
public AttributeType() { }
3030

31-
public AttributeType(string name, string description, Color color, Texture2D icon) {
31+
public AttributeType(string name, string description, Color color, Texture2D icon, int minValue, int maxValue) {
32+
if (minValue >= maxValue) {
33+
throw new ArgumentException("MinValue must be less than MaxValue");
34+
}
35+
3236
Name = name;
3337
Description = description;
3438
Color = color;
3539
Icon = icon;
40+
MinValue = minValue;
41+
MaxValue = maxValue;
42+
}
43+
44+
public void ValidateValues() {
45+
if (MinValue >= MaxValue) {
46+
throw new ArgumentException("MinValue must be less than MaxValue");
47+
}
3648
}
3749
}

0 commit comments

Comments
 (0)