Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
hdescottes committed Mar 23, 2024
1 parent 4062168 commit eb1f7a8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 38 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ For now, you can do a basic attack and use objects to restore your health and ma
#### Option Screen
The option screen is divided into 3 buttons : <br>
- The music settings (music is ok / sound is not implemented yet) <br>
- The control settings (which will be added later) <br>
- The control settings <br>
- A back input, so we can return to the previous screen <br>

The option screen is triggered on the "O" key.
Expand Down Expand Up @@ -75,8 +75,6 @@ graph TD;

-------
## Game idea
- [ ] possibility to custom controls / default control schema

- [ ] add sounds & sounds settings

- [x] battle feature
Expand Down
11 changes: 3 additions & 8 deletions core/src/main/java/com/gdx/game/component/InputComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,26 @@ public boolean scrolled(float amountX, float amountY) {
public static HashMap<Integer, Keys> playerControls = new HashMap<>();

public static void setPlayerControlMapFromJsonControlsMap(HashMap<String, String> jsonMap){

HashMap<Integer, Keys> newPlayerControls = new HashMap<>();

for (var entry : jsonMap.entrySet()) {
for (Map.Entry<String, String> entry : jsonMap.entrySet()) {
newPlayerControls.put(Integer.valueOf(entry.getKey()), InputComponent.Keys.valueOf(entry.getValue()));
}

playerControls = newPlayerControls;

}

public static HashMap<String, String> mapJsonControlsToPlayerControl(HashMap<Integer, Keys> playerControls){

HashMap<String, String> result = new HashMap<>();

for (var entry : playerControls.entrySet()) {
for (Map.Entry<Integer, InputComponent.Keys> entry : playerControls.entrySet()) {
result.put(entry.getKey().toString(), entry.getValue().toString());
}

return result;
}

public static HashMap<String, String> changeValueFromJsonControlsMap(HashMap<String, String> jsonMap,
Keys keyValue,
Integer keyCode){
public static HashMap<String, String> changeValueFromJsonControlsMap(HashMap<String, String> jsonMap, Keys keyValue, Integer keyCode){
jsonMap = mapInverter(jsonMap);
jsonMap.put(keyValue.name(), String.valueOf(keyCode));
jsonMap = mapInverter(jsonMap);
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/com/gdx/game/screen/GameScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public GameScreen(GdxGame gdxGame, ResourceManager resourceManager) {

//initialize controls
HashMap<String, String> controlMap;

if(playerControls.isEmpty()){
try {
controlMap = json.fromJson(HashMap.class, Gdx.files.local(PARTIAL_CONTROLS_SETTINGS_PATH));
Expand All @@ -110,7 +110,6 @@ public GameScreen(GdxGame gdxGame, ResourceManager resourceManager) {
throw new SerializationException("Not valid control map");
}
} catch (SerializationException se) {LOGGER.error(se.getMessage());

// if I can not read the file , so use the default controls binding and save it
controlMap = DEFAULT_CONTROLS;

Expand Down
32 changes: 7 additions & 25 deletions core/src/main/java/com/gdx/game/screen/OptionScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ public void clicked(InputEvent even, float x, float y) {
}

private void handleControlSettings() {

Json jsonObject = new Json();

if (playerControls.isEmpty()){
Expand All @@ -114,9 +113,7 @@ private void handleControlSettings() {
if (DEFAULT_CONTROLS.size() != playerControlsNew.size()) {
throw new SerializationException("Not valid control map");
}

} catch (SerializationException se) {

LOGGER.error(se.getMessage());

playerControlsNew = DEFAULT_CONTROLS;
Expand All @@ -127,26 +124,19 @@ private void handleControlSettings() {
playerControlsNew = mapInverter(playerControlsNew);

Label upLabel = new Label(InputComponent.Keys.UP.name(), skin);
TextField upText = new TextField(
Input.Keys.toString(Integer.parseInt(playerControlsNew.get(InputComponent.Keys.UP.name()))), skin);
TextField upText = new TextField(Input.Keys.toString(Integer.parseInt(playerControlsNew.get(InputComponent.Keys.UP.name()))), skin);
Label downLabel = new Label(InputComponent.Keys.DOWN.name(), skin);
TextField downText = new TextField(
Input.Keys.toString(Integer.parseInt(playerControlsNew.get(InputComponent.Keys.DOWN.name()))), skin);
TextField downText = new TextField(Input.Keys.toString(Integer.parseInt(playerControlsNew.get(InputComponent.Keys.DOWN.name()))), skin);
Label leftLabel = new Label(InputComponent.Keys.LEFT.name(), skin);
TextField leftText = new TextField(
Input.Keys.toString(Integer.parseInt(playerControlsNew.get(InputComponent.Keys.LEFT.name()))), skin);
TextField leftText = new TextField(Input.Keys.toString(Integer.parseInt(playerControlsNew.get(InputComponent.Keys.LEFT.name()))), skin);
Label rightLabel = new Label(InputComponent.Keys.RIGHT.name(), skin);
TextField rightText = new TextField(
Input.Keys.toString(Integer.parseInt(playerControlsNew.get(InputComponent.Keys.RIGHT.name()))), skin);
TextField rightText = new TextField(Input.Keys.toString(Integer.parseInt(playerControlsNew.get(InputComponent.Keys.RIGHT.name()))), skin);
Label interactLabel = new Label(InputComponent.Keys.INTERACT.name(), skin);
TextField interactText = new TextField(
Input.Keys.toString(Integer.parseInt(playerControlsNew.get(InputComponent.Keys.INTERACT.name()))), skin);
TextField interactText = new TextField(Input.Keys.toString(Integer.parseInt(playerControlsNew.get(InputComponent.Keys.INTERACT.name()))), skin);
Label optionLabel = new Label(InputComponent.Keys.OPTION.name(), skin);
TextField optionText = new TextField(
Input.Keys.toString(Integer.parseInt(playerControlsNew.get(InputComponent.Keys.OPTION.name()))), skin);
TextField optionText = new TextField(Input.Keys.toString(Integer.parseInt(playerControlsNew.get(InputComponent.Keys.OPTION.name()))), skin);
Label quitLabel = new Label(InputComponent.Keys.QUIT.name(), skin);
TextField quitText = new TextField(
Input.Keys.toString(Integer.parseInt(playerControlsNew.get(InputComponent.Keys.QUIT.name()))), skin);
TextField quitText = new TextField(Input.Keys.toString(Integer.parseInt(playerControlsNew.get(InputComponent.Keys.QUIT.name()))), skin);

playerControlsNew = mapInverter(playerControlsNew);

Expand All @@ -162,7 +152,6 @@ private void handleControlSettings() {

@Override
public boolean keyDown(InputEvent event, int keycode) {

playerControlsNew = changeValueFromJsonControlsMap(playerControlsNew, Keys.DOWN, keycode);

downText.setMaxLength(Input.Keys.toString(keycode).length());
Expand All @@ -176,7 +165,6 @@ public boolean keyDown(InputEvent event, int keycode) {

@Override
public boolean keyDown(InputEvent event, int keycode) {

playerControlsNew = changeValueFromJsonControlsMap(playerControlsNew, Keys.UP, keycode);

upText.setMaxLength(Input.Keys.toString(keycode).length());
Expand All @@ -190,7 +178,6 @@ public boolean keyDown(InputEvent event, int keycode) {

@Override
public boolean keyDown(InputEvent event, int keycode) {

playerControlsNew = changeValueFromJsonControlsMap(playerControlsNew, Keys.LEFT, keycode);

leftText.setMaxLength(Input.Keys.toString(keycode).length());
Expand All @@ -204,7 +191,6 @@ public boolean keyDown(InputEvent event, int keycode) {

@Override
public boolean keyDown(InputEvent event, int keycode) {

playerControlsNew = changeValueFromJsonControlsMap(playerControlsNew, Keys.RIGHT, keycode);

rightText.setMaxLength(Input.Keys.toString(keycode).length());
Expand All @@ -218,7 +204,6 @@ public boolean keyDown(InputEvent event, int keycode) {

@Override
public boolean keyDown(InputEvent event, int keycode) {

playerControlsNew = changeValueFromJsonControlsMap(playerControlsNew, Keys.INTERACT, keycode);

interactText.setMaxLength(Input.Keys.toString(keycode).length());
Expand All @@ -232,7 +217,6 @@ public boolean keyDown(InputEvent event, int keycode) {

@Override
public boolean keyDown(InputEvent event, int keycode) {

playerControlsNew = changeValueFromJsonControlsMap(playerControlsNew, Keys.OPTION, keycode);

optionText.setMaxLength(Input.Keys.toString(keycode).length());
Expand All @@ -246,7 +230,6 @@ public boolean keyDown(InputEvent event, int keycode) {

@Override
public boolean keyDown(InputEvent event, int keycode) {

playerControlsNew = changeValueFromJsonControlsMap(playerControlsNew, Keys.QUIT, keycode);

quitText.setMaxLength(Input.Keys.toString(keycode).length());
Expand Down Expand Up @@ -287,7 +270,6 @@ private void handleControlBackButton() {
backButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent even, float x, float y) {

Json json = new Json();

FileHandle commandsFile = Gdx.files.local(FULL_CONTROLS_SETTINGS_PATH);
Expand Down

0 comments on commit eb1f7a8

Please sign in to comment.