1
0
forked from Clones/Controlify

✏️ New ControllerManager class to store controllers

This commit is contained in:
isXander
2023-05-11 16:32:39 +01:00
parent fa1e1293c7
commit 0e8bf0cc9b
9 changed files with 135 additions and 105 deletions

View File

@ -1,5 +1,6 @@
package dev.isxander.controlify.controller.joystick;
import dev.isxander.controlify.ControllerManager;
import dev.isxander.controlify.controller.Controller;
import dev.isxander.controlify.controller.ControllerType;
@ -13,7 +14,7 @@ public record CompoundJoystickInfo(Collection<String> joystickUids, String frien
}
public boolean canBeUsed() {
List<Controller<?, ?>> joysticks = Controller.CONTROLLERS.values().stream().filter(c -> joystickUids.contains(c.uid())).toList();
List<Controller<?, ?>> joysticks = ControllerManager.getConnectedControllers().stream().filter(c -> joystickUids.contains(c.uid())).toList();
if (joysticks.size() != joystickUids().size()) {
return false; // not all controllers are connected
}
@ -25,13 +26,13 @@ public record CompoundJoystickInfo(Collection<String> joystickUids, String frien
}
public boolean isLoaded() {
return Controller.CONTROLLERS.containsKey(createUID(joystickUids));
return ControllerManager.isControllerConnected(createUID(joystickUids));
}
public Optional<CompoundJoystickController> attemptCreate() {
if (!canBeUsed()) return Optional.empty();
List<Integer> joystickIDs = Controller.CONTROLLERS.values().stream()
List<Integer> joystickIDs = ControllerManager.getConnectedControllers().stream()
.filter(c -> joystickUids.contains(c.uid()))
.map(Controller::joystickId)
.toList();