Skip to content

Commit

Permalink
BMControllerInputProcessor : set unique name when detecting same devices
Browse files Browse the repository at this point in the history
  • Loading branch information
exch-bms2 committed Nov 25, 2017
1 parent 37fbd3d commit 2d64ddd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
10 changes: 5 additions & 5 deletions src/bms/player/beatoraja/config/KeyConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ public void render() {
if (controllers.length > 0) {
int index = 0;
for (; index < controllers.length; index++) {
if (controllers[index].getController().getName().equals(pc.getController()[0].getName())) {
if (controllers[index].getName().equals(pc.getController()[0].getName())) {
break;
}
}
pc.getController()[0]
.setName(controllers[(index + 1) % controllers.length].getController().getName());
.setName(controllers[(index + 1) % controllers.length].getName());
pc.setController(pc.getController());
}
}
Expand All @@ -198,12 +198,12 @@ public void render() {
if (controllers.length > 0 && pc.getController().length > 1) {
int index = 0;
for (; index < controllers.length; index++) {
if (controllers[index].getController().getName().equals(pc.getController()[1].getName())) {
if (controllers[index].getName().equals(pc.getController()[1].getName())) {
break;
}
}
pc.getController()[1]
.setName(controllers[(index + 1) % controllers.length].getController().getName());
.setName(controllers[(index + 1) % controllers.length].getName());
pc.setController(pc.getController());
}
}
Expand Down Expand Up @@ -367,7 +367,7 @@ private int getControllerKeyAssign(int device, int index) {
private void setControllerKeyAssign(int index, BMControllerInputProcessor bmc) {
int cindex = -1;
for (int i = 0; i < controllerConfigs.length; i++) {
if (bmc.getController().getName().equals(controllerConfigs[i].getName())) {
if (bmc.getName().equals(controllerConfigs[i].getName())) {
cindex = i;
break;
}
Expand Down
15 changes: 9 additions & 6 deletions src/bms/player/beatoraja/input/BMControllerInputProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.Arrays;
import java.util.logging.Logger;

import bms.player.beatoraja.Config;
import bms.player.beatoraja.PlayConfig.ControllerConfig;
import com.badlogic.gdx.controllers.Controller;
import com.badlogic.gdx.controllers.ControllerListener;
Expand All @@ -20,8 +19,11 @@ public class BMControllerInputProcessor extends BMSPlayerInputDevice implements

private final BMSPlayerInputProcessor bmsPlayerInputProcessor;

private Controller controller;

private final Controller controller;
/**
* デバイス名称
*/
private final String name;
/**
* ボタンキーアサイン
*/
Expand All @@ -43,10 +45,11 @@ public class BMControllerInputProcessor extends BMSPlayerInputDevice implements
private boolean jkoc;
private boolean analogScratch;

public BMControllerInputProcessor(BMSPlayerInputProcessor bmsPlayerInputProcessor, Controller controller,
public BMControllerInputProcessor(BMSPlayerInputProcessor bmsPlayerInputProcessor, String name, Controller controller,
ControllerConfig controllerConfig) {
super(Type.BM_CONTROLLER);
this.bmsPlayerInputProcessor = bmsPlayerInputProcessor;
this.name = name;
this.controller = controller;
this.setConfig(controllerConfig);
}
Expand All @@ -59,8 +62,8 @@ public void setConfig(ControllerConfig controllerConfig) {
this.analogScratch = controllerConfig.isAnalogScratch();
}

public Controller getController() {
return controller;
public String getName() {
return name;
}

public boolean accelerometerMoved(Controller arg0, int arg1, Vector3 arg2) {
Expand Down
17 changes: 13 additions & 4 deletions src/bms/player/beatoraja/input/BMSPlayerInputProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,16 @@ public BMSPlayerInputProcessor(Config config, PlayerConfig player) {
}
}).findFirst()
.orElse(new ControllerConfig());
BMControllerInputProcessor bm = new BMControllerInputProcessor(this, controller, controllerConfig);
// デバイス名のユニーク化
int index = 1;
String name = controller.getName();
for(BMControllerInputProcessor bm : bminput) {
if(bm.getName().equals(name)) {
index++;
name = controller.getName() + "-" + index;
}
}
BMControllerInputProcessor bm = new BMControllerInputProcessor(this, name, controller, controllerConfig);
// controller.addListener(bm);
bminput.add(bm);
}
Expand Down Expand Up @@ -140,9 +149,9 @@ public void setControllerConfig(ControllerConfig[] configs) {
continue;
}
if(configs[i].getName() == null || configs[i].getName().length() == 0) {
configs[i].setName(controller.getController().getName());
configs[i].setName(controller.getName());
}
if(controller.getController().getName().equals(configs[i].getName())) {
if(controller.getName().equals(configs[i].getName())) {
controller.setConfig(configs[i]);
b[i] = true;
break;
Expand Down Expand Up @@ -229,7 +238,7 @@ public void setPlayConfig(PlayConfig playconfig) {
kbinput.setConfig(playconfig.getKeyboardConfig());
for(int i = 0;i < bminput.length;i++) {
for(ControllerConfig controller : playconfig.getController()) {
if(bminput[i].getController().getName().equals(controller.getName())) {
if(bminput[i].getName().equals(controller.getName())) {
bminput[i].setConfig(controller);
break;
}
Expand Down

0 comments on commit 2d64ddd

Please sign in to comment.