Skip to content

Commit 1eecfb6

Browse files
committed
refactor(decorators): simplify logic in the three new decorators
Remove unneeded local variables, and let the three new decorators return `TaskStatus.Failure` if they have no child
1 parent 9cd1c99 commit 1eecfb6

File tree

3 files changed

+6
-22
lines changed

3 files changed

+6
-22
lines changed

Assets/FluidBehaviorTree/Runtime/Decorators/RepeatForever.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace CleverCrow.Fluid.BTs.Decorators {
66
public class RepeatForever : DecoratorBase {
77
protected override TaskStatus OnUpdate () {
8-
Child?.Update();
8+
Child.Update();
99
return TaskStatus.Continue;
1010
}
1111
}

Assets/FluidBehaviorTree/Runtime/Decorators/RepeatUntilFailure.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,11 @@
55
namespace CleverCrow.Fluid.BTs.Decorators {
66
public class RepeatUntilFailure : DecoratorBase {
77
protected override TaskStatus OnUpdate () {
8-
if (Child == null) {
8+
if (Child.Update() == TaskStatus.Failure) {
99
return TaskStatus.Failure;
1010
}
11-
12-
var childStatus = Child.Update();
13-
var status = childStatus;
14-
15-
if (status == TaskStatus.Failure) {
16-
return TaskStatus.Failure;
17-
}
18-
else {
19-
return TaskStatus.Continue;
20-
}
11+
12+
return TaskStatus.Continue;
2113
}
2214
}
2315
}

Assets/FluidBehaviorTree/Runtime/Decorators/RepeatUntilSuccess.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,11 @@
55
namespace CleverCrow.Fluid.BTs.Decorators {
66
public class RepeatUntilSuccess : DecoratorBase {
77
protected override TaskStatus OnUpdate () {
8-
if (Child == null) {
8+
if (Child.Update() == TaskStatus.Success) {
99
return TaskStatus.Success;
1010
}
1111

12-
var childStatus = Child.Update();
13-
var status = childStatus;
14-
15-
if (status == TaskStatus.Success) {
16-
return TaskStatus.Success;
17-
}
18-
else {
19-
return TaskStatus.Continue;
20-
}
12+
return TaskStatus.Continue;
2113
}
2214
}
2315
}

0 commit comments

Comments
 (0)