1
0
forked from Clones/Controlify

gyro & look input modifier & deadzone bug

This commit is contained in:
isXander
2023-04-11 11:04:47 +01:00
parent d3fc0a946b
commit beece493c3
13 changed files with 416 additions and 104 deletions

View File

@ -11,7 +11,6 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -32,6 +31,7 @@ public class ControlifyConfig {
private Map<String, CompoundJoystickInfo> compoundJoysticks = Map.of();
private GlobalSettings globalSettings = new GlobalSettings();
private boolean firstLaunch;
private boolean dirty;
public ControlifyConfig(Controlify controlify) {
@ -101,14 +101,19 @@ public class ControlifyConfig {
private void applyConfig(JsonObject object) {
globalSettings = GSON.fromJson(object.getAsJsonObject("global"), GlobalSettings.class);
if (globalSettings == null) globalSettings = new GlobalSettings();
if (globalSettings == null) {
globalSettings = new GlobalSettings();
setDirty();
}
JsonObject controllers = object.getAsJsonObject("controllers");
if (controllers != null) {
this.controllerData = controllers;
for (var controller : Controller.CONTROLLERS.values()) {
_loadOrCreateControllerData(controller);
loadOrCreateControllerData(controller);
}
} else {
setDirty();
}
this.compoundJoysticks = object
@ -122,25 +127,18 @@ public class ControlifyConfig {
currentControllerUid = object.get("current_controller").getAsString();
} else {
currentControllerUid = controlify.currentController().uid();
setDirty();
}
}
public boolean loadOrCreateControllerData(Controller<?, ?> controller) {
boolean result = _loadOrCreateControllerData(controller);
saveIfDirty();
return result;
}
private boolean _loadOrCreateControllerData(Controller<?, ?> controller) {
public void loadOrCreateControllerData(Controller<?, ?> controller) {
var uid = controller.uid();
if (controllerData.has(uid)) {
Controlify.LOGGER.info("Loading controller data for " + uid);
applyControllerConfig(controller, controllerData.getAsJsonObject(uid));
return true;
} else {
Controlify.LOGGER.info("New controller found, creating controller data for " + uid);
save();
return false;
setDirty();
}
}
@ -155,17 +153,17 @@ public class ControlifyConfig {
}
}
private void saveIfDirty() {
public void setDirty() {
dirty = true;
}
public void saveIfDirty() {
if (dirty) {
Controlify.LOGGER.info("Config is dirty. Saving...");
save();
}
}
public Optional<JsonObject> getLoadedControllerConfig(String uid) {
return Optional.ofNullable(controllerData.getAsJsonObject(uid));
}
public Map<String, CompoundJoystickInfo> getCompoundJoysticks() {
return compoundJoysticks;
}