mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-04-11 02:16:07 +00:00
fixed invert and trigger settings not being saved
This commit is contained in:
@@ -19,8 +19,6 @@ public enum ControllerComponent implements Serializable {
|
||||
private JCheckBox invertBox;
|
||||
private JCheckBox triggerBox;
|
||||
private boolean analog;
|
||||
private boolean invert;
|
||||
private boolean trigger;
|
||||
|
||||
private ControllerComponent(String name, boolean analog) {
|
||||
this.label = new JLabel(name);
|
||||
@@ -32,8 +30,6 @@ public enum ControllerComponent implements Serializable {
|
||||
this.triggerBox.setName(this.name());
|
||||
this.triggerBox.setToolTipText("If this component should act as a trigger.");
|
||||
this.analog = analog;
|
||||
this.invert = false;
|
||||
this.trigger = false;
|
||||
}
|
||||
|
||||
public JLabel getLabel() {
|
||||
@@ -56,19 +52,7 @@ public enum ControllerComponent implements Serializable {
|
||||
return analog;
|
||||
}
|
||||
|
||||
public boolean isTrigger() {
|
||||
return trigger;
|
||||
}
|
||||
|
||||
public void trigger(boolean isTrigger) {
|
||||
trigger = isTrigger;
|
||||
}
|
||||
|
||||
public void invert(boolean invert) {
|
||||
this.invert = invert;
|
||||
}
|
||||
|
||||
public boolean invert() {
|
||||
return invert;
|
||||
public boolean sameAs(ControllerComponent other) {
|
||||
return this.name().equals(other.name());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.limelight.input;
|
||||
|
||||
import com.limelight.input.GamepadMapping.Mapping;
|
||||
import com.limelight.nvstream.NvConnection;
|
||||
import com.limelight.nvstream.input.ControllerPacket;
|
||||
|
||||
@@ -104,22 +105,22 @@ public class Gamepad {
|
||||
}
|
||||
|
||||
private void handleComponent(Component comp, float value) {
|
||||
ControllerComponent contComp = config.getControllerComponent(comp);
|
||||
if (contComp != null) {
|
||||
if (contComp.isAnalog()) {
|
||||
handleAnalog(contComp, sanitizeValue(contComp, value));
|
||||
Mapping mapping = config.getMapping(comp);
|
||||
if (mapping != null) {
|
||||
if (mapping.contComp.isAnalog()) {
|
||||
handleAnalog(mapping.contComp, sanitizeValue(mapping, value));
|
||||
} else {
|
||||
handleButtons(contComp, sanitizeValue(contComp, value));
|
||||
handleButtons(mapping.contComp, sanitizeValue(mapping, value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private float sanitizeValue(ControllerComponent contComp, float value) {
|
||||
private float sanitizeValue(Mapping mapping, float value) {
|
||||
float sanitized = value;
|
||||
if (contComp.invert()) {
|
||||
if (mapping.invert) {
|
||||
sanitized = -sanitized;
|
||||
}
|
||||
if (contComp.isTrigger()) {
|
||||
if (mapping.trigger) {
|
||||
sanitized = (sanitized + 1)/2;
|
||||
}
|
||||
return sanitized;
|
||||
|
||||
@@ -9,17 +9,17 @@ import net.java.games.input.Component;
|
||||
public class GamepadMapping implements Serializable {
|
||||
private static final long serialVersionUID = -185035113915743149L;
|
||||
|
||||
private HashMap<String, ControllerComponent> mapping;
|
||||
|
||||
private HashMap<String, Mapping> mapping;
|
||||
|
||||
public GamepadMapping() {
|
||||
mapping = new HashMap<String, ControllerComponent>();
|
||||
mapping = new HashMap<String, Mapping>();
|
||||
}
|
||||
|
||||
public void insertMapping(ControllerComponent contComp, Component comp) {
|
||||
mapping.put(comp.getIdentifier().getName(), contComp);
|
||||
public void insertMapping(Mapping toMap, Component comp) {
|
||||
mapping.put(comp.getIdentifier().getName(), toMap);
|
||||
}
|
||||
|
||||
public ControllerComponent getControllerComponent(Component comp) {
|
||||
public Mapping getMapping(Component comp) {
|
||||
return mapping.get(comp.getIdentifier().getName());
|
||||
}
|
||||
|
||||
@@ -27,6 +27,21 @@ public class GamepadMapping implements Serializable {
|
||||
mapping.remove(comp.getIdentifier().getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the mapped ControllerComponent for the specified ControllerComponent.</br>
|
||||
* NOTE: Use sparingly takes O(N) time.
|
||||
* @param contComp the component to get a mapping for
|
||||
* @return a mapping or an null if there is none
|
||||
*/
|
||||
public Mapping getMappedComponent(ControllerComponent contComp) {
|
||||
for (Entry<String, Mapping> entry : mapping.entrySet()) {
|
||||
if (entry.getValue().contComp.sameAs(contComp)) {
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the mapping for the specified component.</br>
|
||||
* NOTE: Use sparingly takes O(N) time.
|
||||
@@ -34,11 +49,25 @@ public class GamepadMapping implements Serializable {
|
||||
* @return a mapping or an empty string if there is none
|
||||
*/
|
||||
public String getMapping(ControllerComponent contComp) {
|
||||
for (Entry<String, ControllerComponent> entry : mapping.entrySet()) {
|
||||
if (entry.getValue().equals(contComp)) {
|
||||
for (Entry<String, Mapping> entry : mapping.entrySet()) {
|
||||
if (entry.getValue().contComp.sameAs(contComp)) {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public class Mapping implements Serializable {
|
||||
private static final long serialVersionUID = -8407172977953214242L;
|
||||
|
||||
public ControllerComponent contComp;
|
||||
public boolean invert;
|
||||
public boolean trigger;
|
||||
|
||||
public Mapping(ControllerComponent contComp, boolean invert, boolean trigger) {
|
||||
this.contComp = contComp;
|
||||
this.invert = invert;
|
||||
this.trigger = trigger;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user