diff --git a/server/src/main/java/com/colonelpanic/n64all/server/model/ControllerProperty.java b/server/src/main/java/com/colonelpanic/n64all/server/model/ControllerProperty.java new file mode 100644 index 0000000..5c94ce3 --- /dev/null +++ b/server/src/main/java/com/colonelpanic/n64all/server/model/ControllerProperty.java @@ -0,0 +1,46 @@ +package com.colonelpanic.n64all.server.model; + +public enum ControllerProperty { + ANALOG_X(0, -80, 80), + ANALOG_Y(0, -80, 80), + A_BTN(0, 0, 1), + B_BTN(0, 0, 1), + Z_BTN(0, 0, 1), + C_UP_ARROW(0, 0, 1), + C_LEFT_ARROW(0, 0, 1), + C_RIGHT_ARROW(0, 0, 1), + C_DOWN_ARROW(0, 0, 1), + L_TRIGGER(0, 0, 1), + R_TRIGGER(0, 0, 1), + START(0, 0, 1); + + private final int defaultValue; + private final int minValue; + private final int maxValue; + + /** + * The definition of the schema for each player controller property. This defines + * defaults, as well as the allowed values. + * + * @param defaultValue the default value that this property is set to + * @param min the minimum value (inclusive) the property can be + * @param max the maximum value (inclusive) the property can be + */ + ControllerProperty(int defaultValue, int min, int max) { + this.defaultValue = defaultValue; + this.minValue = min; + this.maxValue = max; + } + + public int getDefaultValue() { + return defaultValue; + } + + public int getMinValue() { + return minValue; + } + + public int getMaxValue() { + return maxValue; + } +} diff --git a/server/src/main/java/com/colonelpanic/n64all/server/model/ControllerState.java b/server/src/main/java/com/colonelpanic/n64all/server/model/ControllerState.java new file mode 100644 index 0000000..85622f7 --- /dev/null +++ b/server/src/main/java/com/colonelpanic/n64all/server/model/ControllerState.java @@ -0,0 +1,32 @@ +package com.colonelpanic.n64all.server.model; + +import com.colonelpanic.n64all.server.service.PlayerController; +import com.google.common.collect.Maps; + +import java.util.Map; + +public class ControllerState implements PlayerController { + private Map properties; + + public ControllerState() { + this.properties = Maps.newConcurrentMap(); + + for (ControllerProperty prop : ControllerProperty.values()) { + setState(prop, prop.getDefaultValue()); + } + } + + public void setState(ControllerProperty property, int value) { + if (isValidPropertyValue(property, value)) { + properties.put(property, value); + } + } + + public int getState(ControllerProperty property) { + return properties.get(property); + } + + private boolean isValidPropertyValue(ControllerProperty prop, int value) { + return prop.getMinValue() <= value && prop.getMaxValue() >= value; + } +} diff --git a/server/src/main/java/com/colonelpanic/n64all/server/service/ControllerService.java b/server/src/main/java/com/colonelpanic/n64all/server/service/ControllerService.java index 9419a4e..36fe140 100644 --- a/server/src/main/java/com/colonelpanic/n64all/server/service/ControllerService.java +++ b/server/src/main/java/com/colonelpanic/n64all/server/service/ControllerService.java @@ -1,4 +1,8 @@ package com.colonelpanic.n64all.server.service; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class ControllerService { + private static final Logger logger = LoggerFactory.getLogger(ControllerService.class); } diff --git a/server/src/main/java/com/colonelpanic/n64all/server/service/PlayerController.java b/server/src/main/java/com/colonelpanic/n64all/server/service/PlayerController.java new file mode 100644 index 0000000..1ef33d6 --- /dev/null +++ b/server/src/main/java/com/colonelpanic/n64all/server/service/PlayerController.java @@ -0,0 +1,10 @@ +package com.colonelpanic.n64all.server.service; + +import com.colonelpanic.n64all.server.model.ControllerProperty; + +public interface PlayerController { + void setState(ControllerProperty property, int value); + + int getState(ControllerProperty property); + +}