-
Notifications
You must be signed in to change notification settings - Fork 12
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
Feature/setting veto system fields #229
base: develop
Are you sure you want to change the base?
Feature/setting veto system fields #229
Conversation
vetoTokensPerPlayerInput.textProperty().addListener((observable, oldValue, newValue) -> { | ||
try { | ||
int value = Integer.parseInt(newValue); | ||
if (value < 0 || value > 255) | ||
throw new NumberFormatException("veto tokens per player must be between 0 and 255"); | ||
if (!Objects.equals(property.get(), value)) { | ||
property.set(value); | ||
} | ||
vetoTokensPerPlayerInput.setStyle(""); | ||
} catch (NumberFormatException e) { | ||
log.error(e.getMessage()); | ||
vetoTokensPerPlayerInput.setStyle("-fx-background-color: rgb(255,100,100)"); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a TextFormatter instead of parsing and limiting the values and throwing an exception ourselves.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like that?
vetoTokensPerPlayerInput.setTextFormatter(new TextFormatter<>(new IntegerStringConverter(), 0, change -> {
String newText = change.getControlNewText();
try {
int v = Integer.parseInt(newText);
if (v >= 0 && v <= 255) {
return change;
}
return null;
} catch (NumberFormatException e) {
log.error(e.getMessage());
return null;
}
}));
vetoTokensPerPlayerInput.textProperty().addListener((observable, oldValue, newValue) -> {
try {
int value = Integer.parseInt(newValue);
if (!Objects.equals(property.get(), value)) {
property.set(value);
}
} catch (NumberFormatException e) {
log.error(e.getMessage());
}
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or should i put property.set inside the formatter too
maxTokensPerMapInput.textProperty().addListener((observable, oldValue, newValue) -> { | ||
try { | ||
if (Objects.equals(newValue, "D")) { | ||
property.set(0); | ||
maxTokensPerMapInput.setStyle(""); | ||
return; | ||
} | ||
int value = Integer.parseInt(newValue); | ||
if (value < 1 || value > 255) | ||
throw new NumberFormatException("max tokens per map must be between 1 and 255, or D (dynamic)"); | ||
if (!Objects.equals(property.get(), value)) { | ||
property.set(value); | ||
} | ||
maxTokensPerMapInput.setStyle(""); | ||
} catch (NumberFormatException e) { | ||
log.error(e.getMessage()); | ||
maxTokensPerMapInput.setStyle("-fx-background-color: rgb(255,100,100)"); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TextFormatter
minimumMapsAfterVetoInput.textProperty().addListener((observable, oldValue, newValue) -> { | ||
try { | ||
float value = Float.parseFloat(newValue); | ||
|
||
if (value <= 0) { | ||
throw new NumberFormatException("Minimum maps after veto must be greater than 0"); | ||
} | ||
String formattedValue = String.format(Locale.US, "%.2f", value); | ||
if (!Objects.equals(minimumMapsAfterVetoInput.getText(), formattedValue)) { | ||
minimumMapsAfterVetoInput.setText(formattedValue); | ||
} | ||
if (!Objects.equals(property.get(), value)) { | ||
property.set(value); | ||
} | ||
minimumMapsAfterVetoInput.setStyle(""); | ||
} catch (NumberFormatException e) { | ||
log.error(e.getMessage()); | ||
minimumMapsAfterVetoInput.setStyle("-fx-background-color: rgb(255,100,100)"); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TextFormatter
fixes #227
requires updated database and api with veto system fields updates
maxTokenPerMap: set "D" into the field as "Dynamic". I think this is more clear than 0.
Under the hood, D transforms to 0 anyway. Would be nice to have null instead of 0, but not possible currently due to patch request limitations in current api-service code.