Skip to content

Commit

Permalink
Changing to use NewConfig - Phase 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryptically committed Aug 14, 2016
1 parent d6e5056 commit 06af292
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
13 changes: 13 additions & 0 deletions src/me/corriekay/pokegoutil/utils/ConfigKey.java
Expand Up @@ -9,6 +9,19 @@ public enum ConfigKey {
TRANSFER_AFTER_EVOLVE("transfer.afterEvolve", false, Boolean.class),
SHOW_BULK_POPUP("popup.afterBulk", true, Boolean.class),

LANGUAGE("options.lang", "en", String.class),
FONT_SIZE("options.fontsize", 0, Integer.class),

DELAY_RENAME_MIN("delay.rename.min", 1000, Integer.class),
DELAY_RENAME_MAX("delay.rename.max", 5000, Integer.class),
DELAY_TRANSFER_MIN("delay.transfer.min", 1000, Integer.class),
DELAY_TRANSFER_MAX("delay.transfer.max", 5000, Integer.class),
DELAY_EVOLVE_MIN("delay.evolve.min", 3000, Integer.class),
DELAY_EVOLVE_MAX("delay.evolve.max", 12000, Integer.class),
DELAY_POWERUP_MIN("delay.powerUp.min", 1000, Integer.class),
DELAY_POWERUP_MAX("delay.powerUp.max", 5000, Integer.class),
DELAY_FAVORITE_MIN("delay.favorite.min", 1000, Integer.class),
DELAY_FAVORITE_MAX("delay.favorite.max", 3000, Integer.class),
;

public final String keyName;
Expand Down
36 changes: 18 additions & 18 deletions src/me/corriekay/pokegoutil/windows/PokemonTab.java
Expand Up @@ -48,7 +48,7 @@ public class PokemonTab extends JPanel {
private final JTextField searchBar = new JTextField("");
private final JTextField ivTransfer = new JTextField("", 20);

private Config config = Config.getConfig();
private ConfigNew config = ConfigNew.getConfig();

public PokemonTab(PokemonGo go) {
setLayout(new BorderLayout());
Expand Down Expand Up @@ -166,7 +166,7 @@ protected Void doInBackground() throws Exception {
// pokemon name language drop down
String[] locales = {"en", "de", "fr", "ru", "zh_CN", "zh_HK"};
JComboBox<String> pokelang = new JComboBox<>(locales);
String locale = config.getString("options.lang", "en");
String locale = config.getString(ConfigKey.LANGUAGE);
pokelang.setSelectedItem(locale);
pokelang.addActionListener(e -> new SwingWorker<Void, Void>() {
protected Void doInBackground() throws Exception {
Expand All @@ -181,7 +181,7 @@ protected Void doInBackground() throws Exception {

// Set font size if specified in config
Font font = pt.getFont();
int size = Config.getConfig().getInt("options.fontsize", font.getSize());
int size = config.getInt(ConfigKey.FONT_SIZE, font.getSize());
if (size != font.getSize()) {
pt.setFont(font.deriveFont((float) size));
}
Expand All @@ -196,7 +196,7 @@ protected Void doInBackground() throws Exception {
JComboBox<String> source = (JComboBox<String>) e.getSource();
String size = source.getSelectedItem().toString();
pt.setFont(pt.getFont().deriveFont(Float.parseFloat(size)));
config.setInt("options.fontsize", Integer.parseInt(size));
config.setInt(ConfigKey.FONT_SIZE, Integer.parseInt(size));
return null;
}
}.execute());
Expand All @@ -212,7 +212,7 @@ protected Void doInBackground() throws Exception {
}

private void changeLanguage(String langCode) {
config.setString("options.lang", langCode);
config.setString(ConfigKey.LANGUAGE, langCode);
refreshPkmn();
}

Expand All @@ -233,7 +233,7 @@ private void showFinishedText(String message, int size, MutableInt success, Muta
(skipped.getValue() > 0 ? "\nSkipped: " + skipped.getValue() : "") +
(err.getValue() > 0 ? "\nErrors: " + err.getValue() : "");

if (config.getBool("popup.afterBulk", true)) {
if (config.getBool(ConfigKey.SHOW_BULK_POPUP)) {
JOptionPane.showMessageDialog(null, finishText);
} else {
System.out.println(finishText);
Expand Down Expand Up @@ -271,8 +271,8 @@ private void renameSelected() {

// If not last element and API was queried, sleep until the next one
if (!selection.get(selection.size() - 1).equals(pokemon)) {
int sleepMin = config.getInt("delay.rename.min", 1000);
int sleepMax = config.getInt("delay.rename.max", 5000);
int sleepMin = config.getInt(ConfigKey.DELAY_RENAME_MIN);
int sleepMax = config.getInt(ConfigKey.DELAY_RENAME_MAX);
Utilities.sleepRandom(sleepMin, sleepMax);
}
};
Expand Down Expand Up @@ -324,8 +324,8 @@ private void transferSelected() {

// If not last element, sleep until the next one
if (!selection.get(selection.size() - 1).equals(poke)) {
int sleepMin = config.getInt("delay.transfer.min", 1000);
int sleepMax = config.getInt("delay.transfer.max", 5000);
int sleepMin = config.getInt(ConfigKey.DELAY_TRANSFER_MIN);
int sleepMax = config.getInt(ConfigKey.DELAY_TRANSFER_MAX);
Utilities.sleepRandom(sleepMin, sleepMax);
}
} catch (Exception e) {
Expand Down Expand Up @@ -370,7 +370,7 @@ private void evolveSelected() {
int newHp = newPoke.getStamina();
System.out.println(
"Evolving " + PokeHandler.getLocalPokeName(poke) + ". Evolve result: Success!");
if (config.getBool("transfer.afterEvolve", false)) {
if (config.getBool(ConfigKey.TRANSFER_AFTER_EVOLVE)) {
ReleasePokemonResponseOuterClass.ReleasePokemonResponse.Result result = newPoke.transferPokemon();
System.out.println("Transferring " + StringUtils.capitalize(newPoke.getPokemonId().toString().toLowerCase()) + ", Result: " + result);
System.out.println("Stat changes: (Candies: " + newCandies + "[" + candies + "-" + candiesToEvolve + "]");
Expand All @@ -386,8 +386,8 @@ private void evolveSelected() {

// If not last element, sleep until the next one
if (!selection.get(selection.size() - 1).equals(poke)) {
int sleepMin = Config.getConfig().getInt("delay.evolve.min", 3000);
int sleepMax = Config.getConfig().getInt("delay.evolve.max", 12000);
int sleepMin = config.getInt(ConfigKey.DELAY_EVOLVE_MIN);
int sleepMax = config.getInt(ConfigKey.DELAY_EVOLVE_MAX);
Utilities.sleepRandom(sleepMin, sleepMax);
}
} catch (Exception e) {
Expand All @@ -402,7 +402,7 @@ private void evolveSelected() {
}
SwingUtilities.invokeLater(this::refreshList);
showFinishedText("Pokémon batch evolve"
+ ((config.getBool("transfer.afterEvolve", false)) ? "/transfer" : "")
+ (config.getBool(ConfigKey.TRANSFER_AFTER_EVOLVE) ? "/transfer" : "")
+ " complete!", selection.size(), success, skipped, err);
}
}
Expand Down Expand Up @@ -446,8 +446,8 @@ private void powerUpSelected() {

// If not last element, sleep until the next one
if (!selection.get(selection.size() - 1).equals(poke)) {
int sleepMin = config.getInt("delay.powerUp.min", 1000);
int sleepMax = config.getInt("delay.powerUp.max", 5000);
int sleepMin = config.getInt(ConfigKey.DELAY_POWERUP_MIN);
int sleepMax = config.getInt(ConfigKey.DELAY_POWERUP_MAX);
Utilities.sleepRandom(sleepMin, sleepMax);
}
} catch (Exception e) {
Expand Down Expand Up @@ -493,8 +493,8 @@ private void toggleFavorite() {

// If not last element, sleep until the next one
if (!selection.get(selection.size() - 1).equals(poke)) {
int sleepMin = config.getInt("delay.favorite.min", 1000);
int sleepMax = config.getInt("delay.favorite.max", 3000);
int sleepMin = config.getInt(ConfigKey.DELAY_FAVORITE_MIN);
int sleepMax = config.getInt(ConfigKey.DELAY_FAVORITE_MAX);
Utilities.sleepRandom(sleepMin, sleepMax);
}
} catch (Exception e) {
Expand Down

0 comments on commit 06af292

Please sign in to comment.