-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#18: create basic models that are necessary for this to work
- Loading branch information
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
server/src/main/java/com/colonelpanic/n64all/server/model/ControllerProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
server/src/main/java/com/colonelpanic/n64all/server/model/ControllerState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
server/src/main/java/com/colonelpanic/n64all/server/service/ControllerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
10 changes: 10 additions & 0 deletions
10
server/src/main/java/com/colonelpanic/n64all/server/service/PlayerController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |