// we'll use this enum
enum Layers {
TELEOP,
ENDGAME
}
// WARNING: once you add a gamepad to a layering system, it will cease to function normally
// when a gamepad is put into a layering system, it is modified to go to being 'at-rest' when its not the active layer for the system
// 'at-rest' gamepads have 0 for all axis, and false for all buttons
// If you want to get more advanced, you can use a layering system to control the layers of your gamepad
// gamepads on inactive layers will immediately go to an 'at-rest' state, layering systems achieve this by modifying all gamepads given to it
SDKGamepad teleopGamepad = new SDKGamepad(gamepad1);
// WARNING: if your layering system is not very stable, you will need to be careful, as a layered gamepad will crash if it can't find a gamepad for the current layer
SDKGamepad endgameGamepad = new SDKGamepad(gamepad1);
// there are lots of generics here, this just allows us to use this system with a whole bunch of different systems, like Mercurial
Map<Layers, PasteurizedGamepad<EnhancedDoubleSupplier, EnhancedBooleanSupplier>> pasteurizedGamepadMap = new HashMap<Layers, PasteurizedGamepad<EnhancedDoubleSupplier, EnhancedBooleanSupplier>>(){{
put(Layers.TELEOP, teleopGamepad);
put(Layers.ENDGAME, endgameGamepad);
}};
MapLayeringSystem<Layers, EnhancedDoubleSupplier, EnhancedBooleanSupplier, PasteurizedGamepad<EnhancedDoubleSupplier, EnhancedBooleanSupplier>> enumLayeringSystem = new MapLayeringSystem<>(Layers.TELEOP, pasteurizedGamepadMap);
// LayeredGamepad takes a LayeringSystem and makes a gamepad from it
LayeredGamepad<EnhancedDoubleSupplier, EnhancedBooleanSupplier, PasteurizedGamepad<EnhancedDoubleSupplier, EnhancedBooleanSupplier>> layeredGamepad = new LayeredGamepad<>(enumLayeringSystem);
layeredGamepad.a(); // a from teleopGamepad
enumLayeringSystem.setLayer(Layers.ENDGAME);
layeredGamepad.a(); // a from endgameGamepad
// there are many more options for a layering system, and its fairly easy to implement your own!
// additionally, you can nest layered gamepads in other layered gamepads
// linking across layers using or
teleopGamepad.b(teleopGamepad.b().or(endgameGamepad.b()));
endgameGamepad.b(teleopGamepad.b());
// now b on both layers is linked!
// returns true if this gamepad is active on this layering system
enumLayeringSystem.isActive(teleopGamepad);
enumLayeringSystem.getLayer(); // current layer
enumLayeringSystem.getGamepad(); // current gamepad
//
// Other Layering Systems
//
// the map layering system can be used for any hashable type, but is probably best for enums
Map<String, PasteurizedGamepad<EnhancedDoubleSupplier, EnhancedBooleanSupplier>> pasteurizedGamepadMap2 = new HashMap<>();
pasteurizedGamepadMap2.put("one", teleopGamepad);
pasteurizedGamepadMap2.put("two", endgameGamepad);
MapLayeringSystem<String, EnhancedDoubleSupplier, EnhancedBooleanSupplier, PasteurizedGamepad<EnhancedDoubleSupplier, EnhancedBooleanSupplier>> stringLayeringSystem = new MapLayeringSystem<>("one", pasteurizedGamepadMap2);
// list layering system can move linearly
ListLayeringSystem<EnhancedDoubleSupplier, EnhancedBooleanSupplier, PasteurizedGamepad<EnhancedDoubleSupplier, EnhancedBooleanSupplier>> listLayeringSystem = new ListLayeringSystem<>(teleopGamepad, endgameGamepad);
// next in the list
listLayeringSystem.next();
// previous in the list
listLayeringSystem.previous();
// you can't go out of bounds
// wrapping layering system is similar, but when you reach the end of the bounds, it wraps back to the start
WrappingLayeringSystem<EnhancedDoubleSupplier, EnhancedBooleanSupplier, PasteurizedGamepad<EnhancedDoubleSupplier, EnhancedBooleanSupplier>> wrappingLayeringSystem = new WrappingLayeringSystem<>(teleopGamepad, endgameGamepad);
// next in the list
wrappingLayeringSystem.next();
// we've reached the end, so back to the start
wrappingLayeringSystem.next();
// we've reached the start of the list, so back to the end
wrappingLayeringSystem.previous();