Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #423 (node blunder colors in the default theme) #802

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions src/main/java/featurecat/lizzie/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,56 @@ private boolean validateAndCorrectSettings(JSONObject config) {
madeCorrections = true;
}

if (checkEmptyBlunderThresholds(ui)) {
madeCorrections = true;
}

return madeCorrections;
}

/**
* Apply the default blunder thresholds in Default theme if they are empty. This works only once
* as the fix of #423 (missing default thresholds) so that users can set them empty again if they
* like.
*
* @param ui The UI config json object to check
* @return if any correction has been made.
*/
private boolean checkEmptyBlunderThresholds(JSONObject ui) {
boolean alreadyTriedOnce = persisted.optBoolean("checked-empty-blunder-thresholds", false);
if (alreadyTriedOnce) return false;

boolean modified = false;
JSONArray blunderWinrateThresholds = ui.optJSONArray("blunder-winrate-thresholds");
JSONArray blunderNodeColors = ui.optJSONArray("blunder-node-colors");
boolean isEmptyBlunderWinrateThresholds =
(blunderWinrateThresholds == null || blunderWinrateThresholds.length() == 0);
boolean isEmptyBlunderNodeColors =
(blunderNodeColors == null || blunderNodeColors.length() == 0);

if (isEmptyBlunderWinrateThresholds && isEmptyBlunderNodeColors) {
// https://github.com/featurecat/lizzie/issues/423#issuecomment-438878060
ui.put("blunder-winrate-thresholds", new JSONArray("[-30, -20, -10.1, -5.1, 5, 10.1]"));
ui.put(
"blunder-node-colors",
new JSONArray(
"[[255, 0, 0], [255, 120, 0], [255, 200, 0], [255, 255, 0], [150, 255, 0], [0, 255, 0]]"));
modified = true;
}

persisted.put("checked-empty-blunder-thresholds", true);
return modified;
}

public Config() throws IOException {
JSONObject defaultConfig = createDefaultConfig();
JSONObject persistConfig = createPersistConfig();

// Main properties
this.config = loadAndMergeConfig(defaultConfig, configFilename, true);
// Load "persisted" before "config" for checkEmptyBlunderThresholds.
// Persisted properties
this.persisted = loadAndMergeConfig(persistConfig, persistFilename, false);
// Main properties
this.config = loadAndMergeConfig(defaultConfig, configFilename, true);

leelazConfig = config.getJSONObject("leelaz");
uiConfig = config.getJSONObject("ui");
Expand Down