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

Feature/setting veto system fields #229

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

K-ETFreeman
Copy link
Contributor

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.
image
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.

Comment on lines +51 to +64
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)");
}
});
Copy link
Member

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.

Copy link
Contributor Author

@K-ETFreeman K-ETFreeman Nov 29, 2024

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());
           }
       });

Copy link
Contributor Author

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

Comment on lines +80 to +98
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)");
}
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TextFormatter

Comment on lines +120 to +139
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)");
}
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TextFormatter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to set Veto System fields by MM team
2 participants