@@ -4,10 +4,14 @@ namespace BfevLibrary.Core;
44
55public class VariableDefValue
66{
7+ public bool ? Bool { get ; set ; }
8+
79 public int ? Int { get ; set ; }
810
911 public float ? Float { get ; set ; }
1012
13+ public bool [ ] ? BoolArray { get ; set ; }
14+
1115 public int [ ] ? IntArray { get ; set ; }
1216
1317 public float [ ] ? FloatArray { get ; set ; }
@@ -20,12 +24,19 @@ protected void Read(BfevReader reader, long value, ushort count, ContainerDataTy
2024 {
2125 // ReSharper disable once SwitchStatementMissingSomeEnumCasesNoDefault
2226 switch ( type ) {
27+ case ContainerDataType . Bool :
28+ Bool = ( int ) value != 0 ;
29+ break ;
2330 case ContainerDataType . Int :
2431 Int = ( int ) value ;
2532 break ;
2633 case ContainerDataType . Float :
2734 Float = ( float ) value ;
2835 break ;
36+ case ContainerDataType . BoolArray : {
37+ BoolArray = reader . ReadObjectsPtr ( new bool [ count ] , ( ) => reader . ReadInt32 ( ) != 0 , value ) ;
38+ break ;
39+ }
2940 case ContainerDataType . IntArray : {
3041 IntArray = reader . ReadObjectsPtr ( new int [ count ] , reader . ReadInt32 , value ) ;
3142 break ;
@@ -34,11 +45,18 @@ protected void Read(BfevReader reader, long value, ushort count, ContainerDataTy
3445 FloatArray = reader . ReadObjectsPtr ( new float [ count ] , reader . ReadSingle , value ) ;
3546 break ;
3647 }
48+ default :
49+ throw new NotSupportedException ( $ "Unsupported variable type: { type } ") ;
3750 }
3851 }
3952
4053 protected Action ? WriteData ( BfevWriter writer )
4154 {
55+ if ( Bool != null ) {
56+ writer . Write ( Bool . Value ? 1L : 0L ) ;
57+ return null ;
58+ }
59+
4260 if ( Int != null ) {
4361 writer . Write ( ( ulong ) Int ) ;
4462 return null ;
@@ -49,7 +67,7 @@ protected void Read(BfevReader reader, long value, ushort count, ContainerDataTy
4967 return null ;
5068 }
5169
52- if ( IntArray != null || FloatArray != null ) {
70+ if ( BoolArray != null || IntArray != null || FloatArray != null ) {
5371 return writer . ReservePtr ( ) ;
5472 }
5573
@@ -60,8 +78,10 @@ protected int GetCount(ContainerDataType type)
6078 {
6179 // ReSharper disable once SwitchExpressionHandlesSomeKnownEnumValuesWithExceptionInDefault
6280 return type switch {
81+ ContainerDataType . Bool => 1 ,
6382 ContainerDataType . Int => 1 ,
6483 ContainerDataType . Float => 1 ,
84+ ContainerDataType . BoolArray => BoolArray ! . Length ,
6585 ContainerDataType . IntArray => IntArray ! . Length ,
6686 ContainerDataType . FloatArray => FloatArray ! . Length ,
6787 _ => throw new NotSupportedException ( $ "Unsupported variable type: { type } ")
@@ -70,6 +90,10 @@ protected int GetCount(ContainerDataType type)
7090
7191 public ContainerDataType GetDataType ( )
7292 {
93+ if ( Bool != null ) {
94+ return ContainerDataType . Bool ;
95+ }
96+
7397 if ( Int != null ) {
7498 return ContainerDataType . Int ;
7599 }
@@ -78,6 +102,10 @@ public ContainerDataType GetDataType()
78102 return ContainerDataType . Float ;
79103 }
80104
105+ if ( BoolArray != null ) {
106+ return ContainerDataType . BoolArray ;
107+ }
108+
81109 if ( IntArray != null ) {
82110 return ContainerDataType . IntArray ;
83111 }
0 commit comments