1
1
package cardillan .mlogassertions .logic ;
2
2
3
3
import mindustry .logic .LExecutor ;
4
- import mindustry .logic .LVar ;
4
+ import mindustry .logic .LExecutor . Var ;
5
5
6
6
public class AssertsLInstructions {
7
7
8
8
public static class AssertI implements LExecutor .LInstruction {
9
- public TypeAssertion type ;
10
- public LVar min ;
11
- public AssertOp opMin ;
12
- public LVar value ;
13
- public AssertOp opMax ;
14
- public LVar max ;
15
- public LVar message ;
16
-
17
- public AssertI (TypeAssertion type , LVar min , AssertOp opMin , LVar value , AssertOp opMax , LVar max , LVar message ) {
9
+ public TypeAssertion type = TypeAssertion . any ;
10
+ public int min ;
11
+ public AssertOp opMin = AssertOp . lessThanEq ;
12
+ public int value ;
13
+ public AssertOp opMax = AssertOp . lessThanEq ;
14
+ public int max ;
15
+ public int message ;
16
+
17
+ public AssertI (TypeAssertion type , int min , AssertOp opMin , int value , AssertOp opMax , int max , int message ) {
18
18
this .type = type ;
19
19
this .min = min ;
20
20
this .opMin = opMin ;
@@ -24,18 +24,32 @@ public AssertI(TypeAssertion type, LVar min, AssertOp opMin, LVar value, AssertO
24
24
this .message = message ;
25
25
}
26
26
27
+ public AssertI () {
28
+ }
29
+
27
30
@ Override
28
31
public final void run (LExecutor exec ) {
29
- boolean typeAssert = value .isobj ? type .objFunction .get (value .objval ) : type .function .get (value .numval );
30
- boolean minAssert = opMin .function .get (min .num (), value .num ());
31
- boolean maxAssert = opMax .function .get (value .num (), max .num ());
32
+ Var vaVal = var (exec , value );
33
+ boolean typeAssert = vaVal .isobj ? type .objFunction .get (vaVal .objval ) : type .function .get (vaVal .numval );
34
+ boolean minAssert = opMin .function .get (num (exec ,min ), num (exec ,value ));
35
+ boolean maxAssert = opMax .function .get (num (exec ,value ), num (exec ,max ));
32
36
33
37
if (!typeAssert || !minAssert || !maxAssert ) {
34
38
//skip back to self.
35
39
// TODO enter broken assertion state
36
40
exec .counter .numval --;
37
- exec .yield = true ;
41
+ // exec.yield = true;
38
42
}
39
43
}
44
+
45
+ // For easier switching between v7 and v8 logic
46
+
47
+ private Var var (LExecutor exec , int var ) {
48
+ return exec .var (value );
49
+ }
50
+
51
+ private double num (LExecutor exec , int var ) {
52
+ return exec .num (var );
53
+ }
40
54
}
41
55
}
0 commit comments