Skip to content

Commit

Permalink
#18: create basic models that are necessary for this to work
Browse files Browse the repository at this point in the history
  • Loading branch information
OhmGeek committed Oct 19, 2019
1 parent c9f38ea commit fbd7214
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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<ControllerProperty, Integer> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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);

}

0 comments on commit fbd7214

Please sign in to comment.