Skip to content

Commit 1b51afe

Browse files
committed
Fix threads persisting through stages
Add help flag Update config handling Fixes #13
1 parent a26ac7b commit 1b51afe

19 files changed

+357
-293
lines changed

core/src/com/rolandoislas/drcsimclient/Client.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ public Client(Control[] controls, Audio audio) {
3232
this(controls, audio, new ArgumentParser());
3333
}
3434

35-
@Override
35+
public static Stage getStage() {
36+
return stage;
37+
}
38+
39+
@Override
3640
public void create () {
3741
sockets = new Sockets();
3842
stage = new Stage();
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,127 @@
11
package com.rolandoislas.drcsimclient.config;
22

3+
import com.badlogic.gdx.Preferences;
4+
import com.rolandoislas.drcsimclient.util.PreferencesUtil;
5+
6+
import java.util.Map;
7+
38
/**
49
* Created by Rolando on 2/7/2017.
510
*/
6-
public class Config {
7-
public static final String BUTTON_A = "BUTTON_A";
8-
public static final String BUTTON_B = "BUTTON_B";
9-
public static final String BUTTON_X = "BUTTON_X";
10-
public static final String BUTTON_Y = "BUTTON_Y";
11-
public static final String BUTTON_UP = "BUTTON_UP";
12-
public static final String BUTTON_DOWN = "BUTTON_DOWN";
13-
public static final String BUTTON_LEFT = "BUTTON_LEFT";
14-
public static final String BUTTON_RIGHT = "BUTTON_RIGHT";
15-
public static final String BUTTON_L = "BUTTON_L";
16-
public static final String BUTTON_R = "BUTTON_R";
17-
public static final String BUTTON_ZL = "BUTTON_ZL";
18-
public static final String BUTTON_ZR = "BUTTON_ZR";
19-
public static final String BUTTON_L3 = "BUTTON_L3";
20-
public static final String BUTTON_R3 = "BUTTON_R3";
21-
public static final String BUTTON_MINUS = "BUTTON_MINUS";
22-
public static final String BUTTON_PLUS = "BUTTON_PLUS";
23-
public static final String BUTTON_HOME = "BUTTON_HOME";
24-
public static final String JOYSTICK_LEFT_X = "JOYSTICK_LEFT_X";
25-
public static final String JOYSTICK_LEFT_Y = "JOYSTICK_LEFT_Y";
26-
public static final String JOYSTICK_RIGHT_X = "JOYSTICK_RIGHT_X";
27-
public static final String JOYSTICK_RIGHT_Y = "JOYSTICK_RIGHT_Y";
28-
public static final String MIC_BLOW = "MIC_BLOW";
29-
public int buttonA;
30-
public int buttonB;
31-
public int buttonX;
32-
public int buttonY;
33-
public int buttonUp;
34-
public int buttonDown;
35-
public int buttonLeft;
36-
public int buttonRight;
37-
public int buttonL;
38-
public int buttonR;
39-
public int buttonZL;
40-
public int buttonZR;
41-
public int buttonL3;
42-
public int buttonR3;
43-
public int buttonMinus;
44-
public int buttonPlus;
45-
public int buttonHome;
46-
public int micBlow;
47-
48-
public void set(String item, int input) {}
49-
50-
public void load() {}
51-
52-
public String get(String key) {
53-
return "";
11+
public class Config implements Preferences {
12+
private final Preferences config;
13+
14+
public Config(String configName) {
15+
config = PreferencesUtil.get(configName);
16+
}
17+
18+
public void load() {
19+
throw new RuntimeException("Not implemented");
20+
}
21+
22+
// Config wrapper
23+
@Override
24+
public Preferences putBoolean(String key, boolean val) {
25+
return config.putBoolean(key, val);
26+
}
27+
28+
@Override
29+
public Preferences putInteger(String key, int val) {
30+
return config.putInteger(key, val);
31+
}
32+
33+
@Override
34+
public Preferences putLong(String key, long val) {
35+
return config.putLong(key, val);
36+
}
37+
38+
@Override
39+
public Preferences putFloat(String key, float val) {
40+
return config.putFloat(key, val);
41+
}
42+
43+
@Override
44+
public Preferences putString(String key, String val) {
45+
return config.putString(key, val);
46+
}
47+
48+
@Override
49+
public Preferences put(Map<String, ?> vals) {
50+
return config.put(vals);
51+
}
52+
53+
@Override
54+
public boolean getBoolean(String key) {
55+
return config.getBoolean(key);
56+
}
57+
58+
@Override
59+
public int getInteger(String key) {
60+
return config.getInteger(key);
61+
}
62+
63+
@Override
64+
public long getLong(String key) {
65+
return config.getLong(key);
66+
}
67+
68+
@Override
69+
public float getFloat(String key) {
70+
return config.getFloat(key);
71+
}
72+
73+
@Override
74+
public String getString(String key) {
75+
return config.getString(key);
76+
}
77+
78+
@Override
79+
public boolean getBoolean(String key, boolean defValue) {
80+
return config.getBoolean(key, defValue);
81+
}
82+
83+
@Override
84+
public int getInteger(String key, int defValue) {
85+
return config.getInteger(key, defValue);
86+
}
87+
88+
@Override
89+
public long getLong(String key, long defValue) {
90+
return config.getLong(key, defValue);
91+
}
92+
93+
@Override
94+
public float getFloat(String key, float defValue) {
95+
return config.getFloat(key, defValue);
96+
}
97+
98+
@Override
99+
public String getString(String key, String defValue) {
100+
return config.getString(key, defValue);
101+
}
102+
103+
@Override
104+
public Map<String, ?> get() {
105+
return config.get();
106+
}
107+
108+
@Override
109+
public boolean contains(String key) {
110+
return config.contains(key);
111+
}
112+
113+
@Override
114+
public void clear() {
115+
config.clear();
116+
}
117+
118+
@Override
119+
public void remove(String key) {
120+
config.remove(key);
121+
}
122+
123+
@Override
124+
public void flush() {
125+
config.flush();
54126
}
55127
}
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,45 @@
11
package com.rolandoislas.drcsimclient.config;
22

3-
import com.badlogic.gdx.controllers.Controller;
4-
import com.badlogic.gdx.controllers.Controllers;
5-
import com.badlogic.gdx.utils.Array;
6-
7-
import java.util.HashMap;
8-
93
/**
104
* Created by Rolando on 2/6/2017.
115
*/
12-
public class ConfigController {
13-
private HashMap<String, ConfigControllerConfig> configs = new HashMap<String, ConfigControllerConfig>();
6+
public class ConfigController extends ConfigKeymap {
7+
public ConfigController(String controllerName) {
8+
super(cleanName(controllerName));
9+
}
1410

15-
private void loadAll() {
16-
Array<Controller> controllers = Controllers.getControllers();
17-
for (int controllerN = 0; controllerN < controllers.size; controllerN++) {
18-
Controller controller = controllers.get(controllerN);
19-
ConfigControllerConfig config = configs.get(controller.getName());
20-
if (config == null) {
21-
config = new ConfigControllerConfig(controller.getName());
22-
config.load();
23-
configs.put(controller.getName(), config);
24-
}
25-
}
11+
private static String cleanName(String controllerName) {
12+
controllerName = controllerName
13+
.replaceAll(" ", "_")
14+
.replaceAll("\\.", "")
15+
.replaceAll("-", "_")
16+
.toLowerCase();
17+
return "controller." + controllerName;
2618
}
2719

28-
public ConfigControllerConfig get(String name) {
29-
ConfigControllerConfig config = configs.get(name);
30-
if (config == null)
31-
loadAll();
32-
return configs.get(name);
20+
public void load() {
21+
buttonA = getInteger(BUTTON_A, -1);
22+
buttonB = getInteger(BUTTON_B, -1);
23+
buttonX = getInteger(BUTTON_X, -1);
24+
buttonY = getInteger(BUTTON_Y, -1);
25+
buttonUp = getInteger(BUTTON_UP, -1);
26+
buttonDown = getInteger(BUTTON_DOWN, -1);
27+
buttonLeft = getInteger(BUTTON_LEFT, -1);
28+
buttonRight = getInteger(BUTTON_RIGHT, -1);
29+
buttonL = getInteger(BUTTON_L, -1);
30+
buttonR = getInteger(BUTTON_R, -1);
31+
buttonZL = getInteger(BUTTON_ZL, -1);
32+
buttonZR = getInteger(BUTTON_ZR, -1);
33+
buttonL3 = getInteger(BUTTON_L3, -1);
34+
buttonR3 = getInteger(BUTTON_R3, -1);
35+
buttonMinus = getInteger(BUTTON_MINUS, -1);
36+
buttonPlus = getInteger(BUTTON_PLUS, -1);
37+
buttonHome = getInteger(BUTTON_HOME, -1);
38+
joystickLeftX = getInteger(JOYSTICK_LEFT_X, -1);
39+
joystickLeftY = getInteger(JOYSTICK_LEFT_Y, -1);
40+
joystickRightX = getInteger(JOYSTICK_RIGHT_X, -1);
41+
joystickRightY = getInteger(JOYSTICK_RIGHT_Y, -1);
42+
micBlow = getInteger(MIC_BLOW, -1);
43+
flush();
3344
}
3445
}

core/src/com/rolandoislas/drcsimclient/config/ConfigControllerConfig.java

-59
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,21 @@
11
package com.rolandoislas.drcsimclient.config;
22

3-
import com.badlogic.gdx.Preferences;
4-
import com.rolandoislas.drcsimclient.util.PreferencesUtil;
5-
63
/**
74
* Created by rolando on 4/13/17.
85
*/
96
public class ConfigGeneral extends Config {
107
public static final String TOUCH_SCREEN = "TOUCH_SCREEN";
118
public static final String VIBRATE = "VIBRATE";
12-
private final Preferences config;
13-
public int touchScreen;
14-
public int vibrate;
9+
public boolean touchScreen;
10+
public boolean vibrate;
1511

1612
public ConfigGeneral() {
17-
config = PreferencesUtil.get("general");
18-
}
19-
20-
@Override
21-
public void set(String item, int input) {
22-
config.putInteger(item, input);
23-
config.flush();
24-
load();
13+
super("general");
2514
}
2615

2716
@Override
2817
public void load() {
29-
touchScreen = config.getInteger(TOUCH_SCREEN, 1); // Who needs a boolean?
30-
vibrate = config.getInteger(VIBRATE, 1);
31-
}
32-
33-
@Override
34-
public String get(String key) {
35-
return config.getString(key);
18+
touchScreen = getBoolean(TOUCH_SCREEN, true);
19+
vibrate = getBoolean(VIBRATE, true);
3620
}
3721
}

0 commit comments

Comments
 (0)