|
3 | 3 | import com.google.common.io.ByteStreams; |
4 | 4 | import com.mrcrayfish.controllable.Constants; |
5 | 5 | import com.mrcrayfish.controllable.client.input.ControllerManager; |
| 6 | +import com.mrcrayfish.controllable_sdl.jna.SdlNativeLibraryLoader; |
| 7 | +import com.mrcrayfish.framework.platform.Services; |
6 | 8 | import com.sun.jna.Memory; |
7 | 9 | import com.mrcrayfish.controllable_sdl.api.joystick.SDL_JoystickID; |
8 | 10 | import com.mrcrayfish.controllable_sdl.api.rwops.SDL_RWops; |
|
11 | 13 | import org.jetbrains.annotations.Nullable; |
12 | 14 | import java.io.IOException; |
13 | 15 | import java.io.InputStream; |
| 16 | +import java.nio.file.Files; |
| 17 | +import java.nio.file.Path; |
14 | 18 | import java.util.HashMap; |
15 | 19 | import java.util.Map; |
16 | 20 |
|
|
28 | 32 | */ |
29 | 33 | public class SDL2ControllerManager extends ControllerManager |
30 | 34 | { |
| 35 | + static |
| 36 | + { |
| 37 | + try |
| 38 | + { |
| 39 | + Path natives = Services.CONFIG.getGamePath().resolve("controllable_natives"); |
| 40 | + Path sdl = natives.resolve("SDL"); |
| 41 | + Files.createDirectories(sdl); |
| 42 | + SdlNativeLibraryLoader.setExtractionPath(sdl); |
| 43 | + |
| 44 | + // Add a readme to the natives directory for users |
| 45 | + Path readMeFile = natives.resolve("README.txt"); |
| 46 | + if(!Files.exists(readMeFile)) |
| 47 | + { |
| 48 | + Files.writeString(readMeFile, """ |
| 49 | + This directory holds the natives for Controllable, which are used to interface |
| 50 | + with game controllers and read their inputs. It is safe to delete, just make sure |
| 51 | + the game is closed as the natives may be loaded; preventing you from deleting them. |
| 52 | + If you are developing a modpack, make sure to exclude this directory."""); |
| 53 | + } |
| 54 | + } |
| 55 | + catch(IOException e) |
| 56 | + { |
| 57 | + throw new RuntimeException(e); |
| 58 | + } |
| 59 | + } |
| 60 | + |
31 | 61 | @Override |
32 | 62 | public void init() |
33 | 63 | { |
|
0 commit comments