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
|
package coffee.liz.dyl.config;
import com.badlogic.gdx.Input;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;
@AllArgsConstructor
@RequiredArgsConstructor
@Getter
public class KeyBinds {
private Set<Integer> moveLeftKeys = Set.of(Input.Keys.H, Input.Keys.LEFT, Input.Keys.A);
private Set<Integer> moveRightKeys = Set.of(Input.Keys.L, Input.Keys.RIGHT, Input.Keys.D);
private Set<Integer> jumpKeys = Set.of(Input.Keys.K, Input.Keys.W, Input.Keys.UP, Input.Keys.SPACE);
public Set<Action> filterActiveActions(final Predicate<Integer> isDown) {
final Set<Action> actions = new HashSet<>();
Map.of(moveLeftKeys, Action.MOVE_LEFT, moveRightKeys, Action.MOVE_RIGHT, jumpKeys, Action.JUMP)
.forEach((keys, action) -> {
if (keys.stream().anyMatch(isDown)) {
actions.add(action);
}
});
return actions;
}
public enum Action {
MOVE_LEFT, MOVE_RIGHT, JUMP;
}
}
|